Build optimization (#2591)
This commit is contained in:
parent
4589860efb
commit
f01d1e257e
|
@ -71,8 +71,95 @@
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>${maven-surefire-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<forkCount>3</forkCount>
|
||||||
|
<reuseForks>true</reuseForks>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*IntegrationTest.java</exclude>
|
||||||
|
<exclude>**/*LongRunningUnitTest.java</exclude>
|
||||||
|
<exclude>**/*ManualTest.java</exclude>
|
||||||
|
<exclude>**/JdbcTest.java</exclude>
|
||||||
|
<exclude>**/*LiveTest.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
<testFailureIgnore>true</testFailureIgnore>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>integration</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>integration-test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>test</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*LiveTest.java</exclude>
|
||||||
|
<exclude>**/AutoconfigurationTest.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
<includes>
|
||||||
|
<include>**/*IntegrationTest.java</include>
|
||||||
|
</includes>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<test.mime>json</test.mime>
|
||||||
|
</systemPropertyVariables>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>autoconfiguration</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>integration-test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>test</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*LiveTest.java</exclude>
|
||||||
|
<exclude>**/*IntegrationTest.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
<includes>
|
||||||
|
<include>**/AutoconfigurationTest.java</include>
|
||||||
|
</includes>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<test.mime>json</test.mime>
|
||||||
|
</systemPropertyVariables>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<mustache.compiler.api.version>0.9.2</mustache.compiler.api.version>
|
<mustache.compiler.api.version>0.9.2</mustache.compiler.api.version>
|
||||||
|
|
|
@ -1,23 +1,20 @@
|
||||||
package com.baeldung.mustache;
|
package com.baeldung.mustache;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import com.baeldung.mustache.model.Todo;
|
||||||
|
import com.github.mustachejava.Mustache;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.temporal.TemporalUnit;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import com.baeldung.mustache.model.Todo;
|
|
||||||
import com.github.mustachejava.Mustache;
|
|
||||||
public class TodoMustacheServiceTest {
|
public class TodoMustacheServiceTest {
|
||||||
|
|
||||||
private String executeTemplate(Mustache m, Map<String, Object> context) throws IOException {
|
private String executeTemplate(Mustache m, Map<String, Object> context) throws IOException {
|
||||||
|
@ -73,7 +70,8 @@ public class TodoMustacheServiceTest {
|
||||||
Mustache m = MustacheUtil.getMustacheFactory().compile("todos.mustache");
|
Mustache m = MustacheUtil.getMustacheFactory().compile("todos.mustache");
|
||||||
|
|
||||||
Map<String, Object> context = new HashMap<>();
|
Map<String, Object> context = new HashMap<>();
|
||||||
assertThat(executeTemplate(m, context)).isEmpty();;
|
assertThat(executeTemplate(m, context)).isEmpty();
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -13,7 +13,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||||
public class SpringMustacheApplicationTests {
|
public class SpringMustacheApplicationIntegrationTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TestRestTemplate restTemplate;
|
private TestRestTemplate restTemplate;
|
|
@ -12,5 +12,4 @@ public class BeanA {
|
||||||
public BeanA() {
|
public BeanA() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,5 +8,4 @@ public class BeanB {
|
||||||
public BeanB() {
|
public BeanB() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>spring-rest-angular</artifactId>
|
<artifactId>spring-rest-angular</artifactId>
|
||||||
<name>spring-rest-angular</name>
|
<name>spring-rest-angular</name>
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.baeldung.controllers;
|
||||||
|
|
||||||
import com.baeldung.services.ExampleService;
|
import com.baeldung.services.ExampleService;
|
||||||
import com.baeldung.transfer.LoginForm;
|
import com.baeldung.transfer.LoginForm;
|
||||||
|
import org.baeldung.web.main.Application;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -12,7 +13,6 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.baeldung.web.main.Application;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
@ -21,11 +21,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = Application.class)
|
@SpringBootTest(classes = Application.class)
|
||||||
public class ExamplePostControllerRequestUnitTest {
|
public class ExamplePostControllerRequestIntegrationTest {
|
||||||
|
|
||||||
MockMvc mockMvc;
|
MockMvc mockMvc;
|
||||||
@Mock private ExampleService exampleService;
|
@Mock
|
||||||
@InjectMocks private ExamplePostController exampleController;
|
private ExampleService exampleService;
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
private ExamplePostController exampleController;
|
||||||
private final String jsonBody = "{\"username\": \"username\", \"password\": \"password\"}";
|
private final String jsonBody = "{\"username\": \"username\", \"password\": \"password\"}";
|
||||||
private LoginForm lf = new LoginForm();
|
private LoginForm lf = new LoginForm();
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.baeldung.controllers;
|
||||||
|
|
||||||
import com.baeldung.services.ExampleService;
|
import com.baeldung.services.ExampleService;
|
||||||
import com.baeldung.transfer.LoginForm;
|
import com.baeldung.transfer.LoginForm;
|
||||||
|
import org.baeldung.web.main.Application;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -10,7 +11,6 @@ import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.baeldung.web.main.Application;
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
|
|
||||||
|
@ -22,12 +22,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = Application.class)
|
@SpringBootTest(classes = Application.class)
|
||||||
public class ExamplePostControllerResponseUnitTest {
|
public class ExamplePostControllerResponseIntegrationTest {
|
||||||
|
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ExampleService exampleService;
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
private ExamplePostController exampleController;
|
||||||
|
|
||||||
MockMvc mockMvc;
|
|
||||||
@Mock private ExampleService exampleService;
|
|
||||||
@InjectMocks private ExamplePostController exampleController;
|
|
||||||
private final String jsonBody = "{\"username\": \"username\", \"password\": \"password\"}";
|
|
||||||
private LoginForm lf = new LoginForm();
|
private LoginForm lf = new LoginForm();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -44,6 +48,7 @@ public class ExamplePostControllerResponseUnitTest {
|
||||||
public void requestBodyTest() {
|
public void requestBodyTest() {
|
||||||
try {
|
try {
|
||||||
when(exampleService.fakeAuthenticate(lf)).thenReturn(true);
|
when(exampleService.fakeAuthenticate(lf)).thenReturn(true);
|
||||||
|
String jsonBody = "{\"username\": \"username\", \"password\": \"password\"}";
|
||||||
mockMvc
|
mockMvc
|
||||||
.perform(post("/post/response")
|
.perform(post("/post/response")
|
||||||
.content(jsonBody)
|
.content(jsonBody)
|
|
@ -1,10 +1,5 @@
|
||||||
package org.baeldung.web.service;
|
package org.baeldung.web.service;
|
||||||
|
|
||||||
import static io.restassured.RestAssured.given;
|
|
||||||
import static org.hamcrest.core.Is.is;
|
|
||||||
import static org.hamcrest.core.IsCollectionContaining.hasItems;
|
|
||||||
import static org.hamcrest.core.IsEqual.equalTo;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
import org.baeldung.web.main.Application;
|
import org.baeldung.web.main.Application;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -13,6 +8,11 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import static io.restassured.RestAssured.given;
|
||||||
|
import static org.hamcrest.core.Is.is;
|
||||||
|
import static org.hamcrest.core.IsCollectionContaining.hasItems;
|
||||||
|
import static org.hamcrest.core.IsEqual.equalTo;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.DEFINED_PORT)
|
@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.DEFINED_PORT)
|
||||||
public class StudentServiceIntegrationTest {
|
public class StudentServiceIntegrationTest {
|
||||||
|
@ -21,7 +21,8 @@ public class StudentServiceIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenRequestForStudents_whenPageIsOne_expectContainsNames() {
|
public void givenRequestForStudents_whenPageIsOne_expectContainsNames() {
|
||||||
given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat().body("content.name", hasItems("Bryan", "Ben"));
|
given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat()
|
||||||
|
.body("content.name", hasItems("Bryan", "Ben"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -58,5 +59,4 @@ public class StudentServiceIntegrationTest {
|
||||||
public void givenResourcesExist_whenFirstPageIsRetrieved_thenPageContainsResources() {
|
public void givenResourcesExist_whenFirstPageIsRetrieved_thenPageContainsResources() {
|
||||||
given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat().body("first", equalTo(true));
|
given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat().body("first", equalTo(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue