From bd40346c8f6a2adc03205a39bebfedb7460791bf Mon Sep 17 00:00:00 2001 From: antarus Date: Sat, 18 Jun 2022 15:41:18 +0200 Subject: [PATCH] Update devttols to new module system --- .../DevToolsApplicationService.java | 23 ++-- .../domain/DevToolsDomainService.java | 54 ---------- .../domain/DevToolsModuleFactory.java | 53 +++++++++ .../devtools/domain/DevToolsService.java | 10 -- .../config/DevToolsBeanConfiguration.java | 25 ----- .../primary/DevToolsModuleConfiguration.java | 23 ++++ .../primary/rest/DevToolsResource.java | 35 ------ .../springboot/devtools/devtools.md.mustache | 8 ++ src/test/features/dev-tools.feature | 22 ++++ .../DevToolsApplicationServiceIT.java | 102 ------------------ .../domain/DevToolsModuleFactoryTest.java | 47 ++++++++ .../config/DevToolsBeanConfigurationIT.java | 21 ---- .../rest/DevToolsResourceIT.java | 72 ------------- 13 files changed, 161 insertions(+), 334 deletions(-) delete mode 100644 src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/domain/DevToolsDomainService.java create mode 100644 src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/domain/DevToolsModuleFactory.java delete mode 100644 src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/domain/DevToolsService.java delete mode 100644 src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/config/DevToolsBeanConfiguration.java create mode 100644 src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/primary/DevToolsModuleConfiguration.java delete mode 100644 src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/primary/rest/DevToolsResource.java create mode 100644 src/main/resources/generator/server/springboot/devtools/devtools.md.mustache create mode 100644 src/test/features/dev-tools.feature delete mode 100644 src/test/java/tech/jhipster/lite/generator/server/springboot/devtools/application/DevToolsApplicationServiceIT.java create mode 100644 src/test/java/tech/jhipster/lite/generator/server/springboot/devtools/domain/DevToolsModuleFactoryTest.java delete mode 100644 src/test/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/config/DevToolsBeanConfigurationIT.java delete mode 100644 src/test/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/rest/DevToolsResourceIT.java diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/application/DevToolsApplicationService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/application/DevToolsApplicationService.java index 94673f9c5c8..031406cf590 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/application/DevToolsApplicationService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/application/DevToolsApplicationService.java @@ -1,27 +1,20 @@ package tech.jhipster.lite.generator.server.springboot.devtools.application; import org.springframework.stereotype.Service; -import tech.jhipster.lite.generator.project.domain.Project; -import tech.jhipster.lite.generator.server.springboot.devtools.domain.DevToolsService; +import tech.jhipster.lite.generator.module.domain.JHipsterModule; +import tech.jhipster.lite.generator.module.domain.properties.JHipsterModuleProperties; +import tech.jhipster.lite.generator.server.springboot.devtools.domain.DevToolsModuleFactory; @Service public class DevToolsApplicationService { - private final DevToolsService devToolsService; + private final DevToolsModuleFactory devToolsFactory; - public DevToolsApplicationService(DevToolsService devToolsService) { - this.devToolsService = devToolsService; + public DevToolsApplicationService() { + devToolsFactory = new DevToolsModuleFactory(); } - public void init(Project project) { - devToolsService.init(project); - } - - public void addSpringBootDevTools(Project project) { - devToolsService.addSpringBootDevTools(project); - } - - public void addProperties(Project project) { - devToolsService.addProperties(project); + public JHipsterModule buildModule(JHipsterModuleProperties properties) { + return devToolsFactory.buildModule(properties); } } diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/domain/DevToolsDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/domain/DevToolsDomainService.java deleted file mode 100644 index 93c1b05de6b..00000000000 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/domain/DevToolsDomainService.java +++ /dev/null @@ -1,54 +0,0 @@ -package tech.jhipster.lite.generator.server.springboot.devtools.domain; - -import java.util.Map; -import java.util.TreeMap; -import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; -import tech.jhipster.lite.generator.buildtool.generic.domain.Dependency; -import tech.jhipster.lite.generator.project.domain.Project; -import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; - -public class DevToolsDomainService implements DevToolsService { - - public static final String SOURCE = "server/springboot/devtools"; - - private final BuildToolService buildToolService; - private final SpringBootCommonService springBootCommonService; - - public DevToolsDomainService(BuildToolService buildToolService, SpringBootCommonService springBootCommonService) { - this.buildToolService = buildToolService; - this.springBootCommonService = springBootCommonService; - } - - @Override - public void init(Project project) { - addSpringBootDevTools(project); - addProperties(project); - } - - @Override - public void addSpringBootDevTools(Project project) { - Dependency dependency = Dependency.builder().groupId("org.springframework.boot").artifactId("spring-boot-devtools").optional().build(); - - buildToolService.addDependency(project, dependency); - } - - @Override - public void addProperties(Project project) { - springBootCommonService.addPropertiesComment(project, "Spring Boot Dev Tools"); - springPropertiesDevTools(false).forEach((k, v) -> springBootCommonService.addProperties(project, k, v)); - springBootCommonService.addPropertiesNewLine(project); - - springBootCommonService.addPropertiesLocalComment(project, "Spring Boot Dev Tools"); - springPropertiesDevTools(true).forEach((k, v) -> springBootCommonService.addPropertiesLocal(project, k, v)); - springBootCommonService.addPropertiesLocalNewLine(project); - } - - private Map springPropertiesDevTools(boolean fast) { - TreeMap result = new TreeMap<>(); - - result.put("spring.devtools.livereload.enabled", fast); - result.put("spring.devtools.restart.enabled", fast); - - return result; - } -} diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/domain/DevToolsModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/domain/DevToolsModuleFactory.java new file mode 100644 index 00000000000..34b9fb423b2 --- /dev/null +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/domain/DevToolsModuleFactory.java @@ -0,0 +1,53 @@ +package tech.jhipster.lite.generator.server.springboot.devtools.domain; + +import static tech.jhipster.lite.generator.module.domain.JHipsterModule.*; + +import tech.jhipster.lite.error.domain.Assert; +import tech.jhipster.lite.generator.module.domain.JHipsterModule; +import tech.jhipster.lite.generator.module.domain.JHipsterSource; +import tech.jhipster.lite.generator.module.domain.javadependency.GroupId; +import tech.jhipster.lite.generator.module.domain.javaproperties.SpringProfile; +import tech.jhipster.lite.generator.module.domain.properties.JHipsterModuleProperties; + +public class DevToolsModuleFactory { + + private static final GroupId SPRING_GROUP = groupId("org.springframework.boot"); + + private static final JHipsterSource SOURCE = from("server/springboot/devtools"); + + public JHipsterModule buildModule(JHipsterModuleProperties properties) { + Assert.notNull("properties", properties); + + //@formatter:off + JHipsterModuleBuilder builder = moduleBuilder(properties) + .context() + .packageName(properties.basePackage()) + .put("applicationName", properties.projectBaseName() + .capitalized()) + .and(); + //@formatter:on + + appendDependencies(builder); + appendSpringProperties(builder); + + builder.documentation(documentationTitle("Dev tools"), SOURCE.append("devtools.md.mustache")); + + return builder.build(); + } + + private void appendDependencies(JHipsterModuleBuilder builder) { + builder.javaDependencies().add(SPRING_GROUP, artifactId("spring-boot-devtools")); + } + + private void appendSpringProperties(JHipsterModuleBuilder builder) { + builder + .springMainProperties() + .set(propertyKey("spring.devtools.livereload.enabled"), propertyValue("false")) + .set(propertyKey("spring.devtools.restart.enabled"), propertyValue("false")); + + builder + .springMainProperties(new SpringProfile("local")) + .set(propertyKey("spring.devtools.livereload.enabled"), propertyValue("true")) + .set(propertyKey("spring.devtools.restart.enabled"), propertyValue("true")); + } +} diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/domain/DevToolsService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/domain/DevToolsService.java deleted file mode 100644 index 33f3fac6cb1..00000000000 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/domain/DevToolsService.java +++ /dev/null @@ -1,10 +0,0 @@ -package tech.jhipster.lite.generator.server.springboot.devtools.domain; - -import tech.jhipster.lite.generator.project.domain.Project; - -public interface DevToolsService { - void init(Project project); - - void addSpringBootDevTools(Project project); - void addProperties(Project project); -} diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/config/DevToolsBeanConfiguration.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/config/DevToolsBeanConfiguration.java deleted file mode 100644 index 0ae8dcfe60e..00000000000 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/config/DevToolsBeanConfiguration.java +++ /dev/null @@ -1,25 +0,0 @@ -package tech.jhipster.lite.generator.server.springboot.devtools.infrastructure.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; -import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; -import tech.jhipster.lite.generator.server.springboot.devtools.domain.DevToolsDomainService; -import tech.jhipster.lite.generator.server.springboot.devtools.domain.DevToolsService; - -@Configuration -public class DevToolsBeanConfiguration { - - private final BuildToolService buildToolService; - private final SpringBootCommonService springBootCommonService; - - public DevToolsBeanConfiguration(BuildToolService buildToolService, SpringBootCommonService springBootCommonService) { - this.buildToolService = buildToolService; - this.springBootCommonService = springBootCommonService; - } - - @Bean - public DevToolsService devToolsService() { - return new DevToolsDomainService(buildToolService, springBootCommonService); - } -} diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/primary/DevToolsModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/primary/DevToolsModuleConfiguration.java new file mode 100644 index 00000000000..214daaba71d --- /dev/null +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/primary/DevToolsModuleConfiguration.java @@ -0,0 +1,23 @@ +package tech.jhipster.lite.generator.server.springboot.devtools.infrastructure.primary; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import tech.jhipster.lite.generator.module.domain.properties.JHipsterModulePropertiesDefinition; +import tech.jhipster.lite.generator.module.infrastructure.primary.JHipsterModuleApiDoc; +import tech.jhipster.lite.generator.module.infrastructure.primary.JHipsterModuleResource; +import tech.jhipster.lite.generator.server.springboot.devtools.application.DevToolsApplicationService; + +@Configuration +class DevToolsModuleConfiguration { + + @Bean + JHipsterModuleResource devTools(DevToolsApplicationService devtools) { + return JHipsterModuleResource + .builder() + .legacyUrl("/api/servers/spring-boot/technical-tools/devtools") + .slug("springboot-devtools") + .propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addBasePackage().addProjectBaseName().addIndentation().build()) + .apiDoc(new JHipsterModuleApiDoc("Spring Boot - Tools", "Add spring boot tools.")) + .factory(devtools::buildModule); + } +} diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/primary/rest/DevToolsResource.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/primary/rest/DevToolsResource.java deleted file mode 100644 index 718e8bdf07e..00000000000 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/primary/rest/DevToolsResource.java +++ /dev/null @@ -1,35 +0,0 @@ -package tech.jhipster.lite.generator.server.springboot.devtools.infrastructure.primary.rest; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import tech.jhipster.lite.generator.project.domain.GeneratorAction; -import tech.jhipster.lite.generator.project.domain.Project; -import tech.jhipster.lite.generator.project.infrastructure.primary.dto.ProjectDTO; -import tech.jhipster.lite.generator.server.springboot.devtools.application.DevToolsApplicationService; -import tech.jhipster.lite.technical.infrastructure.primary.annotation.GeneratorStep; - -@RestController -@RequestMapping("/api/servers/spring-boot/technical-tools/devtools") -@Tag(name = "Spring Boot - Tools") -class DevToolsResource { - - private final DevToolsApplicationService devToolsApplicationService; - - public DevToolsResource(DevToolsApplicationService devToolsApplicationService) { - this.devToolsApplicationService = devToolsApplicationService; - } - - @Operation(summary = "Add Developer Tools dependencies") - @ApiResponse(responseCode = "500", description = "An error occurred while adding Developer Tools") - @PostMapping - @GeneratorStep(id = GeneratorAction.DEV_TOOLS) - public void init(@RequestBody ProjectDTO projectDTO) { - Project project = ProjectDTO.toProject(projectDTO); - devToolsApplicationService.init(project); - } -} diff --git a/src/main/resources/generator/server/springboot/devtools/devtools.md.mustache b/src/main/resources/generator/server/springboot/devtools/devtools.md.mustache new file mode 100644 index 00000000000..365a2f235c6 --- /dev/null +++ b/src/main/resources/generator/server/springboot/devtools/devtools.md.mustache @@ -0,0 +1,8 @@ +# Introduction + +Add the spring dev tool and enable it in local profile. + +# How to use it + +[official documentation:](https://docs.spring.io/spring-boot/docs/2.7.x/reference/html/using.html#using.devtools) + diff --git a/src/test/features/dev-tools.feature b/src/test/features/dev-tools.feature new file mode 100644 index 00000000000..be3bf195119 --- /dev/null +++ b/src/test/features/dev-tools.feature @@ -0,0 +1,22 @@ +Feature: Cucumber module + + Scenario: Should add devtools elements using legacy url + When I apply legacy module "/api/servers/spring-boot/technical-tools/devtools" to default project with maven file + Then I should have files in "documentation" + | dev-tools.md | + + Scenario: Should get devtools module properties definition + When I get module "springboot-devtools" properties definition + Then I should have properties definitions + | Key | Type | Mandatory | + | packageName | STRING | true | + | baseName | STRING | true | + | prettierDefaultIndent | INTEGER | false | + + Scenario: Should add devtools elements using module url + When I apply "springboot-devtools" module to default project with maven file + | packageName | tech.jhipster.chips | + | baseName | jhipster | + Then I should have files in "documentation" + | dev-tools.md | + And I should have history entry for "springboot-devtools" diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/devtools/application/DevToolsApplicationServiceIT.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/devtools/application/DevToolsApplicationServiceIT.java deleted file mode 100644 index 862f1a4cb97..00000000000 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/devtools/application/DevToolsApplicationServiceIT.java +++ /dev/null @@ -1,102 +0,0 @@ -package tech.jhipster.lite.generator.server.springboot.devtools.application; - -import static tech.jhipster.lite.TestUtils.assertFileContent; -import static tech.jhipster.lite.TestUtils.tmpProject; -import static tech.jhipster.lite.common.domain.FileUtils.getPath; -import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_RESOURCES; -import static tech.jhipster.lite.generator.project.domain.Constants.POM_XML; -import static tech.jhipster.lite.generator.project.domain.DefaultConfig.BASE_NAME; -import static tech.jhipster.lite.generator.project.domain.DefaultConfig.PACKAGE_NAME; -import static tech.jhipster.lite.generator.server.springboot.core.domain.SpringBoot.APPLICATION_LOCAL_PROPERTIES; -import static tech.jhipster.lite.generator.server.springboot.core.domain.SpringBoot.APPLICATION_PROPERTIES; - -import java.util.List; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import tech.jhipster.lite.IntegrationTest; -import tech.jhipster.lite.generator.buildtool.maven.application.MavenApplicationService; -import tech.jhipster.lite.generator.init.application.InitApplicationService; -import tech.jhipster.lite.generator.project.domain.Project; -import tech.jhipster.lite.generator.server.springboot.core.application.SpringBootApplicationService; - -@IntegrationTest -class DevToolsApplicationServiceIT { - - @Autowired - DevToolsApplicationService devToolsApplicationService; - - @Autowired - InitApplicationService initApplicationService; - - @Autowired - MavenApplicationService mavenApplicationService; - - @Autowired - SpringBootApplicationService springBootApplicationService; - - @Test - void shouldInit() { - Project project = tmpProject(); - initApplicationService.init(project); - mavenApplicationService.addPomXml(project); - springBootApplicationService.init(project); - - devToolsApplicationService.init(project); - - assertPomContainsDependency(project); - - assertProperties(project); - } - - @Test - void shouldAddSpringBootDevTools() { - Project project = tmpProject(); - initApplicationService.init(project); - mavenApplicationService.addPomXml(project); - - devToolsApplicationService.addSpringBootDevTools(project); - - assertPomContainsDependency(project); - } - - @Test - void shouldAddProperties() { - Project project = tmpProject(); - project.addConfig(PACKAGE_NAME, "tech.jhipster.chips"); - project.addConfig(BASE_NAME, "chips"); - initApplicationService.init(project); - mavenApplicationService.addPomXml(project); - springBootApplicationService.init(project); - - devToolsApplicationService.addProperties(project); - - assertProperties(project); - } - - private List springBootDevTools() { - return List.of( - "", - "org.springframework.boot", - "spring-boot-devtools", - "true", - "" - ); - } - - private void assertPomContainsDependency(Project project) { - assertFileContent(project, POM_XML, springBootDevTools()); - } - - private void assertProperties(Project project) { - assertFileContent( - project, - getPath(MAIN_RESOURCES, "config", APPLICATION_PROPERTIES), - List.of("spring.devtools.livereload.enabled=false", "spring.devtools.restart.enabled=false") - ); - assertFileContent( - project, - getPath(MAIN_RESOURCES, "config", APPLICATION_LOCAL_PROPERTIES), - List.of("spring.devtools.livereload.enabled=true", "spring.devtools.restart.enabled=true") - ); - } -} diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/devtools/domain/DevToolsModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/devtools/domain/DevToolsModuleFactoryTest.java new file mode 100644 index 00000000000..dfc1c01b878 --- /dev/null +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/devtools/domain/DevToolsModuleFactoryTest.java @@ -0,0 +1,47 @@ +package tech.jhipster.lite.generator.server.springboot.devtools.domain; + +import static tech.jhipster.lite.generator.module.infrastructure.secondary.JHipsterModulesAssertions.assertThatModuleWithFiles; +import static tech.jhipster.lite.generator.module.infrastructure.secondary.JHipsterModulesAssertions.pomFile; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.junit.jupiter.MockitoExtension; +import tech.jhipster.lite.UnitTest; +import tech.jhipster.lite.common.domain.FileUtils; +import tech.jhipster.lite.generator.module.domain.JHipsterModule; +import tech.jhipster.lite.generator.module.domain.JHipsterModulesFixture; +import tech.jhipster.lite.generator.module.domain.properties.JHipsterModuleProperties; +import tech.jhipster.lite.generator.server.springboot.devtools.domain.DevToolsModuleFactory; + +@UnitTest +@ExtendWith(MockitoExtension.class) +class DevToolsModuleFactoryTest { + + @InjectMocks + private DevToolsModuleFactory factory; + + @Test + void shouldCreateOAuth2Module() { + JHipsterModuleProperties properties = JHipsterModulesFixture + .propertiesBuilder(FileUtils.tmpDirForTest()) + .basePackage("com.jhipster.test") + .projectBaseName("myapp") + .build(); + + JHipsterModule module = factory.buildModule(properties); + + assertThatModuleWithFiles(module, pomFile()) + .createPrefixedFiles("documentation", "dev-tools.md") + .createFile("pom.xml") + .containing("spring-boot-devtools") + .and() + .createFile("src/main/resources/config/application.properties") + .containing("spring.devtools.livereload.enabled=false") + .containing("spring.devtools.restart.enabled=false") + .and() + .createFile("src/main/resources/config/application-local.properties") + .containing("spring.devtools.livereload.enabled=true") + .containing("spring.devtools.restart.enabled=true"); + } +} diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/config/DevToolsBeanConfigurationIT.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/config/DevToolsBeanConfigurationIT.java deleted file mode 100644 index eb4abd1b32b..00000000000 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/config/DevToolsBeanConfigurationIT.java +++ /dev/null @@ -1,21 +0,0 @@ -package tech.jhipster.lite.generator.server.springboot.devtools.infrastructure.config; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import tech.jhipster.lite.IntegrationTest; -import tech.jhipster.lite.generator.server.springboot.devtools.domain.DevToolsDomainService; - -@IntegrationTest -class DevToolsBeanConfigurationIT { - - @Autowired - ApplicationContext applicationContext; - - @Test - void shouldGetBean() { - assertThat(applicationContext.getBean("devToolsService")).isNotNull().isInstanceOf(DevToolsDomainService.class); - } -} diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/rest/DevToolsResourceIT.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/rest/DevToolsResourceIT.java deleted file mode 100644 index e888c5b5ca7..00000000000 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/devtools/infrastructure/rest/DevToolsResourceIT.java +++ /dev/null @@ -1,72 +0,0 @@ -package tech.jhipster.lite.generator.server.springboot.devtools.infrastructure.rest; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static tech.jhipster.lite.TestUtils.assertFileContent; -import static tech.jhipster.lite.generator.project.domain.Constants.POM_XML; - -import java.util.List; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; -import tech.jhipster.lite.IntegrationTest; -import tech.jhipster.lite.TestUtils; -import tech.jhipster.lite.common.domain.FileUtils; -import tech.jhipster.lite.error.domain.GeneratorException; -import tech.jhipster.lite.generator.buildtool.maven.application.MavenApplicationService; -import tech.jhipster.lite.generator.init.application.InitApplicationService; -import tech.jhipster.lite.generator.project.domain.Project; -import tech.jhipster.lite.generator.project.infrastructure.primary.dto.ProjectDTO; -import tech.jhipster.lite.generator.server.springboot.core.application.SpringBootApplicationService; - -@IntegrationTest -@AutoConfigureMockMvc -class DevToolsResourceIT { - - @Autowired - InitApplicationService initApplicationService; - - @Autowired - MavenApplicationService mavenApplicationService; - - @Autowired - SpringBootApplicationService springBootApplicationService; - - @Autowired - MockMvc mockMvc; - - @Test - void shouldInit() throws Exception { - ProjectDTO projectDTO = TestUtils.readFileToObject("json/chips.json", ProjectDTO.class); - if (projectDTO == null) { - throw new GeneratorException("Error when reading file"); - } - projectDTO.folder(FileUtils.tmpDirForTest()); - Project project = ProjectDTO.toProject(projectDTO); - initApplicationService.init(project); - mavenApplicationService.init(project); - springBootApplicationService.init(project); - - mockMvc - .perform( - post("/api/servers/spring-boot/technical-tools/devtools") - .contentType(MediaType.APPLICATION_JSON) - .content(TestUtils.convertObjectToJsonBytes(projectDTO)) - ) - .andExpect(status().isOk()); - - assertFileContent(project, POM_XML, springBootDevTools()); - } - - private List springBootDevTools() { - return List.of( - "", - "org.springframework.boot", - "spring-boot-devtools", - "true", - "" - ); - } -}