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 1628daf

Browse files
committed
test update product.
1 parent dbde34f commit 1628daf

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

‎src/test/java/com/nihat/springwebfluxdemo/controllers/fn/ProductEndpointTest.java‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,50 @@ void testCreateProductBadRequest() {
109109
.expectStatus().isBadRequest();
110110
}
111111

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

113153

114154

115-
private ProductDTO getSavedTestProduct() {
155+
private ProductDTO getSavedTestProduct() {
116156
return productService.getAllProducts().next().block();
117157
}
118158

0 commit comments

Comments
(0)

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