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;
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.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;
41 * @author Waqas Ikram (waqas.ikram@est.tech)
44 @RunWith(SpringRunner.class)
45 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
46 @ActiveProfiles("test")
47 public class NetworkServiceDescriptorParserTest {
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";
53 private NetworkServiceDescriptorParser objUnderTest;
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());
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());
72 public void testEmptyEtsiNsd_returnEmptyOptional() throws IOException {
73 assertFalse(objUnderTest.parse(new byte[] {}).isPresent());
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());
82 private String getAbsolutePath(final String path) {
83 final File file = new File(path);
84 return file.getAbsolutePath();