Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
spring-boot-data-mongodb-curd
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Syed Javed Ali
spring-boot-data-mongodb-curd
Commits
7036f8c9
Commit
7036f8c9
authored
4 years ago
by
Syed Javed Ali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added http response status and Stepverifier test
parent
a0b5d0b7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
11 deletions
+39
-11
EmployeeController.java
.../nisum/example/mongodb/controller/EmployeeController.java
+10
-8
EmployeeServiceImpl.java
...om/nisum/example/mongodb/service/EmployeeServiceImpl.java
+1
-0
EmployeeControllerTest.java
...um/example/mongodb/controller/EmployeeControllerTest.java
+3
-3
EmployeeServiceTest.java
...om/nisum/example/mongodb/service/EmployeeServiceTest.java
+25
-0
No files found.
src/main/java/com/nisum/example/mongodb/controller/EmployeeController.java
View file @
7036f8c9
...
...
@@ -27,7 +27,7 @@ public class EmployeeController {
@PostMapping
(
path
=
"/create"
)
@ResponseStatus
(
HttpStatus
.
CREATED
)
public
Mono
<
Employee
>
create
(
@RequestBody
Employee
e
)
{
return
employeeService
.
insert
(
e
);
return
employeeService
.
insert
(
e
)
.
log
()
;
}
/**
...
...
@@ -37,7 +37,7 @@ public class EmployeeController {
*/
@GetMapping
(
"/{id}"
)
public
ResponseEntity
<
Mono
<
Employee
>>
findById
(
@PathVariable
(
"id"
)
Integer
id
)
{
Mono
<
Employee
>
emp
=
employeeService
.
fetchById
(
id
);
Mono
<
Employee
>
emp
=
employeeService
.
fetchById
(
id
)
.
log
()
;
HttpStatus
status
=
emp
!=
null
?
HttpStatus
.
OK
:
HttpStatus
.
NOT_FOUND
;
return
new
ResponseEntity
<
Mono
<
Employee
>>(
emp
,
status
);
}
...
...
@@ -48,8 +48,11 @@ public class EmployeeController {
* @return Flux
*/
@GetMapping
(
"/name/{name}"
)
public
Flux
<
Employee
>
findByName
(
@PathVariable
(
"name"
)
String
name
)
{
return
employeeService
.
fetchByName
(
name
);
public
ResponseEntity
<
Flux
<
Employee
>>
findByName
(
@PathVariable
(
"name"
)
String
name
)
{
Flux
<
Employee
>
employeeFlux
=
employeeService
.
fetchByName
(
name
).
log
();
HttpStatus
status
=
employeeFlux
!=
null
?
HttpStatus
.
OK
:
HttpStatus
.
NOT_FOUND
;
return
new
ResponseEntity
<>(
employeeFlux
,
status
);
}
/**
...
...
@@ -58,7 +61,7 @@ public class EmployeeController {
*/
@GetMapping
(
value
=
""
,
produces
=
MediaType
.
TEXT_EVENT_STREAM_VALUE
)
public
Flux
<
Employee
>
findAll
()
{
Flux
<
Employee
>
emps
=
employeeService
.
fetchAll
();
Flux
<
Employee
>
emps
=
employeeService
.
fetchAll
()
.
log
()
;
return
emps
;
}
...
...
@@ -68,9 +71,8 @@ public class EmployeeController {
* @return Mono
*/
@PutMapping
(
"/update"
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
Mono
<
Employee
>
update
(
@RequestBody
Employee
emp
)
{
return
employeeService
.
modify
(
emp
);
return
employeeService
.
modify
(
emp
)
.
log
()
;
}
/**
...
...
@@ -79,7 +81,7 @@ public class EmployeeController {
* @return Void
*/
@DeleteMapping
(
"/delete/{id}"
)
@ResponseStatus
(
HttpStatus
.
OK
)
@ResponseStatus
(
HttpStatus
.
NO_CONTENT
)
public
void
deleteById
(
@PathVariable
(
"id"
)
Integer
id
)
{
employeeService
.
removeById
(
id
);
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/nisum/example/mongodb/service/EmployeeServiceImpl.java
View file @
7036f8c9
...
...
@@ -24,6 +24,7 @@ public class EmployeeServiceImpl implements IEmployeeService {
*/
@Override
public
Mono
<
Employee
>
insert
(
Employee
emp
)
{
return
employeeRepository
.
save
(
emp
);
}
...
...
This diff is collapsed.
Click to expand it.
src/test/java/com/nisum/example/mongodb/controller/EmployeeControllerTest.java
View file @
7036f8c9
...
...
@@ -156,11 +156,11 @@ public class EmployeeControllerTest {
{
Mono
<
Void
>
voidReturn
=
Mono
.
empty
();
Mockito
.
when
(
repository
.
deleteById
(
1
))
.
when
(
repository
.
deleteById
(
20
1
))
.
thenReturn
(
voidReturn
);
webTestClient
.
delete
().
uri
(
"/delete/{id}"
,
1
)
webTestClient
.
delete
().
uri
(
"/delete/{id}"
,
20
1
)
.
exchange
()
.
expectStatus
().
is
Ok
();
.
expectStatus
().
is
NoContent
();
}
}
This diff is collapsed.
Click to expand it.
src/test/java/com/nisum/example/mongodb/service/EmployeeServiceTest.java
View file @
7036f8c9
...
...
@@ -9,6 +9,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import
org.springframework.boot.test.mock.mockito.MockBean
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
reactor.test.StepVerifier
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
...
...
@@ -27,6 +28,10 @@ public class EmployeeServiceTest {
Mono
<
Employee
>
employeeMono
=
Mono
.
just
(
employee
);
Mockito
.
when
(
employeeRepository
.
save
(
employee
)).
thenReturn
(
employeeMono
);
assertEquals
(
employeeMono
,
employeeService
.
insert
(
employee
));
StepVerifier
.
create
(
employeeService
.
insert
(
employee
).
log
())
.
expectNext
(
employee
)
.
expectComplete
()
.
verify
();
}
...
...
@@ -36,15 +41,24 @@ public class EmployeeServiceTest {
Mono
<
Employee
>
employeeMono
=
Mono
.
just
(
employee
);
Mockito
.
when
(
employeeRepository
.
findById
(
101
)).
thenReturn
(
employeeMono
);
assertEquals
(
employeeMono
,
employeeService
.
fetchById
(
101
));
StepVerifier
.
create
(
employeeService
.
fetchById
(
101
).
log
())
.
expectNext
(
employee
)
.
expectComplete
()
.
verify
();
}
@Test
void
testEmployeeFetchByName
(){
Employee
employee
=
new
Employee
(
101
,
"SYED"
,
1500L
);
Flux
<
Employee
>
employeeFlux
=
Flux
.
just
(
employee
);
Mockito
.
when
(
employeeRepository
.
findByName
(
"SYED"
)).
thenReturn
(
employeeFlux
);
assertEquals
(
employeeFlux
,
employeeService
.
fetchByName
(
"SYED"
));
StepVerifier
.
create
(
employeeService
.
fetchByName
(
"SYED"
).
log
())
.
expectNext
(
employee
)
.
expectComplete
()
.
verify
();
}
...
...
@@ -54,6 +68,10 @@ public class EmployeeServiceTest {
Flux
<
Employee
>
employeeFlux
=
Flux
.
just
(
employee
);
Mockito
.
when
(
employeeRepository
.
findAll
()).
thenReturn
(
employeeFlux
);
assertEquals
(
employeeFlux
,
employeeService
.
fetchAll
());
StepVerifier
.
create
(
employeeService
.
fetchAll
())
.
expectNext
(
employee
)
.
expectComplete
()
.
verify
();
}
@Test
...
...
@@ -62,6 +80,10 @@ public class EmployeeServiceTest {
Mono
<
Employee
>
employeeMono
=
Mono
.
just
(
employee
);
Mockito
.
when
(
employeeRepository
.
save
(
employee
)).
thenReturn
(
employeeMono
);
assertEquals
(
employeeMono
,
employeeService
.
modify
(
employee
));
StepVerifier
.
create
(
employeeService
.
modify
(
employee
))
.
expectNext
(
employee
)
.
expectComplete
()
.
verify
();
}
@Test
...
...
@@ -69,6 +91,9 @@ public class EmployeeServiceTest {
Mono
<
Void
>
voidMono
=
Mono
.
empty
();
Mockito
.
when
(
employeeRepository
.
deleteById
(
1
)).
thenReturn
(
voidMono
);
assertEquals
(
voidMono
,
employeeService
.
removeById
(
1
));
StepVerifier
.
create
(
employeeService
.
removeById
(
1
))
.
expectComplete
()
.
verify
();
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment