From e7e089fed8f3d4b04b389f63825c0cd70c1e361d Mon Sep 17 00:00:00 2001 From: MathieuAA Date: Tue, 11 May 2021 07:54:01 +0200 Subject: [PATCH] Added missing jdl deployment options fixes #14817 --- jdl/jhipster/deployment-options.js | 39 ++++++++++++++++++------- test/jdl/jdl-importer.spec.js | 47 ++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 11 deletions(-) diff --git a/jdl/jhipster/deployment-options.js b/jdl/jhipster/deployment-options.js index ea01ff12f7a..4ec3c416109 100644 --- a/jdl/jhipster/deployment-options.js +++ b/jdl/jhipster/deployment-options.js @@ -25,6 +25,29 @@ const DeploymentTypes = { exists: deploymentType => !!deploymentType && !!DeploymentTypes[deploymentType.toUpperCase().replace('-', '')], }; +const kubernetesRelatedOptions = { + kubernetesNamespace: 'default', + kubernetesServiceType: { + loadBalancer: 'LoadBalancer', + nodePort: 'NodePort', + ingress: 'Ingress', + }, + kubernetesStorageClassName: '', + kubernetesUseDynamicStorage: { + false: false, + true: true, + }, + ingressDomain: '', + ingressType: { + nginx: 'nginx', + gke: 'gke', + }, + istio: { + false: false, + true: true, + }, +}; + const Options = { deploymentType: { dockerCompose: DeploymentTypes.DOCKERCOMPOSE, @@ -50,17 +73,7 @@ const Options = { dockerRepositoryName: '', dockerPushCommand: 'docker push', // Kubernetes specific - kubernetesNamespace: 'default', - kubernetesServiceType: { - loadBalancer: 'LoadBalancer', - nodePort: 'NodePort', - ingress: 'Ingress', - }, - ingressDomain: '', - istio: { - false: false, - true: true, - }, + ...kubernetesRelatedOptions, // openshift specific openshiftNamespace: 'default', storageType: { @@ -84,7 +97,11 @@ Options.defaults = (deploymentType = Options.deploymentType.dockerCompose) => dockerPushCommand: Options.dockerPushCommand, kubernetesNamespace: deploymentType === Options.deploymentType.kubernetes ? Options.kubernetesNamespace : undefined, kubernetesServiceType: deploymentType === Options.deploymentType.kubernetes ? Options.kubernetesServiceType.loadBalancer : undefined, + kubernetesStorageClassName: deploymentType === Options.deploymentType.kubernetes ? Options.kubernetesStorageClassName : '', + kubernetesUseDynamicStorage: + deploymentType === Options.deploymentType.kubernetes ? deploymentType === Options.deploymentType.kubernetes : false, ingressDomain: deploymentType === Options.deploymentType.kubernetes ? Options.ingressDomain : undefined, + ingressType: deploymentType === Options.deploymentType.kubernetes ? Options.ingressType.nginx : undefined, istio: deploymentType === Options.deploymentType.kubernetes ? Options.istio.false : undefined, openshiftNamespace: deploymentType === Options.deploymentType.openshift ? Options.openshiftNamespace : undefined, storageType: deploymentType === Options.deploymentType.openshift ? Options.storageType.ephemeral : undefined, diff --git a/test/jdl/jdl-importer.spec.js b/test/jdl/jdl-importer.spec.js index 83cc10032b4..8f2e22613cb 100644 --- a/test/jdl/jdl-importer.spec.js +++ b/test/jdl/jdl-importer.spec.js @@ -619,6 +619,53 @@ relationship OneToOne { }); }); }); + context('when parsing two JDL applications with and without entities ', () => { + let returned; + const APPLICATION_NAMES = ['app1', 'app2']; + + before(() => { + const importer = createImporterFromFiles([path.join(__dirname, 'test-files', 'applications_with_and_without_entities.jdl')]); + returned = importer.import(); + }); + + after(() => { + APPLICATION_NAMES.forEach(applicationName => { + fse.removeSync(applicationName); + }); + }); + + it('should return the import state', () => { + expect(returned.exportedEntities).to.have.lengthOf(1); + expect(returned.exportedApplications).to.have.lengthOf(2); + expect(Object.keys(returned.exportedApplicationsWithEntities).length).to.equal(2); + expect(returned.exportedDeployments).to.have.lengthOf(0); + }); + it('should create the folders and the .yo-rc.json files', () => { + APPLICATION_NAMES.forEach(applicationName => { + expect(fse.statSync(path.join(applicationName, '.yo-rc.json')).isFile()).to.be.true; + expect(fse.statSync(applicationName).isDirectory()).to.be.true; + }); + }); + it('should create the entity folder in only one app folder', () => { + expect(fse.existsSync(path.join(APPLICATION_NAMES[0], '.jhipster'))).to.be.false; + expect(fse.statSync(path.join(APPLICATION_NAMES[1], '.jhipster')).isDirectory()).to.be.true; + expect(fse.statSync(path.join(APPLICATION_NAMES[1], '.jhipster', 'BankAccount.json')).isFile()).to.be.true; + }); + it('should export the application contents', () => { + expect(returned.exportedApplicationsWithEntities[APPLICATION_NAMES[0]].entities).to.have.lengthOf(0); + expect(returned.exportedApplicationsWithEntities[APPLICATION_NAMES[1]].entities).to.have.lengthOf(1); + }); + it('should return the corresponding exportedApplicationsWithEntities', () => { + returned.exportedApplications.forEach(application => { + const applicationConfig = application['generator-jhipster']; + const entityNames = application.entities || []; + const applicationWithEntities = returned.exportedApplicationsWithEntities[applicationConfig.baseName]; + expect(applicationConfig).to.be.eql(applicationWithEntities.config); + expect(applicationWithEntities.entities.map(entity => entity.name)).to.be.eql(entityNames); + expect(returned.exportedEntities.filter(entity => entityNames.includes(entity.name))).to.be.eql(applicationWithEntities.entities); + }); + }); + }); context('when parsing one JDL application and entities passed as string', () => { let returned;