diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java similarity index 100% rename from spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java rename to spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java similarity index 92% rename from spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java rename to spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java index 3e9a3291d9..364a7e8a66 100644 --- a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java +++ b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java @@ -24,7 +24,6 @@ public class ProductController { this.productService = productService; } - @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Product successfully added!") }) @PostMapping("/create") public Product addProduct(@RequestBody Product product) { return productService.addProducts(product); diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java new file mode 100644 index 0000000000..036ecbc853 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java @@ -0,0 +1,28 @@ +package com.baeldung.swaggerresponseapi.model; + +public class Product { + String code; + String name; + + public Product(String code, String name) { + this.code = code; + this.name = name; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} + diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java similarity index 100% rename from spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java rename to spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/.gitignore b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/.gitignore deleted file mode 100644 index f60f3beecd..0000000000 --- a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/.gitignore +++ /dev/null @@ -1,33 +0,0 @@ -HELP.md -target/ -.mvn/wrapper/ -!**/src/main/**/target/ -!**/src/test/**/target/ -mvnv* - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/pom.xml b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/pom.xml deleted file mode 100644 index c168248df2..0000000000 --- a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/pom.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.6.3 - - - com.baeldung - swaggerResponseAPI - 0.0.1-SNAPSHOT - swaggerResponseAPI - swaggerResponseAPI - - 11 - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-test - test - - - org.projectlombok - lombok - true - - - org.springdoc - springdoc-openapi-ui - 1.6.6 - - - junit - junit - 4.13.2 - test - - - com.fasterxml.jackson.core - jackson-databind - 2.13.0 - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - - - - diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java deleted file mode 100644 index 0a100582fc..0000000000 --- a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.swaggerresponseapi.model; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@AllArgsConstructor -@NoArgsConstructor -public class Product { - String code; - String name; -} diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/resources/application.properties b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/resources/application.properties deleted file mode 100644 index 8b13789179..0000000000 --- a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/ProductIntegrationTest.java b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/ProductIntegrationTest.java deleted file mode 100644 index ef6a8953e2..0000000000 --- a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/ProductIntegrationTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.baeldung.swaggerresponseapi; - -import com.baeldung.swaggerresponseapi.controller.ProductController; -import com.baeldung.swaggerresponseapi.model.Product; -import com.baeldung.swaggerresponseapi.service.ProductService; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; - -import java.util.Arrays; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.reset; -import static org.hamcrest.CoreMatchers.is; -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.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@RunWith(SpringRunner.class) -@WebMvcTest(ProductController.class) -public class ProductIntegrationTest { - - @Autowired - MockMvc mock; - - @MockBean - private ProductService productService; - - @Test - public void givenProduct_whenAddNewProduct_thenReturnValidStatusCode() throws Exception { - Product product = new Product("1001", "Milk"); - given(productService.addProducts(any(Product.class))).willReturn(product); - - mock.perform(post("/create").contentType(MediaType.APPLICATION_JSON) - .content(toJsonString(product))) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("1001")); - - reset(productService); - } - - @Test - public void givenProductsList_whenGetAllProducts_thenReturnValidProducts() throws Exception { - Product product1 = new Product("1001", "Milk"); - Product product2 = new Product("2002", "Butter"); - - given(productService.getProductsList()).willReturn(Arrays.asList(product1, product2)); - - mock.perform(get("/products").contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andDo(print()) - .andExpect(jsonPath("$[0].code", is(product1.getCode()))) - .andExpect(jsonPath("$[1].name", is(product2.getName()))); - - reset(productService); - } - - public String toJsonString(Product product) throws JsonProcessingException { - ObjectMapper om = new ObjectMapper(); - String json = om.writeValueAsString(product); - return json; - } -} diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplicationTests.java b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplicationTests.java deleted file mode 100644 index 9e8c6ee0fa..0000000000 --- a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.swaggerresponseapi; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class SwaggerResponseApiApplicationTests { - - @Test - void contextLoads() { - } - -}