Skip to content

Commit

Permalink
Merge pull request #1897 from pascalgrimaud/front-pulsar-button
Browse files Browse the repository at this point in the history
Front: add Pulsar button
  • Loading branch information
pascalgrimaud authored May 31, 2022
2 parents e2620a8 + 14bc664 commit b79d568
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/webapp/app/common/domain/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/app/common/secondary/RestServiceId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const SERVICES: Record<string, Service> = {
'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,
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/app/springboot/domain/SpringBootService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ export interface SpringBootService {
addSpringBootDockerJib(project: Project): Promise<void>;

addCucumber(project: Project): Promise<void>;
addPulsar(project: Project): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -75,6 +76,7 @@ const SERVICES_PROJECTION: Record<Service, ServiceProjection> = {
[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',
Expand Down Expand Up @@ -118,6 +120,7 @@ const SERVICES: Record<ServiceProjection, Service> = {
'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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ export default defineComponent({
}
};

const addPulsar = async (): Promise<void> => {
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,
Expand All @@ -238,6 +247,7 @@ export default defineComponent({
addLiquibaseUser,
addMongock,
addCucumber,
addPulsar,
};
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@
/>
<GeneratorButtonVue :label="'Mongock'" :service="'mongock'" :selector-prefix="selectorPrefix" @click.prevent="addMongock" />
</div>
<div>
<GeneratorButtonVue
:label="'Pulsar'"
:service="'spring-boot-pulsar'"
:selector-prefix="selectorPrefix"
@click.prevent="addPulsar"
/>
</div>
<div>
<GeneratorButtonVue
:label="'Cucumber'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,8 @@ export default class SpringBootRepository implements SpringBootService {
async addCucumber(project: Project): Promise<void> {
await this.postAndGetHistory('/api/servers/spring-boot/component-tests/cucumber', toRestProject(project));
}

async addPulsar(project: Project): Promise<void> {
await this.postAndGetHistory('/api/servers/spring-boot/brokers/pulsar', toRestProject(project));
}
}
1 change: 1 addition & 0 deletions src/test/javascript/cypress/integration/Generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('RestServiceId', () => {
expect(toService('springboot-tomcat')).toEqual<Service>(Service.SPRINGBOOT_MVC_WITH_TOMCAT);
expect(toService('springboot-webflux-netty')).toEqual<Service>(Service.SPRINGBOOT_WEBFLUX_NETTY);
expect(toService('springboot-cucumber')).toEqual<Service>(Service.SPRINGBOOT_CUCUMBER);
expect(toService('springboot-pulsar')).toEqual<Service>(Service.SPRINGBOOT_PULSAR);
expect(toService('react')).toEqual<Service>(Service.REACT);
expect(toService('react-styled')).toEqual<Service>(Service.REACT_STYLED);
expect(toService('vue')).toEqual<Service>(Service.VUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface SpringBootServiceFixture extends SpringBootService {
addOAuth2Account: SinonStub;
addSpringdocJWT: SinonStub;

addPulsar: SinonStub;
addCucumber: SinonStub;
}

Expand Down Expand Up @@ -88,5 +89,6 @@ export const stubSpringBootService = (): SpringBootServiceFixture => ({
addOAuth2Account: sinon.stub(),
addSpringdocJWT: sinon.stub(),

addPulsar: sinon.stub(),
addCucumber: sinon.stub(),
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('ServiceProjection', () => {
expect(toServiceProjection(Service.SPRINGBOOT_MVC_WITH_TOMCAT)).toEqual<ServiceProjection>('spring-boot-mvc-with-tomcat');
expect(toServiceProjection(Service.SPRINGBOOT_WEBFLUX_NETTY)).toEqual<ServiceProjection>('spring-boot-webflux-netty');
expect(toServiceProjection(Service.SPRINGBOOT_CUCUMBER)).toEqual<ServiceProjection>('spring-boot-cucumber');
expect(toServiceProjection(Service.SPRINGBOOT_PULSAR)).toEqual<ServiceProjection>('spring-boot-pulsar');
expect(toServiceProjection(Service.REACT)).toEqual<ServiceProjection>('react');
expect(toServiceProjection(Service.REACT_STYLED)).toEqual<ServiceProjection>('react-styled');
expect(toServiceProjection(Service.VUE)).toEqual<ServiceProjection>('vue');
Expand Down Expand Up @@ -87,6 +88,7 @@ describe('ServiceProjection', () => {
);
expect(fromServiceProjection('spring-boot-mvc-with-tomcat')).toEqual<Service>(Service.SPRINGBOOT_MVC_WITH_TOMCAT);
expect(fromServiceProjection('spring-boot-webflux-netty')).toEqual<Service>(Service.SPRINGBOOT_WEBFLUX_NETTY);
expect(fromServiceProjection('spring-boot-pulsar')).toEqual<Service>(Service.SPRINGBOOT_PULSAR);
expect(fromServiceProjection('spring-boot-cucumber')).toEqual<Service>(Service.SPRINGBOOT_CUCUMBER);
expect(fromServiceProjection('react')).toEqual<Service>(Service.REACT);
expect(fromServiceProjection('react-styled')).toEqual<Service>(Service.REACT_STYLED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RestProject>(expectedRestProject);
const [projectFolder] = projectHistoryService.get.getCall(0).args;
expect(projectFolder).toBe(PROJECT_FOLDER);
});

it('should add Cucumber', async () => {
const projectHistoryService = stubProjectHistoryService();
const axiosHttpStub = stubAxiosHttp();
Expand Down

0 comments on commit b79d568

Please sign in to comment.