change the module directory
This commit is contained in:
parent
f62de53554
commit
a735229a84
|
@ -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);
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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/
|
|
@ -1,70 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.3</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>swaggerResponseAPI</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>swaggerResponseAPI</name>
|
||||
<description>swaggerResponseAPI</description>
|
||||
<properties>
|
||||
<java.version>11</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-ui</artifactId>
|
||||
<version>1.6.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.13.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -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;
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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() {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue