Updating jaxb-runtime version
[so.git] / so-etsi-nfvo / so-etsi-nfvo-ns-lcm / so-etsi-nfvo-ns-lcm-bpmn-flows / src / test / java / org / onap / so / etsi / nfvo / ns / lcm / bpmn / flows / nsd / NetworkServiceDescriptorParserTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 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  *
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.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertTrue;
25 import java.io.File;
26 import java.io.IOException;
27 import java.nio.file.Files;
28 import java.nio.file.Paths;
29 import java.util.Map;
30 import java.util.Optional;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.TestApplication;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.boot.test.context.SpringBootTest;
36 import org.springframework.test.context.ActiveProfiles;
37 import org.springframework.test.context.junit4.SpringRunner;
38
39
40 /**
41  * @author Waqas Ikram (waqas.ikram@est.tech)
42  *
43  */
44 @RunWith(SpringRunner.class)
45 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
46 @ActiveProfiles("test")
47 public class NetworkServiceDescriptorParserTest {
48
49     private static final String VALID_ETSI_NSD_FILE = "src/test/resources/ns.csar";
50     private static final String INVALID_ETSI_NSD_FILE = "src/test/resources/invalid_ns.csar";
51
52     @Autowired
53     private NetworkServiceDescriptorParser objUnderTest;
54
55     @Test
56     public void testValidEtsiNsd_ableToParseIt() throws IOException {
57         final byte[] zipBytes = Files.readAllBytes(Paths.get(getAbsolutePath(VALID_ETSI_NSD_FILE)));
58         final Optional<NetworkServiceDescriptor> optional = objUnderTest.parse(zipBytes);
59         assertTrue(optional.isPresent());
60         final NetworkServiceDescriptor actualNsd = optional.get();
61         assertEquals(NetworkServiceDescriptorParser.NS_NODE_TYPE, actualNsd.getType());
62         assertFalse(actualNsd.getProperties().isEmpty());
63
64         final Map<String, Object> actualNsdProperties = actualNsd.getProperties();
65         assertEquals(5, actualNsdProperties.size());
66         assertEquals("ffdddc5d-a44b-45ae-8fc3-e6551cce350f", actualNsdProperties.get("descriptor_id"));
67         assertEquals(5, actualNsd.getVnfs().size());
68
69     }
70
71     @Test
72     public void testEmptyEtsiNsd_returnEmptyOptional() throws IOException {
73         assertFalse(objUnderTest.parse(new byte[] {}).isPresent());
74     }
75
76     @Test
77     public void testInvalidEtsiNsd_returnEmptyOptional() throws IOException {
78         final byte[] zipBytes = Files.readAllBytes(Paths.get(getAbsolutePath(INVALID_ETSI_NSD_FILE)));
79         assertFalse(objUnderTest.parse(zipBytes).isPresent());
80     }
81
82     private String getAbsolutePath(final String path) {
83         final File file = new File(path);
84         return file.getAbsolutePath();
85     }
86
87 }