diff options
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java')
-rw-r--r-- | openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java new file mode 100644 index 0000000000..72f235e287 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java @@ -0,0 +1,157 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.vendorsoftwareproduct.impl.orchestration.csar.validation; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.isEmptyString; + +import java.io.ByteArrayInputStream; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import org.junit.Before; +import org.junit.Test; +import org.openecomp.sdc.tosca.csar.CSARConstants; +import org.openecomp.sdc.tosca.csar.Manifest; +import org.openecomp.sdc.tosca.csar.SOL004ManifestOnboarding; + +public class ManifestBuilderTest { + + private ManifestBuilder manifestBuilder; + + @Before + public void setUp() { + manifestBuilder = new ManifestBuilder(); + } + + @Test + public void givenNoManifestInformation_whenBuildingManifest_thenEmptyStringShouldBeReturned() { + final String manifest = manifestBuilder.build(); + assertThat("Manifest should be empty", manifest, isEmptyString()); + } + + @Test + public void givenSourceFiles_whenBuildingManifestWithSources_thenManifestSourceListShouldBeTheSame() { + final List<String> expectedSourceList = mockSourceList(); + mockManifestMetadata(); + expectedSourceList.forEach(source -> manifestBuilder.withSource(source)); + + final Manifest onboardingManifest = parseManifest(); + final List<String> actualSourceList = onboardingManifest.getSources(); + + assertThat("Source list should have the same size as expected source items", actualSourceList, + hasSize(expectedSourceList.size())); + assertThat("Source list should contain all expected source items", actualSourceList, + hasItems(expectedSourceList.toArray(new String[0]))); + assertThat("Source list should contain only expected sources items", expectedSourceList, + hasItems(actualSourceList.toArray(new String[expectedSourceList.size()]))); + } + + @Test + public void givenSourceFiles_whenBuildingManifestWithSignedSources_thenManifestSourceListShouldBeTheSame() { + final List<String> expectedSourceList = mockSourceList(); + mockManifestMetadata(); + expectedSourceList.forEach(sourceArtifact -> + manifestBuilder.withSignedSource(sourceArtifact, "anyAlgorithm", "anyHash") + ); + + final Manifest onboardingManifest = parseManifest(); + final List<String> sources = onboardingManifest.getSources(); + + assertThat("Source list should have the same size as expected source items", sources, + hasSize(expectedSourceList.size())); + assertThat("Source list should contain all expected source items", sources, + hasItems(expectedSourceList.toArray(new String[0]))); + assertThat("Source list should contain only expected sources items", expectedSourceList, + hasItems(sources.toArray(new String[expectedSourceList.size()]))); + } + + @Test + public void givenMetadata_whenBuildingManifestWithMetadata_thenParsedManifestMetadataShouldBeTheSame() { + final Map<String, String> expectedMetadataMap = new TreeMap<>(); + expectedMetadataMap.put(CSARConstants.PNFD_NAME, "myPnf"); + expectedMetadataMap.put(CSARConstants.PNFD_PROVIDER, "Acme"); + expectedMetadataMap.put(CSARConstants.PNFD_ARCHIVE_VERSION, "1.0"); + expectedMetadataMap.put(CSARConstants.PNFD_RELEASE_DATE_TIME, "2019-03-11T11:25:00+00:00"); + + expectedMetadataMap.forEach((key, value) -> manifestBuilder.withMetaData(key, value)); + + final Manifest onboardingManifest = parseManifest(); + final Map<String, String> actualMetadataMap = onboardingManifest.getMetadata(); + + assertThat("Metadata should be as expected", actualMetadataMap, is(expectedMetadataMap)); + } + + @Test + public void givenNonManoArtifacts_whenBuildingManifestWithArtifacts_thenParsedManifestNonManoArtifactsShouldBeTheSame() { + mockManifestMetadata(); + mockManifestSource(); + + final Map<String, List<String>> expectedNonManoArtifactMap = new TreeMap<>(); + expectedNonManoArtifactMap.put("onap_ves_events", Arrays.asList("Files/Events/MyPnf_Pnf_v1.yaml")); + expectedNonManoArtifactMap.put("onap_pm_dictionary", Arrays.asList("Files/Measurements/PM_Dictionary.yaml")); + expectedNonManoArtifactMap.put("onap_yang_modules", + Arrays.asList("Files/Yang_module/mynetconf.yang", "Files/Yang_module/mynetconf2.yang")); + expectedNonManoArtifactMap + .put("onap_others", Arrays.asList("Files/Guides/user_guide.txt", "Files/Test/test.txt")); + + expectedNonManoArtifactMap.forEach((key, artifacts) -> + artifacts.forEach(s -> manifestBuilder.withNonManoArtifact(key, s)) + ); + + final Manifest onboardingManifest = parseManifest(); + final Map<String, List<String>> actualNonManoArtifactMap = onboardingManifest.getNonManoSources(); + + assertThat("Non Mano Sources should be as expected", actualNonManoArtifactMap, is(expectedNonManoArtifactMap)); + } + + private Manifest parseManifest() { + final Manifest onboardingManifest = new SOL004ManifestOnboarding(); + onboardingManifest.parse(new ByteArrayInputStream(manifestBuilder.build().getBytes())); + return onboardingManifest; + } + + private List<String> mockSourceList() { + return Arrays.asList("pnf_main_descriptor.mf" + , "Definitions/pnf_main_descriptor.yaml" + , "Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml" + , "Definitions/etsi_nfv_sol001_vnfd_2_5_1_types.yaml" + , "Files/ChangeLog.txt" + , "Files/Events/MyPnf_Pnf_v1.yaml" + , "Files/Guides/user_guide.txt" + , "Files/Measurements/PM_Dictionary.yaml" + , "Files/Scripts/my_script.sh" + , "Files/Yang_module/mynetconf.yang" + , "TOSCA-Metadata/TOSCA.meta" + ); + } + + private void mockManifestMetadata() { + manifestBuilder.withMetaData(CSARConstants.PNFD_PROVIDER, "test"); + } + + private void mockManifestSource() { + manifestBuilder.withSource("/test.yaml"); + } +}
\ No newline at end of file |