From bc55ee62ef8e970218e199105eeadafdbb14e983 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sat, 7 Oct 2023 12:36:56 +0530 Subject: [PATCH] fix : junit and polish swagger --- .../orderservice/web/api/OrderApi.java | 44 +++++++++++++++++-- .../web/controllers/OrderControllerTest.java | 12 +++-- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/order-service/src/main/java/com/example/orderservice/web/api/OrderApi.java b/order-service/src/main/java/com/example/orderservice/web/api/OrderApi.java index 42474592..6e6f115c 100644 --- a/order-service/src/main/java/com/example/orderservice/web/api/OrderApi.java +++ b/order-service/src/main/java/com/example/orderservice/web/api/OrderApi.java @@ -10,12 +10,50 @@ Licensed under MIT License Copyright (c) 2023 Raja Kolli. import com.example.orderservice.utils.AppConstants; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; import java.util.List; +import org.springframework.http.MediaType; +import org.springframework.http.ProblemDetail; +import org.springframework.validation.annotation.Validated; +@Validated +@Tag(name = "order-controller", description = "the order-controller API") public interface OrderApi { - @Operation(summary = "fetches all orders from Kinesis Stream") + @Operation( + summary = "fetches all orders from kafka Streams", + tags = {"order-controller"}, + responses = { + @ApiResponse( + responseCode = "200", + description = "Success", + content = { + @Content( + mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = OrderDto.class)) + }), + @ApiResponse( + responseCode = "400", + description = "Bad Request", + content = { + @Content( + mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = ProblemDetail.class)) + }) + }) List all( - @Parameter(name = "pageNo", example = AppConstants.DEFAULT_PAGE_SIZE) int pageNo, - @Parameter(name = "pageSize", example = AppConstants.DEFAULT_PAGE_SIZE) int pageSize); + @Parameter( + name = "pageNo", + example = AppConstants.DEFAULT_PAGE_SIZE, + in = ParameterIn.QUERY) + int pageNo, + @Parameter( + name = "pageSize", + example = AppConstants.DEFAULT_PAGE_SIZE, + in = ParameterIn.QUERY) + int pageSize); } diff --git a/order-service/src/test/java/com/example/orderservice/web/controllers/OrderControllerTest.java b/order-service/src/test/java/com/example/orderservice/web/controllers/OrderControllerTest.java index 17f4370e..f12fa667 100644 --- a/order-service/src/test/java/com/example/orderservice/web/controllers/OrderControllerTest.java +++ b/order-service/src/test/java/com/example/orderservice/web/controllers/OrderControllerTest.java @@ -13,8 +13,13 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli. import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doNothing; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.example.orderservice.entities.Order; import com.example.orderservice.model.request.OrderItemRequest; @@ -234,7 +239,8 @@ void shouldUpdateOrder() throws Exception { void shouldReturn404WhenUpdatingNonExistingOrder() throws Exception { Long orderId = 1L; given(orderService.findOrderById(orderId)).willReturn(Optional.empty()); - OrderRequest order = new OrderRequest(1L, new ArrayList<>()); + OrderRequest order = + new OrderRequest(1L, List.of(new OrderItemRequest("Product1", 10, BigDecimal.TEN))); this.mockMvc .perform(