Skip to content

Commit

Permalink
Spring Boot Core: add Integration Test annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalgrimaud committed Nov 26, 2021
1 parent 31eae4f commit 97f6028
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ public void addApplicationFastProperties(Project project) {
public void addApplicationTestProperties(Project project) {
springBootService.addApplicationTestProperties(project);
}

public void addIntegrationTestAnnotation(Project project) {
springBootService.addIntegrationTestAnnotation(project);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public void init(Project project) {
addApplicationProperties(project);
addApplicationFastProperties(project);
addApplicationTestProperties(project);
addIntegrationTestAnnotation(project);
}

@Override
Expand Down Expand Up @@ -119,4 +120,12 @@ public void addApplicationTestProperties(Project project) {

projectRepository.template(project, SOURCE, "application-test.properties", getPath(TEST_RESOURCES, "config"), "application.properties");
}

@Override
public void addIntegrationTestAnnotation(Project project) {
project.addDefaultConfig(PACKAGE_NAME);
String packageNamePath = project.getPackageNamePath().orElse("com/mycompany/myapp");

projectRepository.template(project, SOURCE, "IntegrationTest.java", getPath(TEST_JAVA, packageNamePath));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public interface SpringBootService {
void addApplicationProperties(Project project);
void addApplicationFastProperties(Project project);
void addApplicationTestProperties(Project project);
void addIntegrationTestAnnotation(Project project);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package {{packageName}};

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.springframework.boot.test.context.SpringBootTest;

@DisplayNameGeneration(ReplaceCamelCase.class)
@Retention(RetentionPolicy.RUNTIME)
@SpringBootTest(classes = { JhlightApp.class })
@Target(ElementType.TYPE)
public @interface IntegrationTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import java.net.UnknownHostException;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
@IntegrationTest
class {{mainClass}}AppIT {
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import static tech.jhipster.light.TestUtils.*;
import static tech.jhipster.light.common.domain.FileUtils.getPath;
import static tech.jhipster.light.generator.buildtool.maven.domain.MavenDomainService.POM_XML;
import static tech.jhipster.light.generator.project.domain.Constants.MAIN_RESOURCES;
import static tech.jhipster.light.generator.project.domain.Constants.TEST_RESOURCES;
import static tech.jhipster.light.generator.project.domain.Constants.*;

import java.util.List;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -50,8 +49,9 @@ void shouldInit() {
assertFileContent(project, "pom.xml", "<groupId>org.springframework.boot</groupId>");
assertFileContent(project, "pom.xml", "<artifactId>spring-boot-maven-plugin</artifactId>");

assertFileExist(project, "src/main/java/com/mycompany/myapp/JhipsterApp.java");
assertFileExist(project, "src/test/java/com/mycompany/myapp/JhipsterAppIT.java");
assertFileExist(project, getPath(MAIN_JAVA, "com/mycompany/myapp/JhipsterApp.java"));
assertFileExist(project, getPath(TEST_JAVA, "com/mycompany/myapp/JhipsterAppIT.java"));
assertFileExist(project, getPath(TEST_JAVA, "com/mycompany/myapp", "IntegrationTest.java"));

assertFileExist(project, getPath(MAIN_RESOURCES, "config/application.properties"));
assertFileExist(project, getPath(MAIN_RESOURCES, "config/application-fast.properties"));
Expand Down Expand Up @@ -178,4 +178,13 @@ void shouldAddApplicationTestProperties() {

assertFileExist(project, getPath(TEST_RESOURCES, "config/application.properties"));
}

@Test
void shouldAddIntegrationTestAnnotation() {
Project project = tmpProject();

springBootApplicationService.addIntegrationTestAnnotation(project);

assertFileExist(project, getPath(TEST_JAVA, "com/mycompany/myapp", "IntegrationTest.java"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static tech.jhipster.light.TestUtils.tmpProject;
import static tech.jhipster.light.TestUtils.tmpProjectWithPomXml;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -41,8 +42,8 @@ void shouldInit() {
verify(buildToolService, times(3)).addDependency(any(Project.class), any(Dependency.class));
verify(buildToolService).addPlugin(any(Project.class), any(Plugin.class));

// for application.properties and application-fast.properties
verify(projectRepository, times(2)).template(any(Project.class), anyString(), anyString(), anyString());
// for application.properties, application-fast.properties, Integration Test annotation
verify(projectRepository, times(3)).template(any(Project.class), anyString(), anyString(), anyString());
// for main class + test + application.properties in test
verify(projectRepository, times(3)).template(any(Project.class), anyString(), anyString(), anyString(), anyString());
}
Expand Down Expand Up @@ -73,4 +74,13 @@ void shouldAddSpringBootPlugin() {

verify(buildToolService).addPlugin(any(Project.class), any(Plugin.class));
}

@Test
void shouldAddIntegrationTestAnnotation() {
Project project = tmpProject();

springBootDomainService.addIntegrationTestAnnotation(project);

verify(projectRepository, times(1)).template(any(Project.class), anyString(), anyString(), anyString());
}
}

0 comments on commit 97f6028

Please sign in to comment.