Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
reactor-api-sample
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
vikram singh
reactor-api-sample
Commits
23ea0734
Commit
23ea0734
authored
Apr 03, 2020
by
vikram singh
2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
segregated integration and component test cases
parent
942fa67b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
70 additions
and
18 deletions
+70
-18
EmployeeController.java
...java/com/nisum/webflux/controller/EmployeeController.java
+3
-1
SampleController.java
...n/java/com/nisum/webflux/controller/SampleController.java
+1
-0
EmployeeControllerIntegrationTest.java
...webflux/controller/EmployeeControllerIntegrationTest.java
+1
-6
FruitControllerComponentTest.java
...isum/webflux/controller/FruitControllerComponentTest.java
+23
-11
FruitControllerIntegrationTest.java
...um/webflux/controller/FruitControllerIntegrationTest.java
+39
-0
TestConfig.java
src/test/java/com/nisum/webflux/service/impl/TestConfig.java
+3
-0
No files found.
src/main/java/com/nisum/webflux/controller/EmployeeController.java
View file @
23ea0734
...
...
@@ -2,12 +2,14 @@ package com.nisum.webflux.controller;
import
com.nisum.webflux.model.Employee
;
import
com.nisum.webflux.service.IEmployeeService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
@RestController
@Slf4j
public
class
EmployeeController
{
@Autowired
...
...
@@ -17,7 +19,7 @@ public class EmployeeController {
@PostMapping
(
"/employee"
)
public
Mono
<
Employee
>
save
(
@RequestBody
Employee
employee
)
{
System
.
out
.
println
(
"employee obj ##################################################"
+
employee
);
log
.
info
(
"employee obj ##################################################"
+
employee
);
return
employeeService
.
save
(
employee
);
}
...
...
src/main/java/com/nisum/webflux/controller/SampleController.java
View file @
23ea0734
...
...
@@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@Slf4j
//basic kafka
public
class
SampleController
{
@Autowired
KafkaServer
kafkaServer
;
...
...
src/test/java/com/nisum/webflux/controller/EmployeeControllerTest.java
→
src/test/java/com/nisum/webflux/controller/EmployeeController
Integration
Test.java
View file @
23ea0734
...
...
@@ -30,17 +30,12 @@ import static org.mockito.Mockito.when;
@SpringBootTest
@RunWith
(
SpringRunner
.
class
)
@AutoConfigureWebTestClient
public
class
EmployeeControllerTest
{
public
class
EmployeeController
Integration
Test
{
@Autowired
WebTestClient
webTestClient
;
//// @MockBean
// @Autowired
// EmployeeRepo empRepo;
@InjectMocks
EmployeeController
employeeController
;
...
...
src/test/java/com/nisum/webflux/controller/FruitControllerComponentTest.java
100755 → 100644
View file @
23ea0734
package
com
.
nisum
.
webflux
.
controller
;
import
com.nisum.webflux.model.Fruit
;
import
com.nisum.webflux.repository.FruitRepository
;
import
com.nisum.webflux.service.impl.TestConfig
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.ArgumentCaptor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.web.reactive.server.WebTestClient
;
import
org.springframework.web.reactive.function.BodyInserters
;
import
reactor.core.publisher.Mono
;
import
static
org
.
mockito
.
Mockito
.
when
;
@SpringBootTest
@RunWith
(
SpringRunner
.
class
)
@AutoConfigureWebTestClient
//
@ContextConfiguration(classes = TestConfig.class)
@ContextConfiguration
(
classes
=
TestConfig
.
class
)
public
class
FruitControllerComponentTest
{
@Autowired
@Autowired
WebTestClient
webTestClient
;
@Test
public
void
save_UsingWebTestClient
()
{
Fruit
fruit
=
new
Fruit
(
"1"
,
"apple"
,
"300"
);
webTestClient
.
post
().
uri
(
"/fruit"
).
contentType
(
MediaType
.
APPLICATION_JSON_UTF8
).
body
(
BodyInserters
.
fromObject
(
fruit
))
.
exchange
()
.
expectStatus
().
isOk
().
expectBody
().
jsonPath
(
"$.id"
).
isEqualTo
(
"1"
);
}
@Autowired
FruitRepository
fruitRepo
;
Mohandu anil
@mohanduanil
·
Apr 05, 2020
change this property to private
change this property to private
Please
register
or
sign in
to reply
@Test
public
void
save
()
{
ArgumentCaptor
<
Fruit
>
requestCaptor
=
ArgumentCaptor
.
forClass
(
Fruit
.
class
);
when
(
fruitRepo
.
save
(
requestCaptor
.
capture
())).
thenReturn
(
Mono
.
error
(
new
RuntimeException
()));
Fruit
fruit
=
new
Fruit
(
"1"
,
"apple"
,
"300"
);
webTestClient
.
post
().
uri
(
"/fruit"
).
contentType
(
MediaType
.
APPLICATION_JSON_UTF8
).
body
(
BodyInserters
.
fromObject
(
fruit
))
.
exchange
()
.
expectStatus
().
isOk
().
expectBody
().
jsonPath
(
"$.id"
).
isEqualTo
(
"1"
);
}
}
src/test/java/com/nisum/webflux/controller/FruitControllerIntegrationTest.java
0 → 100755
View file @
23ea0734
package
com
.
nisum
.
webflux
.
controller
;
import
com.nisum.webflux.model.Fruit
;
import
com.nisum.webflux.repository.FruitRepository
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.ArgumentCaptor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.web.reactive.server.WebTestClient
;
import
org.springframework.web.reactive.function.BodyInserters
;
import
reactor.core.publisher.Mono
;
import
static
org
.
mockito
.
Mockito
.
when
;
@SpringBootTest
@RunWith
(
SpringRunner
.
class
)
@AutoConfigureWebTestClient
public
class
FruitControllerIntegrationTest
{
@Autowired
WebTestClient
webTestClient
;
Mohandu anil
@mohanduanil
·
Apr 05, 2020
change this property to private
change this property to private
Please
register
or
sign in
to reply
@Test
public
void
save
()
{
Fruit
fruit
=
new
Fruit
(
"1"
,
"apple"
,
"300"
);
webTestClient
.
post
().
uri
(
"/fruit"
).
contentType
(
MediaType
.
APPLICATION_JSON_UTF8
).
body
(
BodyInserters
.
fromObject
(
fruit
))
.
exchange
()
.
expectStatus
().
isOk
().
expectBody
().
jsonPath
(
"$.id"
).
isEqualTo
(
"1"
);
}
}
src/test/java/com/nisum/webflux/service/impl/TestConfig.java
View file @
23ea0734
package
com
.
nisum
.
webflux
.
service
.
impl
;
import
com.nisum.webflux.repository.EmployeeRepo
;
import
com.nisum.webflux.repository.FruitRepository
;
import
org.springframework.boot.test.context.TestConfiguration
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
...
...
@@ -9,5 +10,7 @@ public class TestConfig {
@MockBean
EmployeeRepo
empRepo
;
@MockBean
FruitRepository
fruitRepo
;
}
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