From 14bc664255daafb31d5cb1264e35f599fa1de349 Mon Sep 17 00:00:00 2001 From: Pascal Grimaud Date: Mon, 30 May 2022 22:11:20 +0200 Subject: [PATCH] Front: add Pulsar button --- src/main/webapp/app/common/domain/Service.ts | 1 + .../app/common/secondary/RestServiceId.ts | 1 + .../springboot/domain/SpringBootService.ts | 1 + .../primary/generator/ServiceProjection.ts | 3 ++ .../SpringBootGenerator.component.ts | 10 +++++ .../SpringBootGenerator.vue | 8 ++++ .../secondary/SpringBootRepository.ts | 4 ++ .../cypress/integration/Generator.spec.ts | 1 + .../common/secondary/RestServiceId.spec.ts | 1 + .../domain/SpringBootService.fixture.ts | 2 + .../generator/ServiceProjection.spec.ts | 2 + .../SpringBootGenerator.spec.ts | 42 +++++++++++++++++++ .../secondary/SpringBootRepository.spec.ts | 17 ++++++++ 13 files changed, 93 insertions(+) diff --git a/src/main/webapp/app/common/domain/Service.ts b/src/main/webapp/app/common/domain/Service.ts index 3a17c2aa5f4..2d74ff36877 100644 --- a/src/main/webapp/app/common/domain/Service.ts +++ b/src/main/webapp/app/common/domain/Service.ts @@ -33,6 +33,7 @@ export enum Service { SPRINGBOOT_MVC_WITH_TOMCAT = 'SPRINGBOOT_MVC_WITH_TOMCAT', SPRINGBOOT_WEBFLUX_NETTY = 'SPRINGBOOT_WEBFLUX_NETTY', SPRINGBOOT_CUCUMBER = 'SPRINGBOOT_CUCUMBER', + SPRINGBOOT_PULSAR = 'SPRINGBOOT_PULSAR', REACT = 'REACT', REACT_STYLED = 'REACT_STYLED', VUE = 'VUE', diff --git a/src/main/webapp/app/common/secondary/RestServiceId.ts b/src/main/webapp/app/common/secondary/RestServiceId.ts index f3bcb35ab3a..b3b929dd281 100644 --- a/src/main/webapp/app/common/secondary/RestServiceId.ts +++ b/src/main/webapp/app/common/secondary/RestServiceId.ts @@ -37,6 +37,7 @@ const SERVICES: Record = { 'springboot-tomcat': Service.SPRINGBOOT_MVC_WITH_TOMCAT, 'springboot-webflux-netty': Service.SPRINGBOOT_WEBFLUX_NETTY, 'springboot-cucumber': Service.SPRINGBOOT_CUCUMBER, + 'springboot-pulsar': Service.SPRINGBOOT_PULSAR, react: Service.REACT, 'react-styled': Service.REACT_STYLED, vue: Service.VUE, diff --git a/src/main/webapp/app/springboot/domain/SpringBootService.ts b/src/main/webapp/app/springboot/domain/SpringBootService.ts index cb1e8d1d77e..42b4347b160 100644 --- a/src/main/webapp/app/springboot/domain/SpringBootService.ts +++ b/src/main/webapp/app/springboot/domain/SpringBootService.ts @@ -41,4 +41,5 @@ export interface SpringBootService { addSpringBootDockerJib(project: Project): Promise; addCucumber(project: Project): Promise; + addPulsar(project: Project): Promise; } diff --git a/src/main/webapp/app/springboot/primary/generator/ServiceProjection.ts b/src/main/webapp/app/springboot/primary/generator/ServiceProjection.ts index 729562d0f39..6f0823b5f12 100644 --- a/src/main/webapp/app/springboot/primary/generator/ServiceProjection.ts +++ b/src/main/webapp/app/springboot/primary/generator/ServiceProjection.ts @@ -35,6 +35,7 @@ export type ServiceProjection = | 'spring-boot-mvc-with-tomcat' | 'spring-boot-webflux-netty' | 'spring-boot-cucumber' + | 'spring-boot-pulsar' | 'react' | 'react-styled' | 'vue' @@ -75,6 +76,7 @@ const SERVICES_PROJECTION: Record = { [Service.SPRINGBOOT_MVC_WITH_TOMCAT]: 'spring-boot-mvc-with-tomcat', [Service.SPRINGBOOT_WEBFLUX_NETTY]: 'spring-boot-webflux-netty', [Service.SPRINGBOOT_CUCUMBER]: 'spring-boot-cucumber', + [Service.SPRINGBOOT_PULSAR]: 'spring-boot-pulsar', [Service.REACT]: 'react', [Service.REACT_STYLED]: 'react-styled', [Service.VUE]: 'vue', @@ -118,6 +120,7 @@ const SERVICES: Record = { 'spring-boot-mvc-with-tomcat': Service.SPRINGBOOT_MVC_WITH_TOMCAT, 'spring-boot-webflux-netty': Service.SPRINGBOOT_WEBFLUX_NETTY, 'spring-boot-cucumber': Service.SPRINGBOOT_CUCUMBER, + 'spring-boot-pulsar': Service.SPRINGBOOT_PULSAR, react: Service.REACT, 'react-styled': Service.REACT_STYLED, vue: Service.VUE, 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 c3be1f22e8f..63f66eeba55 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 @@ -215,6 +215,15 @@ export default defineComponent({ } }; + const addPulsar = async (): Promise => { + if (props.project.folder !== '') { + await springBootService + .addPulsar(toProject(props.project as ProjectToUpdate)) + .then(() => alertBus.success('Pulsar successfully added')) + .catch(error => alertBus.error(`Adding Pulsar to project failed ${error}`)); + } + }; + return { selectorPrefix, addSpringBoot, @@ -238,6 +247,7 @@ export default defineComponent({ addLiquibaseUser, addMongock, addCucumber, + addPulsar, }; }, }); 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 2b500b3d39e..f657695032a 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 @@ -96,6 +96,14 @@ /> +
+ +
{ await this.postAndGetHistory('/api/servers/spring-boot/component-tests/cucumber', toRestProject(project)); } + + async addPulsar(project: Project): Promise { + await this.postAndGetHistory('/api/servers/spring-boot/brokers/pulsar', toRestProject(project)); + } } diff --git a/src/test/javascript/cypress/integration/Generator.spec.ts b/src/test/javascript/cypress/integration/Generator.spec.ts index 5c9aea47e1b..a1d66f9d16b 100644 --- a/src/test/javascript/cypress/integration/Generator.spec.ts +++ b/src/test/javascript/cypress/integration/Generator.spec.ts @@ -58,6 +58,7 @@ describe('Generator', () => { 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-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 7f48977b477..a17ec4b9b0b 100644 --- a/src/test/javascript/spec/common/secondary/RestServiceId.spec.ts +++ b/src/test/javascript/spec/common/secondary/RestServiceId.spec.ts @@ -37,6 +37,7 @@ describe('RestServiceId', () => { expect(toService('springboot-tomcat')).toEqual(Service.SPRINGBOOT_MVC_WITH_TOMCAT); expect(toService('springboot-webflux-netty')).toEqual(Service.SPRINGBOOT_WEBFLUX_NETTY); expect(toService('springboot-cucumber')).toEqual(Service.SPRINGBOOT_CUCUMBER); + expect(toService('springboot-pulsar')).toEqual(Service.SPRINGBOOT_PULSAR); expect(toService('react')).toEqual(Service.REACT); expect(toService('react-styled')).toEqual(Service.REACT_STYLED); expect(toService('vue')).toEqual(Service.VUE); diff --git a/src/test/javascript/spec/springboot/domain/SpringBootService.fixture.ts b/src/test/javascript/spec/springboot/domain/SpringBootService.fixture.ts index 3b11a398588..0b60f9d1846 100644 --- a/src/test/javascript/spec/springboot/domain/SpringBootService.fixture.ts +++ b/src/test/javascript/spec/springboot/domain/SpringBootService.fixture.ts @@ -43,6 +43,7 @@ export interface SpringBootServiceFixture extends SpringBootService { addOAuth2Account: SinonStub; addSpringdocJWT: SinonStub; + addPulsar: SinonStub; addCucumber: SinonStub; } @@ -88,5 +89,6 @@ export const stubSpringBootService = (): SpringBootServiceFixture => ({ addOAuth2Account: sinon.stub(), addSpringdocJWT: sinon.stub(), + addPulsar: sinon.stub(), addCucumber: sinon.stub(), }); 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 a57b933a8a5..6ee29b069a3 100644 --- a/src/test/javascript/spec/springboot/primary/generator/ServiceProjection.spec.ts +++ b/src/test/javascript/spec/springboot/primary/generator/ServiceProjection.spec.ts @@ -43,6 +43,7 @@ describe('ServiceProjection', () => { expect(toServiceProjection(Service.SPRINGBOOT_MVC_WITH_TOMCAT)).toEqual('spring-boot-mvc-with-tomcat'); expect(toServiceProjection(Service.SPRINGBOOT_WEBFLUX_NETTY)).toEqual('spring-boot-webflux-netty'); expect(toServiceProjection(Service.SPRINGBOOT_CUCUMBER)).toEqual('spring-boot-cucumber'); + expect(toServiceProjection(Service.SPRINGBOOT_PULSAR)).toEqual('spring-boot-pulsar'); expect(toServiceProjection(Service.REACT)).toEqual('react'); expect(toServiceProjection(Service.REACT_STYLED)).toEqual('react-styled'); expect(toServiceProjection(Service.VUE)).toEqual('vue'); @@ -87,6 +88,7 @@ describe('ServiceProjection', () => { ); expect(fromServiceProjection('spring-boot-mvc-with-tomcat')).toEqual(Service.SPRINGBOOT_MVC_WITH_TOMCAT); expect(fromServiceProjection('spring-boot-webflux-netty')).toEqual(Service.SPRINGBOOT_WEBFLUX_NETTY); + expect(fromServiceProjection('spring-boot-pulsar')).toEqual(Service.SPRINGBOOT_PULSAR); expect(fromServiceProjection('spring-boot-cucumber')).toEqual(Service.SPRINGBOOT_CUCUMBER); expect(fromServiceProjection('react')).toEqual(Service.REACT); expect(fromServiceProjection('react-styled')).toEqual(Service.REACT_STYLED); 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 45c8c6ac7ed..a4d8115e62a 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 @@ -864,6 +864,48 @@ describe('SpringBootGenerator', () => { }); }); + describe('Brokers', () => { + it('should not add Pulsar when project path is not filled', async () => { + const springBootService = stubSpringBootService(); + springBootService.addPulsar.resolves({}); + await wrap({ springBootService, project: createProjectToUpdate({ folder: '' }) }); + + await component.addPulsar(); + + expect(springBootService.addPulsar.called).toBe(false); + }); + + it('should add Pulsar when project path is filled', async () => { + const springBootService = stubSpringBootService(); + springBootService.addPulsar.resolves({}); + const alertBus = stubAlertBus(); + await wrap({ alertBus, springBootService, project: createProjectToUpdate({ folder: 'project/path' }) }); + + await component.addPulsar(); + + const args = springBootService.addPulsar.getCall(0).args[0]; + expect(args).toEqual({ + baseName: 'beer', + folder: 'project/path', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: 8080, + }); + expectAlertSuccessToBe(alertBus, 'Pulsar successfully added'); + }); + + it('should handle error on adding Pulsar failure', async () => { + const springBootService = stubSpringBootService(); + springBootService.addPulsar.rejects('error'); + const alertBus = stubAlertBus(); + await wrap({ alertBus, springBootService, project: createProjectToUpdate({ folder: 'project/path' }) }); + + await component.addPulsar(); + + expectAlertErrorToBe(alertBus, 'Adding Pulsar to project failed error'); + }); + }); + describe('Component tests', () => { it('should not add Cucumber when project path is not filled', async () => { const springBootService = stubSpringBootService(); diff --git a/src/test/javascript/spec/springboot/secondary/SpringBootRepository.spec.ts b/src/test/javascript/spec/springboot/secondary/SpringBootRepository.spec.ts index 6200cf340f2..943cf93b2a9 100644 --- a/src/test/javascript/spec/springboot/secondary/SpringBootRepository.spec.ts +++ b/src/test/javascript/spec/springboot/secondary/SpringBootRepository.spec.ts @@ -639,6 +639,23 @@ describe('SpringBootRepository', () => { expect(projectFolder).toBe(PROJECT_FOLDER); }); + it('should add Pulsar', 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.addPulsar(project); + + const expectedRestProject: RestProject = toRestProject(project); + const [uri, payload] = axiosHttpStub.post.getCall(0).args; + expect(uri).toBe('/api/servers/spring-boot/brokers/pulsar'); + expect(payload).toEqual(expectedRestProject); + const [projectFolder] = projectHistoryService.get.getCall(0).args; + expect(projectFolder).toBe(PROJECT_FOLDER); + }); + it('should add Cucumber', async () => { const projectHistoryService = stubProjectHistoryService(); const axiosHttpStub = stubAxiosHttp();