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