gnodet-bot commented on code in PR #27897:
URL: https://github.com/apache/camel/pull/27897#discussion_r4282688191


##########
components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenapiProcessorStrategyTest.java:
##########
@@ -88,6 +92,27 @@ public void configure() {
         assertEquals("GENOPID_GET.user._id_", userByIdOp.getOperationId());
     }
 
+    @Test
+    void testMockModeWithoutOkResponseReturnsEmpty204() {
+        // CAMEL-25663: an operation whose responses have no 200 (only 
default, 201, 204, ...) must not throw a
+        // NullPointerException in mock mode; with no mock data it returns an 
empty 204.
+        DefaultRestOpenapiProcessorStrategy strategy = new 
DefaultRestOpenapiProcessorStrategy();
+        strategy.setCamelContext(camelContext);
+
+        Operation onlyDefault = new Operation()
+                .responses(new ApiResponses().addApiResponse("default", new 
ApiResponse()));
+        Exchange exchange = new DefaultExchange(camelContext);
+        assertDoesNotThrow(() -> strategy.loadMockData(onlyDefault, "GET", 
"/x", exchange));
+        assertEquals(204, 
exchange.getMessage().getHeader(Exchange.HTTP_RESPONSE_CODE, int.class));
+        assertEquals("", exchange.getMessage().getBody());
+
+        Operation only201 = new Operation()
+                .responses(new ApiResponses().addApiResponse("201", new 
ApiResponse()));
+        Exchange exchange201 = new DefaultExchange(camelContext);
+        assertDoesNotThrow(() -> strategy.loadMockData(only201, "GET", "/x", 
exchange201));
+        assertEquals(204, 
exchange201.getMessage().getHeader(Exchange.HTTP_RESPONSE_CODE, int.class));

Review Comment:
   💡 **Suggestion:** The `only201` test asserts the response code but omits the 
body assertion that the `onlyDefault` case includes. For symmetry and 
completeness:
   
   ```suggestion
           assertEquals(204, 
exchange201.getMessage().getHeader(Exchange.HTTP_RESPONSE_CODE, int.class));
           assertEquals("", exchange201.getMessage().getBody());
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to