diff options
author | 2021-10-27 19:20:36 +0000 | |
---|---|---|
committer | 2021-10-27 19:20:36 +0000 | |
commit | c6f1b58aae6ecddeb4d2a615e017c625c7e29bfa (patch) | |
tree | 964fc26ae0dfa876d081871f00ce1d33b505e503 /mod2/helm-generator/helmchartgenerator-core/src/test | |
parent | 9e930892d28fc4a3378fad8f942c9f91cffe4698 (diff) | |
parent | f98abd8de6b9457a7edcd3457e664bd9200de2bf (diff) |
Merge "Add cmpv2Certificate flag, removed hyphens from config under postgres and enhanced Readme file"
Diffstat (limited to 'mod2/helm-generator/helmchartgenerator-core/src/test')
4 files changed, 99 insertions, 15 deletions
diff --git a/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/AddOnsManagerTest.java b/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/AddOnsManagerTest.java new file mode 100644 index 0000000..d7c697b --- /dev/null +++ b/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/AddOnsManagerTest.java @@ -0,0 +1,77 @@ +/** # ============LICENSE_START======================================================= + * # Copyright (c) 2021 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.helmchartgenerator; + +import org.apache.commons.io.FileUtils; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.dcaegen2.platform.helmchartgenerator.chartbuilder.AddOnsManager; +import org.onap.dcaegen2.platform.helmchartgenerator.models.componentspec.base.Auxilary; +import org.onap.dcaegen2.platform.helmchartgenerator.models.componentspec.base.ComponentSpec; +import org.onap.dcaegen2.platform.helmchartgenerator.models.componentspec.common.TlsInfo; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; + +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class AddOnsManagerTest { + + private AddOnsManager manager; + + @Mock + private Utils utils; + + @BeforeEach + void setUp() { + manager = new AddOnsManager(utils); + } + + @Test + void testIncludeCertificationYamlAddOn() throws Exception { + final String specFileLocation = "src/test/input/specs/ves.json"; + when(utils.deserializeJsonFileToModel(specFileLocation, ComponentSpec.class)).thenReturn(getMockCs()); + manager.includeAddons(specFileLocation, + new File("src/test/dcae-ves-collector"), + "src/test/input/blueprint"); + Assertions.assertTrue(Files.exists(Path.of("src/test/dcae-ves-collector/templates/certificates.yaml"))); + } + + private ComponentSpec getMockCs() { + ComponentSpec cs = new ComponentSpec(); + Auxilary auxilary = new Auxilary(); + TlsInfo tlsInfo = new TlsInfo(); + tlsInfo.setUseExternalTls(true); + tlsInfo.setUseTls(true); + auxilary.setTlsInfo(tlsInfo); + cs.setAuxilary(auxilary); + return cs; + } + + @AfterEach + void tearDown() throws Exception{ + FileUtils.deleteDirectory(new File("src/test/dcae-ves-collector")); + } +} diff --git a/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/ChartBuilderTest.java b/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/ChartBuilderTest.java index dd19382..b9ad2cb 100644 --- a/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/ChartBuilderTest.java +++ b/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/ChartBuilderTest.java @@ -48,7 +48,7 @@ class ChartBuilderTest { builder.build("someSpec", "someChartLocation", "someOutputLocation", "someSpecSchemaLocation"); Mockito.verify(specParser, Mockito.times(1)).extractChartInfo(any(), any(), any()); - Mockito.verify(chartGenerator, Mockito.times(1)).generate(any(), any(), any()); + Mockito.verify(chartGenerator, Mockito.times(1)).generate(any(), any(), any(), any()); Mockito.verify(validator, Mockito.times(1)).validateChartTemplateStructure(any()); } } diff --git a/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/ChartGeneratorTest.java b/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/ChartGeneratorTest.java index 1c2c9bc..65fafc2 100644 --- a/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/ChartGeneratorTest.java +++ b/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/ChartGeneratorTest.java @@ -24,6 +24,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.dcaegen2.platform.helmchartgenerator.chartbuilder.AddOnsManager; import org.onap.dcaegen2.platform.helmchartgenerator.chartbuilder.ChartGenerator; import org.onap.dcaegen2.platform.helmchartgenerator.chartbuilder.HelmClient; import org.onap.dcaegen2.platform.helmchartgenerator.chartbuilder.KeyValueMerger; @@ -43,12 +44,15 @@ class ChartGeneratorTest { @Mock private Utils utils; + @Mock + private AddOnsManager addOnsManager; + @Test void testChartGenerationSteps() throws Exception{ - ChartGenerator chartGenerator = new ChartGenerator(helmClient, kvMerger, utils); + ChartGenerator chartGenerator = new ChartGenerator(helmClient, kvMerger, utils, addOnsManager); Mockito.when(utils.cloneFileToTempLocation(any())).thenReturn(any()); - chartGenerator.generate("src/test/input/blueprint", new ChartInfo(), "src/test/output"); + chartGenerator.generate("src/test/input/blueprint", new ChartInfo(), "src/test/output", "specFileLocation"); Mockito.verify(kvMerger, Mockito.times(1)).mergeValuesToChart(any(), any()); Mockito.verify(helmClient, Mockito.times(1)).lint(any()); diff --git a/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/ComponentSpecParserTest.java b/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/ComponentSpecParserTest.java index f29ea1b..8b26d25 100644 --- a/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/ComponentSpecParserTest.java +++ b/mod2/helm-generator/helmchartgenerator-core/src/test/java/org/onap/dcaegen2/platform/helmchartgenerator/ComponentSpecParserTest.java @@ -19,6 +19,7 @@ package org.onap.dcaegen2.platform.helmchartgenerator; import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -33,6 +34,7 @@ import java.util.List; import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; @ExtendWith({MockitoExtension.class}) class ComponentSpecParserTest { @@ -78,7 +80,8 @@ class ComponentSpecParserTest { assertThat(outerKv.get("image")).isEqualTo("nexus3.onap.org:10001/onap/org.onap.dcaegen2.collectors.ves.vescollector:latest"); assertThat(outerKv.get("logDirectory")).isEqualTo("/opt/app/VESCollector/logs/"); assertThat(outerKv.get("certDirectory")).isEqualTo("/opt/app/dcae-certificate/"); - assertThat(outerKv.get("tlsServer")).isEqualTo(true); + assertTrue((Boolean) outerKv.get("tlsServer")); + assertTrue((Boolean) outerKv.get("useCmpv2Certificates")); } private void assertMetadata(ChartInfo chartInfo) { @@ -119,16 +122,16 @@ class ComponentSpecParserTest { } assertThat(service.get("type")).isEqualTo("NodePort"); assertThat(service.get("name")).isEqualTo("dcae-ves-collector"); - assertThat(service.get("has_internal_only_ports")).isEqualTo(true); + assertTrue((Boolean) service.get("has_internal_only_ports")); assertThat(ports.get(0).get("name")).isEqualTo("http"); assertThat(ports.get(0).get("port")).isEqualTo(8443); assertThat(ports.get(0).get("plain_port")).isEqualTo(8080); assertThat(ports.get(0).get("port_protocol")).isEqualTo("http"); assertThat(ports.get(0).get("nodePort")).isEqualTo(17); - assertThat(ports.get(0).get("useNodePortExt")).isEqualTo(true); + assertTrue((Boolean) ports.get(0).get("useNodePortExt")); assertThat(ports.get(1).get("name")).isEqualTo("metrics"); assertThat(ports.get(1).get("port")).isEqualTo(4444); - assertThat(ports.get(1).get("internal_only")).isEqualTo(true); + assertTrue((Boolean) ports.get(1).get("internal_only")); } private void assertPolicyInfo(ChartInfo chartInfo) { @@ -143,9 +146,9 @@ class ComponentSpecParserTest { assertThat(certificate.get("commonName")).isEqualTo("dcae-ves-collector"); assertThat(((List) certificate.get("dnsNames")).get(0)).isEqualTo("dcae-ves-collector"); assertThat(((List) ((Map<String, Map>) certificate.get("keystore")).get("outputType")).get(0)).isEqualTo("jks"); - assertThat((((Map<String, Map>) certificate.get("keystore")).get("passwordSecretRef")).get("name")).isEqualTo("ves-collector-cmpv2-keystore-password"); + assertThat((((Map<String, Map>) certificate.get("keystore")).get("passwordSecretRef")).get("name")).isEqualTo("vescollector-cmpv2-keystore-password"); assertThat((((Map<String, Map>) certificate.get("keystore")).get("passwordSecretRef")).get("key")).isEqualTo("password"); - assertThat((((Map<String, Map>) certificate.get("keystore")).get("passwordSecretRef")).get("create")).isEqualTo(true); + assertTrue((Boolean) (((Map<String, Map>) certificate.get("keystore")).get("passwordSecretRef")).get("create")); } private void assertConfigMap(ChartInfo chartInfo) { @@ -155,7 +158,7 @@ class ComponentSpecParserTest { assertThat(volume_one.get("name")).isEqualTo("dcae-external-repo-configmap-schema-map"); assertThat(volume_one.get("type")).isEqualTo("configMap"); assertThat(volume_one.get("mountPath")).isEqualTo("/opt/app/VESCollector/etc/externalRepo/"); - assertThat(volume_one.get("optional")).isEqualTo(true); + assertTrue((Boolean) volume_one.get("optional")); } private void assertPostgres(ChartInfo chartInfo) { @@ -168,18 +171,18 @@ class ComponentSpecParserTest { assertThat(((Map<String, Object>) ((Map<String, Object>) postgres.get("container")).get("name")).get("replica")).isEqualTo("dcae-ves-collector-pg-replica"); assertThat(((Map<String, Object>) postgres.get("persistence")).get("mountSubPath")).isEqualTo("dcae-ves-collector/data"); assertThat(((Map<String, Object>) postgres.get("persistence")).get("mountInitPath")).isEqualTo("dcae-ves-collector"); - assertThat(((Map<String, Object>) postgres.get("config")).get("pgUserName")).isEqualTo("ves-collector"); - assertThat(((Map<String, Object>) postgres.get("config")).get("pgDatabase")).isEqualTo("ves-collector"); - assertThat(((Map<String, Object>) postgres.get("config")).get("pgUserExternalSecret")).isEqualTo("{{ include \"common.release\" . }}-ves-collector-pg-user-creds"); + assertThat(((Map<String, Object>) postgres.get("config")).get("pgUserName")).isEqualTo("vescollector"); + assertThat(((Map<String, Object>) postgres.get("config")).get("pgDatabase")).isEqualTo("vescollector"); + assertThat(((Map<String, Object>) postgres.get("config")).get("pgUserExternalSecret")).isEqualTo("{{ include \"common.release\" . }}-vescollector-pg-user-creds"); } private void assertSecrets(ChartInfo chartInfo) { List<Object> secrets = (List<Object>) chartInfo.getValues().get("secrets"); Map<String, Object> secret1 = (Map<String, Object>) secrets.get(0); assertThat(secret1.get("uid")).isEqualTo("pg-user-creds"); - assertThat(secret1.get("name")).isEqualTo("{{ include \"common.release\" . }}-ves-collector-pg-user-creds"); + assertThat(secret1.get("name")).isEqualTo("{{ include \"common.release\" . }}-vescollector-pg-user-creds"); assertThat(secret1.get("type")).isEqualTo("basicAuth"); - assertThat(secret1.get("externalSecret")).isEqualTo("{{ ternary \"\" (tpl (default \"\" .Values.postgres.config.pgUserExternalSecret) .) (hasSuffix \"ves-collector-pg-user-creds\" .Values.postgres.config.pgUserExternalSecret) }}"); + assertThat(secret1.get("externalSecret")).isEqualTo("{{ ternary \"\" (tpl (default \"\" .Values.postgres.config.pgUserExternalSecret) .) (hasSuffix \"vescollector-pg-user-creds\" .Values.postgres.config.pgUserExternalSecret) }}"); assertThat(secret1.get("login")).isEqualTo("{{ .Values.postgres.config.pgUserName }}"); assertThat(secret1.get("password")).isEqualTo("{{ .Values.postgres.config.pgUserPassword }}"); assertThat(secret1.get("passwordPolicy")).isEqualTo("generate"); |