diff options
Diffstat (limited to 'catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test')
5 files changed, 207 insertions, 19 deletions
diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/builder/NsdCsarManifestBuilderTest.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/builder/NsdCsarManifestBuilderTest.java new file mode 100644 index 0000000000..8a1a4cffaa --- /dev/null +++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/builder/NsdCsarManifestBuilderTest.java @@ -0,0 +1,110 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.be.plugins.etsi.nfv.nsd.builder; + +import static org.junit.jupiter.api.Assertions.*; +import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.builder.NsdCsarManifestBuilder.ATTRIBUTE_SEPARATOR; +import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.builder.NsdCsarManifestBuilder.COMPATIBLE_SPECIFICATION_VERSIONS; +import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.builder.NsdCsarManifestBuilder.METADATA; +import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.builder.NsdCsarManifestBuilder.NSD_RELEASE_DATE_TIME; +import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.builder.NsdCsarManifestBuilder.SOURCE; + +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.Test; + + +class NsdCsarManifestBuilderTest { + + @Test + void testBuildSuccess() { + final NsdCsarManifestBuilder nsdCsarManifestBuilder = new NsdCsarManifestBuilder(); + nsdCsarManifestBuilder.withDesigner("designer"); + nsdCsarManifestBuilder.withName("name"); + nsdCsarManifestBuilder.withInvariantId("invariantId"); + nsdCsarManifestBuilder.withFileStructureVersion("fileStructureVersion"); + nsdCsarManifestBuilder.withCompatibleSpecificationVersion("1.0.0"); + nsdCsarManifestBuilder.withCompatibleSpecificationVersion("1.0.1"); + final List<String> sourceList = new ArrayList<>(); + final String source1 = "Definitions/aSource1.yaml"; + sourceList.add(source1); + final String source2 = "Definitions/aSource2.yaml"; + sourceList.add(source2); + nsdCsarManifestBuilder.withSources(sourceList); + final String manifest = nsdCsarManifestBuilder.build(); + assertSource(manifest, source1); + assertSource(manifest, source2); + assertCompatibleSpecificationVersions(manifest, "1.0.0,1.0.1"); + final String expectedManifest = "metadata: \n" + + "nsd_designer: designer\n" + + "nsd_invariant_id: invariantId\n" + + "nsd_name: name\n" + + "nsd_file_structure_version: fileStructureVersion\n" + + "compatible_specification_versions: 1.0.0,1.0.1\n" + + "\n" + + "Source: Definitions/aSource1.yaml\n" + + "Source: Definitions/aSource2.yaml\n" + + ""; + assertEquals(expectedManifest, manifest); + } + + + @Test + void testMetadataReleaseDateTime() { + final NsdCsarManifestBuilder nsdCsarManifestBuilder = new NsdCsarManifestBuilder(); + nsdCsarManifestBuilder.withNowReleaseDateTime(); + final String manifest = nsdCsarManifestBuilder.build(); + System.out.println(manifest); + assertTrue(manifest.contains(METADATA + ATTRIBUTE_SEPARATOR)); + assertTrue(manifest.contains(NSD_RELEASE_DATE_TIME + ATTRIBUTE_SEPARATOR)); + } + + @Test + void testDuplicatedCompatibleSpecificationVersion() { + final NsdCsarManifestBuilder nsdCsarManifestBuilder = new NsdCsarManifestBuilder(); + nsdCsarManifestBuilder.withCompatibleSpecificationVersion("1.0.0"); + nsdCsarManifestBuilder.withCompatibleSpecificationVersion("1.0.0"); + final String manifest = nsdCsarManifestBuilder.build(); + assertCompatibleSpecificationVersions(manifest, "1.0.0"); + assertFalse(manifest.contains(COMPATIBLE_SPECIFICATION_VERSIONS + ATTRIBUTE_SEPARATOR + "1.0.0,1.0.0")); + } + + @Test + void testCompatibleSpecificationVersionSuccess() { + final NsdCsarManifestBuilder nsdCsarManifestBuilder = new NsdCsarManifestBuilder(); + nsdCsarManifestBuilder.withCompatibleSpecificationVersion("1.0.0"); + String manifest = nsdCsarManifestBuilder.build(); + assertCompatibleSpecificationVersions(manifest, "1.0.0"); + nsdCsarManifestBuilder.withCompatibleSpecificationVersion("2.0.0"); + nsdCsarManifestBuilder.withCompatibleSpecificationVersion("3.0.0"); + manifest = nsdCsarManifestBuilder.build(); + assertCompatibleSpecificationVersions(manifest, "1.0.0,2.0.0,3.0.0"); + } + + void assertCompatibleSpecificationVersions(final String manifest, final String versions) { + assertTrue(manifest.contains(COMPATIBLE_SPECIFICATION_VERSIONS + ATTRIBUTE_SEPARATOR + versions)); + } + + void assertSource(final String manifest, final String source) { + assertTrue(manifest.contains(SOURCE + ATTRIBUTE_SEPARATOR + source)); + } + + +}
\ No newline at end of file diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGeneratorTest.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGeneratorTest.java index e02e17034e..720ed77860 100644 --- a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGeneratorTest.java +++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGeneratorTest.java @@ -25,10 +25,12 @@ import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.core.Is.is; import static org.mockito.Mockito.when; import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.EtsiNfvNsCsarEntryGenerator.ETSI_NS_COMPONENT_CATEGORY; +import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.EtsiNfvNsCsarEntryGenerator.ETSI_VERSION_METADATA; import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.EtsiNfvNsCsarEntryGenerator.NSD_FILE_PATH_FORMAT; import static org.openecomp.sdc.common.api.ArtifactTypeEnum.ETSI_PACKAGE; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.jupiter.api.BeforeEach; @@ -40,11 +42,15 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.model.category.CategoryDefinition; import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.exception.NsdException; +import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.factory.EtsiNfvNsdCsarGeneratorFactory; +import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.config.EtsiVersion; class EtsiNfvNsCsarEntryGeneratorTest { @Mock + private EtsiNfvNsdCsarGeneratorFactory etsiNfvNsdCsarGeneratorFactory; + @Mock private EtsiNfvNsdCsarGenerator etsiNfvNsdCsarGenerator; @Mock private Service service; @@ -53,10 +59,12 @@ class EtsiNfvNsCsarEntryGeneratorTest { private static final String SERVICE_NORMALIZED_NAME = "normalizedName"; private static final String CSAR_ENTRY_EMPTY_ASSERT = "Csar Entries should be empty"; + private static final EtsiVersion nsdVersion = EtsiVersion.VERSION_2_5_1; @BeforeEach void setUp() { MockitoAnnotations.initMocks(this); + when(etsiNfvNsdCsarGeneratorFactory.create(nsdVersion)).thenReturn(etsiNfvNsdCsarGenerator); } @Test @@ -116,6 +124,10 @@ class EtsiNfvNsCsarEntryGeneratorTest { when(service.getComponentType()).thenReturn(ComponentTypeEnum.SERVICE); when(service.getNormalizedName()).thenReturn(SERVICE_NORMALIZED_NAME); + final Map<String, String> categorySpecificMetadataMap = new HashMap<>(); + categorySpecificMetadataMap.put(ETSI_VERSION_METADATA, nsdVersion.getVersion()); + when(service.getCategorySpecificMetadata()).thenReturn(categorySpecificMetadataMap); + final List<CategoryDefinition> categoryDefinitionList = new ArrayList<>(); final CategoryDefinition nsComponentCategoryDefinition = new CategoryDefinition(); nsComponentCategoryDefinition.setName(ETSI_NS_COMPONENT_CATEGORY); diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsdCsarGeneratorImplTest.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsdCsarGeneratorImplTest.java index 9144140f9a..ce66d2e0c3 100644 --- a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsdCsarGeneratorImplTest.java +++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsdCsarGeneratorImplTest.java @@ -37,7 +37,6 @@ import java.util.Map; import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; @@ -49,6 +48,9 @@ import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.model.category.CategoryDefinition; import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.exception.NsdException; import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.exception.VnfDescriptorException; +import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.factory.NsDescriptorGeneratorFactory; +import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.config.NsDescriptorConfig; +import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.config.EtsiVersion; import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.model.Nsd; import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.model.VnfDescriptor; import org.openecomp.sdc.be.resources.data.DAOArtifactData; @@ -60,17 +62,23 @@ class EtsiNfvNsdCsarGeneratorImplTest { @Mock private NsDescriptorGenerator nsDescriptorGeneratorImpl; @Mock + private NsDescriptorGeneratorFactory nsDescriptorGeneratorFactory; + @Mock private ArtifactCassandraDao artifactCassandraDao; - @InjectMocks - private EtsiNfvNsdCsarGeneratorImpl etsiNfvNsdCsarGenerator; @Mock private Service service; + private EtsiNfvNsdCsarGeneratorImpl etsiNfvNsdCsarGenerator; + private static final String SERVICE_NORMALIZED_NAME = "normalizedName"; @BeforeEach void setUp() { MockitoAnnotations.initMocks(this); + final EtsiVersion version2_5_1 = EtsiVersion.VERSION_2_5_1; + etsiNfvNsdCsarGenerator = new EtsiNfvNsdCsarGeneratorImpl(new NsDescriptorConfig(version2_5_1), + vnfDescriptorGenerator, nsDescriptorGeneratorFactory, artifactCassandraDao); + when(nsDescriptorGeneratorFactory.create()).thenReturn(nsDescriptorGeneratorImpl); } @Test diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImplTest.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImplTest.java index 7ed7b7d357..59fa445eaf 100644 --- a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImplTest.java +++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImplTest.java @@ -63,7 +63,6 @@ import org.openecomp.sdc.be.tosca.model.ToscaTemplate; import org.openecomp.sdc.be.tosca.model.ToscaTemplateCapability; import org.openecomp.sdc.be.tosca.model.ToscaTopolgyTemplate; import org.openecomp.sdc.common.api.ConfigurationSource; -import org.springframework.beans.BeansException; import org.springframework.beans.factory.ObjectProvider; import org.yaml.snakeyaml.Yaml; @@ -75,7 +74,7 @@ class NsDescriptorGeneratorImplTest { @Mock private ToscaExportHandler toscaExportHandler; - private final ObjectProvider<ToscaTemplateYamlGenerator> toscaTemplateYamlGeneratorProvider = new ObjectProvider<ToscaTemplateYamlGenerator>() { + private final ObjectProvider<ToscaTemplateYamlGenerator> toscaTemplateYamlGeneratorProvider = new ObjectProvider<>() { @Override public ToscaTemplateYamlGenerator getObject(Object... args) { return new ToscaTemplateYamlGenerator((ToscaTemplate) args[0]); @@ -158,13 +157,12 @@ class NsDescriptorGeneratorImplTest { componentToscaTopologyTemplate.setSubstitution_mappings(substitutionMapping); final ToscaTemplate componentInterfaceToscaTemplate = new ToscaTemplate(""); - final ToscaNodeType interfaceToscaNodeType = new ToscaNodeType(); - interfaceToscaNodeType.setProperties( - ImmutableMap.of("designer", createToscaProperty("designerValue"), - "version", createToscaProperty("versionValue"), - "name", createToscaProperty("nameValue"), - "invariant_id", createToscaProperty("invariantIdValue")) - ); + final String designerPropertyValue = "designerValue"; + final String versionPropertyValue = "versionValue"; + final String namePropertyValue = "nameValue"; + final String invariantIdPropertyValue = "invariantIdValue"; + final ToscaNodeType interfaceToscaNodeType = createDefaultInterfaceToscaNodeType(designerPropertyValue, + versionPropertyValue, namePropertyValue, invariantIdPropertyValue); final String nsNodeTypeName = "nsNodeTypeName"; componentInterfaceToscaTemplate.setNode_types(ImmutableMap.of(nsNodeTypeName, interfaceToscaNodeType)); @@ -184,13 +182,11 @@ class NsDescriptorGeneratorImplTest { //when final Nsd nsd = nsDescriptorGenerator.generate(component, vnfDescriptorList).orElse(null); //then - assertThat("Nsd should not be null", nsd, is(notNullValue())); - assertThat("Nsd designer should be as expected", nsd.getDesigner(), is("designerValue")); - assertThat("Nsd version should be as expected", nsd.getVersion(), is("versionValue")); - assertThat("Nsd name should be as expected", nsd.getName(), is("nameValue")); - assertThat("Nsd invariantId should be as expected", nsd.getInvariantId(), is("invariantIdValue")); - assertThat("Nsd content should not be empty", nsd.getContents(), is(notNullValue())); - assertThat("Nsd content should not be empty", nsd.getContents().length, is(greaterThan(0))); + assertNotEmpty(nsd); + assertThat("Nsd designer should be as expected", nsd.getDesigner(), is(designerPropertyValue)); + assertThat("Nsd version should be as expected", nsd.getVersion(), is(versionPropertyValue)); + assertThat("Nsd name should be as expected", nsd.getName(), is(namePropertyValue)); + assertThat("Nsd invariantId should be as expected", nsd.getInvariantId(), is(invariantIdPropertyValue)); final Map<String, Object> toscaTemplateYaml = readYamlAsMap(nsd.getContents()); @SuppressWarnings("unchecked") @@ -222,6 +218,26 @@ class NsDescriptorGeneratorImplTest { nodeTemplate.get("capabilities"), is(nullValue())); } + private ToscaNodeType createDefaultInterfaceToscaNodeType(final String designerPropertyValue, + final String versionPropertyValue, + final String namePropertyValue, + final String invariantIdPropertyValue) { + final ToscaNodeType interfaceToscaNodeType = new ToscaNodeType(); + interfaceToscaNodeType.setProperties( + ImmutableMap.of("designer", createToscaProperty(designerPropertyValue), + "version", createToscaProperty(versionPropertyValue), + "name", createToscaProperty(namePropertyValue), + "invariant_id", createToscaProperty(invariantIdPropertyValue)) + ); + return interfaceToscaNodeType; + } + + private void assertNotEmpty(Nsd nsd) { + assertThat("Nsd should not be null", nsd, is(notNullValue())); + assertThat("Nsd content should not be empty", nsd.getContents(), is(notNullValue())); + assertThat("Nsd content should not be empty", nsd.getContents().length, is(greaterThan(0))); + } + private ToscaProperty createToscaProperty(final String value) { final ToscaProperty toscaProperty = new ToscaProperty(); final ToscaPropertyConstraint toscaPropertyConstraint = diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/config/EtsiVersionComparatorTest.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/config/EtsiVersionComparatorTest.java new file mode 100644 index 0000000000..6225cea924 --- /dev/null +++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/config/EtsiVersionComparatorTest.java @@ -0,0 +1,42 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.config; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.config.EtsiVersion.VERSION_2_5_1; +import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.config.EtsiVersion.VERSION_2_7_1; +import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.config.EtsiVersion.VERSION_3_3_1; + +import org.junit.jupiter.api.Test; + +class EtsiVersionComparatorTest { + + @Test + void compareTest() { + final NsDescriptorVersionComparator comparator = new NsDescriptorVersionComparator(); + assertEquals(0, comparator.compare(VERSION_2_5_1, VERSION_2_5_1)); + assertEquals(0, comparator.compare(VERSION_2_7_1, VERSION_2_7_1)); + assertEquals(0, comparator.compare(VERSION_3_3_1, VERSION_3_3_1)); + assertEquals(-1, comparator.compare(VERSION_2_5_1, VERSION_2_7_1)); + assertEquals(1, comparator.compare(VERSION_2_7_1, VERSION_2_5_1)); + assertEquals(1, comparator.compare(VERSION_3_3_1, VERSION_2_7_1)); + assertEquals(-1, comparator.compare(VERSION_2_7_1, VERSION_3_3_1)); + } +}
\ No newline at end of file |