Build optimization (#2591)

This commit is contained in:
Grzegorz Piwowarek
2017-09-09 16:55:05 +02:00
committed by GitHub
parent 4589860efb
commit f01d1e257e
9 changed files with 148 additions and 58 deletions

View File

@@ -71,9 +71,96 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</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>
</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>
<mustache.compiler.api.version>0.9.2</mustache.compiler.api.version>
<assertj.version>3.7.0</assertj.version>

View File

@@ -1,100 +1,98 @@
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.StringWriter;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.temporal.TemporalUnit;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
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 {
private String executeTemplate(Mustache m, Map<String, Object> context) throws IOException{
private String executeTemplate(Mustache m, Map<String, Object> context) throws IOException {
StringWriter writer = new StringWriter();
m.execute(writer, context).flush();
return writer.toString();
}
private String executeTemplate(Mustache m, Todo todo) throws IOException{
private String executeTemplate(Mustache m, Todo todo) throws IOException {
StringWriter writer = new StringWriter();
m.execute(writer, todo).flush();
return writer.toString();
}
@Test
public void givenTodoObject_whenGetHtml_thenSuccess() throws IOException{
public void givenTodoObject_whenGetHtml_thenSuccess() throws IOException {
Todo todo = new Todo("Todo 1", "Todo description");
Mustache m = MustacheUtil.getMustacheFactory().compile("todo.mustache");
Map<String, Object> context = new HashMap<>();
context.put("todo", todo);
String expected = "<h2>Todo 1</h2>";
assertThat(executeTemplate(m, todo)).contains(expected);
}
@Test
public void givenNullTodoObject_whenGetHtml_thenEmptyHtml() throws IOException{
public void givenNullTodoObject_whenGetHtml_thenEmptyHtml() throws IOException {
Mustache m = MustacheUtil.getMustacheFactory().compile("todo-section.mustache");
Map<String, Object> context = new HashMap<>();
assertThat(executeTemplate(m, context)).isEmpty();
}
@Test
public void givenTodoList_whenGetHtml_thenSuccess() throws IOException{
public void givenTodoList_whenGetHtml_thenSuccess() throws IOException {
Mustache m = MustacheUtil.getMustacheFactory().compile("todos.mustache");
List<Todo> todos = Arrays.asList(
new Todo("Todo 1", "Todo description"),
new Todo("Todo 2", "Todo description another"),
new Todo("Todo 3", "Todo description another")
);
new Todo("Todo 1", "Todo description"),
new Todo("Todo 2", "Todo description another"),
new Todo("Todo 3", "Todo description another")
);
Map<String, Object> context = new HashMap<>();
context.put("todos", todos);
assertThat(executeTemplate(m, context))
.contains("<h2>Todo 1</h2>")
.contains("<h2>Todo 2</h2>")
.contains("<h2>Todo 3</h2>");
}
@Test
public void givenEmptyList_whenGetHtml_thenEmptyHtml() throws IOException{
public void givenEmptyList_whenGetHtml_thenEmptyHtml() throws IOException {
Mustache m = MustacheUtil.getMustacheFactory().compile("todos.mustache");
Map<String, Object> context = new HashMap<>();
assertThat(executeTemplate(m, context)).isEmpty();;
assertThat(executeTemplate(m, context)).isEmpty();
;
}
@Test
public void givenEmptyList_whenGetHtmlUsingInvertedSection_thenHtml() throws IOException{
public void givenEmptyList_whenGetHtmlUsingInvertedSection_thenHtml() throws IOException {
Mustache m = MustacheUtil.getMustacheFactory().compile("todos-inverted-section.mustache");
Map<String, Object> context = new HashMap<>();
assertThat(executeTemplate(m, context).trim()).isEqualTo("<p>No todos!</p>");
}
@Test
public void givenTodoList_whenGetHtmlUsingLamdba_thenHtml() throws IOException{
public void givenTodoList_whenGetHtmlUsingLamdba_thenHtml() throws IOException {
Mustache m = MustacheUtil.getMustacheFactory().compile("todos-lambda.mustache");
List<Todo> todos = Arrays.asList(
new Todo("Todo 1", "Todo description"),
new Todo("Todo 2", "Todo description another"),
new Todo("Todo 3", "Todo description another")
);
new Todo("Todo 1", "Todo description"),
new Todo("Todo 2", "Todo description another"),
new Todo("Todo 3", "Todo description another")
);
todos.get(2).setDone(true);
todos.get(2).setCompletedOn(Date.from(Instant.now().plusSeconds(300)));
Map<String, Object> context = new HashMap<>();
context.put("todos", todos);
assertThat(executeTemplate(m, context).trim()).contains("Done 5 minutes ago");

View File

@@ -13,7 +13,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class SpringMustacheApplicationTests {
public class SpringMustacheApplicationIntegrationTest {
@Autowired
private TestRestTemplate restTemplate;