diff --git a/src/main/webapp/app/common/domain/Service.ts b/src/main/webapp/app/common/domain/Service.ts index 0268ea3544d..12f69d1471b 100644 --- a/src/main/webapp/app/common/domain/Service.ts +++ b/src/main/webapp/app/common/domain/Service.ts @@ -3,6 +3,7 @@ export enum Service { ANGULAR = 'ANGULAR', ANGULAR_WITH_JWT = 'ANGULAR_WITH_JWT', ANGULAR_OAUTH2 = 'ANGULAR_OAUTH2', + DOCKERFILE = 'DOCKERFILE', DOWNLOAD = 'DOWNLOAD', FLYWAY = 'FLYWAY', FLYWAY_WITH_USERS_AND_AUTHORITY_CHANGELOGS = 'FLYWAY_WITH_USERS_AND_AUTHORITY_CHANGELOGS', diff --git a/src/main/webapp/app/common/secondary/RestServiceId.ts b/src/main/webapp/app/common/secondary/RestServiceId.ts index ac4c40b2589..1c5b331674a 100644 --- a/src/main/webapp/app/common/secondary/RestServiceId.ts +++ b/src/main/webapp/app/common/secondary/RestServiceId.ts @@ -7,6 +7,7 @@ const SERVICES: Record = { angular: Service.ANGULAR, 'angular-jwt': Service.ANGULAR_WITH_JWT, 'angular-oauth2': Service.ANGULAR_OAUTH2, + dockerfile: Service.DOCKERFILE, download: Service.DOWNLOAD, flyway: Service.FLYWAY, 'flyway-user-and-authority-changelogs': Service.FLYWAY_WITH_USERS_AND_AUTHORITY_CHANGELOGS, diff --git a/src/main/webapp/app/springboot/primary/generator/ServiceProjection.ts b/src/main/webapp/app/springboot/primary/generator/ServiceProjection.ts index 48c44ae76a3..94c18ee078a 100644 --- a/src/main/webapp/app/springboot/primary/generator/ServiceProjection.ts +++ b/src/main/webapp/app/springboot/primary/generator/ServiceProjection.ts @@ -5,6 +5,7 @@ export type ServiceProjection = | 'angular' | 'angular-with-jwt' | 'angular-oauth2' + | 'dockerfile' | 'download' | 'initialization' | 'flyway' @@ -49,6 +50,7 @@ const SERVICES_PROJECTION: Record = { [Service.ANGULAR]: 'angular', [Service.ANGULAR_WITH_JWT]: 'angular-with-jwt', [Service.ANGULAR_OAUTH2]: 'angular-oauth2', + [Service.DOCKERFILE]: 'dockerfile', [Service.DOWNLOAD]: 'download', [Service.FLYWAY]: 'flyway', [Service.FLYWAY_WITH_USERS_AND_AUTHORITY_CHANGELOGS]: 'flyway-with-users-and-authority-changelogs', @@ -96,6 +98,7 @@ const SERVICES: Record = { angular: Service.ANGULAR, 'angular-with-jwt': Service.ANGULAR_WITH_JWT, 'angular-oauth2': Service.ANGULAR_OAUTH2, + dockerfile: Service.DOCKERFILE, download: Service.DOWNLOAD, flyway: Service.FLYWAY, 'flyway-with-users-and-authority-changelogs': Service.FLYWAY_WITH_USERS_AND_AUTHORITY_CHANGELOGS, diff --git a/src/main/webapp/app/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.component.ts b/src/main/webapp/app/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.component.ts index 2eebff11a9e..c463d8650f4 100644 --- a/src/main/webapp/app/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.component.ts +++ b/src/main/webapp/app/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.component.ts @@ -251,6 +251,15 @@ export default defineComponent({ } }; + const addDockerFile = async (): Promise => { + if (props.project.folder !== '') { + await springBootService + .addSpringBootDockerfile(toProject(props.project as ProjectToUpdate)) + .then(() => alertBus.success('SpringBoot Docker file successfully added')) + .catch(error => alertBus.error(`Adding SpringBoot Docker file to project failed ${error}`)); + } + }; + return { selectorPrefix, addSpringBoot, @@ -278,6 +287,7 @@ export default defineComponent({ addMongock, addCucumber, addPulsar, + addDockerFile, }; }, }); diff --git a/src/main/webapp/app/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.vue b/src/main/webapp/app/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.vue index 54e69bc4b0d..116cc525027 100644 --- a/src/main/webapp/app/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.vue +++ b/src/main/webapp/app/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.vue @@ -108,6 +108,14 @@ /> +
+ +
{ cy.get(springBootGeneratorSelector('add-liquibase-with-users-and-authority-changelogs-button')).contains('Liquibase with users'); cy.get(springBootGeneratorSelector('add-mongock-button')).contains('Mongock'); + cy.get(springBootGeneratorSelector('add-dockerfile-button')).contains('Docker file'); + cy.get(springBootGeneratorSelector('add-spring-boot-pulsar-button')).contains('Pulsar'); cy.get(springBootGeneratorSelector('add-spring-boot-cucumber-button')).contains('Cucumber'); diff --git a/src/test/javascript/spec/common/secondary/RestServiceId.spec.ts b/src/test/javascript/spec/common/secondary/RestServiceId.spec.ts index c25374163c9..cef50e5dd9e 100644 --- a/src/test/javascript/spec/common/secondary/RestServiceId.spec.ts +++ b/src/test/javascript/spec/common/secondary/RestServiceId.spec.ts @@ -7,6 +7,7 @@ describe('RestServiceId', () => { expect(toService('angular')).toEqual(Service.ANGULAR); expect(toService('angular-jwt')).toEqual(Service.ANGULAR_WITH_JWT); expect(toService('angular-oauth2')).toEqual(Service.ANGULAR_OAUTH2); + expect(toService('dockerfile')).toEqual(Service.DOCKERFILE); expect(toService('download')).toEqual(Service.DOWNLOAD); expect(toService('flyway')).toEqual(Service.FLYWAY); expect(toService('flyway-user-and-authority-changelogs')).toEqual(Service.FLYWAY_WITH_USERS_AND_AUTHORITY_CHANGELOGS); diff --git a/src/test/javascript/spec/springboot/primary/generator/ServiceProjection.spec.ts b/src/test/javascript/spec/springboot/primary/generator/ServiceProjection.spec.ts index 94a70bb085e..5a9d059fe9c 100644 --- a/src/test/javascript/spec/springboot/primary/generator/ServiceProjection.spec.ts +++ b/src/test/javascript/spec/springboot/primary/generator/ServiceProjection.spec.ts @@ -60,6 +60,7 @@ describe('ServiceProjection', () => { expect(fromServiceProjection('angular')).toEqual(Service.ANGULAR); expect(fromServiceProjection('angular-with-jwt')).toEqual(Service.ANGULAR_WITH_JWT); expect(fromServiceProjection('angular-oauth2')).toEqual(Service.ANGULAR_OAUTH2); + expect(fromServiceProjection('dockerfile')).toEqual(Service.DOCKERFILE); expect(fromServiceProjection('download')).toEqual(Service.DOWNLOAD); expect(fromServiceProjection('flyway')).toEqual(Service.FLYWAY); expect(fromServiceProjection('flyway-with-users-and-authority-changelogs')).toEqual( diff --git a/src/test/javascript/spec/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.spec.ts b/src/test/javascript/spec/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.spec.ts index 2f4d96ad903..6343e327ee1 100644 --- a/src/test/javascript/spec/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.spec.ts +++ b/src/test/javascript/spec/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.spec.ts @@ -1062,4 +1062,45 @@ describe('SpringBootGenerator', () => { expectAlertErrorToBe(alertBus, 'Adding Cucumber to project failed error'); }); }); + describe('Tools', () => { + it('should not add docker file when project path is not filled', async () => { + const springBootService = stubSpringBootService(); + springBootService.addSpringBootDockerfile.resolves({}); + await wrap({ springBootService, project: createProjectToUpdate({ folder: '' }) }); + + await component.addDockerFile(); + + expect(springBootService.addSpringBootDockerfile.called).toBe(false); + }); + + it('should add docker file when project path is filled', async () => { + const springBootService = stubSpringBootService(); + springBootService.addSpringBootDockerfile.resolves({}); + const alertBus = stubAlertBus(); + await wrap({ alertBus, springBootService, project: createProjectToUpdate({ folder: 'project/path' }) }); + + await component.addDockerFile(); + + const args = springBootService.addSpringBootDockerfile.getCall(0).args[0]; + expect(args).toEqual({ + baseName: 'beer', + folder: 'project/path', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: 8080, + }); + expectAlertSuccessToBe(alertBus, 'SpringBoot Docker file successfully added'); + }); + + it('should handle error on adding docker file failure', async () => { + const springBootService = stubSpringBootService(); + springBootService.addSpringBootDockerfile.rejects('error'); + const alertBus = stubAlertBus(); + await wrap({ alertBus, springBootService, project: createProjectToUpdate({ folder: 'project/path' }) }); + + await component.addDockerFile(); + + expectAlertErrorToBe(alertBus, 'Adding SpringBoot Docker file to project failed error'); + }); + }); }); diff --git a/src/test/javascript/spec/springboot/secondary/SpringBootRepository.spec.ts b/src/test/javascript/spec/springboot/secondary/SpringBootRepository.spec.ts index 66af1e446f6..1079578f28a 100644 --- a/src/test/javascript/spec/springboot/secondary/SpringBootRepository.spec.ts +++ b/src/test/javascript/spec/springboot/secondary/SpringBootRepository.spec.ts @@ -706,4 +706,21 @@ describe('SpringBootRepository', () => { const [projectFolder] = projectHistoryService.get.getCall(0).args; expect(projectFolder).toBe(PROJECT_FOLDER); }); + + it('should add Docker file', async () => { + const projectHistoryService = stubProjectHistoryService(); + const axiosHttpStub = stubAxiosHttp(); + axiosHttpStub.post.resolves(); + const springBootRepository = new SpringBootRepository(axiosHttpStub, projectHistoryService); + const project: Project = createProject({ folder: PROJECT_FOLDER }); + + await springBootRepository.addSpringBootDockerfile(project); + + const expectedRestProject: RestProject = toRestProject(project); + const [uri, payload] = axiosHttpStub.post.getCall(0).args; + expect(uri).toBe('/api/servers/spring-boot/containers/docker/dockerfile'); + expect(payload).toEqual(expectedRestProject); + const [projectFolder] = projectHistoryService.get.getCall(0).args; + expect(projectFolder).toBe(PROJECT_FOLDER); + }); });