@@ -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