Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
inventory-service
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
Ascend
inventory-service
Commits
a5f7220d
Commit
a5f7220d
authored
May 05, 2021
by
John Lam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add testing for find product by sku / invalid sku
parent
d90fbf02
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
6 deletions
+46
-6
ProductController.java
.../nisum/ascend/inventory/controller/ProductController.java
+2
-2
ProductService.java
...va/com/nisum/ascend/inventory/service/ProductService.java
+1
-1
ProductControllerTest.java
...um/ascend/inventory/controller/ProductControllerTest.java
+43
-3
No files found.
src/main/java/com/nisum/ascend/inventory/controller/ProductController.java
View file @
a5f7220d
...
...
@@ -19,8 +19,8 @@ public class ProductController {
ProductService
productService
;
@GetMapping
(
"{sku}"
)
public
ResponseEntity
<
Mono
<
ProductDto
>>
getProduct
Dto
(
@PathVariable
String
sku
)
{
Mono
<
ProductDto
>
monoProd
=
productService
.
getProduct
(
sku
);
public
ResponseEntity
<
Mono
<
ProductDto
>>
getProduct
BySku
(
@PathVariable
String
sku
)
{
Mono
<
ProductDto
>
monoProd
=
productService
.
getProduct
BySku
(
sku
);
HttpStatus
status
=
monoProd
!=
null
?
HttpStatus
.
OK
:
HttpStatus
.
NOT_FOUND
;
return
new
ResponseEntity
<>(
monoProd
,
status
);
}
...
...
src/main/java/com/nisum/ascend/inventory/service/ProductService.java
View file @
a5f7220d
...
...
@@ -17,7 +17,7 @@ public class ProductService {
@Autowired
ProductRepository
productRepository
;
public
Mono
<
ProductDto
>
getProduct
(
String
sku
){
public
Mono
<
ProductDto
>
getProduct
BySku
(
String
sku
){
return
productRepository
.
findBySku
(
sku
)
.
map
(
existingProduct
->
generateDtoFromProduct
(
existingProduct
))
.
switchIfEmpty
(
Mono
.
error
(
new
ResourceNotFoundException
(
HttpStatus
.
NOT_FOUND
,
"product not found"
)));
...
...
src/test/java/com/nisum/ascend/inventory/controller/ProductControllerTest.java
View file @
a5f7220d
package
com
.
nisum
.
ascend
.
inventory
.
controller
;
import
com.nisum.ascend.inventory.dto.ProductDto
;
import
com.nisum.ascend.inventory.model.Product
;
import
com.nisum.ascend.inventory.repository.ProductRepository
;
import
com.nisum.ascend.inventory.service.ProductService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
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.ResponseEntity
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.context.junit.jupiter.SpringExtension
;
import
org.springframework.test.web.reactive.server.WebTestClient
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
reactor.core.publisher.Mono
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
@ExtendWith
(
SpringExtension
.
class
)
//integrates springtestframework into junit 5
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
//provides support for testing springboot app
@DirtiesContext
@AutoConfigureWebTestClient
//autoconfigures the webclient
@ActiveProfiles
(
"test"
)
@Slf4j
class
ProductControllerTest
{
@BeforeEach
void
setUp
()
{
@Autowired
private
WebTestClient
client
;
@Test
void
testProductInvalidSkuNotFound
()
{
client
.
get
()
.
uri
(
"/products/"
.
concat
(
"{sku}"
),
"invalid"
)
.
exchange
()
.
expectStatus
()
.
is5xxServerError
();
}
@Test
void
getProductDto
()
{
void
testProductBySkuFound
()
{
String
sku
=
"100000"
;
client
.
get
()
.
uri
(
"/products/"
.
concat
(
"/{sku}"
),
sku
)
.
exchange
()
.
expectStatus
()
.
isOk
()
.
expectBody
()
.
jsonPath
(
"$.sku"
,
sku
);
}
}
\ No newline at end of file
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