New unit test format

This commit is contained in:
Nick
2019-08-30 21:11:18 +01:00
parent db85c8f275
commit 6cd385e4c0
19972 changed files with 1626600 additions and 0 deletions
@@ -0,0 +1,47 @@
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-swagger-codegen-app</artifactId>
<name>spring-swagger-codegen-app</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>spring-swagger-codegen</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../spring-swagger-codegen</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>com.baeldung</groupId>
<artifactId>spring-swagger-codegen-api-client</artifactId>
<version>${spring-swagger-codegen-api-client.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.version}</version>
</plugin>
</plugins>
</build>
<properties>
<spring-swagger-codegen-api-client.version>0.0.1-SNAPSHOT</spring-swagger-codegen-api-client.version>
<spring.version>1.5.10.RELEASE</spring.version>
</properties>
</project>
@@ -0,0 +1,30 @@
package com.baeldung.petstore.app;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baeldung.petstore.client.api.PetApi;
import com.baeldung.petstore.client.model.Pet;
@Service
public class DefaultPetService implements PetService {
@Autowired
private PetApi petApi;
public List<Pet> findAvailablePets() {
return petApi.findPetsByStatus(Arrays.asList("available"));
}
public List<Pet> findPendingPets() {
return petApi.findPetsByStatus(Arrays.asList("pending"));
}
public List<Pet> findSoldPets() {
return petApi.findPetsByStatus(Arrays.asList("sold"));
}
}
@@ -0,0 +1,26 @@
package com.baeldung.petstore.app;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class PetController {
@Autowired
private PetService petService;
@RequestMapping("/pets")
@ResponseBody
public String listAvailablePets() {
StringBuilder sb = new StringBuilder("<h1>Available pets:</h1>");
sb.append("<ul>");
petService.findAvailablePets()
.forEach( p -> sb.append("<li>" + p.getName() + "</li>"));
sb.append("</ul>");
return sb.toString();
}
}
@@ -0,0 +1,27 @@
package com.baeldung.petstore.app;
import java.util.List;
import com.baeldung.petstore.client.model.Pet;
public interface PetService {
/**
* Find available pets
* @return List of available pets
*/
List<Pet> findAvailablePets();
/**
* Find Pending pets
* @return List of pending pets
*/
List<Pet> findPendingPets();
/**
* Find sold pets
* @return List of sold pets
*/
List<Pet> findSoldPets();
}
@@ -0,0 +1,15 @@
package com.baeldung.petstore.app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
@SpringBootApplication
@Import(PetStoreIntegrationConfig.class)
public class PetStoreApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(PetStoreApplication.class, args);
}
}
@@ -0,0 +1,23 @@
package com.baeldung.petstore.app;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baeldung.petstore.client.api.PetApi;
import com.baeldung.petstore.client.invoker.ApiClient;
@Configuration
public class PetStoreIntegrationConfig {
@Bean
public PetApi petpi() {
return new PetApi(apiClient());
}
@Bean
public ApiClient apiClient() {
ApiClient apiClient = new ApiClient();
return apiClient;
}
}
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
@@ -0,0 +1,17 @@
package org.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.petstore.app.PetStoreApplication;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = PetStoreApplication.class)
public class SpringContextIntegrationTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}
@@ -0,0 +1,17 @@
package org.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.petstore.app.PetStoreApplication;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = PetStoreApplication.class)
public class SpringContextTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}