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
9 * 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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.parser;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertTrue;
26 import java.io.IOException;
27 import java.nio.file.Files;
28 import java.nio.file.Paths;
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.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptor;
35 import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.parser.NetworkServiceDescriptorParser;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.boot.test.context.SpringBootTest;
38 import org.springframework.test.context.ActiveProfiles;
39 import org.springframework.test.context.junit4.SpringRunner;
43 * @author Waqas Ikram (waqas.ikram@est.tech)
46 @RunWith(SpringRunner.class)
47 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
48 @ActiveProfiles("test")
49 public class NetworkServiceDescriptorParserTest {
51 private static final String VALID_ETSI_NSD_FILE = "src/test/resources/ns.csar";
52 private static final String INVALID_ETSI_NSD_FILE = "src/test/resources/invalid_ns.csar";
55 private NetworkServiceDescriptorParser objUnderTest;
58 public void testValidEtsiNsd_ableToParseIt() throws IOException {
59 final byte[] zipBytes = Files.readAllBytes(Paths.get(getAbsolutePath(VALID_ETSI_NSD_FILE)));
60 final Optional<NetworkServiceDescriptor> optional = objUnderTest.parse(zipBytes);
61 assertTrue(optional.isPresent());
62 final NetworkServiceDescriptor actualNsd = optional.get();
63 assertEquals(NetworkServiceDescriptorParser.NS_NODE_TYPE, actualNsd.getType());
64 assertFalse(actualNsd.getProperties().isEmpty());
66 final Map<String, Object> actualNsdProperties = actualNsd.getProperties();
67 assertEquals(5, actualNsdProperties.size());
68 assertEquals("ffdddc5d-a44b-45ae-8fc3-e6551cce350f", actualNsdProperties.get("descriptor_id"));
69 assertEquals(5, actualNsd.getVnfs().size());
74 public void testEmptyEtsiNsd_returnEmptyOptional() throws IOException {
75 assertFalse(objUnderTest.parse(new byte[] {}).isPresent());
79 public void testInvalidEtsiNsd_returnEmptyOptional() throws IOException {
80 final byte[] zipBytes = Files.readAllBytes(Paths.get(getAbsolutePath(INVALID_ETSI_NSD_FILE)));
81 assertFalse(objUnderTest.parse(zipBytes).isPresent());
84 private String getAbsolutePath(final String path) {
85 final File file = new File(path);
86 return file.getAbsolutePath();