2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.sdc.toscaparser.api.elements;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25 import org.onap.sdc.toscaparser.api.JToscaImportTest;
26 import org.onap.sdc.toscaparser.api.NodeTemplate;
27 import org.onap.sdc.toscaparser.api.Property;
28 import org.onap.sdc.toscaparser.api.ToscaTemplate;
29 import org.onap.sdc.toscaparser.api.common.JToscaException;
33 import java.util.List;
35 import static org.junit.Assert.assertEquals;
36 import static org.junit.Assert.assertTrue;
38 public class CalculatePropertyByPathTest {
39 private static ToscaTemplate toscaTemplate;
42 public static void setUpClass() throws JToscaException {
43 URL scarUrl = JToscaImportTest.class.getClassLoader().getResource("csars/service-NetworkCloudVnfServiceMock-csar.csar");
44 if (scarUrl != null) {
45 File file = new File(scarUrl.getFile());
46 toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
52 public void testGetPropertyWhenPropertyHasListOfDataTypesAndPathIsNotEmpty() throws JToscaException {
53 NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
54 .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
55 .getSubMappingToscaTemplate().getNodeTemplates().get(0); //testVM_testVM_SRIOVtrunk1_port
57 Property property = cp.getProperties().get("related_networks");
58 List<String> propertyValueList = property.getLeafPropertyValue("related_network_role");
59 assertEquals(3, propertyValueList.size());
60 assertTrue(propertyValueList.contains("cor_direct_2"));
61 assertTrue(propertyValueList.contains("sgi_direct_2"));
62 assertTrue(propertyValueList.contains("int_imbl_2"));
66 public void testGetPropertyWhenPropertyHasDataTypeAndPathIsEmpty() {
67 NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
68 .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
69 .getSubMappingToscaTemplate().getNodeTemplates().get(1); //testVM_testVM_SRIOVNonTrunk0_port
71 Property property = cp.getProperties().get("exCP_naming");
72 List<String> propertyValueList = property.getLeafPropertyValue("");
73 assertTrue(propertyValueList.isEmpty());
77 public void testGetPropertyWhenPropertyHasSimpleTypeAndValueAsGetInputIsNotResolvedCorrectlyAndPathIsEmpty() {
78 NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
79 .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
80 .getSubMappingToscaTemplate().getNodeTemplates().get(1); //testVM_testVM_SRIOVNonTrunk0_port
82 Property property = cp.getProperties().get("network");
83 List<String> propertyValueList = property.getLeafPropertyValue("");
84 assertTrue(propertyValueList.isEmpty());
88 public void testGetPropertyWhenPropertyHasSimpleTypeAndPathIsEmpty() {
89 NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
90 .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
91 .getSubMappingToscaTemplate().getNodeTemplates().get(1); //testVM_testVM_SRIOVNonTrunk0_port
93 Property property = cp.getProperties().get("subinterface_indicator");
94 List<String> propertyValueList = property.getLeafPropertyValue("");
95 assertEquals(1, propertyValueList.size());
96 assertEquals("false", propertyValueList.get(0));
101 public void testGetPropertyWhenPropertyHasDataTypeAndPathIsNotEmpty() {
102 NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
103 .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
104 .getSubMappingToscaTemplate().getNodeTemplates().get(2); //testVM_testVM_OVS_port
106 Property property = cp.getProperties().get("ip_requirements");
107 List<String> propertyValueList = property.getLeafPropertyValue("ip_version");
108 assertEquals(1, propertyValueList.size());
109 assertEquals("4", propertyValueList.get(0));
113 public void testGetPropertyWhenPropertyHasListOfDataTypesAndPathIsNull() {
114 NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
115 .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
116 .getSubMappingToscaTemplate().getNodeTemplates().get(2); //testVM_testVM_OVS_port
118 Property property = cp.getProperties().get("ip_requirements");
119 assertTrue(property.getLeafPropertyValue(null).isEmpty());
123 public void testGetPropertyWhenPropertyHasListOfDataTypesAndPathIsComplex() {
124 NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
125 .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
126 .getSubMappingToscaTemplate().getNodeTemplates().get(0); //testVM_testVM_SRIOVtrunk1_port
128 Property property = cp.getProperties().get("ip_requirements");
129 List<String> propertyValueList = property.getLeafPropertyValue("ip_count_required#is_required");
130 assertEquals(1, propertyValueList.size());
131 assertEquals("false", propertyValueList.get(0));
135 public void testGetPropertyWhenPropertyHasListOfDataTypesAndPathIsWrong() {
136 NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
137 .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
138 .getSubMappingToscaTemplate().getNodeTemplates().get(0); //testVM_testVM_SRIOVtrunk1_port
140 Property property = cp.getProperties().get("ip_requirements");
141 List<String> propertyValueList = property.getLeafPropertyValue("ip_count_required#is_required_1");
142 assertEquals(0, propertyValueList.size());
146 public void testGetPropertyWhenPropertyHasDataTypeWithoutSchemaAndComplexPath() {
147 NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
148 .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
149 .getSubMappingToscaTemplate().getNodeTemplates().get(0); //testVM_testVM_SRIOVtrunk1_port
151 Property property = cp.getProperties().get("mac_requirements");
152 List<String> propertyValueList = property.getLeafPropertyValue("mac_count_required#is_required");
153 assertEquals(1, propertyValueList.size());
154 assertEquals("false", propertyValueList.get(0));
158 public void testGetPropertyWhenPropertyHasDataTypeWithoutSchemaAndSimplePath() {
159 NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
160 .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
161 .getSubMappingToscaTemplate().getNodeTemplates().get(0); //testVM_testVM_SRIOVtrunk1_port
163 Property property = cp.getProperties().get("mac_requirements");
164 List<String> propertyValueList = property.getLeafPropertyValue("mac_count_required");
165 assertEquals(0, propertyValueList.size());