From 3747d8e19361d11918c48e3cef7ec9cf3fe38de6 Mon Sep 17 00:00:00 2001 From: Colin DAMON Date: Tue, 17 May 2022 14:27:57 +0200 Subject: [PATCH] Rework template methods --- .../gradle/domain/GradleDomainService.java | 4 +- .../maven/domain/MavenDomainService.java | 2 +- .../domain/GitHubActionsDomainService.java | 27 +++-- .../core/domain/AngularDomainService.java | 24 +++- .../jwt/domain/AngularJwtDomainService.java | 67 +++++++---- .../react/core/domain/ReactDomainService.java | 27 ++++- .../core/domain/SvelteDomainService.java | 32 +++-- .../cypress/domain/CypressDomainService.java | 21 +++- .../domain/PlaywrightDomainService.java | 34 +++++- .../vue/core/domain/VueDomainService.java | 85 +++++++++++--- .../init/domain/InitDomainService.java | 8 +- .../generator/project/domain/FilePath.java | 2 +- .../project/domain/ProjectRepository.java | 13 ++- .../secondary/ProjectLocalRepository.java | 43 +++---- .../domain/JavaArchUnitDomainService.java | 30 +++-- .../base/domain/JavaBaseDomainService.java | 53 ++++++--- .../domain/FrontendMavenDomainService.java | 15 ++- .../sonar/domain/SonarDomainService.java | 17 ++- .../domain/SpringBootAsyncDomainService.java | 15 ++- .../kafka/domain/KafkaDomainService.java | 96 +++++++++++---- .../domain/SpringBootCacheDomainService.java | 15 ++- .../ehcache/domain/EhcacheDomainService.java | 16 +-- .../domain/SpringBootCommonDomainService.java | 36 +++--- .../core/domain/SpringBootDomainService.java | 81 ++++++++----- .../mongodb/domain/MongodbDomainService.java | 41 +++++-- .../domain/PostgresqlDomainService.java | 15 ++- .../domain/SQLCommonDomainService.java | 24 ++-- .../domain/LiquibaseDomainService.java | 45 +++++--- .../mongock/domain/MongockDomainService.java | 24 ++-- .../domain/SpringBootDockerDomainService.java | 7 +- .../aop/domain/AopLoggingDomainService.java | 22 +++- .../domain/LogstashDomainService.java | 8 +- .../mvc/dummy/domain/DummyDomainService.java | 3 +- .../jwt/domain/JwtSecurityDomainService.java | 63 +++++++--- .../domain/OAuth2SecurityDomainService.java | 109 +++++++++++++----- .../domain/SpringdocDomainService.java | 40 +++---- .../domain/SpringBootMvcDomainService.java | 45 +++++--- .../SpringCloudCommonDomainService.java | 23 ++-- .../consul/domain/ConsulDomainService.java | 29 ++--- .../gateway/domain/GatewayDomainService.java | 24 +++- .../domain/SpringBootUserDomainService.java | 84 ++++++++++---- .../SpringBootWebfluxDomainService.java | 16 ++- .../domain/CodespacesDomainService.java | 4 +- .../gradle/GradleDomainServiceTest.java | 5 +- .../domain/maven/MavenDomainServiceTest.java | 16 +-- .../GitHubActionsDomainServiceTest.java | 43 ++----- .../core/domain/AngularDomainServiceTest.java | 16 +-- .../domain/AngularJwtDomainServiceTest.java | 6 +- .../core/domain/ReactDomainServiceTest.java | 6 +- .../core/domain/SvelteDomainServiceTest.java | 5 +- .../domain/CypressDomainServiceTest.java | 14 +-- .../domain/PlaywrightDomainServiceTest.java | 21 +--- .../vue/core/domain/VueDomainServiceTest.java | 18 ++- .../init/domain/InitDomainServiceTest.java | 8 +- .../project/domain/ProjectFilesAsserter.java | 4 +- .../secondary/ProjectLocalRepositoryTest.java | 43 +++---- .../domain/JavaArchUnitDomainServiceTest.java | 14 +-- .../domain/JavaBaseDomainServiceTest.java | 12 +- .../FrontendMavenDomainServiceTest.java | 18 +-- .../sonar/domain/SonarDomainServiceTest.java | 16 +-- .../kafka/domain/KafkaDomainServiceTest.java | 15 ++- .../domain/SpringBootDomainServiceTest.java | 23 ++-- .../domain/MongodbDomainServiceTest.java | 3 +- .../domain/PostgresqlDomainServiceTest.java | 3 +- .../domain/SQLCommonDomainServiceTest.java | 17 ++- .../domain/MongockDomainServiceTest.java | 27 +---- .../SpringBootDockerDomainServiceTest.java | 3 +- .../maven/AopLoggingDomainServiceTest.java | 5 +- .../domain/LogstashDomainServiceTest.java | 8 +- .../dummy/domain/DummyDomainServiceTest.java | 3 +- .../domain/JwtSecurityDomainServiceTest.java | 19 ++- .../OAuth2SecurityDomainServiceTest.java | 21 ++-- .../domain/SpringdocDomainServiceTest.java | 47 ++------ .../SpringBootMvcDomainServiceTest.java | 27 ++--- .../SpringCloudCommonDomainServiceTest.java | 30 ++--- .../domain/ConsulDomainServiceTest.java | 24 ++-- .../domain/GatewayDomainServiceTest.java | 33 +----- .../SpringBootWebfluxDomainServiceTest.java | 55 ++------- .../domain/CodespacesDomainServiceTest.java | 2 +- 79 files changed, 1173 insertions(+), 846 deletions(-) diff --git a/src/main/java/tech/jhipster/lite/generator/buildtool/gradle/domain/GradleDomainService.java b/src/main/java/tech/jhipster/lite/generator/buildtool/gradle/domain/GradleDomainService.java index 8ba43195ca6..c28457376c8 100644 --- a/src/main/java/tech/jhipster/lite/generator/buildtool/gradle/domain/GradleDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/buildtool/gradle/domain/GradleDomainService.java @@ -38,8 +38,8 @@ public void addJavaBuildGradleKts(Project project) { String baseName = project.getBaseName().orElse(""); project.addConfig("dasherizedBaseName", WordUtils.kebabCase(baseName)); - projectRepository.template(project, SOURCE, BUILD_GRADLE_KTS); - projectRepository.template(project, SOURCE, SETTINGS_GRADLE_KTS); + projectRepository.template(ProjectFile.forProject(project).withSource(SOURCE, BUILD_GRADLE_KTS).withSameDestination()); + projectRepository.template(ProjectFile.forProject(project).withSource(SOURCE, SETTINGS_GRADLE_KTS).withSameDestination()); } @Override diff --git a/src/main/java/tech/jhipster/lite/generator/buildtool/maven/domain/MavenDomainService.java b/src/main/java/tech/jhipster/lite/generator/buildtool/maven/domain/MavenDomainService.java index 6a727a812d6..e999c6f8fdf 100644 --- a/src/main/java/tech/jhipster/lite/generator/buildtool/maven/domain/MavenDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/buildtool/maven/domain/MavenDomainService.java @@ -242,7 +242,7 @@ public void addJavaPomXml(Project project) { String baseName = project.getBaseName().orElse(""); project.addConfig("dasherizedBaseName", WordUtils.kebabCase(baseName)); - projectRepository.template(project, SOURCE, POM_XML); + projectRepository.template(ProjectFile.forProject(project).withSource(SOURCE, POM_XML).withSameDestination()); } @Override diff --git a/src/main/java/tech/jhipster/lite/generator/ci/github/actions/domain/GitHubActionsDomainService.java b/src/main/java/tech/jhipster/lite/generator/ci/github/actions/domain/GitHubActionsDomainService.java index 4894b5621ea..79ad972e717 100644 --- a/src/main/java/tech/jhipster/lite/generator/ci/github/actions/domain/GitHubActionsDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/ci/github/actions/domain/GitHubActionsDomainService.java @@ -1,6 +1,7 @@ package tech.jhipster.lite.generator.ci.github.actions.domain; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; public class GitHubActionsDomainService implements GitHubActionsService { @@ -26,30 +27,28 @@ public void addGitHubActions(Project project) { addSetupYamls(project); if (project.isMavenProject()) { projectRepository.template( - project, - GITHUB_ACTIONS_CI_SOURCE_FOLDER, - GITHUB_ACTIONS_MAVEN_CI_YML, - GITHUB_ACTIONS_CI_DESTINATION_FOLDER, - GITHUB_ACTIONS_CI_YML + ProjectFile + .forProject(project) + .withSource(GITHUB_ACTIONS_CI_SOURCE_FOLDER, GITHUB_ACTIONS_MAVEN_CI_YML) + .withDestination(GITHUB_ACTIONS_CI_DESTINATION_FOLDER, GITHUB_ACTIONS_CI_YML) ); } if (project.isGradleProject()) { projectRepository.template( - project, - GITHUB_ACTIONS_CI_SOURCE_FOLDER, - GITHUB_ACTIONS_GRADLE_CI_YML, - GITHUB_ACTIONS_CI_DESTINATION_FOLDER, - GITHUB_ACTIONS_CI_YML + ProjectFile + .forProject(project) + .withSource(GITHUB_ACTIONS_CI_SOURCE_FOLDER, GITHUB_ACTIONS_GRADLE_CI_YML) + .withDestination(GITHUB_ACTIONS_CI_DESTINATION_FOLDER, GITHUB_ACTIONS_CI_YML) ); } } private void addSetupYamls(Project project) { projectRepository.template( - project, - GITHUB_ACTIONS_SETUP_SOURCE_FOLDER, - GITHUB_ACTIONS_SETUP_YML, - GITHUB_ACTIONS_SETUP_DESTINATION_FOLDER + ProjectFile + .forProject(project) + .withSource(GITHUB_ACTIONS_SETUP_SOURCE_FOLDER, GITHUB_ACTIONS_SETUP_YML) + .withDestinationFolder(GITHUB_ACTIONS_SETUP_DESTINATION_FOLDER) ); } } diff --git a/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularDomainService.java b/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularDomainService.java index 0505a808339..cec5a5cb278 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularDomainService.java @@ -5,6 +5,7 @@ import static tech.jhipster.lite.generator.project.domain.Constants.*; import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*; +import java.util.List; import tech.jhipster.lite.error.domain.GeneratorException; import tech.jhipster.lite.generator.packagemanager.npm.domain.NpmService; import tech.jhipster.lite.generator.project.domain.Project; @@ -45,8 +46,12 @@ private void addCommonAngular(Project project) { public void addAppFiles(Project project) { project.addDefaultConfig(BASE_NAME); - projectRepository.template(project, SOURCE_PRIMARY, APP_COMPONENT_HTML, DESTINATION_PRIMARY); - projectRepository.template(project, SOURCE_PRIMARY, APP_COMPONENT, DESTINATION_PRIMARY); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE_PRIMARY, APP_COMPONENT_HTML).withDestinationFolder(DESTINATION_PRIMARY) + ); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE_PRIMARY, APP_COMPONENT).withDestinationFolder(DESTINATION_PRIMARY) + ); addImages(project); } @@ -91,9 +96,20 @@ public void addFiles(Project project) { public void addAngularFiles(Project project) { project.addDefaultConfig(BASE_NAME); - Angular + + List files = Angular .angularFiles() - .forEach((file, path) -> projectRepository.template(project, getPath(SOURCE_WEBAPP, path), file, getPath(MAIN_WEBAPP, path))); + .entrySet() + .stream() + .map(entry -> + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE_WEBAPP, entry.getValue()), entry.getKey()) + .withDestinationFolder(getPath(MAIN_WEBAPP, entry.getValue())) + ) + .toList(); + + projectRepository.template(files); } public void addImages(Project project) { diff --git a/src/main/java/tech/jhipster/lite/generator/client/angular/security/jwt/domain/AngularJwtDomainService.java b/src/main/java/tech/jhipster/lite/generator/client/angular/security/jwt/domain/AngularJwtDomainService.java index 081d18166a3..22c5efe571d 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/angular/security/jwt/domain/AngularJwtDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/client/angular/security/jwt/domain/AngularJwtDomainService.java @@ -5,9 +5,11 @@ import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_WEBAPP; import static tech.jhipster.lite.generator.project.domain.DefaultConfig.BASE_NAME; +import java.util.List; import tech.jhipster.lite.error.domain.GeneratorException; import tech.jhipster.lite.generator.packagemanager.npm.domain.NpmService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; public class AngularJwtDomainService implements AngularJwtService { @@ -46,34 +48,34 @@ public void updateAngularFilesForJwt(Project project) { String oldHtml = "// jhipster-needle-angular-jwt-login-form"; String newHtml = """ - { - path: '', - loadChildren: () => import('./login/login.module').then(m => m.LoginModule), - }"""; + { + path: '', + loadChildren: () => import('./login/login.module').then(m => m.LoginModule), + }"""; projectRepository.replaceText(project, APP, APP_ROUTING_MODULE, oldHtml, newHtml); oldHtml = "import \\{ AppRoutingModule \\} from './app-routing.module';"; newHtml = """ - import { TestBed } from '@angular/core/testing'; - import { Router } from '@angular/router'; - import { RouterTestingModule } from '@angular/router/testing'; - import { AppRoutingModule, routes } from './app-routing.module';"""; + import { TestBed } from '@angular/core/testing'; + import { Router } from '@angular/router'; + import { RouterTestingModule } from '@angular/router/testing'; + import { AppRoutingModule, routes } from './app-routing.module';"""; projectRepository.replaceText(project, APP, APP_ROUTING_MODULE_SPEC, oldHtml, newHtml); oldHtml = "// jhipster-needle-angular-jwt-login-form"; newHtml = """ - let router: Router; - - beforeEach(() => { - TestBed.configureTestingModule({ - imports: [RouterTestingModule.withRoutes(routes)] - }).compileComponents(); - router = TestBed.get(Router); - router.initialNavigation(); - }); - """; + let router: Router; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [RouterTestingModule.withRoutes(routes)] + }).compileComponents(); + router = TestBed.get(Router); + router.initialNavigation(); + }); + """; projectRepository.replaceText(project, APP, APP_ROUTING_MODULE_SPEC, oldHtml, newHtml); oldHtml = "import \\{ NgModule \\} from '@angular/core';"; @@ -121,14 +123,37 @@ public void updateAngularFilesForJwt(Project project) { public void addJwtFiles(Project project) { project.addConfig("serverPort", 8080); - AngularJwt.jwtFiles().forEach((file, path) -> projectRepository.template(project, getPath(SOURCE, path), file, getPath("", path))); + + List files = AngularJwt + .jwtFiles() + .entrySet() + .stream() + .map(entry -> + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, entry.getValue()), entry.getKey()) + .withDestinationFolder(getPath("", entry.getValue())) + ) + .toList(); + + projectRepository.template(files); } public void addAngularJwtFiles(Project project) { project.addDefaultConfig(BASE_NAME); - AngularJwt + + List files = AngularJwt .angularJwtFiles() - .forEach((file, path) -> projectRepository.template(project, getPath(SOURCE_WEBAPP, path), file, getPath(MAIN_WEBAPP, path))); + .entrySet() + .stream() + .map(entry -> + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE_WEBAPP, entry.getValue()), entry.getKey()) + .withDestinationFolder(getPath(MAIN_WEBAPP, entry.getValue())) + ) + .toList(); + projectRepository.template(files); } private void addDependency(Project project, String dependency) { diff --git a/src/main/java/tech/jhipster/lite/generator/client/react/core/domain/ReactDomainService.java b/src/main/java/tech/jhipster/lite/generator/client/react/core/domain/ReactDomainService.java index 30d19c86d4d..219f2909bd0 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/react/core/domain/ReactDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/client/react/core/domain/ReactDomainService.java @@ -3,6 +3,7 @@ import static tech.jhipster.lite.common.domain.FileUtils.*; import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*; +import java.util.List; import tech.jhipster.lite.error.domain.GeneratorException; import tech.jhipster.lite.generator.packagemanager.npm.domain.NpmService; import tech.jhipster.lite.generator.project.domain.Project; @@ -84,17 +85,35 @@ public void addFiles(Project project) { } public void addReactCommonFiles(Project project) { - React.reactCommonFiles().forEach((file, path) -> projectRepository.template(project, getPath(SOURCE, path), file, path)); + List files = React + .reactCommonFiles() + .entrySet() + .stream() + .map(entry -> + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, entry.getValue()), entry.getKey()) + .withDestinationFolder(entry.getValue()) + ) + .toList(); + + projectRepository.template(files); } public void addReactUnstyledFiles(Project project) { - projectRepository.template(project, getPath(SOURCE, SOURCE_APP), "App.tsx", SOURCE_APP); + projectRepository.template( + ProjectFile.forProject(project).withSource(getPath(SOURCE, SOURCE_APP), "App.tsx").withDestinationFolder(SOURCE_APP) + ); } public void addReactStyledFiles(Project project) { String imagesPath = "src/main/webapp/content/images"; - projectRepository.template(project, getPath(SOURCE, SOURCE_APP), "StyledApp.tsx", SOURCE_APP, "App.tsx"); - projectRepository.template(project, getPath(SOURCE, SOURCE_APP), "App.css", SOURCE_APP); + projectRepository.template( + ProjectFile.forProject(project).withSource(getPath(SOURCE, SOURCE_APP), "StyledApp.tsx").withDestination(SOURCE_APP, "App.tsx") + ); + projectRepository.template( + ProjectFile.forProject(project).withSource(getPath(SOURCE, SOURCE_APP), "App.css").withDestinationFolder(SOURCE_APP) + ); projectRepository.add( ProjectFile.forProject(project).withSource(getPath(SOURCE, imagesPath), "ReactLogo.png").withDestinationFolder(imagesPath) diff --git a/src/main/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteDomainService.java b/src/main/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteDomainService.java index 4f6d4a44e0e..037ec436b32 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteDomainService.java @@ -103,33 +103,45 @@ public void addSvelteConfigFile(Project project) { public void addRootFiles(Project project) { String pathWebapp = "src/main/webapp"; - projectRepository.template(project, getPath(SOURCE, pathWebapp), "app.html", pathWebapp); - projectRepository.template(project, getPath(SOURCE, pathWebapp), "app.d.ts", pathWebapp); - projectRepository.template(project, getPath(SOURCE, pathWebapp), "jest-setup.ts", pathWebapp); + projectRepository.template( + ProjectFile.forProject(project).withSource(getPath(SOURCE, pathWebapp), "app.html").withDestinationFolder(pathWebapp) + ); + projectRepository.template( + ProjectFile.forProject(project).withSource(getPath(SOURCE, pathWebapp), "app.d.ts").withDestinationFolder(pathWebapp) + ); + projectRepository.template( + ProjectFile.forProject(project).withSource(getPath(SOURCE, pathWebapp), "jest-setup.ts").withDestinationFolder(pathWebapp) + ); } public void addAppFiles(Project project) { String sourceRoutes = getPath(SOURCE, "src/main/webapp/routes"); String destinationRoutes = "src/main/webapp/routes"; - projectRepository.template(project, sourceRoutes, "index.svelte", destinationRoutes); + projectRepository.template( + ProjectFile.forProject(project).withSource(sourceRoutes, "index.svelte").withDestinationFolder(destinationRoutes) + ); projectRepository.template( - project, - getPath(SOURCE, "src/test/spec/common/primary/app"), - "App.spec.ts", - "src/test/javascript/spec/common/primary/app" + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, "src/test/spec/common/primary/app"), "App.spec.ts") + .withDestinationFolder("src/test/javascript/spec/common/primary/app") ); } public void addUnstyledHomeFiles(Project project) { - projectRepository.template(project, SOURCE_PRIMARY, "App.svelte", DESTINATION_PRIMARY); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE_PRIMARY, "App.svelte").withDestinationFolder(DESTINATION_PRIMARY) + ); } public void addStyledHomeFiles(Project project) { String assets = "src/main/webapp/assets"; - projectRepository.template(project, SOURCE_PRIMARY, "StyledApp.svelte", DESTINATION_PRIMARY, "App.svelte"); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE_PRIMARY, "StyledApp.svelte").withDestination(DESTINATION_PRIMARY, "App.svelte") + ); projectRepository.add( ProjectFile.forProject(project).withSource(getPath(SOURCE, assets), "JHipster-Lite-neon-orange.png").withDestinationFolder(assets) diff --git a/src/main/java/tech/jhipster/lite/generator/client/tools/cypress/domain/CypressDomainService.java b/src/main/java/tech/jhipster/lite/generator/client/tools/cypress/domain/CypressDomainService.java index 662f7518aa2..6595c4190e2 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/tools/cypress/domain/CypressDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/client/tools/cypress/domain/CypressDomainService.java @@ -55,7 +55,12 @@ public void addCypressScripts(Project project) { public void addCypressFiles(Project project) { project.addConfig("serverPort", 8080); - projectRepository.template(project, getPath(SOURCE, JAVASCRIPT_INTEGRATION), "cypress-config.json", getPath(JAVASCRIPT_INTEGRATION)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, JAVASCRIPT_INTEGRATION), "cypress-config.json") + .withDestinationFolder(getPath(JAVASCRIPT_INTEGRATION)) + ); List files = Cypress .cypressFiles() @@ -73,7 +78,19 @@ public void addCypressFiles(Project project) { } public void addCypressTestFiles(Project project) { - Cypress.cypressTestFiles().forEach((file, path) -> projectRepository.template(project, getPath(SOURCE, path), file, path)); + List files = Cypress + .cypressTestFiles() + .entrySet() + .stream() + .map(entry -> + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, entry.getValue()), entry.getKey()) + .withDestinationFolder(entry.getValue()) + ) + .toList(); + + projectRepository.template(files); } private void excludeIntegrationFilesTsConfig(Project project) { diff --git a/src/main/java/tech/jhipster/lite/generator/client/tools/playwright/domain/PlaywrightDomainService.java b/src/main/java/tech/jhipster/lite/generator/client/tools/playwright/domain/PlaywrightDomainService.java index e11ab0edb44..3ec924edfb6 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/tools/playwright/domain/PlaywrightDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/client/tools/playwright/domain/PlaywrightDomainService.java @@ -2,10 +2,12 @@ import static tech.jhipster.lite.common.domain.FileUtils.getPath; +import java.util.List; import tech.jhipster.lite.common.domain.FileUtils; import tech.jhipster.lite.error.domain.GeneratorException; import tech.jhipster.lite.generator.packagemanager.npm.domain.NpmService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; public class PlaywrightDomainService implements PlaywrightService { @@ -50,14 +52,40 @@ public void addPlaywrightScripts(Project project) { public void addPlaywrightFiles(Project project) { project.addConfig("serverPort", 8080); - projectRepository.template(project, FileUtils.getPath(SOURCE), "playwright.config.ts"); + projectRepository.template( + ProjectFile.forProject(project).withSource(FileUtils.getPath(SOURCE), "playwright.config.ts").withSameDestination() + ); } public void addPlaywrightTestFiles(Project project) { - Playwright.playwrightTestFiles().forEach((file, path) -> projectRepository.template(project, getPath(SOURCE, path), file, path)); + List files = Playwright + .playwrightTestFiles() + .entrySet() + .stream() + .map(entry -> + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, entry.getValue()), entry.getKey()) + .withDestinationFolder(entry.getValue()) + ) + .toList(); + + projectRepository.template(files); } public void addPlaywrightPageObjectFiles(Project project) { - Playwright.playwrightPageObjectFiles().forEach((file, path) -> projectRepository.template(project, getPath(SOURCE, path), file, path)); + List files = Playwright + .playwrightPageObjectFiles() + .entrySet() + .stream() + .map(entry -> + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, entry.getValue()), entry.getKey()) + .withDestinationFolder(entry.getValue()) + ) + .toList(); + + projectRepository.template(files); } } diff --git a/src/main/java/tech/jhipster/lite/generator/client/vue/core/domain/VueDomainService.java b/src/main/java/tech/jhipster/lite/generator/client/vue/core/domain/VueDomainService.java index aabb4bd99ed..67df3998c38 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/vue/core/domain/VueDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/client/vue/core/domain/VueDomainService.java @@ -94,9 +94,24 @@ public void addAxios(Project project) { private void addAxiosTestFiles(Project project) { String destinationAxiosTest = "src/test/javascript/spec/http"; String sourceAxiosTest = "test/spec/http"; - projectRepository.template(project, getPath(SOURCE, sourceAxiosTest), "AxiosHttp.spec.ts", destinationAxiosTest); - projectRepository.template(project, getPath(SOURCE, sourceAxiosTest), "AxiosHttpStub.ts", destinationAxiosTest); - projectRepository.template(project, getPath(SOURCE, sourceAxiosTest), "AxiosStub.ts", destinationAxiosTest); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, sourceAxiosTest), "AxiosHttp.spec.ts") + .withDestinationFolder(destinationAxiosTest) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, sourceAxiosTest), "AxiosHttpStub.ts") + .withDestinationFolder(destinationAxiosTest) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, sourceAxiosTest), "AxiosStub.ts") + .withDestinationFolder(destinationAxiosTest) + ); } private void addAxiosDependency(Project project) { @@ -104,7 +119,12 @@ private void addAxiosDependency(Project project) { } private void addAxiosFile(Project project) { - projectRepository.template(project, getPath(SOURCE, "webapp/app/http"), "AxiosHttp.ts", "src/main/webapp/app/http"); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, "webapp/app/http"), "AxiosHttp.ts") + .withDestinationFolder("src/main/webapp/app/http") + ); } public void addDevDependencies(Project project) { @@ -155,9 +175,15 @@ public void addViteConfigFiles(Project project) { } public void addRootFiles(Project project) { - projectRepository.template(project, getPath(SOURCE, "webapp"), "index.html", "src/main/webapp"); - projectRepository.template(project, getPath(SOURCE, "webapp/app"), "env.d.ts", DESTINATION_APP); - projectRepository.template(project, getPath(SOURCE, "webapp/app"), MAIN_TYPESCRIPT, DESTINATION_APP); + projectRepository.template( + ProjectFile.forProject(project).withSource(getPath(SOURCE, "webapp"), "index.html").withDestinationFolder("src/main/webapp") + ); + projectRepository.template( + ProjectFile.forProject(project).withSource(getPath(SOURCE, "webapp/app"), "env.d.ts").withDestinationFolder(DESTINATION_APP) + ); + projectRepository.template( + ProjectFile.forProject(project).withSource(getPath(SOURCE, "webapp/app"), MAIN_TYPESCRIPT).withDestinationFolder(DESTINATION_APP) + ); } private void addRouterFiles(Project project) { @@ -166,8 +192,18 @@ private void addRouterFiles(Project project) { } private void addRouterConfigAndTestFiles(Project project) { - projectRepository.template(project, getPath(SOURCE, "webapp/app/router"), ROUTER_TYPESCRIPT, "src/main/webapp/app/router"); - projectRepository.template(project, getPath(SOURCE, "test/spec/router"), "Router.spec.ts", "src/test/javascript/spec/router"); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, "webapp/app/router"), ROUTER_TYPESCRIPT) + .withDestinationFolder("src/main/webapp/app/router") + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, "test/spec/router"), "Router.spec.ts") + .withDestinationFolder("src/test/javascript/spec/router") + ); } private void addRouterMainConfiguration(Project project) { @@ -183,24 +219,41 @@ private void addNewNeedleLineToFile(Project project, String importLine, String f public void addAppFiles(Project project) { project.addDefaultConfig(BASE_NAME); - projectRepository.template(project, SOURCE_PRIMARY_APP, "App.component.ts", DESTINATION_PRIMARY_APP); - projectRepository.template(project, SOURCE_PRIMARY_APP, "index.ts", DESTINATION_PRIMARY_APP); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE_PRIMARY_APP, "App.component.ts").withDestinationFolder(DESTINATION_PRIMARY_APP) + ); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE_PRIMARY_APP, "index.ts").withDestinationFolder(DESTINATION_PRIMARY_APP) + ); - projectRepository.template(project, getPath(SOURCE_TEST_PRIMARY, "app"), "App.spec.ts", DESTINATION_PRIMARY_TEST + "/app"); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE_TEST_PRIMARY, "app"), "App.spec.ts") + .withDestinationFolder(DESTINATION_PRIMARY_TEST + "/app") + ); } public void addAppFilesWithoutCss(Project project) { project.addDefaultConfig(BASE_NAME); - projectRepository.template(project, SOURCE_PRIMARY_APP, "App.html", DESTINATION_PRIMARY_APP); - projectRepository.template(project, SOURCE_PRIMARY_APP, "App.vue", DESTINATION_PRIMARY_APP); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE_PRIMARY_APP, "App.html").withDestinationFolder(DESTINATION_PRIMARY_APP) + ); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE_PRIMARY_APP, "App.vue").withDestinationFolder(DESTINATION_PRIMARY_APP) + ); } public void addAppFilesWithCss(Project project) { project.addDefaultConfig(BASE_NAME); - projectRepository.template(project, SOURCE_PRIMARY_APP, "StyledApp.html", DESTINATION_PRIMARY_APP, "App.html"); - projectRepository.template(project, SOURCE_PRIMARY_APP, "StyledApp.vue", DESTINATION_PRIMARY_APP, "App.vue"); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE_PRIMARY_APP, "StyledApp.html").withDestination(DESTINATION_PRIMARY_APP, "App.html") + ); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE_PRIMARY_APP, "StyledApp.vue").withDestination(DESTINATION_PRIMARY_APP, "App.vue") + ); projectRepository.add( ProjectFile diff --git a/src/main/java/tech/jhipster/lite/generator/init/domain/InitDomainService.java b/src/main/java/tech/jhipster/lite/generator/init/domain/InitDomainService.java index 77b71a6aa1a..e80d5055d94 100644 --- a/src/main/java/tech/jhipster/lite/generator/init/domain/InitDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/init/domain/InitDomainService.java @@ -56,7 +56,7 @@ public void addPackageJson(Project project) { String baseName = project.getBaseName().orElse(""); project.addConfig("dasherizedBaseName", WordUtils.kebabCase(baseName)); - projectRepository.template(project, SOURCE, PACKAGE_JSON); + projectRepository.template(ProjectFile.forProject(project).withSource(SOURCE, PACKAGE_JSON).withSameDestination()); addDevDependencies(project); addScripts(project); } @@ -93,7 +93,7 @@ private void addScripts(Project project) { public void addReadme(Project project) { project.addDefaultConfig(PROJECT_NAME); - projectRepository.template(project, SOURCE, "README.md"); + projectRepository.template(ProjectFile.forProject(project).withSource(SOURCE, "README.md").withSameDestination()); } @Override @@ -108,7 +108,7 @@ public void addEditorConfiguration(Project project) { project.addDefaultConfig(PRETTIER_DEFAULT_INDENT); project.addConfig("editorConfigEndOfLine", CRLF.equals(project.getEndOfLine()) ? "crlf" : "lf"); - projectRepository.template(project, SOURCE, ".editorconfig"); + projectRepository.template(ProjectFile.forProject(project).withSource(SOURCE, ".editorconfig").withSameDestination()); projectRepository.add(ProjectFile.forProject(project).withSource(SOURCE, ".eslintignore").withSameDestination()); } @@ -123,7 +123,7 @@ public void addPrettier(Project project) { projectRepository.setExecutable(project, HUSKY_FOLDER, "pre-commit"); project.addConfig("prettierEndOfLine", CRLF.equals(project.getEndOfLine()) ? "crlf" : "lf"); - projectRepository.template(project, SOURCE, ".prettierrc"); + projectRepository.template(ProjectFile.forProject(project).withSource(SOURCE, ".prettierrc").withSameDestination()); } @Override diff --git a/src/main/java/tech/jhipster/lite/generator/project/domain/FilePath.java b/src/main/java/tech/jhipster/lite/generator/project/domain/FilePath.java index 443f4e79a23..5d019d00281 100644 --- a/src/main/java/tech/jhipster/lite/generator/project/domain/FilePath.java +++ b/src/main/java/tech/jhipster/lite/generator/project/domain/FilePath.java @@ -4,7 +4,7 @@ public record FilePath(String folder, String file) { public FilePath { - Assert.notBlank("folder", folder); + Assert.notNull("folder", folder); Assert.notBlank("file", file); } diff --git a/src/main/java/tech/jhipster/lite/generator/project/domain/ProjectRepository.java b/src/main/java/tech/jhipster/lite/generator/project/domain/ProjectRepository.java index f2877645709..1934f68da1b 100644 --- a/src/main/java/tech/jhipster/lite/generator/project/domain/ProjectRepository.java +++ b/src/main/java/tech/jhipster/lite/generator/project/domain/ProjectRepository.java @@ -9,17 +9,17 @@ public interface ProjectRepository { void add(Collection files); - void template(Project project, String source, String sourceFilename); - void template(Project project, String source, String sourceFilename, String destination); - void template(Project project, String source, String sourceFilename, String destination, String destinationFilename); + void template(Collection files); void rename(Project project, String source, String sourceFilename, String destinationFilename); String getComputedTemplate(Project project, String source, String sourceFilename); boolean containsRegexp(Project project, String source, String sourceFilename, String regexp); + void replaceText(Project project, String source, String sourceFilename, String oldText, String newText); void replaceRegexp(Project project, String source, String sourceFilename, String regexpText, String newText); + void write(Project project, String text, String destination, String destinationFilename); void setExecutable(Project project, String source, String sourceFilename); @@ -29,6 +29,7 @@ public interface ProjectRepository { void gitApplyPatch(Project project, String patchFilename); String zip(Project project); + byte[] download(Project project); boolean isJHipsterLiteProject(String path); @@ -38,4 +39,10 @@ default void add(ProjectFile file) { add(List.of(file)); } + + default void template(ProjectFile file) { + Assert.notNull("file", file); + + template(List.of(file)); + } } diff --git a/src/main/java/tech/jhipster/lite/generator/project/infrastructure/secondary/ProjectLocalRepository.java b/src/main/java/tech/jhipster/lite/generator/project/infrastructure/secondary/ProjectLocalRepository.java index 18fb0bf8907..22d394ad814 100644 --- a/src/main/java/tech/jhipster/lite/generator/project/infrastructure/secondary/ProjectLocalRepository.java +++ b/src/main/java/tech/jhipster/lite/generator/project/infrastructure/secondary/ProjectLocalRepository.java @@ -14,9 +14,8 @@ import java.util.Collection; import java.util.HashSet; import java.util.Set; +import java.util.function.Consumer; import org.eclipse.jgit.api.errors.GitAPIException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Repository; import org.zeroturnaround.zip.ZipException; import org.zeroturnaround.zip.ZipUtil; @@ -33,8 +32,6 @@ public class ProjectLocalRepository implements ProjectRepository { private static final String FILE_SEPARATOR = "/"; - private final Logger log = LoggerFactory.getLogger(ProjectLocalRepository.class); - @Override public void create(Project project) { try { @@ -46,7 +43,7 @@ public void create(Project project) { @Override public void add(Collection files) { - Assert.notEmpty("files", files); + Assert.field("files", files).notEmpty().noNullElement(); files.forEach(file -> { try (InputStream in = getInputStream(file.source())) { @@ -74,26 +71,32 @@ private static InputStream getInputStream(FilePath path) { } @Override - public void template(Project project, String source, String sourceFilename) { - template(project, source, sourceFilename, "."); + public void template(Collection files) { + Assert.field("files", files).notEmpty().noNullElement(); + + files.forEach(templatizeFile()); } - @Override - public void template(Project project, String source, String sourceFilename, String destination) { - template(project, source, sourceFilename, destination, MustacheUtils.withoutExt(sourceFilename)); + private Consumer templatizeFile() { + return file -> { + try { + String result = templatizeContent(file); + + writeTemplatizedContent(file, result); + } catch (IOException ex) { + throw new GeneratorException("The file '" + file.destination().file() + "' can't be added"); + } + }; } - @Override - public void template(Project project, String source, String sourceFilename, String destination, String destinationFilename) { - try { - log.info("Adding file '{}'", destinationFilename); - String filename = MustacheUtils.withExt(sourceFilename); - String result = MustacheUtils.template(FileUtils.getPath(TEMPLATE_FOLDER, source, filename), project.getConfig()); + private String templatizeContent(ProjectFile file) throws IOException { + String sourcePath = FileUtils.getPath(TEMPLATE_FOLDER, file.source().folder(), MustacheUtils.withExt(file.source().file())); - write(project, result, destination, destinationFilename); - } catch (IOException ex) { - throw new GeneratorException("The file '" + destinationFilename + "' can't be added"); - } + return MustacheUtils.template(sourcePath, file.project().getConfig()); + } + + private void writeTemplatizedContent(ProjectFile file, String result) { + write(file.project(), result, file.destination().folder(), MustacheUtils.withoutExt(file.destination().file())); } @Override diff --git a/src/main/java/tech/jhipster/lite/generator/server/javatool/arch/domain/JavaArchUnitDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/javatool/arch/domain/JavaArchUnitDomainService.java index 670df100d7b..1b1f76f59ee 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/javatool/arch/domain/JavaArchUnitDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/javatool/arch/domain/JavaArchUnitDomainService.java @@ -1,17 +1,15 @@ package tech.jhipster.lite.generator.server.javatool.arch.domain; -import static tech.jhipster.lite.common.domain.FileUtils.getPath; -import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_JAVA; -import static tech.jhipster.lite.generator.project.domain.Constants.TEST_JAVA; -import static tech.jhipster.lite.generator.project.domain.Constants.TEST_RESOURCES; -import static tech.jhipster.lite.generator.project.domain.DefaultConfig.PACKAGE_NAME; -import static tech.jhipster.lite.generator.project.domain.DefaultConfig.PACKAGE_PATH; +import static tech.jhipster.lite.common.domain.FileUtils.*; +import static tech.jhipster.lite.generator.project.domain.Constants.*; +import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*; import java.util.Arrays; import java.util.stream.Collectors; import tech.jhipster.lite.error.domain.GeneratorException; import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.Level; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -48,11 +46,21 @@ private void addHexagobalArchJavaFiles(Project project) { String packageWalkPath = Arrays.stream(packageNamePath.split("/")).map(s -> "\"" + s + "\"").collect(Collectors.joining(", ")); project.addConfig("packageWalkPath", packageWalkPath); - projectRepository.template(project, SOURCE, "BusinessContext.java", getPath(MAIN_JAVA, packageNamePath)); - projectRepository.template(project, SOURCE, "SharedKernel.java", getPath(MAIN_JAVA, packageNamePath)); - - projectRepository.template(project, SOURCE, "archunit.properties", getPath(TEST_RESOURCES)); - projectRepository.template(project, SOURCE, "HexagonalArchTest.java", getPath(TEST_JAVA, packageNamePath)); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE, "BusinessContext.java").withDestinationFolder(getPath(MAIN_JAVA, packageNamePath)) + ); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE, "SharedKernel.java").withDestinationFolder(getPath(MAIN_JAVA, packageNamePath)) + ); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE, "archunit.properties").withDestinationFolder(getPath(TEST_RESOURCES)) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "HexagonalArchTest.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath)) + ); } private void addArchUnitMavenPlugin(Project project) { diff --git a/src/main/java/tech/jhipster/lite/generator/server/javatool/base/domain/JavaBaseDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/javatool/base/domain/JavaBaseDomainService.java index e07206dc3cf..7665755dabf 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/javatool/base/domain/JavaBaseDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/javatool/base/domain/JavaBaseDomainService.java @@ -5,9 +5,11 @@ import static tech.jhipster.lite.generator.project.domain.Constants.TEST_JAVA; import static tech.jhipster.lite.generator.project.domain.DefaultConfig.PACKAGE_NAME; +import java.util.List; import tech.jhipster.lite.common.domain.WordUtils; import tech.jhipster.lite.generator.project.domain.DefaultConfig; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; public class JavaBaseDomainService implements JavaBaseService { @@ -33,13 +35,30 @@ public void addJavaBase(Project project) { } private void addErrors(Project project, String packageNamePath) { - JavaBase + List errorFiles = JavaBase .errorDomainFiles() - .forEach(file -> projectRepository.template(project, SOURCE, file, getPath(MAIN_JAVA, packageNamePath, ERROR_DOMAIN_PATH))); + .stream() + .map(file -> + ProjectFile + .forProject(project) + .withSource(SOURCE, file) + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, ERROR_DOMAIN_PATH)) + ) + .toList(); - JavaBase + projectRepository.template(errorFiles); + + List testFiles = JavaBase .errorDomainTestFiles() - .forEach(file -> projectRepository.template(project, SOURCE, file, getPath(TEST_JAVA, packageNamePath, ERROR_DOMAIN_PATH))); + .stream() + .map(file -> + ProjectFile + .forProject(project) + .withSource(SOURCE, file) + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath, ERROR_DOMAIN_PATH)) + ) + .toList(); + projectRepository.template(testFiles); } private void addCollections(Project project, String packageNamePath) { @@ -47,22 +66,26 @@ private void addCollections(Project project, String packageNamePath) { project.addConfig("collectionClass", className); projectRepository.template( - project, - SOURCE, - "ProjectCollections.java", - getPath(MAIN_JAVA, packageNamePath, COMMON_DOMAIN_PATH), - className + "Collections.java" + ProjectFile + .forProject(project) + .withSource(SOURCE, "ProjectCollections.java") + .withDestination(getPath(MAIN_JAVA, packageNamePath, COMMON_DOMAIN_PATH), className + "Collections.java") ); projectRepository.template( - project, - SOURCE, - "ProjectCollectionsTest.java", - getPath(TEST_JAVA, packageNamePath, COMMON_DOMAIN_PATH), - className + "CollectionsTest.java" + ProjectFile + .forProject(project) + .withSource(SOURCE, "ProjectCollectionsTest.java") + .withDestination(getPath(TEST_JAVA, packageNamePath, COMMON_DOMAIN_PATH), className + "CollectionsTest.java") ); } private void addAnnotations(Project project, String packageNamePath) { - JavaBase.annotationsFiles().forEach(file -> projectRepository.template(project, SOURCE, file, getPath(TEST_JAVA, packageNamePath))); + List files = JavaBase + .annotationsFiles() + .stream() + .map(file -> ProjectFile.forProject(project).withSource(SOURCE, file).withDestinationFolder(getPath(TEST_JAVA, packageNamePath))) + .toList(); + + projectRepository.template(files); } } diff --git a/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenDomainService.java index 7be57a4b043..e03862015c5 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenDomainService.java @@ -13,6 +13,7 @@ import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; import tech.jhipster.lite.generator.buildtool.generic.domain.Plugin; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; public class FrontendMavenDomainService implements FrontendMavenService { @@ -47,8 +48,18 @@ private void addRedirectionToWebappFiles(Project project) { String packageNamePath = project.getPackageNamePath().orElse(getPath(PACKAGE_PATH)); String redirectionPath = getPath(TECHNICAL_INFRASTRUCTURE_PRIMARY, "redirection"); - projectRepository.template(project, SOURCE, "RedirectionResource.java", getPath(MAIN_JAVA, packageNamePath, redirectionPath)); - projectRepository.template(project, TEST, "RedirectionResourceIT.java", getPath(TEST_JAVA, packageNamePath, redirectionPath)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "RedirectionResource.java") + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, redirectionPath)) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(TEST, "RedirectionResourceIT.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath, redirectionPath)) + ); } private Plugin frontendMavenPlugin() { diff --git a/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainService.java index ee32deb5817..e49446f4ff4 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainService.java @@ -1,13 +1,13 @@ package tech.jhipster.lite.generator.server.sonar.domain; -import static tech.jhipster.lite.generator.project.domain.DefaultConfig.BASE_NAME; -import static tech.jhipster.lite.generator.project.domain.DefaultConfig.PROJECT_NAME; +import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*; import tech.jhipster.lite.error.domain.GeneratorException; import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; import tech.jhipster.lite.generator.buildtool.generic.domain.Plugin; import tech.jhipster.lite.generator.docker.domain.DockerService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; public class SonarDomainService implements SonarService { @@ -95,13 +95,18 @@ private void addSonarScannerPluginManagement(Project project) { private void addPropertiesFile(Project project) { project.addDefaultConfig(BASE_NAME); project.addDefaultConfig(PROJECT_NAME); - projectRepository.template(project, SOURCE, "sonar-project.properties"); + projectRepository.template(ProjectFile.forProject(project).withSource(SOURCE, "sonar-project.properties").withSameDestination()); } private void addFullstackPropertiesFile(Project project) { project.addDefaultConfig(BASE_NAME); project.addDefaultConfig(PROJECT_NAME); - projectRepository.template(project, SOURCE, "sonar-fullstack-project.properties", "", "sonar-project.properties"); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "sonar-fullstack-project.properties") + .withDestination("", "sonar-project.properties") + ); } private void addDockerCompose(Project project) { @@ -114,6 +119,8 @@ private void addDockerCompose(Project project) { throw new GeneratorException("Version not found for docker image: " + Sonar.getSonarqubeDockerImageName()); } ); - projectRepository.template(project, SOURCE, "sonar.yml", "src/main/docker", "sonar.yml"); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE, "sonar.yml").withDestination("src/main/docker", "sonar.yml") + ); } } diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/async/domain/SpringBootAsyncDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/async/domain/SpringBootAsyncDomainService.java index 037f88aca30..8b4574a0ab4 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/async/domain/SpringBootAsyncDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/async/domain/SpringBootAsyncDomainService.java @@ -1,13 +1,13 @@ package tech.jhipster.lite.generator.server.springboot.async.domain; -import static tech.jhipster.lite.common.domain.FileUtils.getPath; -import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_JAVA; -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.common.domain.FileUtils.*; +import static tech.jhipster.lite.generator.project.domain.Constants.*; +import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*; import java.util.Map; import java.util.TreeMap; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -63,6 +63,11 @@ private Map springPropertiesDatasource(String baseName) { } private void templateToAsync(Project project, String source, String type, String sourceFilename, String destination) { - projectRepository.template(project, getPath(SOURCE, type), sourceFilename, getPath(destination, source, ASYNC_PATH)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, type), sourceFilename) + .withDestinationFolder(getPath(destination, source, ASYNC_PATH)) + ); } } diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/broker/kafka/domain/KafkaDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/broker/kafka/domain/KafkaDomainService.java index 158e3cd2be5..bca9eb88232 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/broker/kafka/domain/KafkaDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/broker/kafka/domain/KafkaDomainService.java @@ -1,12 +1,10 @@ package tech.jhipster.lite.generator.server.springboot.broker.kafka.domain; -import static tech.jhipster.lite.common.domain.FileUtils.getPath; +import static tech.jhipster.lite.common.domain.FileUtils.*; import static tech.jhipster.lite.generator.project.domain.Constants.*; import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*; -import static tech.jhipster.lite.generator.server.springboot.broker.kafka.domain.Akhq.AKHQ_DOCKER_COMPOSE_FILE; -import static tech.jhipster.lite.generator.server.springboot.broker.kafka.domain.Akhq.AKHQ_DOCKER_IMAGE; -import static tech.jhipster.lite.generator.server.springboot.broker.kafka.domain.Kafka.KAFKA_DOCKER_COMPOSE_FILE; -import static tech.jhipster.lite.generator.server.springboot.broker.kafka.domain.Kafka.KAFKA_DOCKER_IMAGE; +import static tech.jhipster.lite.generator.server.springboot.broker.kafka.domain.Akhq.*; +import static tech.jhipster.lite.generator.server.springboot.broker.kafka.domain.Kafka.*; import java.util.TreeMap; import tech.jhipster.lite.common.domain.WordUtils; @@ -16,6 +14,7 @@ import tech.jhipster.lite.generator.docker.domain.DockerService; import tech.jhipster.lite.generator.project.domain.DefaultConfig; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -59,14 +58,24 @@ private void addConfiguration(final Project project) { final String packageNamePath = project.getPackageNamePath().orElse(getPath(DefaultConfig.PACKAGE_PATH)); final String configKafkaPath = TECHNICAL_INFRASTRUCTURE_CONFIG + "/kafka"; - projectRepository.template(project, SOURCE, "KafkaProperties.java", getPath(MAIN_JAVA, packageNamePath, configKafkaPath)); - projectRepository.template(project, SOURCE, "KafkaPropertiesTest.java", getPath(TEST_JAVA, packageNamePath, configKafkaPath)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "KafkaProperties.java") + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, configKafkaPath)) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "KafkaPropertiesTest.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath, configKafkaPath)) + ); projectRepository.template( - project, - SOURCE, - "KafkaConfiguration.java", - getPath(MAIN_JAVA, packageNamePath, TECHNICAL_INFRASTRUCTURE_CONFIG + "/kafka") + ProjectFile + .forProject(project) + .withSource(SOURCE, "KafkaConfiguration.java") + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, TECHNICAL_INFRASTRUCTURE_CONFIG + "/kafka")) ); } @@ -81,14 +90,50 @@ public void addDummyProducerConsumer(final Project project) { springBootCommonService.addProperties(project, DUMMY_TOPIC_NAME, topicName); springBootCommonService.addPropertiesTest(project, DUMMY_TOPIC_NAME, topicName); - projectRepository.template(project, SOURCE, "DummyProducer.java", getPath(MAIN_JAVA, packageNamePath, DUMMY_PRODUCER_PATH)); - projectRepository.template(project, SOURCE, "DummyProducerTest.java", getPath(TEST_JAVA, packageNamePath, DUMMY_PRODUCER_PATH)); - projectRepository.template(project, SOURCE, "DummyProducerIT.java", getPath(TEST_JAVA, packageNamePath, DUMMY_PRODUCER_PATH)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "DummyProducer.java") + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, DUMMY_PRODUCER_PATH)) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "DummyProducerTest.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath, DUMMY_PRODUCER_PATH)) + ); + + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "DummyProducerIT.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath, DUMMY_PRODUCER_PATH)) + ); - projectRepository.template(project, SOURCE, "AbstractConsumer.java", getPath(MAIN_JAVA, packageNamePath, DUMMY_CONSUMER_PATH)); - projectRepository.template(project, SOURCE, "DummyConsumer.java", getPath(MAIN_JAVA, packageNamePath, DUMMY_CONSUMER_PATH)); - projectRepository.template(project, SOURCE, "DummyConsumerIT.java", getPath(TEST_JAVA, packageNamePath, DUMMY_CONSUMER_PATH)); - projectRepository.template(project, SOURCE, "DummyConsumerTest.java", getPath(TEST_JAVA, packageNamePath, DUMMY_CONSUMER_PATH)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "AbstractConsumer.java") + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, DUMMY_CONSUMER_PATH)) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "DummyConsumer.java") + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, DUMMY_CONSUMER_PATH)) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "DummyConsumerIT.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath, DUMMY_CONSUMER_PATH)) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "DummyConsumerTest.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath, DUMMY_CONSUMER_PATH)) + ); } } @@ -96,7 +141,9 @@ public void addDummyProducerConsumer(final Project project) { public void addAkhq(final Project project) { final String akhqDockerImage = dockerService.getImageNameWithVersion(AKHQ_DOCKER_IMAGE).orElseThrow(); project.addConfig("akhqDockerImage", akhqDockerImage); - projectRepository.template(project, SOURCE, AKHQ_DOCKER_COMPOSE_FILE, MAIN_DOCKER, AKHQ_DOCKER_COMPOSE_FILE); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE, AKHQ_DOCKER_COMPOSE_FILE).withDestination(MAIN_DOCKER, AKHQ_DOCKER_COMPOSE_FILE) + ); } private void addApacheKafkaClient(final Project project) { @@ -111,7 +158,9 @@ private void addDockerCompose(final Project project) { project.addDefaultConfig(BASE_NAME); project.addConfig("zookeeperDockerImage", zookeeperDockerImage); project.addConfig("kafkaDockerImage", kafkaDockerImage); - projectRepository.template(project, SOURCE, KAFKA_DOCKER_COMPOSE_FILE, MAIN_DOCKER, KAFKA_DOCKER_COMPOSE_FILE); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE, KAFKA_DOCKER_COMPOSE_FILE).withDestination(MAIN_DOCKER, KAFKA_DOCKER_COMPOSE_FILE) + ); } private void addProperties(final Project project) { @@ -141,7 +190,12 @@ private TreeMap getKafkaCommonProperties(final String kebabBaseN void addTestcontainers(final Project project) { final String packageNamePath = project.getPackageNamePath().orElse(getPath(DefaultConfig.PACKAGE_PATH)); - projectRepository.template(project, SOURCE, "KafkaTestContainerExtension.java", getPath(TEST_JAVA, packageNamePath)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "KafkaTestContainerExtension.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath)) + ); this.buildToolService.getVersion(project, "testcontainers") .ifPresentOrElse( version -> { diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/cache/common/domain/SpringBootCacheDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/cache/common/domain/SpringBootCacheDomainService.java index 0309382fb85..f1f988bb040 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/cache/common/domain/SpringBootCacheDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/cache/common/domain/SpringBootCacheDomainService.java @@ -1,12 +1,12 @@ package tech.jhipster.lite.generator.server.springboot.cache.common.domain; -import static tech.jhipster.lite.common.domain.FileUtils.getPath; -import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_JAVA; -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.common.domain.FileUtils.*; +import static tech.jhipster.lite.generator.project.domain.Constants.*; +import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*; import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; public class SpringBootCacheDomainService implements SpringBootCacheService { @@ -37,6 +37,11 @@ public void addEnableCaching(Project project) { } private void templateToCache(Project project, String source, String type, String sourceFilename, String destination) { - projectRepository.template(project, getPath(SOURCE, type), sourceFilename, getPath(destination, source, DESTINATION)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, type), sourceFilename) + .withDestinationFolder(getPath(destination, source, DESTINATION)) + ); } } diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/cache/ehcache/domain/EhcacheDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/cache/ehcache/domain/EhcacheDomainService.java index c066bdc13be..4878a671200 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/cache/ehcache/domain/EhcacheDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/cache/ehcache/domain/EhcacheDomainService.java @@ -1,11 +1,8 @@ package tech.jhipster.lite.generator.server.springboot.cache.ehcache.domain; -import static tech.jhipster.lite.common.domain.FileUtils.getPath; -import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_JAVA; -import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_RESOURCES; -import static tech.jhipster.lite.generator.project.domain.Constants.TEST_JAVA; -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.common.domain.FileUtils.*; +import static tech.jhipster.lite.generator.project.domain.Constants.*; +import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*; import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; import tech.jhipster.lite.generator.project.domain.Project; @@ -110,7 +107,12 @@ public void addJavaProperties(Project project) { } private void templateToEhcache(Project project, String source, String type, String sourceFilename, String destination) { - projectRepository.template(project, getPath(SOURCE, type), sourceFilename, getPath(destination, source, DESTINATION)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, type), sourceFilename) + .withDestinationFolder(getPath(destination, source, DESTINATION)) + ); } @Override diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/common/domain/SpringBootCommonDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/common/domain/SpringBootCommonDomainService.java index 17b90225a69..32b2c5cc23f 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/common/domain/SpringBootCommonDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/common/domain/SpringBootCommonDomainService.java @@ -1,30 +1,17 @@ package tech.jhipster.lite.generator.server.springboot.common.domain; -import static tech.jhipster.lite.common.domain.FileUtils.getPath; -import static tech.jhipster.lite.common.domain.WordUtils.LF; -import static tech.jhipster.lite.generator.project.domain.Constants.CONFIG; -import static tech.jhipster.lite.generator.project.domain.Constants.INTEGRATION_TEST; -import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_RESOURCES; -import static tech.jhipster.lite.generator.project.domain.Constants.TEST_JAVA; -import static tech.jhipster.lite.generator.project.domain.Constants.TEST_RESOURCES; -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.project.domain.DefaultConfig.PACKAGE_PATH; -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 static tech.jhipster.lite.generator.server.springboot.core.domain.SpringBoot.LOGGING_CONFIGURATION; -import static tech.jhipster.lite.generator.server.springboot.core.domain.SpringBoot.LOGGING_TEST_CONFIGURATION; -import static tech.jhipster.lite.generator.server.springboot.core.domain.SpringBoot.NEEDLE_APPLICATION_LOCAL_PROPERTIES; -import static tech.jhipster.lite.generator.server.springboot.core.domain.SpringBoot.NEEDLE_APPLICATION_PROPERTIES; -import static tech.jhipster.lite.generator.server.springboot.core.domain.SpringBoot.NEEDLE_APPLICATION_TEST_LOGGING_PROPERTIES; -import static tech.jhipster.lite.generator.server.springboot.core.domain.SpringBoot.NEEDLE_APPLICATION_TEST_PROPERTIES; -import static tech.jhipster.lite.generator.server.springboot.core.domain.SpringBoot.NEEDLE_LOGBACK_LOGGER; +import static tech.jhipster.lite.common.domain.FileUtils.*; +import static tech.jhipster.lite.common.domain.WordUtils.*; +import static tech.jhipster.lite.generator.project.domain.Constants.*; +import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*; +import static tech.jhipster.lite.generator.server.springboot.core.domain.SpringBoot.*; import java.util.Optional; import tech.jhipster.lite.common.domain.FileUtils; import tech.jhipster.lite.error.domain.Assert; import tech.jhipster.lite.generator.project.domain.DatabaseType; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; public class SpringBootCommonDomainService implements SpringBootCommonService { @@ -43,7 +30,12 @@ public void addTestLogbackRecorder(Project project) { project.addDefaultConfig(PACKAGE_NAME); project.addDefaultConfig(BASE_NAME); String packageNamePath = project.getPackageNamePath().orElse(getPath("com/mycompany/myapp")); - projectRepository.template(project, getPath(SOURCE, "test"), "LogbackRecorder.java", getPath(TEST_JAVA, packageNamePath)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, "test"), "LogbackRecorder.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath)) + ); } @Override @@ -221,8 +213,8 @@ public void updateIntegrationTestAnnotation(Project project, String className) { String oldAnnotation = "public @interface"; String newAnnotation = String.format(""" - @ExtendWith(%s.class) - public @interface""", className); + @ExtendWith(%s.class) + public @interface""", className); projectRepository.replaceText(project, integrationTestPath, INTEGRATION_TEST, oldAnnotation, newAnnotation); } diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootDomainService.java index 2c335b3d7da..9b2374efe35 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootDomainService.java @@ -1,15 +1,9 @@ package tech.jhipster.lite.generator.server.springboot.core.domain; -import static tech.jhipster.lite.common.domain.FileUtils.getPath; -import static tech.jhipster.lite.generator.project.domain.Constants.CONFIG; -import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_JAVA; -import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_RESOURCES; -import static tech.jhipster.lite.generator.project.domain.Constants.TEST_JAVA; -import static tech.jhipster.lite.generator.project.domain.Constants.TEST_RESOURCES; -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.LOGGING_CONFIGURATION; -import static tech.jhipster.lite.generator.server.springboot.core.domain.SpringBoot.LOGGING_TEST_CONFIGURATION; +import static tech.jhipster.lite.common.domain.FileUtils.*; +import static tech.jhipster.lite.generator.project.domain.Constants.*; +import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*; +import static tech.jhipster.lite.generator.server.springboot.core.domain.SpringBoot.*; import tech.jhipster.lite.common.domain.WordUtils; import tech.jhipster.lite.error.domain.GeneratorException; @@ -17,6 +11,7 @@ import tech.jhipster.lite.generator.buildtool.generic.domain.Dependency; import tech.jhipster.lite.generator.buildtool.generic.domain.Plugin; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; public class SpringBootDomainService implements SpringBootService { @@ -118,17 +113,17 @@ public void addSpringBootMavenPluginManagement(Project project) { private String springBootAdditionalElements() { return """ - - - - repackage - - - - - \\${start-class} - - """; + + + + repackage + + + + + \\${start-class} + + """; } @Override @@ -148,43 +143,71 @@ public void addMainApp(Project project) { String packageNamePath = project.getPackageNamePath().orElse("com/mycompany/myapp"); - projectRepository.template(project, SOURCE, "MainApp.java", getPath(MAIN_JAVA, packageNamePath), className + "App.java"); - projectRepository.template(project, SOURCE, "MainAppTest.java", getPath(TEST_JAVA, packageNamePath), className + "AppTest.java"); - projectRepository.template(project, SOURCE, "IntegrationTest.java", getPath(TEST_JAVA, packageNamePath)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "MainApp.java") + .withDestination(getPath(MAIN_JAVA, packageNamePath), className + "App.java") + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "MainAppTest.java") + .withDestination(getPath(TEST_JAVA, packageNamePath), className + "AppTest.java") + ); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE, "IntegrationTest.java").withDestinationFolder(getPath(TEST_JAVA, packageNamePath)) + ); } @Override public void addApplicationProperties(Project project) { project.addDefaultConfig(BASE_NAME); - projectRepository.template(project, SOURCE, "application.properties", getPath(MAIN_RESOURCES, CONFIG)); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE, "application.properties").withDestinationFolder(getPath(MAIN_RESOURCES, CONFIG)) + ); } @Override public void addApplicationLocalProperties(Project project) { project.addDefaultConfig(BASE_NAME); - projectRepository.template(project, SOURCE, "application-local.properties", getPath(MAIN_RESOURCES, CONFIG)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "application-local.properties") + .withDestinationFolder(getPath(MAIN_RESOURCES, CONFIG)) + ); } @Override public void addApplicationTestProperties(Project project) { project.addDefaultConfig(BASE_NAME); - projectRepository.template(project, SOURCE, "application-test.properties", getPath(TEST_RESOURCES, CONFIG), "application.properties"); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "application-test.properties") + .withDestination(getPath(TEST_RESOURCES, CONFIG), "application.properties") + ); } @Override public void addLoggingConfiguration(Project project) { project.addDefaultConfig(PACKAGE_NAME); - projectRepository.template(project, SOURCE, LOGGING_CONFIGURATION, getPath(MAIN_RESOURCES)); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE, LOGGING_CONFIGURATION).withDestinationFolder(getPath(MAIN_RESOURCES)) + ); } @Override public void addLoggingTestConfiguration(Project project) { project.addDefaultConfig(PACKAGE_NAME); - projectRepository.template(project, SOURCE, LOGGING_TEST_CONFIGURATION, getPath(TEST_RESOURCES)); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE, LOGGING_TEST_CONFIGURATION).withDestinationFolder(getPath(TEST_RESOURCES)) + ); } } diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/database/mongodb/domain/MongodbDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/database/mongodb/domain/MongodbDomainService.java index 5175e815b73..3db92fabc29 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/database/mongodb/domain/MongodbDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/database/mongodb/domain/MongodbDomainService.java @@ -16,6 +16,7 @@ import tech.jhipster.lite.generator.docker.domain.DockerService; import tech.jhipster.lite.generator.project.domain.DatabaseType; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.Level; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -93,19 +94,45 @@ public void addJavaFiles(Project project) { String packageNamePath = project.getPackageNamePath().orElse(getPath("com/mycompany/myapp")); String mongodbPath = "technical/infrastructure/secondary/mongodb"; - projectRepository.template(project, SOURCE, "MongodbDatabaseConfiguration.java", getPath(MAIN_JAVA, packageNamePath, mongodbPath)); - projectRepository.template(project, SOURCE, "JSR310DateConverters.java", getPath(MAIN_JAVA, packageNamePath, mongodbPath)); - - projectRepository.template(project, SOURCE, "JSR310DateConvertersTest.java", getPath(TEST_JAVA, packageNamePath, mongodbPath)); - projectRepository.template(project, SOURCE, "MongodbTestContainerExtension.java", getPath(TEST_JAVA, packageNamePath)); - projectRepository.template(project, SOURCE, "TestContainersSpringContextCustomizerFactory.java", getPath(TEST_JAVA, packageNamePath)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "MongodbDatabaseConfiguration.java") + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, mongodbPath)) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "JSR310DateConverters.java") + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, mongodbPath)) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "JSR310DateConvertersTest.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath, mongodbPath)) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "MongodbTestContainerExtension.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath)) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "TestContainersSpringContextCustomizerFactory.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath)) + ); } @Override public void addConfigurationFiles(Project project) { project.addDefaultConfig(BASE_NAME); - projectRepository.template(project, SOURCE, "spring.factories", getPath(TEST_RESOURCES, "META-INF")); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE, "spring.factories").withDestinationFolder(getPath(TEST_RESOURCES, "META-INF")) + ); } @Override diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/database/postgresql/domain/PostgresqlDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/database/postgresql/domain/PostgresqlDomainService.java index 7c16b650246..c3a7f1120a0 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/database/postgresql/domain/PostgresqlDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/database/postgresql/domain/PostgresqlDomainService.java @@ -16,6 +16,7 @@ import tech.jhipster.lite.generator.project.domain.DatabaseType; import tech.jhipster.lite.generator.project.domain.DefaultConfig; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.Level; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -100,8 +101,18 @@ public void addJavaFiles(Project project) { String packageNamePath = project.getPackageNamePath().orElse(getPath(DefaultConfig.PACKAGE_PATH)); String databasePath = "technical/infrastructure/secondary/postgresql"; - projectRepository.template(project, SOURCE, "FixedPostgreSQL10Dialect.java", getPath(MAIN_JAVA, packageNamePath, databasePath)); - projectRepository.template(project, SOURCE, "FixedPostgreSQL10DialectTest.java", getPath(TEST_JAVA, packageNamePath, databasePath)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "FixedPostgreSQL10Dialect.java") + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, databasePath)) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "FixedPostgreSQL10DialectTest.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath, databasePath)) + ); } @Override diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/database/sqlcommon/domain/SQLCommonDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/database/sqlcommon/domain/SQLCommonDomainService.java index 2a1a92c63e4..508b8494f81 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/database/sqlcommon/domain/SQLCommonDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/database/sqlcommon/domain/SQLCommonDomainService.java @@ -1,12 +1,9 @@ package tech.jhipster.lite.generator.server.springboot.database.sqlcommon.domain; -import static tech.jhipster.lite.common.domain.FileUtils.getPath; -import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_JAVA; -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.database.sqlcommon.domain.SQLCommon.getDatabasePath; -import static tech.jhipster.lite.generator.server.springboot.database.sqlcommon.domain.SQLCommon.getSource; -import static tech.jhipster.lite.generator.server.springboot.database.sqlcommon.domain.SQLCommon.testContainersDependency; +import static tech.jhipster.lite.common.domain.FileUtils.*; +import static tech.jhipster.lite.generator.project.domain.Constants.*; +import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*; +import static tech.jhipster.lite.generator.server.springboot.database.sqlcommon.domain.SQLCommon.*; import java.util.Map; import tech.jhipster.lite.error.domain.Assert; @@ -15,6 +12,7 @@ import tech.jhipster.lite.generator.buildtool.generic.domain.Dependency; import tech.jhipster.lite.generator.project.domain.DefaultConfig; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.Level; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -84,7 +82,9 @@ public void addDockerComposeTemplate(Project project, String database) { Assert.notBlank("database", database); final String ymlFileName = database + ".yml"; - projectRepository.template(project, getSource(database), ymlFileName, "src/main/docker", ymlFileName); + projectRepository.template( + ProjectFile.forProject(project).withSource(getSource(database), ymlFileName).withDestination("src/main/docker", ymlFileName) + ); } @Override @@ -97,10 +97,10 @@ public void addJavaFiles(Project project, String database) { String databasePath = getDatabasePath(database); projectRepository.template( - project, - getSource(database), - "DatabaseConfiguration.java", - getPath(MAIN_JAVA, packageNamePath, databasePath) + ProjectFile + .forProject(project) + .withSource(getSource(database), "DatabaseConfiguration.java") + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, databasePath)) ); } diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/dbmigration/liquibase/domain/LiquibaseDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/dbmigration/liquibase/domain/LiquibaseDomainService.java index 20891f94f24..b8d8522925c 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/dbmigration/liquibase/domain/LiquibaseDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/dbmigration/liquibase/domain/LiquibaseDomainService.java @@ -1,15 +1,10 @@ package tech.jhipster.lite.generator.server.springboot.dbmigration.liquibase.domain; -import static tech.jhipster.lite.common.domain.FileUtils.getPath; -import static tech.jhipster.lite.common.domain.WordUtils.LF; -import static tech.jhipster.lite.common.domain.WordUtils.indent; -import static tech.jhipster.lite.generator.project.domain.Constants.LIQUIBASE_MASTER_XML; -import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_JAVA; -import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_RESOURCES; -import static tech.jhipster.lite.generator.project.domain.Constants.TEST_JAVA; -import static tech.jhipster.lite.generator.project.domain.DefaultConfig.PACKAGE_NAME; -import static tech.jhipster.lite.generator.project.domain.DefaultConfig.PRETTIER_DEFAULT_INDENT; -import static tech.jhipster.lite.generator.server.springboot.dbmigration.liquibase.domain.Liquibase.NEEDLE_LIQUIBASE; +import static tech.jhipster.lite.common.domain.FileUtils.*; +import static tech.jhipster.lite.common.domain.WordUtils.*; +import static tech.jhipster.lite.generator.project.domain.Constants.*; +import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*; +import static tech.jhipster.lite.generator.server.springboot.dbmigration.liquibase.domain.Liquibase.*; import java.time.Clock; import tech.jhipster.lite.common.domain.TimeUtils; @@ -123,7 +118,12 @@ public void addLogger(Project project, String packageName, Level level) { } private void templateToLiquibase(Project project, String source, String type, String sourceFilename, String destination) { - projectRepository.template(project, getPath(SOURCE, type), sourceFilename, getPath(destination, source, LIQUIBASE_PATH)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, type), sourceFilename) + .withDestinationFolder(getPath(destination, source, LIQUIBASE_PATH)) + ); } @Override @@ -138,11 +138,10 @@ private void addSqlSequenceUserChangelog(Project project) { String sequenceUserChangelog = TimeUtils.getDateString(clock) + "_added_sequence_User.xml"; addChangelogXml(project, "", sequenceUserChangelog); projectRepository.template( - project, - getUserResourcePath(), - "sequence_user.xml", - getPath(MAIN_RESOURCES, CHANGELOG), - sequenceUserChangelog + ProjectFile + .forProject(project) + .withSource(getUserResourcePath(), "sequence_user.xml") + .withDestination(getPath(MAIN_RESOURCES, CHANGELOG), sequenceUserChangelog) ); } } @@ -154,7 +153,12 @@ private void addSqlUserChangelog(Project project) { if (springBootCommonService.isSetWithMySQLOrMariaDBDatabase(project)) { userXmlFile = "user_with_autoincrement.xml"; } - projectRepository.template(project, getUserResourcePath(), userXmlFile, getPath(MAIN_RESOURCES, CHANGELOG), userChangelog); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getUserResourcePath(), userXmlFile) + .withDestination(getPath(MAIN_RESOURCES, CHANGELOG), userChangelog) + ); projectRepository.add( ProjectFile.forProject(project).withSource(getUserResourcePath(), "user.csv").withDestinationFolder(getPath(MAIN_RESOURCES, DATA)) @@ -167,7 +171,12 @@ private void addSqlUserAuthorityChangelog(Project project) { addChangelogXml(project, "", authorityChangelog); // Copy liquibase files - projectRepository.template(project, getUserResourcePath(), "authority.xml", getPath(MAIN_RESOURCES, CHANGELOG), authorityChangelog); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getUserResourcePath(), "authority.xml") + .withDestination(getPath(MAIN_RESOURCES, CHANGELOG), authorityChangelog) + ); projectRepository.add( ProjectFile .forProject(project) diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/dbmigration/mongock/domain/MongockDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/dbmigration/mongock/domain/MongockDomainService.java index b52156bc59d..8f5a175fc42 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/dbmigration/mongock/domain/MongockDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/dbmigration/mongock/domain/MongockDomainService.java @@ -12,6 +12,7 @@ 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.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -79,10 +80,10 @@ public void addConfigurationJava(Project project) { String packageNamePath = project.getPackageNamePath().orElse(PACKAGE_PATH); String mongockConfigPath = TECHNICAL_INFRASTRUCTURE_SECONDARY + "/mongock"; projectRepository.template( - project, - SOURCE, - "MongockDatabaseConfiguration.java", - getPath(MAIN_JAVA, packageNamePath, mongockConfigPath) + ProjectFile + .forProject(project) + .withSource(SOURCE, "MongockDatabaseConfiguration.java") + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, mongockConfigPath)) ); } @@ -92,12 +93,17 @@ public void addChangelogJava(Project project) { String packageNamePath = project.getPackageNamePath().orElse(PACKAGE_PATH); String mongockDBMigrationPath = TECHNICAL_INFRASTRUCTURE_SECONDARY + "/mongock/dbmigration"; - projectRepository.template(project, SOURCE, "InitialMigrationSetup.java", getPath(MAIN_JAVA, packageNamePath, mongockDBMigrationPath)); projectRepository.template( - project, - SOURCE, - "InitialMigrationSetupTest.java", - getPath(TEST_JAVA, packageNamePath, mongockDBMigrationPath) + ProjectFile + .forProject(project) + .withSource(SOURCE, "InitialMigrationSetup.java") + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, mongockDBMigrationPath)) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "InitialMigrationSetupTest.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath, mongockDBMigrationPath)) ); } diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/docker/domain/SpringBootDockerDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/docker/domain/SpringBootDockerDomainService.java index 4e6ecfaca3a..5dec6c90ee7 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/docker/domain/SpringBootDockerDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/docker/domain/SpringBootDockerDomainService.java @@ -9,6 +9,7 @@ import tech.jhipster.lite.generator.buildtool.generic.domain.Plugin; import tech.jhipster.lite.generator.project.domain.DefaultConfig; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; public class SpringBootDockerDomainService implements SpringBootDockerService { @@ -36,7 +37,9 @@ public void addJibFiles(Project project) { String packageName = project.getPackageName().orElse(DefaultConfig.DEFAULT_PACKAGE_NAME); String className = WordUtils.upperFirst(baseName); project.addConfig("mainClass", packageName + "." + className + "App"); - projectRepository.template(project, getPath(JIB_SOURCE), "entrypoint.sh", getPath("src/main/docker/jib")); + projectRepository.template( + ProjectFile.forProject(project).withSource(getPath(JIB_SOURCE), "entrypoint.sh").withDestinationFolder(getPath("src/main/docker/jib")) + ); } @Override @@ -108,6 +111,6 @@ public void addJibPlugin(Project project) { @Override public void addDockerfile(Project project) { project.addConfig("serverPort", 8080); - projectRepository.template(project, DOCKER_SOURCE, DOCKERFILE); + projectRepository.template(ProjectFile.forProject(project).withSource(DOCKER_SOURCE, DOCKERFILE).withSameDestination()); } } diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/logging/aop/domain/AopLoggingDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/logging/aop/domain/AopLoggingDomainService.java index e897810a6e0..2f044d06bca 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/logging/aop/domain/AopLoggingDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/logging/aop/domain/AopLoggingDomainService.java @@ -9,6 +9,7 @@ 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.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -67,8 +68,23 @@ public void addJavaFiles(Project project) { String packageNamePath = project.getPackageNamePath().orElse(getPath("com/mycompany/myapp")); String aopLoggingPath = "technical/infrastructure/secondary/aop/logging"; - projectRepository.template(project, SOURCE, "LoggingAspectConfiguration.java", getPath(MAIN_JAVA, packageNamePath, aopLoggingPath)); - projectRepository.template(project, SOURCE, "LoggingAspect.java", getPath(MAIN_JAVA, packageNamePath, aopLoggingPath)); - projectRepository.template(project, SOURCE, "LoggingAspectTest.java", getPath(TEST_JAVA, packageNamePath, aopLoggingPath)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "LoggingAspectConfiguration.java") + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, aopLoggingPath)) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "LoggingAspect.java") + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, aopLoggingPath)) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "LoggingAspectTest.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath, aopLoggingPath)) + ); } } diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/logging/logstash/domain/LogstashDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/logging/logstash/domain/LogstashDomainService.java index f9006d6240e..6812473aec2 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/logging/logstash/domain/LogstashDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/logging/logstash/domain/LogstashDomainService.java @@ -11,6 +11,7 @@ import tech.jhipster.lite.error.domain.GeneratorException; import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.Level; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -92,7 +93,12 @@ private Map properties() { } private void templateToLogstash(Project project, String source, String type, String sourceFilename, String destination) { - projectRepository.template(project, getPath(SOURCE, type), sourceFilename, getPath(destination, source, DESTINATION)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, type), sourceFilename) + .withDestinationFolder(getPath(destination, source, DESTINATION)) + ); } @Override diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/dummy/domain/DummyDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/dummy/domain/DummyDomainService.java index afab1edb966..570f7fa870a 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/dummy/domain/DummyDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/dummy/domain/DummyDomainService.java @@ -4,6 +4,7 @@ import tech.jhipster.lite.common.domain.FileUtils; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; public class DummyDomainService implements DummyService { @@ -24,7 +25,7 @@ public void applyDummyGitPatch(Project project) { project.addConfig("packagePath", packagePath); projectRepository.gitInit(project); - projectRepository.template(project, SOURCE, PATCH, ".jhipster"); + projectRepository.template(ProjectFile.forProject(project).withSource(SOURCE, PATCH).withDestinationFolder(".jhipster")); projectRepository.gitApplyPatch(project, FileUtils.getPath(project.getFolder(), ".jhipster", PATCH)); } } diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/security/jwt/domain/JwtSecurityDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/security/jwt/domain/JwtSecurityDomainService.java index c2a24155d0e..5ec162509cf 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/security/jwt/domain/JwtSecurityDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/security/jwt/domain/JwtSecurityDomainService.java @@ -14,10 +14,12 @@ import static tech.jhipster.lite.generator.server.springboot.mvc.security.jwt.domain.JwtSecurity.springSecurityTestDependency; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import tech.jhipster.lite.error.domain.GeneratorException; import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.Level; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -100,28 +102,61 @@ private void addJavaFiles(Project project) { String destinationSrc = getPath(MAIN_JAVA, packageNamePath, SECURITY_JWT_PATH); String destinationTest = getPath(TEST_JAVA, packageNamePath, SECURITY_JWT_PATH); - jwtSecurityFiles() - .forEach((javaFile, destination) -> projectRepository.template(project, sourceSrc, javaFile, getPath(destinationSrc, destination))); - - jwtTestSecurityFiles() - .forEach((javaFile, destination) -> projectRepository.template(project, sourceTest, javaFile, getPath(destinationTest, destination))); + List sourceFiles = jwtSecurityFiles() + .entrySet() + .stream() + .map(entry -> + ProjectFile + .forProject(project) + .withSource(sourceSrc, entry.getKey()) + .withDestinationFolder(getPath(destinationSrc, entry.getValue())) + ) + .toList(); + projectRepository.template(sourceFiles); + + List testFiles = jwtTestSecurityFiles() + .entrySet() + .stream() + .map(entry -> + ProjectFile + .forProject(project) + .withSource(sourceTest, entry.getKey()) + .withDestinationFolder(getPath(destinationTest, entry.getValue())) + ) + .toList(); + projectRepository.template(testFiles); } private void addBasicAuthJavaFiles(Project project) { project.addDefaultConfig(PACKAGE_NAME); String sourceSrc = getPath(SOURCE, "src/account"); - String sourceTest = getPath(SOURCE, "test/account"); - String packageNamePath = project.getPackageNamePath().orElse(getPath(PACKAGE_PATH)); String destinationSrc = getPath(MAIN_JAVA, packageNamePath, "account/infrastructure/primary/rest"); - String destinationTest = getPath(TEST_JAVA, packageNamePath, "account/infrastructure/primary/rest"); - projectRepository.template(project, sourceSrc, "AuthenticationResource.java", getPath(destinationSrc)); - projectRepository.template(project, sourceSrc, "AccountResource.java", getPath(destinationSrc)); - projectRepository.template(project, sourceSrc, "LoginDTO.java", getPath(destinationSrc)); - projectRepository.template(project, sourceTest, "AuthenticationResourceIT.java", getPath(destinationTest)); - projectRepository.template(project, sourceTest, "AccountResourceIT.java", getPath(destinationTest)); - projectRepository.template(project, sourceTest, "LoginDTOTest.java", getPath(destinationTest)); + projectRepository.template( + ProjectFile.forProject(project).withSource(sourceSrc, "AuthenticationResource.java").withDestinationFolder(destinationSrc) + ); + projectRepository.template( + ProjectFile.forProject(project).withSource(sourceSrc, "AccountResource.java").withDestinationFolder(destinationSrc) + ); + projectRepository.template( + ProjectFile.forProject(project).withSource(sourceSrc, "LoginDTO.java").withDestinationFolder(destinationSrc) + ); + + String sourceTest = getPath(SOURCE, "test/account"); + String destinationTest = getPath(TEST_JAVA, packageNamePath, "account/infrastructure/primary/rest"); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(sourceTest, "AuthenticationResourceIT.java") + .withDestinationFolder(getPath(destinationTest)) + ); + projectRepository.template( + ProjectFile.forProject(project).withSource(sourceTest, "AccountResourceIT.java").withDestinationFolder(getPath(destinationTest)) + ); + projectRepository.template( + ProjectFile.forProject(project).withSource(sourceTest, "LoginDTOTest.java").withDestinationFolder(getPath(destinationTest)) + ); } private void addBasicAuthProperties(Project project) { diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/security/oauth2/domain/OAuth2SecurityDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/security/oauth2/domain/OAuth2SecurityDomainService.java index 4c51391d5fc..988cd02e4e6 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/security/oauth2/domain/OAuth2SecurityDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/security/oauth2/domain/OAuth2SecurityDomainService.java @@ -22,11 +22,13 @@ import static tech.jhipster.lite.generator.server.springboot.mvc.security.oauth2.domain.OAuth2Security.springBootStarterSecurityDependency; import static tech.jhipster.lite.generator.server.springboot.mvc.security.oauth2.domain.OAuth2Security.springSecurityTestDependency; +import java.util.List; import tech.jhipster.lite.common.domain.WordUtils; import tech.jhipster.lite.error.domain.GeneratorException; import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; import tech.jhipster.lite.generator.docker.domain.DockerService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; import tech.jhipster.lite.generator.server.springboot.mvc.security.common.domain.CommonSecurityService; @@ -93,9 +95,21 @@ private void addKeycloakDocker(Project project) { String dockerSourcePath = getPath(SOURCE, "docker"); String dockerPathRealm = getPath(MAIN_DOCKER, "keycloak-realm-config"); - projectRepository.template(project, dockerSourcePath, "keycloak.yml", MAIN_DOCKER, "keycloak.yml"); - projectRepository.template(project, dockerSourcePath, "jhipster-realm.json", dockerPathRealm, "jhipster-realm.json"); - projectRepository.template(project, dockerSourcePath, "jhipster-users-0.json", dockerPathRealm, "jhipster-users-0.json"); + projectRepository.template( + ProjectFile.forProject(project).withSource(dockerSourcePath, "keycloak.yml").withDestination(MAIN_DOCKER, "keycloak.yml") + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(dockerSourcePath, "jhipster-realm.json") + .withDestination(dockerPathRealm, "jhipster-realm.json") + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(dockerSourcePath, "jhipster-users-0.json") + .withDestination(dockerPathRealm, "jhipster-users-0.json") + ); } private void addJavaFiles(Project project) { @@ -104,17 +118,32 @@ private void addJavaFiles(Project project) { String sourceSrc = getPath(SOURCE, "src"); String destinationSrc = getPath(MAIN_JAVA, packageNamePath); - oauth2SecurityFiles() - .forEach((javaFile, folder) -> - projectRepository.template(project, getPath(sourceSrc, folder), javaFile, getPath(destinationSrc, folder)) - ); + + List soureFiles = oauth2SecurityFiles() + .entrySet() + .stream() + .map(entry -> + ProjectFile + .forProject(project) + .withSource(getPath(sourceSrc, entry.getValue()), entry.getKey()) + .withDestinationFolder(getPath(destinationSrc, entry.getValue())) + ) + .toList(); + projectRepository.template(soureFiles); String sourceTest = getPath(SOURCE, "test"); String destinationTest = getPath(TEST_JAVA, packageNamePath); - oauth2TestSecurityFiles() - .forEach((javaFile, folder) -> - projectRepository.template(project, getPath(sourceTest, folder), javaFile, getPath(destinationTest, folder)) - ); + List testFiles = oauth2TestSecurityFiles() + .entrySet() + .stream() + .map(entry -> + ProjectFile + .forProject(project) + .withSource(getPath(sourceTest, entry.getValue()), entry.getKey()) + .withDestinationFolder(getPath(destinationTest, entry.getValue())) + ) + .toList(); + projectRepository.template(testFiles); } @Override @@ -124,13 +153,33 @@ public void addAccountContext(Project project) { String sourceSrc = getPath(SOURCE, "src"); String destinationSrc = getPath(MAIN_JAVA, packageNamePath); - oauth2AccountContextFiles() - .forEach((file, folder) -> projectRepository.template(project, getPath(sourceSrc, folder), file, getPath(destinationSrc, folder))); + + List sourceFiles = oauth2AccountContextFiles() + .entrySet() + .stream() + .map(entry -> + ProjectFile + .forProject(project) + .withSource(getPath(sourceSrc, entry.getValue()), entry.getKey()) + .withDestinationFolder(getPath(destinationSrc, entry.getValue())) + ) + .toList(); + projectRepository.template(sourceFiles); String sourceTest = getPath(SOURCE, "test"); String destinationTest = getPath(TEST_JAVA, packageNamePath); - oauth2AccountContextTestFiles() - .forEach((file, folder) -> projectRepository.template(project, getPath(sourceTest, folder), file, getPath(destinationTest, folder))); + + List testFiles = oauth2AccountContextTestFiles() + .entrySet() + .stream() + .map(entry -> + ProjectFile + .forProject(project) + .withSource(getPath(sourceTest, entry.getValue()), entry.getKey()) + .withDestinationFolder(getPath(destinationTest, entry.getValue())) + ) + .toList(); + projectRepository.template(testFiles); } private void addSpringBootProperties(Project project) { @@ -160,8 +209,8 @@ private void updateExceptionTranslatorWithAccountExceptionHandler(Project projec String oldImport = "import org.zalando.problem.violations.ConstraintViolationProblem;"; String newImport = String.format( """ - import org.zalando.problem.violations.ConstraintViolationProblem; - import %s.error.domain.AccountException;""", + import org.zalando.problem.violations.ConstraintViolationProblem; + import %s.error.domain.AccountException;""", packageName ); projectRepository.replaceText(project, exceptionTranslatorPath, exceptionTranslatorFile, oldImport, newImport); @@ -169,13 +218,13 @@ private void updateExceptionTranslatorWithAccountExceptionHandler(Project projec String oldNeedle = "// jhipster-needle-exception-translator"; String newNeedle = """ - @ExceptionHandler - public ResponseEntity handleAccountException(AccountException ex, NativeWebRequest request) { - Problem problem = Problem.builder().withStatus(Status.UNAUTHORIZED).withTitle(ex.getMessage()).build(); - return create(ex, problem, request); - } + @ExceptionHandler + public ResponseEntity handleAccountException(AccountException ex, NativeWebRequest request) { + Problem problem = Problem.builder().withStatus(Status.UNAUTHORIZED).withTitle(ex.getMessage()).build(); + return create(ex, problem, request); + } - // jhipster-needle-exception-translator"""; + // jhipster-needle-exception-translator"""; projectRepository.replaceText(project, exceptionTranslatorPath, exceptionTranslatorFile, oldNeedle, newNeedle); } @@ -188,8 +237,8 @@ private void updateExceptionTranslatorTestController(Project project) { String oldImport = "import org.springframework.http.converter.HttpMessageConversionException;"; String newImport = String.format( """ - import org.springframework.http.converter.HttpMessageConversionException; - import %s.error.domain.AccountException;""", + import org.springframework.http.converter.HttpMessageConversionException; + import %s.error.domain.AccountException;""", packageName ); projectRepository.replaceText(project, exceptionTranslatorPath, fileToReplace, oldImport, newImport); @@ -197,12 +246,12 @@ private void updateExceptionTranslatorTestController(Project project) { String oldNeedle = "// jhipster-needle-exception-translator-test-controller"; String newNeedle = """ - @GetMapping("/account-exception") - public void accountException() { - throw new AccountException("beer"); - } + @GetMapping("/account-exception") + public void accountException() { + throw new AccountException("beer"); + } - // jhipster-needle-exception-translator-test-controller"""; + // jhipster-needle-exception-translator-test-controller"""; projectRepository.replaceText(project, exceptionTranslatorPath, fileToReplace, oldNeedle, newNeedle); } diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringdocDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringdocDomainService.java index 58b9c19ae71..d74be4be73f 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringdocDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringdocDomainService.java @@ -1,23 +1,9 @@ package tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain; -import static tech.jhipster.lite.common.domain.FileUtils.getPath; -import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_JAVA; -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.mvc.springdoc.domain.SpringdocConstants.API_DESCRIPTION_CONFIG_KEY; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.API_EXT_DOC_DESCRIPTION_CONFIG_KEY; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.API_EXT_DOC_URL_CONFIG_KEY; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.API_LICENSE_NAME_CONFIG_KEY; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.API_LICENSE_URL_CONFIG_KEY; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.API_TITLE_CONFIG_KEY; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.DEFAULT_API_DESCRIPTION; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.DEFAULT_API_TITLE; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.DEFAULT_EXT_DOC_DESCRIPTION; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.DEFAULT_EXT_DOC_URL; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.DEFAULT_LICENSE_NAME; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.DEFAULT_LICENSE_URL; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.DEFAULT_SWAGGER_UI_SORT_VALUE; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.DEFAULT_TRY_OUT_ENABLED; +import static tech.jhipster.lite.common.domain.FileUtils.*; +import static tech.jhipster.lite.generator.project.domain.Constants.*; +import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*; +import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.*; import java.util.HashMap; import java.util.Map; @@ -26,6 +12,7 @@ import tech.jhipster.lite.error.domain.GeneratorException; import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -81,10 +68,10 @@ public void addJavaFiles(Project project) { addDefaultParameters(project); String packageNamePath = project.getPackageNamePath().orElse(getPath("com/mycompany/myapp")); projectRepository.template( - project, - getPath(SOURCE, "src"), - "SpringdocConfiguration.java", - getPath(MAIN_JAVA, packageNamePath, DESTINATION) + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, "src"), "SpringdocConfiguration.java") + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, DESTINATION)) ); } @@ -92,11 +79,10 @@ private void addJavaFilesWithSecurityJWT(Project project) { addDefaultParameters(project); String packageNamePath = project.getPackageNamePath().orElse(getPath("com/mycompany/myapp")); projectRepository.template( - project, - getPath(SOURCE, "src"), - "SpringdocConfigurationSecurityJWT.java", - getPath(MAIN_JAVA, packageNamePath, DESTINATION), - "SpringdocConfiguration.java" + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, "src"), "SpringdocConfigurationSecurityJWT.java") + .withDestination(getPath(MAIN_JAVA, packageNamePath, DESTINATION), "SpringdocConfiguration.java") ); } diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/web/domain/SpringBootMvcDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/web/domain/SpringBootMvcDomainService.java index 55309b92374..ca9d0b4b1a7 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/web/domain/SpringBootMvcDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/web/domain/SpringBootMvcDomainService.java @@ -22,6 +22,7 @@ import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; import tech.jhipster.lite.generator.project.domain.DefaultConfig; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.Level; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -128,15 +129,20 @@ public void addExceptionHandler(Project project) { templateToExceptionHandler(project, packageNamePath, "test", "FieldErrorDTOTest.java", TEST_JAVA); templateToExceptionHandler(project, packageNamePath, "test", "HeaderUtilTest.java", TEST_JAVA); - projectRepository.template(project, getPath(SOURCE, "test"), "TestUtil.java", getPath(TEST_JAVA, packageNamePath)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, "test"), "TestUtil.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath)) + ); } private void templateToExceptionHandler(Project project, String source, String type, String sourceFilename, String destination) { projectRepository.template( - project, - getPath(SOURCE, type), - sourceFilename, - getPath(destination, source, TECHNICAL_INFRASTRUCTURE_PRIMARY_EXCEPTION) + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, type), sourceFilename) + .withDestinationFolder(getPath(destination, source, TECHNICAL_INFRASTRUCTURE_PRIMARY_EXCEPTION)) ); } @@ -156,21 +162,24 @@ private void addLoggerInConfiguration(Project project, String packageName, Level private void addCorsFiles(Project project) { String packageNamePath = project.getPackageNamePath().orElse(getPath(PACKAGE_PATH)); - corsFiles() - .forEach((javaFile, destination) -> - projectRepository.template( - project, - getPath(SOURCE, "src", CORS), - javaFile, - getPath(MAIN_JAVA, packageNamePath, TECHNICAL_INFRASTRUCTURE_PRIMARY_CORS) - ) - ); + + List files = corsFiles() + .entrySet() + .stream() + .map(entry -> + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, "src", CORS), entry.getKey()) + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, TECHNICAL_INFRASTRUCTURE_PRIMARY_CORS)) + ) + .toList(); + projectRepository.template(files); projectRepository.template( - project, - getPath(SOURCE, "test", CORS), - "CorsFilterConfigurationIT.java", - getPath(TEST_JAVA, packageNamePath, TECHNICAL_INFRASTRUCTURE_PRIMARY_CORS) + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, "test", CORS), "CorsFilterConfigurationIT.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath, TECHNICAL_INFRASTRUCTURE_PRIMARY_CORS)) ); } diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/springcloud/common/domain/SpringCloudCommonDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/springcloud/common/domain/SpringCloudCommonDomainService.java index 0f35fcd318d..ec1b518b9a3 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/springcloud/common/domain/SpringCloudCommonDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/springcloud/common/domain/SpringCloudCommonDomainService.java @@ -16,6 +16,7 @@ import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; import tech.jhipster.lite.generator.docker.domain.DockerService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; public class SpringCloudCommonDomainService implements SpringCloudCommonService { @@ -63,18 +64,16 @@ public void addJhipsterRegistryDockerCompose(Project project) { project.addConfig("base64JwtSecret", Base64Utils.getBase64Secret()); projectRepository.template( - project, - SPRING_CLOUD_SOURCE, - JHIPSTER_REGISTRY_YML_FILE_NAME, - "src/main/docker", - JHIPSTER_REGISTRY_YML_FILE_NAME + ProjectFile + .forProject(project) + .withSource(SPRING_CLOUD_SOURCE, JHIPSTER_REGISTRY_YML_FILE_NAME) + .withDestination("src/main/docker", JHIPSTER_REGISTRY_YML_FILE_NAME) ); projectRepository.template( - project, - SPRING_CLOUD_SOURCE, - "application.config.properties", - "src/main/docker/central-server-config/localhost-config", - "application.properties" + ProjectFile + .forProject(project) + .withSource(SPRING_CLOUD_SOURCE, "application.config.properties") + .withDestination("src/main/docker/central-server-config/localhost-config", "application.properties") ); } @@ -89,7 +88,9 @@ public void addOrMergeBootstrapProperties(Project project, String sourceFolderPa } private void createFile(Project project, String sourceFolderPath, String sourceFileName, String destinationFileFolder) { - projectRepository.template(project, sourceFolderPath, sourceFileName, destinationFileFolder); + projectRepository.template( + ProjectFile.forProject(project).withSource(sourceFolderPath, sourceFileName).withDestinationFolder(destinationFileFolder) + ); } private void mergeContentFile(Project project, String sourceFolderPath, String sourceFileName, String destinationFilePath) { diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/springcloud/consul/domain/ConsulDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/springcloud/consul/domain/ConsulDomainService.java index 91e52943036..cee3788bbfc 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/springcloud/consul/domain/ConsulDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/springcloud/consul/domain/ConsulDomainService.java @@ -1,22 +1,16 @@ package tech.jhipster.lite.generator.server.springboot.springcloud.consul.domain; -import static tech.jhipster.lite.common.domain.FileUtils.getPath; -import static tech.jhipster.lite.generator.project.domain.Constants.CONFIG; -import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_RESOURCES; -import static tech.jhipster.lite.generator.project.domain.Constants.TEST_RESOURCES; -import static tech.jhipster.lite.generator.project.domain.DefaultConfig.BASE_NAME; -import static tech.jhipster.lite.generator.server.springboot.springcloud.consul.domain.Consul.BOOTSTRAP_LOCAL_PROPERTIES; -import static tech.jhipster.lite.generator.server.springboot.springcloud.consul.domain.Consul.BOOTSTRAP_PROPERTIES; -import static tech.jhipster.lite.generator.server.springboot.springcloud.consul.domain.Consul.getDockerConsulConfigLoaderImageName; -import static tech.jhipster.lite.generator.server.springboot.springcloud.consul.domain.Consul.getDockerConsulImageName; -import static tech.jhipster.lite.generator.server.springboot.springcloud.consul.domain.Consul.springCloudConsulConfigDependency; -import static tech.jhipster.lite.generator.server.springboot.springcloud.consul.domain.Consul.springCloudConsulDiscoveryDependency; +import static tech.jhipster.lite.common.domain.FileUtils.*; +import static tech.jhipster.lite.generator.project.domain.Constants.*; +import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*; +import static tech.jhipster.lite.generator.server.springboot.springcloud.consul.domain.Consul.*; import tech.jhipster.lite.common.domain.Base64Utils; import tech.jhipster.lite.error.domain.GeneratorException; import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; import tech.jhipster.lite.generator.docker.domain.DockerService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.springcloud.common.domain.SpringCloudCommonService; @@ -102,15 +96,16 @@ public void addDockerConsul(Project project) { project.addConfig("dockerConsulImage", consulImage); project.addConfig("dockerConsulConfigLoaderImage", consulConfigLoaderImage); - projectRepository.template(project, getPath(SOURCE, "src"), "consul.yml", "src/main/docker", "consul.yml"); + projectRepository.template( + ProjectFile.forProject(project).withSource(getPath(SOURCE, "src"), "consul.yml").withDestination("src/main/docker", "consul.yml") + ); project.addConfig("base64JwtSecret", Base64Utils.getBase64Secret()); projectRepository.template( - project, - getPath(SOURCE, "docker"), - "application.config.yml", - "src/main/docker/central-server-config/", - "application.yml" + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, "docker"), "application.config.yml") + .withDestination("src/main/docker/central-server-config/", "application.yml") ); } } diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/springcloud/gateway/domain/GatewayDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/springcloud/gateway/domain/GatewayDomainService.java index c1416d459a1..a1642d43ac8 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/springcloud/gateway/domain/GatewayDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/springcloud/gateway/domain/GatewayDomainService.java @@ -13,6 +13,7 @@ import tech.jhipster.lite.error.domain.GeneratorException; import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.springcloud.common.domain.SpringCloudCommonService; @@ -84,13 +85,24 @@ public void addJavaFiles(Project project) { String packageNamePath = project.getPackageNamePath().orElse(getPath("com/mycompany/myapp")); String resourcePath = "technical/infrastructure/primary/rest"; - projectRepository.template(project, getPath(SOURCE, "java"), "GatewayResource.java", getPath(MAIN_JAVA, packageNamePath, resourcePath)); - projectRepository.template(project, getPath(SOURCE, "java"), "RouteVM.java", getPath(MAIN_JAVA, packageNamePath, resourcePath + "/vm")); projectRepository.template( - project, - getPath(SOURCE, "java/test"), - "GatewayResourceIT.java", - getPath(TEST_JAVA, packageNamePath, resourcePath) + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, "java"), "GatewayResource.java") + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, resourcePath)) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, "java"), "RouteVM.java") + .withDestinationFolder(getPath(MAIN_JAVA, packageNamePath, resourcePath + "/vm")) + ); + + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, "java/test"), "GatewayResourceIT.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath, resourcePath)) ); } } diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/user/domain/SpringBootUserDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/user/domain/SpringBootUserDomainService.java index e37ebb1fa86..1191275f0e3 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/user/domain/SpringBootUserDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/user/domain/SpringBootUserDomainService.java @@ -1,15 +1,12 @@ package tech.jhipster.lite.generator.server.springboot.user.domain; -import static tech.jhipster.lite.common.domain.FileUtils.getPath; -import static tech.jhipster.lite.generator.project.domain.Constants.DOMAIN; -import static tech.jhipster.lite.generator.project.domain.Constants.INFRASTRUCTURE_SECONDARY; -import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_JAVA; -import static tech.jhipster.lite.generator.project.domain.Constants.TEST_JAVA; -import static tech.jhipster.lite.generator.project.domain.DefaultConfig.PACKAGE_NAME; -import static tech.jhipster.lite.generator.project.domain.DefaultConfig.PACKAGE_PATH; +import static tech.jhipster.lite.common.domain.FileUtils.*; +import static tech.jhipster.lite.generator.project.domain.Constants.*; +import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*; import tech.jhipster.lite.generator.project.domain.DatabaseType; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; public class SpringBootUserDomainService implements SpringBootUserService { @@ -40,20 +37,41 @@ private void addUserEntity(Project project, DatabaseType sqlDatabase) { if (isDatabaseWhichNoNeedsSequenceStrategy(sqlDatabase)) { projectRepository.template( - project, - SOURCE, - "UserEntity_without_sequence.java", - getSqlJavaPath(packageNamePath, sqlDatabase), - "UserEntity.java" + ProjectFile + .forProject(project) + .withSource(SOURCE, "UserEntity_without_sequence.java") + .withDestination(getSqlJavaPath(packageNamePath, sqlDatabase), "UserEntity.java") ); } else { - projectRepository.template(project, SOURCE, "UserEntity.java", getSqlJavaPath(packageNamePath, sqlDatabase)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "UserEntity.java") + .withDestinationFolder(getSqlJavaPath(packageNamePath, sqlDatabase)) + ); } - projectRepository.template(project, SOURCE, "UserJpaRepository.java", getSqlJavaPath(packageNamePath, sqlDatabase)); - projectRepository.template(project, SOURCE, "UserConstants.java", getSqlDomainJavaPath(packageNamePath)); - - projectRepository.template(project, SOURCE, "UserEntityTest.java", getSqlJavaTestPath(packageNamePath, sqlDatabase)); - projectRepository.template(project, SOURCE, "UserJpaRepositoryIT.java", getSqlJavaTestPath(packageNamePath, sqlDatabase)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "UserJpaRepository.java") + .withDestinationFolder(getSqlJavaPath(packageNamePath, sqlDatabase)) + ); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE, "UserConstants.java").withDestinationFolder(getSqlDomainJavaPath(packageNamePath)) + ); + + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "UserEntityTest.java") + .withDestinationFolder(getSqlJavaTestPath(packageNamePath, sqlDatabase)) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "UserJpaRepositoryIT.java") + .withDestinationFolder(getSqlJavaTestPath(packageNamePath, sqlDatabase)) + ); } private void addAuthorityEntity(Project project, DatabaseType sqlDatabase) { @@ -61,10 +79,25 @@ private void addAuthorityEntity(Project project, DatabaseType sqlDatabase) { String packageNamePath = project.getPackageNamePath().orElse(getPath(PACKAGE_PATH)); project.addConfig(USER_DATABASE_KEY, sqlDatabase.id()); - projectRepository.template(project, SOURCE, "AuthorityEntity.java", getSqlJavaPath(packageNamePath, sqlDatabase)); - projectRepository.template(project, SOURCE, "AuthorityJpaRepository.java", getSqlJavaPath(packageNamePath, sqlDatabase)); - - projectRepository.template(project, SOURCE, "AuthorityEntityTest.java", getSqlJavaTestPath(packageNamePath, sqlDatabase)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "AuthorityEntity.java") + .withDestinationFolder(getSqlJavaPath(packageNamePath, sqlDatabase)) + ); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "AuthorityJpaRepository.java") + .withDestinationFolder(getSqlJavaPath(packageNamePath, sqlDatabase)) + ); + + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "AuthorityEntityTest.java") + .withDestinationFolder(getSqlJavaTestPath(packageNamePath, sqlDatabase)) + ); } private void addAbstractAuditingEntity(Project project, DatabaseType sqlDatabase) { @@ -72,7 +105,12 @@ private void addAbstractAuditingEntity(Project project, DatabaseType sqlDatabase String packageNamePath = project.getPackageNamePath().orElse(getPath(PACKAGE_PATH)); project.addConfig(USER_DATABASE_KEY, sqlDatabase.id()); - projectRepository.template(project, SOURCE, "AbstractAuditingEntity.java", getSqlJavaPath(packageNamePath, sqlDatabase)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(SOURCE, "AbstractAuditingEntity.java") + .withDestinationFolder(getSqlJavaPath(packageNamePath, sqlDatabase)) + ); } private String getSqlJavaPath(String packageNamePath, DatabaseType sqlDatabase) { diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/webflux/web/domain/SpringBootWebfluxDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/webflux/web/domain/SpringBootWebfluxDomainService.java index 3b048874a3e..948be02733b 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/webflux/web/domain/SpringBootWebfluxDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/webflux/web/domain/SpringBootWebfluxDomainService.java @@ -14,6 +14,7 @@ import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; import tech.jhipster.lite.generator.project.domain.DefaultConfig; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -75,7 +76,12 @@ public void addExceptionHandler(Project project) { .testJavaFiles() .forEach(fileName -> templateToExceptionHandler(project, packageNamePath, "test", fileName, TEST_JAVA)); - projectRepository.template(project, getPath(SOURCE, "test"), "TestUtil.java", getPath(TEST_JAVA, packageNamePath)); + projectRepository.template( + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, "test"), "TestUtil.java") + .withDestinationFolder(getPath(TEST_JAVA, packageNamePath)) + ); } private void addProperties(Project project) { @@ -94,10 +100,10 @@ private void addExceptionHandlerProperties(Project project) { private void templateToExceptionHandler(Project project, String source, String type, String sourceFilename, String destination) { projectRepository.template( - project, - getPath(SOURCE, type), - sourceFilename, - getPath(destination, source, TECHNICAL_INFRASTRUCTURE_PRIMARY_EXCEPTION) + ProjectFile + .forProject(project) + .withSource(getPath(SOURCE, type), sourceFilename) + .withDestinationFolder(getPath(destination, source, TECHNICAL_INFRASTRUCTURE_PRIMARY_EXCEPTION)) ); } } diff --git a/src/main/java/tech/jhipster/lite/generator/setup/codespaces/domain/CodespacesDomainService.java b/src/main/java/tech/jhipster/lite/generator/setup/codespaces/domain/CodespacesDomainService.java index b3e47624167..216e1d1c489 100644 --- a/src/main/java/tech/jhipster/lite/generator/setup/codespaces/domain/CodespacesDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/setup/codespaces/domain/CodespacesDomainService.java @@ -23,7 +23,9 @@ public void init(Project project) { private void addConfig(Project project) { project.addConfig("serverPort", 8080); - projectRepository.template(project, SOURCE, "devcontainer.json", DEVCONTAINER_DEST, "devcontainer.json"); + projectRepository.template( + ProjectFile.forProject(project).withSource(SOURCE, "devcontainer.json").withDestination(DEVCONTAINER_DEST, "devcontainer.json") + ); } private void addDockerfile(Project project) { diff --git a/src/test/java/tech/jhipster/lite/generator/buildtool/gradle/domain/gradle/GradleDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/buildtool/gradle/domain/gradle/GradleDomainServiceTest.java index 717c2c5b47b..cbf58610496 100644 --- a/src/test/java/tech/jhipster/lite/generator/buildtool/gradle/domain/gradle/GradleDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/buildtool/gradle/domain/gradle/GradleDomainServiceTest.java @@ -14,6 +14,7 @@ import tech.jhipster.lite.UnitTest; import tech.jhipster.lite.generator.buildtool.gradle.domain.GradleDomainService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; @UnitTest @@ -32,7 +33,7 @@ void shouldInitJava() { gradleDomainService.initJava(project); - verify(projectRepository, times(2)).template(any(Project.class), anyString(), anyString()); + verify(projectRepository, times(2)).template(any(ProjectFile.class)); verify(projectRepository).add(filesCountArgument(4)); verify(projectRepository, times(2)).setExecutable(any(Project.class), anyString(), anyString()); } @@ -43,7 +44,7 @@ void shouldAddJavaBuildGradleKts() { gradleDomainService.addJavaBuildGradleKts(project); - verify(projectRepository, times(2)).template(any(Project.class), anyString(), anyString()); + verify(projectRepository, times(2)).template(any(ProjectFile.class)); } @Test diff --git a/src/test/java/tech/jhipster/lite/generator/buildtool/maven/domain/maven/MavenDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/buildtool/maven/domain/maven/MavenDomainServiceTest.java index b6a0e1d15bc..2ddc4fbb2b6 100644 --- a/src/test/java/tech/jhipster/lite/generator/buildtool/maven/domain/maven/MavenDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/buildtool/maven/domain/maven/MavenDomainServiceTest.java @@ -1,13 +1,9 @@ package tech.jhipster.lite.generator.buildtool.maven.domain.maven; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static tech.jhipster.lite.TestUtils.tmpProject; -import static tech.jhipster.lite.TestUtils.tmpProjectWithPomXml; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; +import static tech.jhipster.lite.TestUtils.*; import java.util.List; import java.util.Optional; @@ -165,7 +161,7 @@ void shouldInitJava() { mavenDomainService.initJava(project); - verify(projectRepository).template(any(Project.class), anyString(), anyString()); + verify(projectRepository).template(any(ProjectFile.class)); verify(projectRepository, times(4)).add(any(ProjectFile.class)); verify(projectRepository, times(2)).setExecutable(any(Project.class), anyString(), anyString()); } @@ -176,7 +172,7 @@ void shouldAddJavaPomXml() { mavenDomainService.addJavaPomXml(project); - verify(projectRepository).template(any(Project.class), anyString(), anyString()); + verify(projectRepository).template(any(ProjectFile.class)); } @Test diff --git a/src/test/java/tech/jhipster/lite/generator/ci/github/actions/domain/GitHubActionsDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/ci/github/actions/domain/GitHubActionsDomainServiceTest.java index b568a33137a..0480aea9331 100644 --- a/src/test/java/tech/jhipster/lite/generator/ci/github/actions/domain/GitHubActionsDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/ci/github/actions/domain/GitHubActionsDomainServiceTest.java @@ -1,11 +1,9 @@ package tech.jhipster.lite.generator.ci.github.actions.domain; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.verify; -import static tech.jhipster.lite.TestUtils.tmpProjectWithBuildGradle; -import static tech.jhipster.lite.TestUtils.tmpProjectWithPomXml; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; +import static tech.jhipster.lite.TestUtils.*; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -14,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import tech.jhipster.lite.UnitTest; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; @UnitTest @@ -32,21 +31,7 @@ void shouldAddGitHubActionsForGradle() { assertThatCode(() -> gitHubActionsDomainService.addGitHubActions(project)).doesNotThrowAnyException(); - verify(projectRepository) - .template( - any(Project.class), - eq("ci/github/actions/.github/actions/setup/"), - eq("action.yml.mustache"), - eq(".github/actions/setup/") - ); - verify(projectRepository) - .template( - any(Project.class), - eq("ci/github/actions/.github/workflows/"), - eq("github-actions-gradle.yml.mustache"), - eq(".github/workflows/"), - eq("github-actions.yml") - ); + verify(projectRepository, times(2)).template(any(ProjectFile.class)); } @Test @@ -55,20 +40,6 @@ void shouldAddGitHubActionsForMaven() { assertThatCode(() -> gitHubActionsDomainService.addGitHubActions(project)).doesNotThrowAnyException(); - verify(projectRepository) - .template( - any(Project.class), - eq("ci/github/actions/.github/actions/setup/"), - eq("action.yml.mustache"), - eq(".github/actions/setup/") - ); - verify(projectRepository) - .template( - any(Project.class), - eq("ci/github/actions/.github/workflows/"), - eq("github-actions-maven.yml.mustache"), - eq(".github/workflows/"), - eq("github-actions.yml") - ); + verify(projectRepository, times(2)).template(any(ProjectFile.class)); } } diff --git a/src/test/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularDomainServiceTest.java index 0dbb290f8de..99405c957c1 100644 --- a/src/test/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularDomainServiceTest.java @@ -1,13 +1,9 @@ package tech.jhipster.lite.generator.client.angular.core.domain; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static tech.jhipster.lite.TestUtils.tmpProjectWithPackageJson; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; +import static tech.jhipster.lite.TestUtils.*; import static tech.jhipster.lite.generator.project.domain.ProjectFilesAsserter.*; import java.util.Optional; @@ -20,7 +16,7 @@ import tech.jhipster.lite.error.domain.GeneratorException; import tech.jhipster.lite.generator.packagemanager.npm.domain.NpmService; import tech.jhipster.lite.generator.project.domain.Project; -import tech.jhipster.lite.generator.project.domain.ProjectFile; +import tech.jhipster.lite.generator.project.domain.ProjectFilesAsserter; import tech.jhipster.lite.generator.project.domain.ProjectRepository; @UnitTest @@ -109,6 +105,6 @@ void shouldAddAngularFiles() { angularDomainService.addAngularFiles(project); - verify(projectRepository, times(15)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository).template(ProjectFilesAsserter.filesCountArgument(15)); } } diff --git a/src/test/java/tech/jhipster/lite/generator/client/angular/security/jwt/domain/AngularJwtDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/client/angular/security/jwt/domain/AngularJwtDomainServiceTest.java index 6a8ef11c6cc..845f4a608d5 100644 --- a/src/test/java/tech/jhipster/lite/generator/client/angular/security/jwt/domain/AngularJwtDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/client/angular/security/jwt/domain/AngularJwtDomainServiceTest.java @@ -19,6 +19,8 @@ import tech.jhipster.lite.error.domain.GeneratorException; import tech.jhipster.lite.generator.packagemanager.npm.domain.NpmService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; +import tech.jhipster.lite.generator.project.domain.ProjectFilesAsserter; import tech.jhipster.lite.generator.project.domain.ProjectRepository; @UnitTest @@ -72,7 +74,7 @@ void shouldAddJwtFiles() { angularJwtDomainService.addJwtFiles(project); - verify(projectRepository, times(1)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository).template(ProjectFilesAsserter.filesCountArgument(1)); } @Test @@ -81,6 +83,6 @@ void shouldAddAngularJwtFiles() { angularJwtDomainService.addAngularJwtFiles(project); - verify(projectRepository, times(15)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository).template(ProjectFilesAsserter.filesCountArgument(15)); } } diff --git a/src/test/java/tech/jhipster/lite/generator/client/react/core/domain/ReactDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/client/react/core/domain/ReactDomainServiceTest.java index 55331a63c4e..695fb5a82be 100644 --- a/src/test/java/tech/jhipster/lite/generator/client/react/core/domain/ReactDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/client/react/core/domain/ReactDomainServiceTest.java @@ -16,6 +16,7 @@ import tech.jhipster.lite.error.domain.GeneratorException; import tech.jhipster.lite.generator.packagemanager.npm.domain.NpmService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; @UnitTest @@ -43,7 +44,8 @@ void shouldAddReact() { verify(npmService, times(6)).addScript(any(Project.class), anyString(), anyString()); verify(projectRepository).add(filesCountArgument(3)); - verify(projectRepository, times(8)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository).template(any(ProjectFile.class)); + verify(projectRepository).template(filesCountArgument(7)); } @Test @@ -58,7 +60,7 @@ void shouldAddStyledReact() { verify(npmService, times(6)).addScript(any(Project.class), anyString(), anyString()); verify(projectRepository).add(filesCountArgument(3)); - verify(projectRepository, times(8)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository).template(filesCountArgument(7)); } @Test diff --git a/src/test/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteDomainServiceTest.java index cfb31336d5c..7ade72a6b3d 100644 --- a/src/test/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteDomainServiceTest.java @@ -16,6 +16,7 @@ import tech.jhipster.lite.error.domain.GeneratorException; import tech.jhipster.lite.generator.packagemanager.npm.domain.NpmService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; @UnitTest @@ -97,7 +98,7 @@ void shouldAddRootFiles() { svelteDomainService.addRootFiles(project); - verify(projectRepository, times(3)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, times(3)).template(any(ProjectFile.class)); } @Test @@ -106,7 +107,7 @@ void shouldAddAppFiles() { svelteDomainService.addAppFiles(project); - verify(projectRepository, times(2)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, times(2)).template(any(ProjectFile.class)); } @Test diff --git a/src/test/java/tech/jhipster/lite/generator/client/tools/cypress/domain/CypressDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/client/tools/cypress/domain/CypressDomainServiceTest.java index 7da3de9401d..e185be2306f 100644 --- a/src/test/java/tech/jhipster/lite/generator/client/tools/cypress/domain/CypressDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/client/tools/cypress/domain/CypressDomainServiceTest.java @@ -4,7 +4,6 @@ import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import static tech.jhipster.lite.TestUtils.*; -import static tech.jhipster.lite.generator.client.tools.cypress.domain.Cypress.*; import static tech.jhipster.lite.generator.project.domain.ProjectFilesAsserter.*; import java.util.Optional; @@ -18,6 +17,8 @@ import tech.jhipster.lite.generator.client.common.domain.ClientCommonService; import tech.jhipster.lite.generator.packagemanager.npm.domain.NpmService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; +import tech.jhipster.lite.generator.project.domain.ProjectFilesAsserter; import tech.jhipster.lite.generator.project.domain.ProjectRepository; @UnitTest @@ -62,15 +63,8 @@ void shouldAddCypress() { verify(projectRepository).add(filesCountArgument(2)); - verify(projectRepository) - .template(project, "client/common/cypress/src/test/javascript/integration", "cypress-config.json", JAVASCRIPT_INTEGRATION); - verify(projectRepository) - .template( - project, - "client/common/cypress/src/test/javascript/integration/common/primary/app", - "Home.spec.ts", - "src/test/javascript/integration/common/primary/app" - ); + verify(projectRepository).template(any(ProjectFile.class)); + verify(projectRepository).template(ProjectFilesAsserter.filesCountArgument(1)); verify(clientCommonService).excludeInTsconfigJson(project, "src/test/javascript/integration/**/*spec.ts"); } diff --git a/src/test/java/tech/jhipster/lite/generator/client/tools/playwright/domain/PlaywrightDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/client/tools/playwright/domain/PlaywrightDomainServiceTest.java index 5b05dc28a17..996184206fb 100644 --- a/src/test/java/tech/jhipster/lite/generator/client/tools/playwright/domain/PlaywrightDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/client/tools/playwright/domain/PlaywrightDomainServiceTest.java @@ -18,6 +18,8 @@ import tech.jhipster.lite.error.domain.GeneratorException; import tech.jhipster.lite.generator.packagemanager.npm.domain.NpmService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; +import tech.jhipster.lite.generator.project.domain.ProjectFilesAsserter; import tech.jhipster.lite.generator.project.domain.ProjectRepository; @UnitTest @@ -46,23 +48,8 @@ void shouldAddPlaywright() { verify(npmService).addScript(project, "e2e", "npx playwright test --headed"); verify(npmService).addScript(project, "e2e:headless", "npx playwright test"); - verify(projectRepository).template(project, "client/common/playwright", "playwright.config.ts"); - - verify(projectRepository) - .template( - project, - "client/common/playwright/src/test/javascript/integration/common/primary/app", - "Home.spec.ts", - "src/test/javascript/integration/common/primary/app" - ); - - verify(projectRepository) - .template( - project, - "client/common/playwright/src/test/javascript/integration/common/primary/app", - "Home-Page.ts", - "src/test/javascript/integration/common/primary/app" - ); + verify(projectRepository).template(any(ProjectFile.class)); + verify(projectRepository, times(2)).template(ProjectFilesAsserter.filesCountArgument(1)); } @Test diff --git a/src/test/java/tech/jhipster/lite/generator/client/vue/core/domain/VueDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/client/vue/core/domain/VueDomainServiceTest.java index e84431d9390..f6473b0ec68 100644 --- a/src/test/java/tech/jhipster/lite/generator/client/vue/core/domain/VueDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/client/vue/core/domain/VueDomainServiceTest.java @@ -102,15 +102,11 @@ void shouldAddRouterDependencies() { @Test void shouldAddRouterFiles() { Project project = tmpProjectWithPackageJson(); - final String version = "0.0.0"; - when(npmService.getVersion(anyString(), anyString())).thenReturn(Optional.of(version)); + when(npmService.getVersion(anyString(), anyString())).thenReturn(Optional.of("0.0.0")); vueDomainService.addRouter(project); - ArgumentCaptor filesCaptor = ArgumentCaptor.forClass(String.class); - verify(projectRepository, times(2)).template(eq(project), any(String.class), filesCaptor.capture(), anyString()); + verify(projectRepository, times(2)).template(any(ProjectFile.class)); verify(projectRepository, times(2)).replaceText(eq(project), anyString(), anyString(), anyString(), anyString()); - - assertThat(filesCaptor.getAllValues()).contains("router.ts", "Router.spec.ts"); } @Test @@ -161,7 +157,7 @@ void shouldAddRootFiles() { vueDomainService.addRootFiles(project); - verify(projectRepository, times(3)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, times(3)).template(any(ProjectFile.class)); } @Test @@ -170,7 +166,7 @@ void shouldAddAppFiles() { vueDomainService.addAppFiles(project); - verify(projectRepository, times(3)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, times(3)).template(any(ProjectFile.class)); } @Test @@ -179,7 +175,7 @@ void shouldAddAppFilesWithoutCss() { vueDomainService.addAppFilesWithoutCss(project); - verify(projectRepository, times(2)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, times(2)).template(any(ProjectFile.class)); } @Test @@ -188,7 +184,7 @@ void shouldAddAppFilesWithCss() { vueDomainService.addAppFilesWithCss(project); - verify(projectRepository, times(2)).template(any(Project.class), anyString(), anyString(), anyString(), anyString()); + verify(projectRepository, times(2)).template(any(ProjectFile.class)); verify(projectRepository, times(2)).add(any(ProjectFile.class)); } @@ -236,6 +232,6 @@ void shouldAddAxiosFile() { vueDomainService.addAxios(project); - verify(projectRepository, times(4)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, times(4)).template(any(ProjectFile.class)); } } diff --git a/src/test/java/tech/jhipster/lite/generator/init/domain/InitDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/init/domain/InitDomainServiceTest.java index 4289232bbaf..2b868d15bae 100644 --- a/src/test/java/tech/jhipster/lite/generator/init/domain/InitDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/init/domain/InitDomainServiceTest.java @@ -58,7 +58,7 @@ void shouldAddPackageJson() { assertThatCode(() -> initDomainService.addPackageJson(project)).doesNotThrowAnyException(); - verify(projectRepository).template(any(Project.class), anyString(), anyString()); + verify(projectRepository).template(any(ProjectFile.class)); verify(npmService, times(6)).addDevDependency(any(Project.class), anyString(), anyString()); verify(npmService, times(3)).addScript(any(Project.class), anyString(), anyString()); } @@ -76,7 +76,7 @@ void shouldAddReadme() { assertThatCode(() -> initDomainService.addReadme(project)).doesNotThrowAnyException(); - verify(projectRepository).template(any(Project.class), anyString(), anyString()); + verify(projectRepository).template(any(ProjectFile.class)); } @Test @@ -94,7 +94,7 @@ void shouldAddEditorConfiguration() { assertThatCode(() -> initDomainService.addEditorConfiguration(project)).doesNotThrowAnyException(); - verify(projectRepository).template(any(Project.class), anyString(), anyString()); + verify(projectRepository).template(any(ProjectFile.class)); verify(projectRepository).add(any(ProjectFile.class)); } @@ -105,7 +105,7 @@ void shouldAddPrettier() { assertThatCode(() -> initDomainService.addPrettier(project)).doesNotThrowAnyException(); verify(projectRepository, times(3)).add(any(ProjectFile.class)); - verify(projectRepository).template(any(Project.class), anyString(), anyString()); + verify(projectRepository).template(any(ProjectFile.class)); verify(projectRepository).setExecutable(any(Project.class), anyString(), anyString()); } diff --git a/src/test/java/tech/jhipster/lite/generator/project/domain/ProjectFilesAsserter.java b/src/test/java/tech/jhipster/lite/generator/project/domain/ProjectFilesAsserter.java index ddf0f36c2a0..2a68130632f 100644 --- a/src/test/java/tech/jhipster/lite/generator/project/domain/ProjectFilesAsserter.java +++ b/src/test/java/tech/jhipster/lite/generator/project/domain/ProjectFilesAsserter.java @@ -9,7 +9,9 @@ public final class ProjectFilesAsserter { private ProjectFilesAsserter() {} public static Collection filesCountArgument(int count) { - return argThat(files -> files.size() == count); + return argThat(files -> { + return files.size() == count; + }); } public static ProjectFile projectFileArgument(Project project, FilePath source, FilePath destination) { diff --git a/src/test/java/tech/jhipster/lite/generator/project/infrastructure/secondary/ProjectLocalRepositoryTest.java b/src/test/java/tech/jhipster/lite/generator/project/infrastructure/secondary/ProjectLocalRepositoryTest.java index aeba511832e..d0f5b48f719 100644 --- a/src/test/java/tech/jhipster/lite/generator/project/infrastructure/secondary/ProjectLocalRepositoryTest.java +++ b/src/test/java/tech/jhipster/lite/generator/project/infrastructure/secondary/ProjectLocalRepositoryTest.java @@ -92,56 +92,59 @@ void shouldAddFiles() { } @Test - void shouldTemplate() { - Project project = tmpProject(); - - repository.template(project, "mustache", "README.md"); - - assertFileExist(project, "README.md"); - } - - @Test - void shouldNotTemplate() { + void shouldHandleTemplatingError() { Project project = Project.builder().folder(FileUtils.tmpDirForTest()).build(); try (MockedStatic mustacheUtils = Mockito.mockStatic(MustacheUtils.class)) { mustacheUtils.when(() -> MustacheUtils.template(anyString(), any())).thenThrow(new IOException()); - assertThatThrownBy(() -> repository.template(project, "mustache", "README.md")).isExactlyInstanceOf(GeneratorException.class); + List files = List.of(ProjectFile.forProject(project).withSource("mustache", "README.md").withSameDestination()); + assertThatThrownBy(() -> repository.template(files)).isExactlyInstanceOf(GeneratorException.class); } } @Test - void shouldNotTemplateWithNonExistingFile() { + void shouldNotTemplateForUnknownFile() { Project project = tmpProject(); + List files = List.of( + ProjectFile.forProject(project).withSource("mustache", "README.md.wrong.mustache").withSameDestination() + ); - assertThatThrownBy(() -> repository.template(project, "mustache", "README.md.wrong.mustache")) - .isInstanceOf(MustacheNotFoundException.class); + assertThatThrownBy(() -> repository.template(files)).isInstanceOf(MustacheNotFoundException.class); } @Test - void shouldTemplateWithExtension() { + void shouldTemplatizeFile() { Project project = tmpProject(); + List files = List.of(ProjectFile.forProject(project).withSource("mustache", "README.md").withSameDestination()); - repository.template(project, "mustache", "README.md.mustache"); + repository.template(files); assertFileExist(project, "README.md"); } @Test - void shouldTemplateWithDestination() { + void shouldTemplatizeFileWithMustacheExtension() { Project project = tmpProject(); + List files = List.of(ProjectFile.forProject(project).withSource("mustache", "README.md.mustache").withSameDestination()); - repository.template(project, "mustache", "README.md.mustache", getPath(MAIN_RESOURCES)); + repository.template(files); - assertFileExist(project, "src/main/resources/README.md"); + assertFileExist(project, "README.md"); } @Test void shouldTemplateWithDestinationAndDestinationFilename() { Project project = tmpProject(); - repository.template(project, "mustache", "README.md.mustache", getPath(MAIN_RESOURCES), "FINAL-README.md"); + repository.template( + List.of( + ProjectFile + .forProject(project) + .withSource("mustache", "README.md.mustache") + .withDestination(getPath(MAIN_RESOURCES), "FINAL-README.md") + ) + ); assertFileExist(project, MAIN_RESOURCES, "FINAL-README.md"); } diff --git a/src/test/java/tech/jhipster/lite/generator/server/javatool/arch/domain/JavaArchUnitDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/javatool/arch/domain/JavaArchUnitDomainServiceTest.java index 5f0346a113b..753ae2fe570 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/javatool/arch/domain/JavaArchUnitDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/javatool/arch/domain/JavaArchUnitDomainServiceTest.java @@ -1,12 +1,9 @@ package tech.jhipster.lite.generator.server.javatool.arch.domain; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static tech.jhipster.lite.TestUtils.tmpProject; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; +import static tech.jhipster.lite.TestUtils.*; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -19,6 +16,7 @@ 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.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.Level; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -46,7 +44,7 @@ void shouldInit() { javaArchUnitDomainService.init(project); - verify(projectRepository, times(4)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, times(4)).template(any(ProjectFile.class)); verify(buildToolService).addProperty(any(Project.class), anyString(), anyString()); verify(buildToolService).addDependency(any(Project.class), any(Dependency.class)); verify(springBootCommonService).addLoggerTest(any(Project.class), anyString(), any(Level.class)); diff --git a/src/test/java/tech/jhipster/lite/generator/server/javatool/base/domain/JavaBaseDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/javatool/base/domain/JavaBaseDomainServiceTest.java index afb15d00f0d..ac28014e263 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/javatool/base/domain/JavaBaseDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/javatool/base/domain/JavaBaseDomainServiceTest.java @@ -1,9 +1,7 @@ package tech.jhipster.lite.generator.server.javatool.base.domain; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static tech.jhipster.lite.TestUtils.tmpProject; +import static org.mockito.Mockito.*; +import static tech.jhipster.lite.TestUtils.*; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -12,6 +10,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import tech.jhipster.lite.UnitTest; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFilesAsserter; import tech.jhipster.lite.generator.project.domain.ProjectRepository; @UnitTest @@ -30,8 +29,7 @@ void shouldAddJavaBase() { javaBaseDomainService.addJavaBase(project); - verify(projectRepository, times(17)).template(any(Project.class), anyString(), anyString(), anyString()); - verify(projectRepository).template(any(Project.class), anyString(), anyString(), anyString(), eq("JhipsterCollections.java")); - verify(projectRepository).template(any(Project.class), anyString(), anyString(), anyString(), eq("JhipsterCollectionsTest.java")); + verify(projectRepository).template(ProjectFilesAsserter.filesCountArgument(13)); + verify(projectRepository, times(2)).template(ProjectFilesAsserter.filesCountArgument(2)); } } diff --git a/src/test/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenDomainServiceTest.java index 3e7223b4296..876dd10bef9 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenDomainServiceTest.java @@ -1,19 +1,13 @@ package tech.jhipster.lite.generator.server.javatool.frontendmaven.domain; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static tech.jhipster.lite.TestUtils.tmpProjectWithPomXml; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; +import static tech.jhipster.lite.TestUtils.*; import java.util.Optional; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -22,6 +16,7 @@ import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; import tech.jhipster.lite.generator.buildtool.generic.domain.Plugin; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; @UnitTest @@ -44,12 +39,9 @@ void shouldAddFrontendMavenPlugin() { frontendMavenDomainService.addFrontendMavenPlugin(project); - ArgumentCaptor redirectionFilesCaptor = ArgumentCaptor.forClass(String.class); verify(buildToolService, times(5)).addProperty(any(Project.class), anyString(), anyString()); verify(buildToolService, times(3)).addPlugin(any(Project.class), any(Plugin.class)); - verify(projectRepository, times(2)).template(eq(project), anyString(), redirectionFilesCaptor.capture(), anyString()); - - assertThat(redirectionFilesCaptor.getAllValues()).containsExactly("RedirectionResource.java", "RedirectionResourceIT.java"); + verify(projectRepository, times(2)).template(any(ProjectFile.class)); } @Test diff --git a/src/test/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainServiceTest.java index 9eea5187cf3..53e644ef03e 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainServiceTest.java @@ -1,12 +1,8 @@ package tech.jhipster.lite.generator.server.sonar.domain; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static tech.jhipster.lite.TestUtils.tmpProjectWithPomXml; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; +import static tech.jhipster.lite.TestUtils.*; import java.util.Optional; import org.assertj.core.api.Assertions; @@ -21,6 +17,7 @@ import tech.jhipster.lite.generator.buildtool.generic.domain.Plugin; import tech.jhipster.lite.generator.docker.domain.DockerService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; @UnitTest @@ -51,8 +48,7 @@ void shouldAddSonarJavaBackend() { verify(buildToolService).addPlugin(any(Project.class), any(Plugin.class)); verify(buildToolService).addPluginManagement(any(Project.class), any(Plugin.class)); - verify(projectRepository).template(any(Project.class), anyString(), anyString()); - verify(projectRepository).template(any(Project.class), anyString(), anyString(), anyString(), anyString()); + verify(projectRepository, times(2)).template(any(ProjectFile.class)); } @Test @@ -83,7 +79,7 @@ void shouldAddSonarJavaBackendAndFrontend() { verify(buildToolService).addPlugin(any(Project.class), any(Plugin.class)); verify(buildToolService).addPluginManagement(any(Project.class), any(Plugin.class)); - verify(projectRepository, times(2)).template(any(Project.class), anyString(), anyString(), anyString(), anyString()); + verify(projectRepository, times(2)).template(any(ProjectFile.class)); } @Test diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/broker/kafka/domain/KafkaDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/broker/kafka/domain/KafkaDomainServiceTest.java index b20ffcf7a1e..5fd920e860e 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/broker/kafka/domain/KafkaDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/broker/kafka/domain/KafkaDomainServiceTest.java @@ -1,10 +1,9 @@ package tech.jhipster.lite.generator.server.springboot.broker.kafka.domain; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import static tech.jhipster.lite.TestUtils.tmpProjectWithPomXml; +import static tech.jhipster.lite.TestUtils.*; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -18,6 +17,7 @@ import tech.jhipster.lite.generator.buildtool.generic.domain.Dependency; import tech.jhipster.lite.generator.docker.domain.DockerService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -50,8 +50,7 @@ void shouldInit() { verify(buildToolService, times(2)).addDependency(any(Project.class), any(Dependency.class)); verify(dockerService, times(2)).getImageNameWithVersion(anyString()); - verify(projectRepository).template(any(Project.class), anyString(), anyString(), anyString(), anyString()); - verify(projectRepository, times(4)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, times(5)).template(any(ProjectFile.class)); verify(springBootCommonService, times(9)).addProperties(any(Project.class), anyString(), any()); verify(springBootCommonService, times(9)).addPropertiesTest(any(Project.class), anyString(), any()); verify(springBootCommonService).updateIntegrationTestAnnotation(any(Project.class), anyString()); @@ -66,7 +65,7 @@ void shouldAddProducerConsumer() { verify(springBootCommonService).addProperties(any(Project.class), anyString(), any()); verify(springBootCommonService).addPropertiesTest(any(Project.class), anyString(), any()); - verify(projectRepository, times(7)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, times(7)).template(any(ProjectFile.class)); } @Test @@ -77,7 +76,7 @@ void shouldAddAkhq() { kafkaDomainService.addAkhq(project); verify(dockerService).getImageNameWithVersion(anyString()); - verify(projectRepository).template(any(Project.class), anyString(), anyString(), anyString(), anyString()); + verify(projectRepository).template(any(ProjectFile.class)); } @Test diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootDomainServiceTest.java index 89eeda25e4a..02ae9a4a1a5 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootDomainServiceTest.java @@ -1,12 +1,9 @@ package tech.jhipster.lite.generator.server.springboot.core.domain; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static tech.jhipster.lite.TestUtils.tmpProjectWithPomXml; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; +import static tech.jhipster.lite.TestUtils.*; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -20,6 +17,7 @@ import tech.jhipster.lite.generator.buildtool.generic.domain.Dependency; import tech.jhipster.lite.generator.buildtool.generic.domain.Plugin; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; @UnitTest @@ -27,13 +25,13 @@ class SpringBootDomainServiceTest { @Mock - ProjectRepository projectRepository; + private ProjectRepository projectRepository; @Mock - BuildToolService buildToolService; + private BuildToolService buildToolService; @InjectMocks - SpringBootDomainService springBootDomainService; + private SpringBootDomainService springBootDomainService; @Test void shouldInit() { @@ -46,10 +44,7 @@ void shouldInit() { verify(buildToolService, times(4)).addDependency(any(Project.class), any(Dependency.class)); verify(buildToolService).addPlugin(any(Project.class), any(Plugin.class)); - // for application.properties, application-local.properties, Integration Test annotation, Logging config and logging test config - verify(projectRepository, times(5)).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()); + verify(projectRepository, times(8)).template(any(ProjectFile.class)); } @Test diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/database/mongodb/domain/MongodbDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/database/mongodb/domain/MongodbDomainServiceTest.java index 511bfb03257..07e2859029d 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/database/mongodb/domain/MongodbDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/database/mongodb/domain/MongodbDomainServiceTest.java @@ -22,6 +22,7 @@ import tech.jhipster.lite.generator.buildtool.generic.domain.Dependency; import tech.jhipster.lite.generator.docker.domain.DockerService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.Level; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -59,7 +60,7 @@ void shouldInit() { verify(buildToolService, times(2)).addDependency(any(Project.class), any(Dependency.class)); - verify(projectRepository, times(6)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, times(6)).template(any(ProjectFile.class)); verify(springBootCommonService).addPropertiesComment(any(Project.class), anyString()); verify(springBootCommonService, times(2)).addProperties(any(Project.class), anyString(), any()); diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/database/postgresql/domain/PostgresqlDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/database/postgresql/domain/PostgresqlDomainServiceTest.java index 7a85d2d3c70..59799940edd 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/database/postgresql/domain/PostgresqlDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/database/postgresql/domain/PostgresqlDomainServiceTest.java @@ -23,6 +23,7 @@ import tech.jhipster.lite.generator.buildtool.generic.domain.Dependency; import tech.jhipster.lite.generator.docker.domain.DockerService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.Level; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -68,7 +69,7 @@ void shouldInit() { verify(buildToolService).addDependency(any(Project.class), any(Dependency.class)); - verify(projectRepository, times(2)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, times(2)).template(any(ProjectFile.class)); verify(springBootCommonService).addLogger(any(Project.class), anyString(), any(Level.class)); verify(springBootCommonService, times(4)).addLoggerTest(any(Project.class), anyString(), any(Level.class)); diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/database/sqlcommon/domain/SQLCommonDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/database/sqlcommon/domain/SQLCommonDomainServiceTest.java index 3acbb081983..74fc269ff67 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/database/sqlcommon/domain/SQLCommonDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/database/sqlcommon/domain/SQLCommonDomainServiceTest.java @@ -1,13 +1,9 @@ package tech.jhipster.lite.generator.server.springboot.database.sqlcommon.domain; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static tech.jhipster.lite.TestUtils.tmpProjectWithPomXml; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; +import static tech.jhipster.lite.TestUtils.*; import java.util.Map; import java.util.Optional; @@ -22,6 +18,7 @@ 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.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -174,7 +171,7 @@ void shouldAddDockerComposeTemplate() { Project project = tmpProjectWithPomXml(); sqlCommonDomainService.addDockerComposeTemplate(project, "anyDB"); - verify(projectRepository).template(eq(project), any(String.class), eq("anyDB.yml"), any(String.class), eq("anyDB.yml")); + verify(projectRepository).template(any(ProjectFile.class)); } @Test @@ -182,7 +179,7 @@ void shouldAddJavaFiles() { Project project = tmpProjectWithPomXml(); sqlCommonDomainService.addJavaFiles(project, "anyDB"); - verify(projectRepository).template(eq(project), any(String.class), eq("DatabaseConfiguration.java"), any(String.class)); + verify(projectRepository).template(any(ProjectFile.class)); } @Test diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/dbmigration/mongock/domain/MongockDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/dbmigration/mongock/domain/MongockDomainServiceTest.java index 38d016ac969..0b6bc7653ee 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/dbmigration/mongock/domain/MongockDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/dbmigration/mongock/domain/MongockDomainServiceTest.java @@ -23,6 +23,7 @@ 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.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -72,31 +73,9 @@ void shouldInit() { expectedDependency = Dependency.builder().groupId("io.mongock").artifactId("mongodb-springdata-v3-driver").build(); assertThat(dependencyList.get(2)).usingRecursiveComparison().isEqualTo(expectedDependency); - verify(projectRepository) - .template( - project, - "server/springboot/database/mongock", - "MongockDatabaseConfiguration.java", - "src/main/java/com/mycompany/myapp/technical/infrastructure/secondary/mongock" - ); - - verify(projectRepository) - .template( - project, - "server/springboot/database/mongock", - "InitialMigrationSetup.java", - "src/main/java/com/mycompany/myapp/technical/infrastructure/secondary/mongock/dbmigration" - ); - - verify(projectRepository) - .template( - project, - "server/springboot/database/mongock", - "InitialMigrationSetupTest.java", - "src/test/java/com/mycompany/myapp/technical/infrastructure/secondary/mongock/dbmigration" - ); + verify(projectRepository, times(3)).template(any(ProjectFile.class)); - verify(springBootCommonService, times(1)).addProperties(any(), anyString(), any()); + verify(springBootCommonService).addProperties(any(), anyString(), any()); verify(springBootCommonService) .addProperties( project, diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/docker/domain/SpringBootDockerDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/docker/domain/SpringBootDockerDomainServiceTest.java index 57aae1bddee..5325f5ab2e5 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/docker/domain/SpringBootDockerDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/docker/domain/SpringBootDockerDomainServiceTest.java @@ -19,6 +19,7 @@ import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; import tech.jhipster.lite.generator.buildtool.generic.domain.Plugin; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; @UnitTest @@ -44,7 +45,7 @@ void shouldAddJib() { verify(buildToolService, times(3)).addProperty(any(Project.class), anyString(), anyString()); verify(buildToolService).addPlugin(any(Project.class), any(Plugin.class)); - verify(projectRepository).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository).template(any(ProjectFile.class)); } @Test diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/logging/aop/domain/maven/AopLoggingDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/logging/aop/domain/maven/AopLoggingDomainServiceTest.java index 4f7c0d6f086..3bd2bc0db7d 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/logging/aop/domain/maven/AopLoggingDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/logging/aop/domain/maven/AopLoggingDomainServiceTest.java @@ -15,6 +15,7 @@ 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.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; import tech.jhipster.lite.generator.server.springboot.logging.aop.domain.AopLoggingDomainService; @@ -41,7 +42,7 @@ void shouldInit() { aopLoggingDomainService.init(project); // Java files - verify(projectRepository, times(3)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, times(3)).template(any(ProjectFile.class)); // Properties modifications verify(springBootCommonService).addProperties(any(Project.class), anyString(), anyString()); verify(springBootCommonService).addPropertiesLocal(any(Project.class), anyString(), anyString()); @@ -55,7 +56,7 @@ void shouldAddDialectJava() { Project project = tmpProjectWithPomXml(); aopLoggingDomainService.addJavaFiles(project); - verify(projectRepository, times(3)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, times(3)).template(any(ProjectFile.class)); } @Test diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/logging/logstash/domain/LogstashDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/logging/logstash/domain/LogstashDomainServiceTest.java index 27abf4acbd0..a3e586a4473 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/logging/logstash/domain/LogstashDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/logging/logstash/domain/LogstashDomainServiceTest.java @@ -19,6 +19,7 @@ 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.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.Level; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -48,11 +49,8 @@ void shouldInit() { verify(buildToolService).addProperty(any(Project.class), anyString(), anyString()); verify(buildToolService).addDependency(any(Project.class), any(Dependency.class)); - - verify(projectRepository, times(7)).template(any(Project.class), anyString(), anyString(), anyString()); - + verify(projectRepository, times(7)).template(any(ProjectFile.class)); verify(springBootCommonService, times(5)).addProperties(any(Project.class), anyString(), any()); - verify(springBootCommonService, times(2)).addLoggerTest(any(Project.class), anyString(), any(Level.class)); } @@ -80,7 +78,7 @@ void shouldAddJavaFiles() { logstashDomainService.addJavaFiles(project); - verify(projectRepository, times(7)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, times(7)).template(any(ProjectFile.class)); } @Test diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/dummy/domain/DummyDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/dummy/domain/DummyDomainServiceTest.java index 5a6f63114f0..51bb7117ea0 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/dummy/domain/DummyDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/dummy/domain/DummyDomainServiceTest.java @@ -12,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import tech.jhipster.lite.UnitTest; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; @UnitTest @@ -31,7 +32,7 @@ void shouldApplyDummyGitPatch() { dummyDomainService.applyDummyGitPatch(project); verify(projectRepository).gitInit(any(Project.class)); - verify(projectRepository).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository).template(any(ProjectFile.class)); verify(projectRepository).gitApplyPatch(any(Project.class), anyString()); } } diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/security/jwt/domain/JwtSecurityDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/security/jwt/domain/JwtSecurityDomainServiceTest.java index 6fd177a5ae2..04b8fbba38e 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/security/jwt/domain/JwtSecurityDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/security/jwt/domain/JwtSecurityDomainServiceTest.java @@ -1,12 +1,9 @@ package tech.jhipster.lite.generator.server.springboot.mvc.security.jwt.domain; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static tech.jhipster.lite.TestUtils.tmpProjectWithPomXml; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; +import static tech.jhipster.lite.TestUtils.*; import java.util.Optional; import org.eclipse.jgit.api.errors.GitAPIException; @@ -20,6 +17,8 @@ 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.project.domain.ProjectFile; +import tech.jhipster.lite.generator.project.domain.ProjectFilesAsserter; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.project.infrastructure.secondary.GitUtils; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -55,8 +54,8 @@ void shouldInit() throws GitAPIException { verify(buildToolService).addProperty(any(Project.class), anyString(), anyString()); verify(buildToolService, times(5)).addDependency(any(Project.class), any(Dependency.class)); - // 9 classes + 3 tests - verify(projectRepository, times(12)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository).template(ProjectFilesAsserter.filesCountArgument(8)); + verify(projectRepository).template(ProjectFilesAsserter.filesCountArgument(4)); verify(springBootCommonService, times(3)).addProperties(any(Project.class), anyString(), any()); verify(springBootCommonService, times(3)).addPropertiesTest(any(Project.class), anyString(), any()); @@ -83,7 +82,7 @@ void shouldAddBasicAuth() { jwtSecurityDomainService.addBasicAuth(project); - verify(projectRepository, times(6)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, times(6)).template(any(ProjectFile.class)); verify(springBootCommonService, times(3)).addProperties(any(Project.class), anyString(), any()); verify(springBootCommonService, times(3)).addPropertiesTest(any(Project.class), anyString(), any()); } diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/security/oauth2/domain/OAuth2SecurityDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/security/oauth2/domain/OAuth2SecurityDomainServiceTest.java index af85f93ba81..8e0ab272cb4 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/security/oauth2/domain/OAuth2SecurityDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/security/oauth2/domain/OAuth2SecurityDomainServiceTest.java @@ -1,12 +1,9 @@ package tech.jhipster.lite.generator.server.springboot.mvc.security.oauth2.domain; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static tech.jhipster.lite.TestUtils.tmpProject; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; +import static tech.jhipster.lite.TestUtils.*; import java.util.Optional; import org.junit.jupiter.api.DisplayName; @@ -21,6 +18,8 @@ import tech.jhipster.lite.generator.buildtool.generic.domain.Dependency; import tech.jhipster.lite.generator.docker.domain.DockerService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; +import tech.jhipster.lite.generator.project.domain.ProjectFilesAsserter; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; import tech.jhipster.lite.generator.server.springboot.mvc.security.common.domain.CommonSecurityService; @@ -62,11 +61,12 @@ void shouldAddOAuth2() { verify(buildToolService, times(4)).addDependency(any(Project.class), any(Dependency.class)); // 3 files related to docker-compose (docker-compose, realm, users) - verify(projectRepository, times(3)).template(any(Project.class), anyString(), anyString(), anyString(), anyString()); + verify(projectRepository, times(3)).template(any(ProjectFile.class)); // 10 files for Java // 11 files for Java Test - verify(projectRepository, times(21)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository).template(ProjectFilesAsserter.filesCountArgument(10)); + verify(projectRepository).template(ProjectFilesAsserter.filesCountArgument(11)); // 5 properties, with 1 comment and 1 new line verify(springBootCommonService).addPropertiesComment(any(Project.class), anyString()); @@ -100,6 +100,7 @@ void shouldAddAccountContext() { oAuth2SecurityDomainService.addAccountContext(project); // 3 java files and 4 for tests - verify(projectRepository, times(7)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository).template(ProjectFilesAsserter.filesCountArgument(3)); + verify(projectRepository).template(ProjectFilesAsserter.filesCountArgument(4)); } } diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringdocDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringdocDomainServiceTest.java index e8a97d80834..a8ce6581d0e 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringdocDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/springdoc/domain/SpringdocDomainServiceTest.java @@ -1,29 +1,11 @@ package tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static tech.jhipster.lite.TestUtils.tmpProject; -import static tech.jhipster.lite.generator.project.domain.DefaultConfig.BASE_NAME; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.API_DESCRIPTION_CONFIG_KEY; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.API_EXT_DOC_DESCRIPTION_CONFIG_KEY; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.API_EXT_DOC_URL_CONFIG_KEY; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.API_LICENSE_NAME_CONFIG_KEY; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.API_LICENSE_URL_CONFIG_KEY; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.API_TITLE_CONFIG_KEY; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.DEFAULT_API_DESCRIPTION; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.DEFAULT_API_TITLE; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.DEFAULT_EXT_DOC_DESCRIPTION; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.DEFAULT_EXT_DOC_URL; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.DEFAULT_LICENSE_NAME; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.DEFAULT_LICENSE_URL; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.DEFAULT_SWAGGER_UI_SORT_VALUE; -import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.DEFAULT_TRY_OUT_ENABLED; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; +import static tech.jhipster.lite.TestUtils.*; +import static tech.jhipster.lite.generator.project.domain.DefaultConfig.*; +import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringdocConstants.*; import java.util.HashMap; import java.util.Map; @@ -39,6 +21,7 @@ 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.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -75,13 +58,7 @@ void shouldInitWithDefaultValues() { verify(buildToolService).addDependency(eq(project), dependencyArgCaptor.capture()); assertThat(dependencyArgCaptor.getValue()).usingRecursiveComparison().isEqualTo(getExpectedDependency()); - verify(projectRepository) - .template( - project, - "server/springboot/mvc/springdoc/src", - "SpringdocConfiguration.java", - "src/main/java/com/mycompany/myapp/technical/infrastructure/primary/springdoc" - ); + verify(projectRepository).template(any(ProjectFile.class)); verify(springBootCommonService, times(3)).addProperties(any(), anyString(), any()); verify(springBootCommonService).addProperties(project, "springdoc.swagger-ui.operationsSorter", DEFAULT_SWAGGER_UI_SORT_VALUE); @@ -122,13 +99,7 @@ void shouldInitWithAdditionalConfigFromProject() { verify(buildToolService).addDependency(eq(project), dependencyArgCaptor.capture()); assertThat(dependencyArgCaptor.getValue()).usingRecursiveComparison().isEqualTo(getExpectedDependency()); - verify(projectRepository) - .template( - project, - "server/springboot/mvc/springdoc/src", - "SpringdocConfiguration.java", - "src/main/java/com/mycompany/myapp/technical/infrastructure/primary/springdoc" - ); + verify(projectRepository).template(any(ProjectFile.class)); verify(springBootCommonService, times(3)).addProperties(any(), anyString(), any()); verify(springBootCommonService).addProperties(project, "springdoc.swagger-ui.operationsSorter", DEFAULT_SWAGGER_UI_SORT_VALUE); diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/web/domain/SpringBootMvcDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/web/domain/SpringBootMvcDomainServiceTest.java index d49526c96ee..da4582e2514 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/web/domain/SpringBootMvcDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/mvc/web/domain/SpringBootMvcDomainServiceTest.java @@ -1,12 +1,9 @@ package tech.jhipster.lite.generator.server.springboot.mvc.web.domain; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static tech.jhipster.lite.TestUtils.tmpProjectWithPomXml; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; +import static tech.jhipster.lite.TestUtils.*; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -19,6 +16,8 @@ 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.project.domain.ProjectFile; +import tech.jhipster.lite.generator.project.domain.ProjectFilesAsserter; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.Level; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -28,16 +27,16 @@ class SpringBootMvcDomainServiceTest { @Mock - ProjectRepository projectRepository; + private ProjectRepository projectRepository; @Mock - BuildToolService buildToolService; + private BuildToolService buildToolService; @Mock - SpringBootCommonService springBootCommonService; + private SpringBootCommonService springBootCommonService; @InjectMocks - SpringBootMvcDomainService springBootMvcDomainService; + private SpringBootMvcDomainService springBootMvcDomainService; @Test void shouldInit() { @@ -55,7 +54,8 @@ void shouldInit() { verify(springBootCommonService).addLogger(any(Project.class), anyString(), any(Level.class)); verify(springBootCommonService).addLoggerTest(any(Project.class), anyString(), any(Level.class)); - verify(projectRepository, times(15)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, times(13)).template(any(ProjectFile.class)); + verify(projectRepository).template(ProjectFilesAsserter.filesCountArgument(2)); } @Test @@ -74,7 +74,8 @@ void shouldAddSpringBootUndertow() { verify(springBootCommonService).addLogger(any(Project.class), anyString(), any(Level.class)); verify(springBootCommonService).addLoggerTest(any(Project.class), anyString(), any(Level.class)); - verify(projectRepository, times(15)).template(any(Project.class), anyString(), anyString(), anyString()); + verify(projectRepository, times(13)).template(any(ProjectFile.class)); + verify(projectRepository).template(ProjectFilesAsserter.filesCountArgument(2)); } @Test diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/springcloud/common/domain/SpringCloudCommonDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/springcloud/common/domain/SpringCloudCommonDomainServiceTest.java index b1e889c99d4..4bdcc60ffb1 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/springcloud/common/domain/SpringCloudCommonDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/springcloud/common/domain/SpringCloudCommonDomainServiceTest.java @@ -32,6 +32,7 @@ import tech.jhipster.lite.generator.buildtool.generic.domain.Dependency; import tech.jhipster.lite.generator.docker.domain.DockerService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; @UnitTest @@ -43,16 +44,16 @@ class SpringCloudCommonDomainServiceTest { public static final String DESTINATION_FILE_FOLDER = "src/main/resources/config"; @Mock - ProjectRepository projectRepository; + private ProjectRepository projectRepository; @Mock - BuildToolService buildToolService; + private BuildToolService buildToolService; @Mock - DockerService dockerService; + private DockerService dockerService; @InjectMocks - SpringCloudCommonDomainService springCloudCommonDomainService; + private SpringCloudCommonDomainService springCloudCommonDomainService; private Dependency getExpectedManagementDependency() { return Dependency @@ -127,24 +128,7 @@ void shouldAddJhipsterRegistryDockerCompose() { assertThat(project.getConfig("jhipsterRegistryDockerImage")).contains("jhipster/jhipster-registry:1.1.1"); assertThat(project.getConfig("base64JwtSecret")).contains(expectedBase64Secret); - verify(projectRepository, times(2)).template(any(Project.class), anyString(), anyString(), anyString(), anyString()); - verify(projectRepository) - .template( - project, - "server/springboot/springcloud/configclient", - "jhipster-registry.yml", - "src/main/docker", - "jhipster-registry.yml" - ); - - verify(projectRepository) - .template( - project, - "server/springboot/springcloud/configclient", - "application.config.properties", - "src/main/docker/central-server-config/localhost-config", - "application.properties" - ); + verify(projectRepository, times(2)).template(any(ProjectFile.class)); } } @@ -183,7 +167,7 @@ void shouldCreatePropertyFiles() { // Then fileUtils.verify(() -> FileUtils.exists(destinationFilePath)); fileUtils.verify(() -> FileUtils.getPath(folderPath, DESTINATION_FILE_FOLDER, SOURCE_FILE_NAME)); - verify(projectRepository).template(project, SOURCE_FOLDER_PATH, SOURCE_FILE_NAME, DESTINATION_FILE_FOLDER); + verify(projectRepository).template(any(ProjectFile.class)); } } diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/springcloud/consul/domain/ConsulDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/springcloud/consul/domain/ConsulDomainServiceTest.java index b012809bf9c..af5861970b2 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/springcloud/consul/domain/ConsulDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/springcloud/consul/domain/ConsulDomainServiceTest.java @@ -1,12 +1,9 @@ package tech.jhipster.lite.generator.server.springboot.springcloud.consul.domain; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static tech.jhipster.lite.TestUtils.tmpProjectWithPomXml; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; +import static tech.jhipster.lite.TestUtils.*; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -20,6 +17,7 @@ import tech.jhipster.lite.generator.buildtool.generic.domain.Dependency; import tech.jhipster.lite.generator.docker.domain.DockerService; import tech.jhipster.lite.generator.project.domain.Project; +import tech.jhipster.lite.generator.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.springcloud.common.domain.SpringCloudCommonService; @@ -28,19 +26,19 @@ class ConsulDomainServiceTest { @Mock - ProjectRepository projectRepository; + private ProjectRepository projectRepository; @Mock - BuildToolService buildToolService; + private BuildToolService buildToolService; @Mock - SpringCloudCommonService springCloudCommonService; + private SpringCloudCommonService springCloudCommonService; @Mock - DockerService dockerService; + private DockerService dockerService; @InjectMocks - ConsulDomainService consulDomainService; + private ConsulDomainService consulDomainService; @Test void shouldInit() { @@ -55,7 +53,7 @@ void shouldInit() { verify(buildToolService, times(2)).addDependency(any(Project.class), any(Dependency.class)); verify(springCloudCommonService, times(3)).addOrMergeBootstrapProperties(any(Project.class), anyString(), anyString(), anyString()); - verify(projectRepository, times(2)).template(any(Project.class), anyString(), anyString(), anyString(), anyString()); + verify(projectRepository, times(2)).template(any(ProjectFile.class)); } @Test diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/springcloud/gateway/domain/GatewayDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/springcloud/gateway/domain/GatewayDomainServiceTest.java index 580ca2d9e77..6f24b7e552a 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/springcloud/gateway/domain/GatewayDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/springcloud/gateway/domain/GatewayDomainServiceTest.java @@ -1,11 +1,9 @@ package tech.jhipster.lite.generator.server.springboot.springcloud.gateway.domain; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static tech.jhipster.lite.TestUtils.tmpProject; -import static tech.jhipster.lite.TestUtils.tmpProjectWithPomXml; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; +import static tech.jhipster.lite.TestUtils.*; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -18,6 +16,7 @@ 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.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.springcloud.common.domain.SpringCloudCommonService; @@ -51,27 +50,7 @@ void shouldInit() { verify(springCloudCommonService).addSpringCloudCommonDependencies(project); verify(buildToolService).addDependency(any(Project.class), any(Dependency.class)); - verify(projectRepository) - .template( - project, - "server/springboot/springcloud/gateway/java", - "GatewayResource.java", - "src/main/java/com/mycompany/myapp/technical/infrastructure/primary/rest" - ); - verify(projectRepository) - .template( - project, - "server/springboot/springcloud/gateway/java", - "RouteVM.java", - "src/main/java/com/mycompany/myapp/technical/infrastructure/primary/rest/vm" - ); - verify(projectRepository) - .template( - project, - "server/springboot/springcloud/gateway/java/test", - "GatewayResourceIT.java", - "src/test/java/com/mycompany/myapp/technical/infrastructure/primary/rest" - ); + verify(projectRepository, times(3)).template(any(ProjectFile.class)); verify(springCloudCommonService) .addOrMergeBootstrapProperties( project, diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/webflux/web/domain/SpringBootWebfluxDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/webflux/web/domain/SpringBootWebfluxDomainServiceTest.java index b4ed2a4a70e..970a9664c85 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/webflux/web/domain/SpringBootWebfluxDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/webflux/web/domain/SpringBootWebfluxDomainServiceTest.java @@ -1,14 +1,8 @@ package tech.jhipster.lite.generator.server.springboot.webflux.web.domain; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.assertj.core.api.Assertions.tuple; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; import java.util.HashMap; import java.util.List; @@ -28,6 +22,7 @@ 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.project.domain.ProjectFile; import tech.jhipster.lite.generator.project.domain.ProjectRepository; import tech.jhipster.lite.generator.server.springboot.common.domain.SpringBootCommonService; @@ -36,17 +31,17 @@ class SpringBootWebfluxDomainServiceTest { @Mock - ProjectRepository projectRepository; + private ProjectRepository projectRepository; @Mock - BuildToolService buildToolService; + private BuildToolService buildToolService; @Mock - SpringBootCommonService springBootCommonService; + private SpringBootCommonService springBootCommonService; - @InjectMocks @Spy - SpringBootWebfluxDomainService springBootWebfluxDomainService; + @InjectMocks + private SpringBootWebfluxDomainService springBootWebfluxDomainService; @Test void shouldInit() { @@ -120,37 +115,7 @@ void shouldAddExceptionHandler() { verify(springBootCommonService, times(1)).addPropertiesTest(any(Project.class), anyString(), anyString()); verify(springBootCommonService).addPropertiesTest(project, "application.exception.package", "org.,java."); - verify(projectRepository, times(12)).template(any(Project.class), anyString(), anyString(), anyString()); - - String expectedSourcePath = "server/springboot/webflux/web/src"; - String expectedDestinationSourcePath = "src/main/java/beer/technical/infrastructure/primary/exception"; - verify(projectRepository) - .template(any(Project.class), eq(expectedSourcePath), eq("ProblemConfiguration.java"), eq(expectedDestinationSourcePath)); - verify(projectRepository) - .template(any(Project.class), eq(expectedSourcePath), eq("HeaderUtil.java"), eq(expectedDestinationSourcePath)); - verify(projectRepository) - .template(any(Project.class), eq(expectedSourcePath), eq("BadRequestAlertException.java"), eq(expectedDestinationSourcePath)); - verify(projectRepository) - .template(any(Project.class), eq(expectedSourcePath), eq("ErrorConstants.java"), eq(expectedDestinationSourcePath)); - verify(projectRepository) - .template(any(Project.class), eq(expectedSourcePath), eq("ExceptionTranslator.java"), eq(expectedDestinationSourcePath)); - verify(projectRepository) - .template(any(Project.class), eq(expectedSourcePath), eq("FieldErrorDTO.java"), eq(expectedDestinationSourcePath)); - - String expectedTestPath = "server/springboot/webflux/web/test"; - String expectedDestinationTestPath = "src/test/java/beer/technical/infrastructure/primary/exception"; - verify(projectRepository) - .template(any(Project.class), eq(expectedTestPath), eq("HeaderUtilTest.java"), eq(expectedDestinationTestPath)); - verify(projectRepository) - .template(any(Project.class), eq(expectedTestPath), eq("BadRequestAlertExceptionTest.java"), eq(expectedDestinationTestPath)); - verify(projectRepository) - .template(any(Project.class), eq(expectedTestPath), eq("ExceptionTranslatorIT.java"), eq(expectedDestinationTestPath)); - verify(projectRepository) - .template(any(Project.class), eq(expectedTestPath), eq("ExceptionTranslatorTestController.java"), eq(expectedDestinationTestPath)); - verify(projectRepository) - .template(any(Project.class), eq(expectedTestPath), eq("FieldErrorDTOTest.java"), eq(expectedDestinationTestPath)); - - verify(projectRepository).template(any(Project.class), eq(expectedTestPath), eq("TestUtil.java"), eq("src/test/java/beer")); + verify(projectRepository, times(12)).template(any(ProjectFile.class)); } @Test diff --git a/src/test/java/tech/jhipster/lite/generator/setup/codespaces/domain/CodespacesDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/setup/codespaces/domain/CodespacesDomainServiceTest.java index 88c98e76eeb..be7e7316bdd 100644 --- a/src/test/java/tech/jhipster/lite/generator/setup/codespaces/domain/CodespacesDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/setup/codespaces/domain/CodespacesDomainServiceTest.java @@ -29,7 +29,7 @@ void shouldAddCodespacesFiles() { Project project = tmpProjectWithPackageJson(); codespacesDomainService.init(project); - verify(projectRepository).template(any(Project.class), anyString(), anyString(), anyString(), anyString()); + verify(projectRepository).template(any(ProjectFile.class)); verify(projectRepository).add(any(ProjectFile.class)); } }