1ff3a6d52b0b11a89ab4d1245b0cbc31abdade08
[sdc.git] /
1
2 /*
3  * ============LICENSE_START=======================================================
4  *  Copyright (C) 2021 Nordix Foundation
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20 package org.openecomp.sdc.be.plugins.etsi.nfv.nsd.builder;
21
22 import static org.junit.jupiter.api.Assertions.assertEquals;
23 import static org.junit.jupiter.api.Assertions.assertFalse;
24 import static org.junit.jupiter.api.Assertions.assertTrue;
25 import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.builder.NsdCsarManifestBuilder.ATTRIBUTE_SEPARATOR;
26 import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.builder.NsdCsarManifestBuilder.COMPATIBLE_SPECIFICATION_VERSIONS;
27 import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.builder.NsdCsarManifestBuilder.METADATA;
28 import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.builder.NsdCsarManifestBuilder.NSD_RELEASE_DATE_TIME;
29 import static org.openecomp.sdc.be.plugins.etsi.nfv.nsd.builder.NsdCsarManifestBuilder.SOURCE;
30
31 import java.util.ArrayList;
32 import java.util.List;
33 import org.junit.jupiter.api.Test;
34
35 class NsdCsarManifestBuilderTest {
36
37     @Test
38     void testBuildSuccess() {
39         final NsdCsarManifestBuilder nsdCsarManifestBuilder = new NsdCsarManifestBuilder();
40         nsdCsarManifestBuilder.withDesigner("designer");
41         nsdCsarManifestBuilder.withName("name");
42         nsdCsarManifestBuilder.withInvariantId("invariantId");
43         nsdCsarManifestBuilder.withFileStructureVersion("fileStructureVersion");
44         nsdCsarManifestBuilder.withCompatibleSpecificationVersion("1.0.0");
45         nsdCsarManifestBuilder.withCompatibleSpecificationVersion("1.0.1");
46         final List<String> sourceList = new ArrayList<>();
47         final String source1 = "Definitions/aSource1.yaml";
48         sourceList.add(source1);
49         final String source2 = "Definitions/aSource2.yaml";
50         sourceList.add(source2);
51         nsdCsarManifestBuilder.withSources(sourceList);
52         final String manifest = nsdCsarManifestBuilder.build();
53         assertSource(manifest, source1);
54         assertSource(manifest, source2);
55         assertCompatibleSpecificationVersions(manifest, "1.0.0,1.0.1");
56         final String expectedManifest = "metadata: \n" + "nsd_designer: designer\n" + "nsd_invariant_id: invariantId\n" + "nsd_name: name\n"
57             + "nsd_file_structure_version: fileStructureVersion\n" + "compatible_specification_versions: 1.0.0,1.0.1\n" + "\n"
58             + "Source: Definitions/aSource1.yaml\n" + "Source: Definitions/aSource2.yaml\n" + "";
59         assertEquals(expectedManifest, manifest);
60     }
61
62     @Test
63     void testMetadataReleaseDateTime() {
64         final NsdCsarManifestBuilder nsdCsarManifestBuilder = new NsdCsarManifestBuilder();
65         nsdCsarManifestBuilder.withNowReleaseDateTime();
66         final String manifest = nsdCsarManifestBuilder.build();
67         System.out.println(manifest);
68         assertTrue(manifest.contains(METADATA + ATTRIBUTE_SEPARATOR));
69         assertTrue(manifest.contains(NSD_RELEASE_DATE_TIME + ATTRIBUTE_SEPARATOR));
70     }
71
72     @Test
73     void testDuplicatedCompatibleSpecificationVersion() {
74         final NsdCsarManifestBuilder nsdCsarManifestBuilder = new NsdCsarManifestBuilder();
75         nsdCsarManifestBuilder.withCompatibleSpecificationVersion("1.0.0");
76         nsdCsarManifestBuilder.withCompatibleSpecificationVersion("1.0.0");
77         final String manifest = nsdCsarManifestBuilder.build();
78         assertCompatibleSpecificationVersions(manifest, "1.0.0");
79         assertFalse(manifest.contains(COMPATIBLE_SPECIFICATION_VERSIONS + ATTRIBUTE_SEPARATOR + "1.0.0,1.0.0"));
80     }
81
82     @Test
83     void testCompatibleSpecificationVersionSuccess() {
84         final NsdCsarManifestBuilder nsdCsarManifestBuilder = new NsdCsarManifestBuilder();
85         nsdCsarManifestBuilder.withCompatibleSpecificationVersion("1.0.0");
86         String manifest = nsdCsarManifestBuilder.build();
87         assertCompatibleSpecificationVersions(manifest, "1.0.0");
88         nsdCsarManifestBuilder.withCompatibleSpecificationVersion("2.0.0");
89         nsdCsarManifestBuilder.withCompatibleSpecificationVersion("3.0.0");
90         manifest = nsdCsarManifestBuilder.build();
91         assertCompatibleSpecificationVersions(manifest, "1.0.0,2.0.0,3.0.0");
92     }
93
94     void assertCompatibleSpecificationVersions(final String manifest, final String versions) {
95         assertTrue(manifest.contains(COMPATIBLE_SPECIFICATION_VERSIONS + ATTRIBUTE_SEPARATOR + versions));
96     }
97
98     void assertSource(final String manifest, final String source) {
99         assertTrue(manifest.contains(SOURCE + ATTRIBUTE_SEPARATOR + source));
100     }
101 }