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 1c696c0

Browse files
committed
Test mvc updateProduct.
1 parent b08de4e commit 1c696c0

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,47 @@ void testCreateProductBadRequest() {
110110
.expectStatus().isBadRequest();
111111
}
112112

113+
@Test
114+
void testUpdateProductSuccess() {
115+
// Given
116+
ProductDTO updatedProductDTO = getSavedTestProduct();
117+
updatedProductDTO.setName("UPDATED name");
118+
119+
String productId = updatedProductDTO.getId();
120+
121+
122+
// When
123+
webTestClient.put().uri(ProductController.PRODUCT_ID_URL, productId)
124+
.body(Mono.just(updatedProductDTO), ProductDTO.class)
125+
.exchange()
126+
// Then
127+
.expectStatus().isOk()
128+
.expectHeader().contentType(MediaType.APPLICATION_JSON)
129+
.expectBody(ProductDTO.class)
130+
.value(dto -> {
131+
assertThat(dto.getName().equals(updatedProductDTO.getName())).isTrue();
132+
});
133+
}
134+
135+
@Test
136+
void testUpdateProductNotFound() {
137+
// Given
138+
String nonExistentProductId = "non_existent_id";
139+
ProductDTO updatedProductDTO = new ProductDTO();
140+
updatedProductDTO.setName("Updated Product");
141+
updatedProductDTO.setDescription("Updated Product");
142+
updatedProductDTO.setImgUrl("https://image.com/image.jpeg");
143+
updatedProductDTO.setPrice(BigDecimal.TEN);
144+
145+
146+
// When
147+
webTestClient.put().uri(ProductController.PRODUCT_ID_URL, nonExistentProductId)
148+
.body(Mono.just(updatedProductDTO), ProductDTO.class)
149+
.exchange()
150+
// Then
151+
.expectStatus().isNotFound();
152+
}
153+
113154
private ProductDTO getSavedTestProduct() {
114155
return productService.getAllProducts().next().block();
115156
}

0 commit comments

Comments
(0)

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