Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Front: add docker file button #2058

Merged
merged 1 commit into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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',
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 @@ -7,6 +7,7 @@ const SERVICES: Record<string, Service> = {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type ServiceProjection =
| 'angular'
| 'angular-with-jwt'
| 'angular-oauth2'
| 'dockerfile'
| 'download'
| 'initialization'
| 'flyway'
Expand Down Expand Up @@ -49,6 +50,7 @@ const SERVICES_PROJECTION: Record<Service, ServiceProjection> = {
[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',
Expand Down Expand Up @@ -96,6 +98,7 @@ const SERVICES: Record<ServiceProjection, Service> = {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ export default defineComponent({
}
};

const addDockerFile = async (): Promise<void> => {
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,
Expand Down Expand Up @@ -278,6 +287,7 @@ export default defineComponent({
addMongock,
addCucumber,
addPulsar,
addDockerFile,
};
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@
/>
<GeneratorButtonVue :label="'Mongock'" :service="'mongock'" :selector-prefix="selectorPrefix" @click.prevent="addMongock" />
</div>
<div>
<GeneratorButtonVue
:label="'Docker file'"
:service="'dockerfile'"
:selector-prefix="selectorPrefix"
@click.prevent="addDockerFile"
/>
</div>
<div>
<GeneratorButtonVue
:label="'Pulsar'"
Expand Down
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 @@ -60,6 +60,8 @@ 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-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');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('RestServiceId', () => {
expect(toService('angular')).toEqual<Service>(Service.ANGULAR);
expect(toService('angular-jwt')).toEqual<Service>(Service.ANGULAR_WITH_JWT);
expect(toService('angular-oauth2')).toEqual<Service>(Service.ANGULAR_OAUTH2);
expect(toService('dockerfile')).toEqual<Service>(Service.DOCKERFILE);
expect(toService('download')).toEqual<Service>(Service.DOWNLOAD);
expect(toService('flyway')).toEqual<Service>(Service.FLYWAY);
expect(toService('flyway-user-and-authority-changelogs')).toEqual<Service>(Service.FLYWAY_WITH_USERS_AND_AUTHORITY_CHANGELOGS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('ServiceProjection', () => {
expect(fromServiceProjection('angular')).toEqual<Service>(Service.ANGULAR);
expect(fromServiceProjection('angular-with-jwt')).toEqual<Service>(Service.ANGULAR_WITH_JWT);
expect(fromServiceProjection('angular-oauth2')).toEqual<Service>(Service.ANGULAR_OAUTH2);
expect(fromServiceProjection('dockerfile')).toEqual<Service>(Service.DOCKERFILE);
expect(fromServiceProjection('download')).toEqual<Service>(Service.DOWNLOAD);
expect(fromServiceProjection('flyway')).toEqual<Service>(Service.FLYWAY);
expect(fromServiceProjection('flyway-with-users-and-authority-changelogs')).toEqual<Service>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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<RestProject>(expectedRestProject);
const [projectFolder] = projectHistoryService.get.getCall(0).args;
expect(projectFolder).toBe(PROJECT_FOLDER);
});
});