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