3 * * ============LICENSE_START=======================================================
4 * * Copyright (C) 2019 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
10 * * http://www.apache.org/licenses/LICENSE-2.0
12 * * Unless required by applicable law or agreed to in writing, software
13 * * distributed under the License is distributed on an "AS IS" BASIS,
14 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * * See the License for the specific language governing permissions and
16 * * limitations under the License.
18 * * SPDX-License-Identifier: Apache-2.0
19 * * ============LICENSE_END=========================================================
23 package org.openecomp.core.impl;
25 import org.apache.commons.io.IOUtils;
26 import org.junit.Test;
27 import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
28 import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
29 import org.openecomp.core.converter.ServiceTemplateReaderService;
30 import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl;
32 import java.io.IOException;
33 import java.io.InputStream;
36 import static org.junit.Assert.assertEquals;
37 import static org.junit.Assert.assertTrue;
39 public class ToscaSolConverterPnfMultipleNodeTemplatesTest {
41 private static final String PNF_EXT_CP_1 = "pnfExtCp_1";
42 private static final String PNF_EXT_CP_2 = "pnfExtCp_2";
45 public void testGivenDescriptorWithPnfAndTwoPnfExts_WhenConvertTopologyTemplate_ThenTwoExtCpsInOutput() throws IOException {
46 // Added this as separate test as data-driven tests compare strings and as order of nodeTemplates
47 // can be different in hashMap and hence test may fail
48 final byte[] descriptor = getFileResource("pnfDescriptor/other/pnfDescriptor_PnfAnd2ExtCps.yaml");
49 ServiceTemplateReaderService serviceTemplateReaderService = new ServiceTemplateReaderServiceImpl(descriptor);
50 ServiceTemplate serviceTemplate = new ServiceTemplate();
51 ToscaSolConverterPnf toscaSolConverter = new ToscaSolConverterPnf();
52 toscaSolConverter.convertTopologyTemplate(serviceTemplate, serviceTemplateReaderService);
53 Map<String, NodeTemplate> nodeTemplates = serviceTemplate.getTopology_template().getNode_templates();
54 assertEquals(2, nodeTemplates.size());
56 nodeTemplates.entrySet().stream()
57 .map(Map.Entry::getKey)
58 .forEach((key -> assertTrue(getErrorString(), hasCorrectName(key))));
61 private byte[] getFileResource(String filePath) throws IOException {
62 try (InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath)) {
63 return IOUtils.toByteArray(inputStream);
67 private boolean hasCorrectName(String name) {
68 return PNF_EXT_CP_1.equals(name) || PNF_EXT_CP_2.equals(name);
71 private String getErrorString() {
72 return "node template name should be either " + PNF_EXT_CP_1 + " or " + PNF_EXT_CP_2;