Skip to content

Commit

Permalink
Merge pull request #1895 from pascalgrimaud/front-cucumber-button
Browse files Browse the repository at this point in the history
Front cucumber button
  • Loading branch information
pascalgrimaud authored May 30, 2022
2 parents cfed1c9 + 1016f89 commit 7bf1229
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import tech.jhipster.lite.technical.infrastructure.primary.annotation.GeneratorStep;

@RestController
@Tag(name = "Spring Boot")
@RequestMapping("/api/servers/spring-boot/cucumber")
@Tag(name = "Spring Boot - Component Tests")
@RequestMapping("/api/servers/spring-boot/component-tests/cucumber")
class CucumberResource {

private final CucumberApplicationService cucumber;
Expand Down
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 @@ -32,6 +32,7 @@ export enum Service {
SPRINGBOOT_OAUTH2_ACCOUNT = 'SPRINGBOOT_OAUTH2_ACCOUNT',
SPRINGBOOT_MVC_WITH_TOMCAT = 'SPRINGBOOT_MVC_WITH_TOMCAT',
SPRINGBOOT_WEBFLUX_NETTY = 'SPRINGBOOT_WEBFLUX_NETTY',
SPRINGBOOT_CUCUMBER = 'SPRINGBOOT_CUCUMBER',
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 @@ -36,6 +36,7 @@ const SERVICES: Record<string, Service> = {
'springboot-oauth2-account': Service.SPRINGBOOT_OAUTH2_ACCOUNT,
'springboot-tomcat': Service.SPRINGBOOT_MVC_WITH_TOMCAT,
'springboot-webflux-netty': Service.SPRINGBOOT_WEBFLUX_NETTY,
'springboot-cucumber': Service.SPRINGBOOT_CUCUMBER,
react: Service.REACT,
'react-styled': Service.REACT_STYLED,
vue: Service.VUE,
Expand Down
2 changes: 2 additions & 0 deletions src/main/webapp/app/springboot/domain/SpringBootService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ export interface SpringBootService {
addSpringBootDevtoolsDependencies(project: Project): Promise<void>;
addSpringBootDockerfile(project: Project): Promise<void>;
addSpringBootDockerJib(project: Project): Promise<void>;

addCucumber(project: Project): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type ServiceProjection =
| 'spring-boot-oauth2-account'
| 'spring-boot-mvc-with-tomcat'
| 'spring-boot-webflux-netty'
| 'spring-boot-cucumber'
| 'react'
| 'react-styled'
| 'vue'
Expand Down Expand Up @@ -73,6 +74,7 @@ const SERVICES_PROJECTION: Record<Service, ServiceProjection> = {
[Service.SPRINGBOOT_OAUTH2_ACCOUNT]: 'spring-boot-oauth2-account',
[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.REACT]: 'react',
[Service.REACT_STYLED]: 'react-styled',
[Service.VUE]: 'vue',
Expand Down Expand Up @@ -115,6 +117,7 @@ const SERVICES: Record<ServiceProjection, Service> = {
'spring-boot-oauth2-account': Service.SPRINGBOOT_OAUTH2_ACCOUNT,
'spring-boot-mvc-with-tomcat': Service.SPRINGBOOT_MVC_WITH_TOMCAT,
'spring-boot-webflux-netty': Service.SPRINGBOOT_WEBFLUX_NETTY,
'spring-boot-cucumber': Service.SPRINGBOOT_CUCUMBER,
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 @@ -206,6 +206,15 @@ export default defineComponent({
}
};

const addCucumber = async (): Promise<void> => {
if (props.project.folder !== '') {
await springBootService
.addCucumber(toProject(props.project as ProjectToUpdate))
.then(() => alertBus.success('Cucumber successfully added'))
.catch(error => alertBus.error(`Adding Cucumber to project failed ${error}`));
}
};

return {
selectorPrefix,
addSpringBoot,
Expand All @@ -228,6 +237,7 @@ export default defineComponent({
addLiquibase,
addLiquibaseUser,
addMongock,
addCucumber,
};
},
});
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="'Cucumber'"
:service="'spring-boot-cucumber'"
:selector-prefix="selectorPrefix"
@click.prevent="addCucumber"
/>
</div>
</div>
</div>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,8 @@ export default class SpringBootRepository implements SpringBootService {
async addSimpleCache(project: Project): Promise<void> {
await this.postAndGetHistory('/api/servers/spring-boot/caches/simple', toRestProject(project));
}

async addCucumber(project: Project): Promise<void> {
await this.postAndGetHistory('/api/servers/spring-boot/component-tests/cucumber', toRestProject(project));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public class CucumberSteps extends ModulesSteps {

@When("I add cucumber to default project with maven file")
public void addCucumberModule() {
applyModuleForDefaultProjectWithMavenFile("/api/servers/spring-boot/cucumber");
applyModuleForDefaultProjectWithMavenFile("/api/servers/spring-boot/component-tests/cucumber");
}
}
2 changes: 2 additions & 0 deletions src/test/javascript/cypress/integration/Generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ describe('Generator', () => {
cy.get(springBootGeneratorSelector('add-liquibase-button')).contains('Liquibase');
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-cucumber-button')).contains('Cucumber');
});

it('should display angular', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('RestServiceId', () => {
expect(toService('springdoc-openapi')).toEqual<Service>(Service.SPRING_DOC);
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('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 @@ -42,6 +42,8 @@ export interface SpringBootServiceFixture extends SpringBootService {
addOAuth2: SinonStub;
addOAuth2Account: SinonStub;
addSpringdocJWT: SinonStub;

addCucumber: SinonStub;
}

export const stubSpringBootService = (): SpringBootServiceFixture => ({
Expand Down Expand Up @@ -85,4 +87,6 @@ export const stubSpringBootService = (): SpringBootServiceFixture => ({
addOAuth2: sinon.stub(),
addOAuth2Account: sinon.stub(),
addSpringdocJWT: sinon.stub(),

addCucumber: sinon.stub(),
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('ServiceProjection', () => {
expect(toServiceProjection(Service.SPRINGBOOT_OAUTH2_ACCOUNT)).toEqual<ServiceProjection>('spring-boot-oauth2-account');
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.REACT)).toEqual<ServiceProjection>('react');
expect(toServiceProjection(Service.REACT_STYLED)).toEqual<ServiceProjection>('react-styled');
expect(toServiceProjection(Service.VUE)).toEqual<ServiceProjection>('vue');
Expand Down Expand Up @@ -86,6 +87,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-cucumber')).toEqual<Service>(Service.SPRINGBOOT_CUCUMBER);
expect(fromServiceProjection('react')).toEqual<Service>(Service.REACT);
expect(fromServiceProjection('react-styled')).toEqual<Service>(Service.REACT_STYLED);
expect(fromServiceProjection('vue')).toEqual<Service>(Service.VUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,4 +863,46 @@ describe('SpringBootGenerator', () => {
expectAlertErrorToBe(alertBus, 'Adding SpringBoot Database Migration Mongock to project failed error');
});
});

describe('Component tests', () => {
it('should not add Cucumber when project path is not filled', async () => {
const springBootService = stubSpringBootService();
springBootService.addCucumber.resolves({});
await wrap({ springBootService, project: createProjectToUpdate({ folder: '' }) });

await component.addCucumber();

expect(springBootService.addCucumber.called).toBe(false);
});

it('should add Cucumber when project path is filled', async () => {
const springBootService = stubSpringBootService();
springBootService.addCucumber.resolves({});
const alertBus = stubAlertBus();
await wrap({ alertBus, springBootService, project: createProjectToUpdate({ folder: 'project/path' }) });

await component.addCucumber();

const args = springBootService.addCucumber.getCall(0).args[0];
expect(args).toEqual({
baseName: 'beer',
folder: 'project/path',
projectName: 'Beer Project',
packageName: 'tech.jhipster.beer',
serverPort: 8080,
});
expectAlertSuccessToBe(alertBus, 'Cucumber successfully added');
});

it('should handle error on adding Cucumber failure', async () => {
const springBootService = stubSpringBootService();
springBootService.addCucumber.rejects('error');
const alertBus = stubAlertBus();
await wrap({ alertBus, springBootService, project: createProjectToUpdate({ folder: 'project/path' }) });

await component.addCucumber();

expectAlertErrorToBe(alertBus, 'Adding Cucumber to project failed error');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -638,4 +638,21 @@ describe('SpringBootRepository', () => {
const [projectFolder] = projectHistoryService.get.getCall(0).args;
expect(projectFolder).toBe(PROJECT_FOLDER);
});

it('should add Cucumber', 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.addCucumber(project);

const expectedRestProject: RestProject = toRestProject(project);
const [uri, payload] = axiosHttpStub.post.getCall(0).args;
expect(uri).toBe('/api/servers/spring-boot/component-tests/cucumber');
expect(payload).toEqual<RestProject>(expectedRestProject);
const [projectFolder] = projectHistoryService.get.getCall(0).args;
expect(projectFolder).toBe(PROJECT_FOLDER);
});
});
2 changes: 1 addition & 1 deletion tests-ci/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ elif [[ $application == 'fullapp' ]]; then

callApi "/api/servers/spring-boot/databases/postgresql"
callApi "/api/servers/spring-boot/features/user/postgresql"
callApi "/api/servers/spring-boot/cucumber"
callApi "/api/servers/spring-boot/component-tests/cucumber"
callApi "/api/servers/spring-boot/database-migration-tools/liquibase"
callApi "/api/servers/spring-boot/database-migration-tools/liquibase/user"

Expand Down

0 comments on commit 7bf1229

Please sign in to comment.