2 * Copyright (c) 2018 Orange
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
15 package org.onap.nbi.apis.servicecatalog;
17 import static org.assertj.core.api.Assertions.assertThat;
19 import java.nio.file.Path;
20 import java.util.ArrayList;
21 import java.util.HashMap;
22 import java.util.LinkedHashMap;
23 import java.util.List;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.onap.nbi.apis.serviceorder.model.consumer.VFModelInfo;
28 import org.onap.nbi.exceptions.TechnicalException;
29 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.boot.test.context.SpringBootTest;
32 import org.springframework.test.annotation.DirtiesContext;
33 import org.springframework.test.context.ActiveProfiles;
34 import org.springframework.test.context.junit4.SpringRunner;
35 import com.fasterxml.jackson.databind.ObjectMapper;
36 import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
38 @RunWith(SpringRunner.class)
39 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
40 @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
41 @ActiveProfiles("test")
42 public class ToscaInfosProcessorTest {
45 ToscaInfosProcessor toscaInfosProcessor;
46 final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); // jackson databind
49 public void buildResponseWithSdcToscaParser() {
51 ClassLoader classLoader = getClass().getClassLoader();
52 Path path = new File(classLoader.getResource("toscafile/service-Sdwanvpninfraservice-csar.csar").getFile())
53 .toPath().toAbsolutePath();
54 List<LinkedHashMap> resources = new ArrayList<>();
55 LinkedHashMap resource1 = new LinkedHashMap();
56 resource1.put("id", "7baa7742-3a13-4288-8330-868015adc340");
57 resources.add(resource1);
58 LinkedHashMap resource2 = new LinkedHashMap();
59 resource2.put("id", "81b9430b-8abe-45d6-8bf9-f41a8f5c735f");
60 resources.add(resource2);
61 LinkedHashMap response = new LinkedHashMap();
62 response.put("resourceSpecification", resources);
65 toscaInfosProcessor.buildResponseWithSdcToscaParser(path, response);
66 } catch (SdcToscaParserException e) {
67 throw new TechnicalException("unable to build response from tosca csar using sdc-parser : "
68 + path.toString() + " " + e.getMessage());
70 resources = (List<LinkedHashMap>) response.get("resourceSpecification");
71 List<LinkedHashMap> serviceSpecCharacteristic = new ArrayList<>();
72 serviceSpecCharacteristic = (List<LinkedHashMap>) response.get("serviceSpecCharacteristic");
73 assertThat(serviceSpecCharacteristic.get(0).get("name")).isEqualTo("sdwanconnectivity0_topology");
74 assertThat(serviceSpecCharacteristic.get(1).get("valueType")).isEqualTo("string");
75 assertThat(serviceSpecCharacteristic.get(0).get("required")).isEqualTo(true);
76 assertThat(serviceSpecCharacteristic.get(1).get("name")).isEqualTo("sdwanconnectivity0_name");
77 assertThat(serviceSpecCharacteristic.get(1).get("valueType")).isEqualTo("string");
78 assertThat(serviceSpecCharacteristic.get(1).get("required")).isEqualTo(true);
79 assertThat(resources.get(0).get("modelCustomizationId")).isEqualTo("94ec574b-2306-4cbd-8214-09662b040f73");
80 assertThat(resources.get(1).get("modelCustomizationId")).isEqualTo("a7baba5d-6ac3-42b5-b47d-070841303ab1");
85 public void buildResponseWithSdcToscaParserWithDefaultInputs() {
87 ClassLoader classLoader = getClass().getClassLoader();
88 Path path = new File(classLoader.getResource("toscafile/service-Sotnvpninfraservice-csar.csar").getFile())
89 .toPath().toAbsolutePath();
90 List<LinkedHashMap> resources = new ArrayList<>();
91 LinkedHashMap resource1 = new LinkedHashMap();
92 resource1.put("id", "218df3c3-50dd-4c26-9e36-4771387bb771");
93 resources.add(resource1);
94 LinkedHashMap resource2 = new LinkedHashMap();
95 resource2.put("id", "81b9430b-8abe-45d6-8bf9-f41a8f5c735f");
96 resources.add(resource2);
97 LinkedHashMap response = new LinkedHashMap();
98 response.put("resourceSpecification", resources);
101 toscaInfosProcessor.buildResponseWithSdcToscaParser(path, response);
102 } catch (SdcToscaParserException e) {
103 throw new TechnicalException("unable to build response from tosca csar using sdc-parser : "
104 + path.toString() + " " + e.getMessage());
106 resources = (List<LinkedHashMap>) response.get("resourceSpecification");
107 List<LinkedHashMap> serviceSpecCharacteristic = new ArrayList<>();
108 serviceSpecCharacteristic = (List<LinkedHashMap>) response.get("serviceSpecCharacteristic");
109 assertThat(resources.get(0).get("modelCustomizationId")).isEqualTo("b44071c8-04fd-4d6b-b6af-772cbfaa1129");
110 assertThat(resources.get(1).get("modelCustomizationId")).isEqualTo("c3612284-6c67-4d8c-8b41-b699cc90e76d");
111 assertThat(serviceSpecCharacteristic.get(12).get("serviceSpecCharacteristicValue")).isNull();
112 assertThat(serviceSpecCharacteristic.get(13).get("serviceSpecCharacteristicValue")).isNotNull();
116 public void buildResponseWithSdcToscaParserwithMetaDataMisMatch() {
118 ClassLoader classLoader = getClass().getClassLoader();
119 Path path = new File(classLoader.getResource("toscafile/service-Sdwanvpninfraservice-csar.csar").getFile())
120 .toPath().toAbsolutePath();
121 List<LinkedHashMap> resources = new ArrayList<>();
122 LinkedHashMap resource1 = new LinkedHashMap();
123 resource1.put("id", "some bad resource id no in TOSCA CSAR");
124 resources.add(resource1);
125 LinkedHashMap resource2 = new LinkedHashMap();
126 resource2.put("id", "some bad resource id no in TOSCA CSAR");
127 resources.add(resource2);
128 LinkedHashMap response = new LinkedHashMap();
129 response.put("resourceSpecification", resources);
132 toscaInfosProcessor.buildResponseWithSdcToscaParser(path, response);
133 } catch (SdcToscaParserException e) {
134 throw new TechnicalException("unable to build response from tosca csar using sdc-parser : "
135 + path.toString() + " " + e.getMessage());
137 resources = (List<LinkedHashMap>) response.get("resourceSpecification");
138 List<LinkedHashMap> serviceSpecCharacteristic = new ArrayList<>();
139 serviceSpecCharacteristic = (List<LinkedHashMap>) response.get("serviceSpecCharacteristic");
140 assertThat(serviceSpecCharacteristic.get(0).get("name")).isEqualTo("sdwanconnectivity0_topology");
141 assertThat(serviceSpecCharacteristic.get(1).get("valueType")).isEqualTo("string");
142 assertThat(serviceSpecCharacteristic.get(0).get("required")).isEqualTo(true);
143 assertThat(serviceSpecCharacteristic.get(1).get("name")).isEqualTo("sdwanconnectivity0_name");
144 assertThat(serviceSpecCharacteristic.get(1).get("valueType")).isEqualTo("string");
145 assertThat(serviceSpecCharacteristic.get(1).get("required")).isEqualTo(true);
146 // Check that resources cannot be found in the TOSCA template
147 assertThat(resources.get(0).get("modelCustomizationId")).isNull();
148 assertThat(resources.get(1).get("modelCustomizationId")).isNull();
153 public void testBuildAndSaveResponseWithSdcToscaParser() {
155 ClassLoader classLoader = getClass().getClassLoader();
156 Path path = new File(classLoader.getResource("toscafile/service-Sotnvpninfraservice-csar.csar").getFile())
157 .toPath().toAbsolutePath();
159 LinkedHashMap response = new LinkedHashMap();
160 response.put("version", "1.0");
161 response.put("name", "Service_vMME");
162 response.put("description", "some service characteristics schema");
163 response.put("id", "7f5e5139-768d-4410-a871-c41430785214");
165 List<LinkedHashMap> resources = new ArrayList<>();
166 LinkedHashMap resource1 = new LinkedHashMap();
167 resource1.put("id", "7baa7742-3a13-4288-8330-868015adc340");
168 resources.add(resource1);
169 LinkedHashMap resource2 = new LinkedHashMap();
170 resource2.put("id", "81b9430b-8abe-45d6-8bf9-f41a8f5c735f");
171 resources.add(resource2);
173 response.put("resourceSpecification", resources);
175 LinkedHashMap serviceSpecCharacteristicValue = new LinkedHashMap();
176 serviceSpecCharacteristicValue.put("valueType", "object");
177 serviceSpecCharacteristicValue.put("@schemaLocation",
178 "/serviceSpecification/7f5e5139-768d-4410-a871-c41430785214/specificationInputSchema");
179 serviceSpecCharacteristicValue.put("@type", "Service_vMME_ServiceCharacteristic");
181 LinkedHashMap serviceSpecCharacteristic = new LinkedHashMap();
182 serviceSpecCharacteristic.put("name", "Service_vMME_ServiceCharacteristics");
183 serviceSpecCharacteristic.put("description",
184 "This object describes all the inputs needed from the client to interact with the Service_vMME Service Topology");
185 // using object to match examples in specifications
186 serviceSpecCharacteristic.put("valueType", "object");
187 serviceSpecCharacteristic.put("@type", "ONAPServiceCharacteristic");
188 serviceSpecCharacteristic.put("@schemaLocation", "null");
189 serviceSpecCharacteristic.put("serviceSpecCharacteristicValue", serviceSpecCharacteristicValue);
191 toscaInfosProcessor.buildAndSaveResponseWithSdcToscaParser(path, response);
192 } catch (SdcToscaParserException ex) {
193 throw new TechnicalException("unable to build response " + ex.getMessage());
195 assertThat(response.get("serviceSpecCharacteristic")).isEqualTo(serviceSpecCharacteristic);
199 public void testBuildAndSaveResponseWithSdcToscaParserWithInputListType() {
201 ClassLoader classLoader = getClass().getClassLoader();
202 Path path = new File(classLoader.getResource("toscafile/service-MscmEvplService-csar.csar").getFile()).toPath()
205 LinkedHashMap response = new LinkedHashMap();
206 response.put("version", "1.0");
207 response.put("name", "MSCM-EVPL-Service");
208 response.put("description", "MSCM EVPL Service");
209 response.put("id", "66a66cc3-178c-45fd-82c2-494336cb3665");
211 List<LinkedHashMap> resources = new ArrayList<>();
212 LinkedHashMap resource1 = new LinkedHashMap();
213 resource1.put("id", "f5f487df-8c02-4485-81d4-695c50e24b22");
214 resources.add(resource1);
215 LinkedHashMap resource2 = new LinkedHashMap();
216 resource2.put("id", "65c34b35-e8ab-426a-b048-d707467f68b2");
217 resources.add(resource2);
219 response.put("resourceSpecification", resources);
221 LinkedHashMap serviceSpecCharacteristicValue = new LinkedHashMap();
222 serviceSpecCharacteristicValue.put("valueType", "object");
223 serviceSpecCharacteristicValue.put("@schemaLocation",
224 "/serviceSpecification/66a66cc3-178c-45fd-82c2-494336cb3665/specificationInputSchema");
225 serviceSpecCharacteristicValue.put("@type", "MSCM-EVPL-Service_ServiceCharacteristic");
227 LinkedHashMap serviceSpecCharacteristic = new LinkedHashMap();
228 serviceSpecCharacteristic.put("name", "MSCM-EVPL-Service_ServiceCharacteristics");
229 serviceSpecCharacteristic.put("description",
230 "This object describes all the inputs needed from the client to interact with the MSCM-EVPL-Service Service Topology");
231 // using object to match examples in specifications
232 serviceSpecCharacteristic.put("valueType", "object");
233 serviceSpecCharacteristic.put("@type", "ONAPServiceCharacteristic");
234 serviceSpecCharacteristic.put("@schemaLocation", "null");
235 serviceSpecCharacteristic.put("serviceSpecCharacteristicValue", serviceSpecCharacteristicValue);
237 toscaInfosProcessor.buildAndSaveResponseWithSdcToscaParser(path, response);
238 } catch (SdcToscaParserException ex) {
239 throw new TechnicalException("unable to build response " + ex.getMessage());
241 assertThat(response.get("serviceSpecCharacteristic")).isEqualTo(serviceSpecCharacteristic);
246 public void testBuildAndSaveResponseWithSdcToscaParserWithVFModule() {
248 ClassLoader classLoader = getClass().getClassLoader();
250 // Adding Path to TOSCA File to provide as parameter
251 Path path = new File(classLoader.getResource("toscafile/service-VlbService-csar.csar").getFile()).toPath()
254 // Preparing Response Data
255 LinkedHashMap<String, Object> response = new LinkedHashMap<>();
256 response.put("version", "1.0");
257 response.put("name", "VLB_Service");
258 response.put("description", "VLB_Service");
259 response.put("id", "82c9fbb4-656c-4973-8c7f-172b22b5fa8f");
262 List<LinkedHashMap<String, Object>> resources = new ArrayList<>();
263 LinkedHashMap<String, Object> resource1 = new LinkedHashMap<>();
264 resource1.put("id", "35d7887d-3c35-4fb4-aed1-d15b4d9f4ccc");
265 resources.add(resource1);
267 // Resources to put in response as resourceSpecification
268 response.put("resourceSpecification", resources);
270 // Test Data for VFModule 1:: An object of vFModelInfo1
271 VFModelInfo vFModelInfo1 = new VFModelInfo();
272 vFModelInfo1.setModelName("VlbVsp..dnsscaling..module-1");
273 vFModelInfo1.setModelUuid("9bfd197c-7e18-41bd-927d-57102a6fda7e");
274 vFModelInfo1.setModelInvariantUuid("888b6342-8aea-4416-b485-e24726c1f964");
275 vFModelInfo1.setModelVersion("1");
276 vFModelInfo1.setModelCustomizationUuid("4c387136-2fa2-420f-94e9-3312f863a352");
278 // Test Data for VFModule 2:: An object of vFModelInfo2
279 VFModelInfo vFModelInfo2 = new VFModelInfo();
280 vFModelInfo2.setModelName("VlbVsp..base_vlb..module-0");
281 vFModelInfo2.setModelUuid("d0325d26-43f2-4c6f-aff5-2832ac2d8ab0");
282 vFModelInfo2.setModelInvariantUuid("bcbdfc80-4fb1-4c3e-b4e3-77721bac61db");
283 vFModelInfo2.setModelVersion("1");
284 vFModelInfo2.setModelCustomizationUuid("0895caa9-b7d3-4e02-9a3c-8337c4076948");
286 // Test data for list of vFModelInfo
287 List<VFModelInfo> vfModelInfoListTestData = new ArrayList<>();
288 vfModelInfoListTestData.add(vFModelInfo1);
289 vfModelInfoListTestData.add(vFModelInfo2);
291 // Calling buildAndSaveResponseWithSdcToscaParser with tosca file and prepared
292 // response as parameter
294 toscaInfosProcessor.buildAndSaveResponseWithSdcToscaParser(path, response);
295 } catch (SdcToscaParserException e) {
296 throw new TechnicalException("unable to build response from tosca csar using sdc-parser : "
297 + path.toString() + " " + e.getMessage());
300 // Getting resourceSpecifications from response
301 List<LinkedHashMap> resourceSpecifications = (List<LinkedHashMap>) response.get("resourceSpecification");
303 // Getting childResourceSpecifications from resourceSpecifications that we got
305 List childResourceSpecifications = (ArrayList<VFModelInfo>) (resourceSpecifications.get(0))
306 .get("childResourceSpecification");
308 // Asserting childResourceSpecifications with our vfModelInfoListTestData ::
309 // CSAR has two vfModules
311 for (int i = 0; i < vfModelInfoListTestData.size(); i++) {
312 assertThat(childResourceSpecifications.get(i)).hasFieldOrPropertyWithValue("modelName",
313 vfModelInfoListTestData.get(i).getModelName());
314 assertThat(childResourceSpecifications.get(i)).hasFieldOrPropertyWithValue("modelUuid",
315 vfModelInfoListTestData.get(i).getModelUuid());
316 assertThat(childResourceSpecifications.get(i)).hasFieldOrPropertyWithValue("modelInvariantUuid",
317 vfModelInfoListTestData.get(i).getModelInvariantUuid());
318 assertThat(childResourceSpecifications.get(i)).hasFieldOrPropertyWithValue("modelVersion",
319 vfModelInfoListTestData.get(i).getModelVersion());
320 assertThat(childResourceSpecifications.get(i)).hasFieldOrPropertyWithValue("modelCustomizationUuid",
321 vfModelInfoListTestData.get(i).getModelCustomizationUuid());
327 public void testBuildAndSaveResponseWithSdcToscaParserWithInstanceSpecification() {
329 ClassLoader classLoader = getClass().getClassLoader();
331 // Adding Path to TOSCA File to provide as parameter
332 Path path = new File(classLoader.getResource("toscafile/service-VlbService-csar.csar").getFile()).toPath()
335 // Creating response to provide as parameter
336 LinkedHashMap response = new LinkedHashMap();
337 response.put("version", "1.0");
338 response.put("name", "VLB_Service");
339 response.put("description", "VLB_Service");
340 response.put("id", "82c9fbb4-656c-4973-8c7f-172b22b5fa8f");
343 List<LinkedHashMap> resources = new ArrayList<>();
344 LinkedHashMap resource1 = new LinkedHashMap();
345 resource1.put("id", "35d7887d-3c35-4fb4-aed1-d15b4d9f4ccc");
346 resources.add(resource1);
348 // instanceSpecification Test Data
349 Map instanceSpecificationTestData = new LinkedHashMap<>();
350 instanceSpecificationTestData.put("cloud_env", "openstack");
351 instanceSpecificationTestData.put("demo_artifacts_version", "1.2.1");
352 instanceSpecificationTestData.put("install_script_version", "1.2.1");
353 instanceSpecificationTestData.put("onap_private_net_id", "09407156-5e6e-45a7-b4aa-6eeb7ad4aba9");
354 instanceSpecificationTestData.put("onap_private_subnet_id", "8c6df8fa-2735-49ad-ba04-24701d85ba79");
355 instanceSpecificationTestData.put("pub_key",
356 "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC/EnxIi7fcHMEi9VPtCGCOpQYblj9r0M/CaD5U15Cb5qHzcHiPtJpVsDMlPGzN9VHxWZG6FqQv1s6oE+PmG1xeahhb+ofrY6s8zvlUCcWGIo/bPexzb2ErvkGyd+1tQo9oLrxNdUG0xeWUX3oFkiw3RBRyxf9n4E5ajZr4cEFQ0sqJkslj87XViw/h555ydIYTY5cPNmIlsIXTObC/2z3muVWYUzaaZE8omfYJE442+UhYLHgb7Cl1JMk/SNu/r+bLrsXeBSPB+/bxVKqjpd659AQ7GRNXvBrgfq6EKNiVjrI76AbpeTM2D/LXbENuUUkvJBWptSd0gPAGkEyc9w2n");
357 instanceSpecificationTestData.put("public_net_id",
358 "60dc8a1c-86b8-4cc4-b5c8-9b0272113c1f0f1c389d-e9db-4c14-b3a2-11dca2d104ed");
360 // Resources to put in response as resourceSpecification
361 response.put("resourceSpecification", resources);
363 // List<LinkedHashMap> vfModelInfoListTestData = new ArrayList();
366 toscaInfosProcessor.buildAndSaveResponseWithSdcToscaParser(path, response);
367 } catch (SdcToscaParserException e) {
368 throw new TechnicalException("unable to build response from tosca csar using sdc-parser : "
369 + path.toString() + " " + e.getMessage());
373 List<LinkedHashMap> resourceSpecifications = (List<LinkedHashMap>) response.get("resourceSpecification");
375 Map instanceSpecification = (HashMap) (resourceSpecifications.get(0)).get("InstanceSpecification");
377 // Test against test data and returned response's data for instanceSpecification
378 // instanceSpecificationTestData = new HashMap();
379 assertThat(instanceSpecificationTestData).isEqualTo(instanceSpecification);
384 public void testBuildAndSaveResponseWithSdcToscaParserWithServiceAndVFNFLevelParams() {
386 ClassLoader classLoader = getClass().getClassLoader();
388 // Adding Path to TOSCA File to provide as parameter
389 Path path = new File(classLoader.getResource("toscafile/service-VfwCnf1308Service-csar.csar").getFile())
390 .toPath().toAbsolutePath();
392 // Creating response to provide as parameter
393 LinkedHashMap response = new LinkedHashMap();
394 response.put("version", "1.0");
395 response.put("name", "vfw_cnf_1308");
396 response.put("description", "vfw_cnf_1308");
397 response.put("id", "edf094cc-281f-4be9-a284-e047ded86066");
400 List<LinkedHashMap> resources = new ArrayList<>();
401 LinkedHashMap resource1 = new LinkedHashMap();
402 resource1.put("id", "679effb6-35e7-425e-9272-4b4e6b2b8382");
403 resources.add(resource1);
405 // instanceSpecification Test Data
406 Map instanceSpecificationTestData = new LinkedHashMap<>();
407 instanceSpecificationTestData.put("vfw_cnf_13080_dummy_vf_2", "xyz");
408 instanceSpecificationTestData.put("vfw_cnf_13080_dummy_vf_1", "abc");
410 // serviceParams Test Data
411 Map serviceParamsTestData = new LinkedHashMap<>();
412 serviceParamsTestData.put("dummy_ser_2", "jklm");
413 serviceParamsTestData.put("skip_post_instantiation_configuration", true);
414 serviceParamsTestData.put("controller_actor", "SO-REF-DATA");
415 serviceParamsTestData.put("dummy_ser_1", "pqrs");
416 serviceParamsTestData.put("cds_model_version", null);
417 serviceParamsTestData.put("cds_model_name", null);
418 serviceParamsTestData.put("vfw_cnf_13080_dummy_vf_2", "xyz");
419 serviceParamsTestData.put("vfw_cnf_13080_dummy_vf_1", "abc");
421 // Resources to put in response as resourceSpecification
422 response.put("resourceSpecification", resources);
425 toscaInfosProcessor.buildAndSaveResponseWithSdcToscaParser(path, response);
426 } catch (SdcToscaParserException e) {
427 throw new TechnicalException("unable to build response from tosca csar using sdc-parser : "
428 + path.toString() + " " + e.getMessage());
432 List<LinkedHashMap> resourceSpecifications = (List<LinkedHashMap>) response.get("resourceSpecification");
434 Map instanceSpecification = (HashMap) (resourceSpecifications.get(0)).get("InstanceSpecification");
436 Map serviceParams = (HashMap) (resourceSpecifications.get(0)).get("serviceInstanceParams");
437 // Test against test data and returned response's data for instanceSpecification and serviceParams
438 assertThat(instanceSpecificationTestData).isEqualTo(instanceSpecification);
439 assertThat(serviceParamsTestData).isEqualTo(serviceParams);