Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0d1bbda

Browse files
committed
Test mvc getById.
1 parent 58391eb commit 0d1bbda

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎src/test/java/com/nihat/springwebfluxdemo/controllers/mvc/ProductControllerTest.java‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,34 @@ void testGetAllProducts() {
3535
.expectBodyList(ProductDTO.class).hasSize(4); // initially loaded + testProduct
3636
}
3737

38+
@Test
39+
@Order(2)
40+
void testGetProductByIdSuccess() {
41+
// Given
42+
String productId = getSavedTestProduct().getId();
43+
44+
// When
45+
webTestClient.get().uri(ProductController.PRODUCT_ID_URL, productId)
46+
.exchange()
47+
// Then
48+
.expectStatus().isOk()
49+
.expectHeader().contentType(MediaType.APPLICATION_JSON)
50+
.expectBody(ProductDTO.class);
51+
}
52+
53+
@Test
54+
@Order(3)
55+
void testGetProductByIdNotFound() {
56+
// Given
57+
String nonExistentProductId = "non_existent_id";
58+
59+
// When
60+
webTestClient.get().uri(ProductController.PRODUCT_ID_URL, nonExistentProductId)
61+
.exchange()
62+
// Then
63+
.expectStatus().isNotFound();
64+
}
65+
3866

3967
private ProductDTO getSavedTestProduct() {
4068
return productService.getAllProducts().next().block();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /