2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 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
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.onap.so.asdc.client;
22 import static com.github.tomakehurst.wiremock.client.WireMock.ok;
23 import static com.github.tomakehurst.wiremock.client.WireMock.post;
24 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.fail;
29 import java.util.ArrayList;
30 import java.util.Collections;
31 import java.util.List;
32 import java.util.UUID;
34 import javax.persistence.EntityNotFoundException;
36 import org.junit.After;
37 import org.junit.Before;
38 import org.junit.Ignore;
39 import org.junit.Rule;
40 import org.junit.Test;
41 import org.junit.rules.TestName;
42 import org.onap.so.asdc.BaseTest;
43 import org.onap.so.asdc.client.exceptions.ASDCControllerException;
44 import org.onap.so.asdc.client.test.emulators.ArtifactInfoImpl;
45 import org.onap.so.asdc.client.test.emulators.DistributionClientEmulator;
46 import org.onap.so.asdc.client.test.emulators.NotificationDataImpl;
47 import org.onap.so.asdc.client.test.emulators.ResourceInfoImpl;
48 import org.onap.so.db.catalog.beans.PnfResource;
49 import org.onap.so.db.catalog.beans.PnfResourceCustomization;
50 import org.onap.so.db.catalog.beans.Service;
51 import org.onap.so.db.catalog.beans.ToscaCsar;
52 import org.onap.so.db.catalog.beans.VnfResource;
53 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
54 import org.onap.so.db.catalog.data.repository.PnfCustomizationRepository;
55 import org.onap.so.db.catalog.data.repository.PnfResourceRepository;
56 import org.onap.so.db.catalog.data.repository.ServiceRepository;
57 import org.onap.so.db.catalog.data.repository.ToscaCsarRepository;
58 import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository;
59 import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
60 import org.slf4j.Logger;
61 import org.slf4j.LoggerFactory;
62 import org.springframework.beans.factory.annotation.Autowired;
63 import org.springframework.transaction.annotation.Transactional;
66 * This is used to run some basic integration test(BIT) for ASDC controller. It will test the csar install and all the
67 * testing csar files are located underneath src/main/resources/download folder,
69 * PNF csar: service-Testservice140-csar.csar VNF csar: service-Svc140-VF-csar.csar
72 public class ASDCControllerITTest extends BaseTest {
74 private Logger logger = LoggerFactory.getLogger(ASDCControllerITTest.class);
77 public TestName testName = new TestName();
79 private String serviceUuid;
80 private String serviceInvariantUuid;
83 * Random UUID served as distribution UUID.
85 private String distributionId;
86 private String artifactUuid;
89 private ASDCController asdcController;
92 private PnfResourceRepository pnfResourceRepository;
95 private PnfCustomizationRepository pnfCustomizationRepository;
98 private VnfResourceRepository vnfResourceRepository;
101 private VnfCustomizationRepository vnfCustomizationRepository;
104 private ToscaCsarRepository toscaCsarRepository;
107 private ServiceRepository serviceRepository;
109 private DistributionClientEmulator distributionClient;
112 public void setUp() {
113 distributionId = UUID.randomUUID().toString();
114 artifactUuid = UUID.randomUUID().toString();
115 logger.info("Using distributionId: {}, artifactUUID: {} for testcase: {}", distributionId, artifactUuid,
116 testName.getMethodName());
118 distributionClient = new DistributionClientEmulator();
119 distributionClient.setResourcePath("src/test/resources");
120 asdcController.setDistributionClient(distributionClient);
122 asdcController.initASDC();
123 } catch (ASDCControllerException e) {
124 logger.error(e.getMessage(), e);
125 fail(e.getMessage());
130 public void shutDown() {
132 asdcController.closeASDC();
133 } catch (ASDCControllerException e) {
134 logger.error(e.getMessage(), e);
135 fail(e.getMessage());
140 * Mock the AAI using wireshark.
142 private void initMockAaiServer(final String serviceUuid, final String serviceInvariantUuid) {
143 String modelEndpoint = "/aai/v15/service-design-and-creation/models/model/" + serviceInvariantUuid
144 + "/model-vers/model-ver/" + serviceUuid + "?depth=0";
146 wireMockServer.stubFor(post(urlEqualTo(modelEndpoint)).willReturn(ok()));
150 * Test with service-Testservice140-csar.csar.
153 public void treatNotification_ValidPnfResource_ExpectedOutput() {
156 * service UUID/invariantUUID from global metadata in service-Testservice140-template.yml.
158 String serviceUuid = "efaea486-561f-4159-9191-a8d3cb346728";
159 String serviceInvariantUuid = "f2edfbf4-bb0a-4fe7-a57a-71362d4b0b23";
161 initMockAaiServer(serviceUuid, serviceInvariantUuid);
163 NotificationDataImpl notificationData = new NotificationDataImpl();
164 notificationData.setServiceUUID(serviceUuid);
165 notificationData.setDistributionID(distributionId);
166 notificationData.setServiceInvariantUUID(serviceInvariantUuid);
167 notificationData.setServiceVersion("1.0");
169 ResourceInfoImpl resourceInfo = constructPnfResourceInfo();
170 List<ResourceInfoImpl> resourceInfoList = new ArrayList<>();
171 resourceInfoList.add(resourceInfo);
172 notificationData.setResources(resourceInfoList);
174 ArtifactInfoImpl artifactInfo = constructPnfServiceArtifact();
175 List<ArtifactInfoImpl> artifactInfoList = new ArrayList<>();
176 artifactInfoList.add(artifactInfo);
177 notificationData.setServiceArtifacts(artifactInfoList);
180 asdcController.treatNotification(notificationData);
181 logger.info("Checking the database for PNF ingestion");
184 * Check the tosca csar entity, it should be the same as provided from NotficationData.
186 ToscaCsar toscaCsar = toscaCsarRepository.findById(artifactUuid)
187 .orElseThrow(() -> new EntityNotFoundException("Tosca csar: " + artifactUuid + " not found"));
188 assertEquals("tosca csar UUID", artifactUuid, toscaCsar.getArtifactUUID());
189 assertEquals("tosca csar name", "service-Testservice140-csar.csar", toscaCsar.getName());
190 assertEquals("tosca csar version", "1.0", toscaCsar.getVersion());
191 assertNull("tosca csar descrption", toscaCsar.getDescription());
192 assertEquals("tosca csar checksum", "MANUAL_RECORD", toscaCsar.getArtifactChecksum());
193 assertEquals("toscar csar URL", "/download/service-Testservice140-csar.csar", toscaCsar.getUrl());
196 * Check the service entity, it should be the same as global metadata information in service-Testservice140-template.yml inside csar.
198 Service service = serviceRepository.findById(serviceUuid)
199 .orElseThrow(() -> new EntityNotFoundException("Service: " + serviceUuid + " not found"));
200 assertEquals("model UUID", "efaea486-561f-4159-9191-a8d3cb346728", service.getModelUUID());
201 assertEquals("model name", "TestService140", service.getModelName());
202 assertEquals("model invariantUUID", "f2edfbf4-bb0a-4fe7-a57a-71362d4b0b23",
203 service.getModelInvariantUUID());
204 assertEquals("model version", "1.0", service.getModelVersion());
205 assertEquals("description", "Test Service for extended attributes of PNF resource",
206 service.getDescription().trim());
207 assertEquals("tosca csar artifact UUID", artifactUuid, service.getCsar().getArtifactUUID());
208 assertEquals("service type", "Network", service.getServiceType());
209 assertEquals("service role", "nfv", service.getServiceRole());
210 assertEquals("environment context", "General_Revenue-Bearing", service.getEnvironmentContext());
211 assertEquals("service category", "Network Service", service.getCategory());
212 assertNull("workload context", service.getWorkloadContext());
213 assertEquals("resource order", "Test140PNF", service.getResourceOrder());
216 * Check PNF resource, it should be the same as metadata in the topology template in service-Testservice140-template.yml
218 * global metadata in the resource-Test140pnf-template.yml
220 String pnfResourceKey = "9c54e269-122b-4e8a-8b2a-6eac849b441a";
221 PnfResource pnfResource = pnfResourceRepository.findById(pnfResourceKey)
222 .orElseThrow(() -> new EntityNotFoundException("PNF resource:" + pnfResourceKey + " not found"));
223 assertNull("orchestration mode", pnfResource.getOrchestrationMode());
224 assertEquals("Description", "Oracle", pnfResource.getDescription().trim());
225 assertEquals("model UUID", pnfResourceKey, pnfResource.getModelUUID());
226 assertEquals("model invariant UUID", "d832a027-75f3-455d-9de4-f02fcdee7e7e",
227 pnfResource.getModelInvariantUUID());
228 assertEquals("model version", "1.0", pnfResource.getModelVersion());
229 assertEquals("model name", "Test140PNF", pnfResource.getModelName());
230 assertEquals("tosca node type", "org.openecomp.resource.pnf.Test140pnf", pnfResource.getToscaNodeType());
231 assertEquals("resource category", "Application L4+", pnfResource.getCategory());
232 assertEquals("resource sub category", "Call Control", pnfResource.getSubCategory());
235 * Check PNF resource customization, it should be the same as metadata in the topology template in service-Testservice140-template.yml
237 * global metadata in the resource-Test140pnf-template.yml
239 String pnfCustomizationKey = "428a3d73-f962-4cc2-ba62-2483c45d6b12";
240 PnfResourceCustomization pnfCustomization = pnfCustomizationRepository
241 .findById(pnfCustomizationKey).orElseThrow(
242 () -> new EntityNotFoundException(
243 "PNF resource customization: " + pnfCustomizationKey + " not found"));
244 assertEquals("model customizationUUID", pnfCustomizationKey, pnfCustomization.getModelCustomizationUUID());
245 assertEquals("model instance name", "Test140PNF 0", pnfCustomization.getModelInstanceName());
246 assertEquals("NF type", "", pnfCustomization.getNfType());
247 assertEquals("NF Role", "nf", pnfCustomization.getNfRole());
248 assertEquals("NF function", "nf", pnfCustomization.getNfFunction());
249 assertEquals("NF naming code", "", pnfCustomization.getNfNamingCode());
250 assertEquals("PNF resource model UUID", pnfResourceKey, pnfCustomization.getPnfResources().getModelUUID());
251 assertEquals("Multi stage design", "", pnfCustomization.getMultiStageDesign());
252 assertNull("resource input", pnfCustomization.getResourceInput());
253 assertEquals("cds blueprint name(sdnc_model_name property)", pnfCustomization.getBlueprintName(),
254 pnfCustomization.getBlueprintName());
255 assertEquals("cds blueprint version(sdnc_model_version property)", pnfCustomization.getBlueprintVersion(),
256 pnfCustomization.getBlueprintVersion());
259 * Check the pnf resource customization with service mapping
261 List<PnfResourceCustomization> pnfCustList = service.getPnfCustomizations();
262 assertEquals("PNF resource customization entity", 1, pnfCustList.size());
263 assertEquals(pnfCustomizationKey, pnfCustList.get(0).getModelCustomizationUUID());
265 } catch (Exception e) {
266 logger.info(e.getMessage(), e);
267 fail(e.getMessage());
271 private ArtifactInfoImpl constructPnfServiceArtifact() {
272 ArtifactInfoImpl artifactInfo = new ArtifactInfoImpl();
273 artifactInfo.setArtifactType(ASDCConfiguration.TOSCA_CSAR);
274 artifactInfo.setArtifactURL("/download/service-Testservice140-csar.csar");
275 artifactInfo.setArtifactName("service-Testservice140-csar.csar");
276 artifactInfo.setArtifactVersion("1.0");
277 artifactInfo.setArtifactUUID(artifactUuid);
282 * Construct the PnfResourceInfo based on the resource-Test140Pnf-template.yml from
283 * service-Testservice140-csar.csar.
285 private ResourceInfoImpl constructPnfResourceInfo() {
286 ResourceInfoImpl resourceInfo = new ResourceInfoImpl();
287 resourceInfo.setResourceInstanceName("Test140PNF");
288 resourceInfo.setResourceInvariantUUID("d832a027-75f3-455d-9de4-f02fcdee7e7e");
289 resourceInfo.setResoucreType("PNF");
290 resourceInfo.setCategory("Application L4+");
291 resourceInfo.setSubcategory("Call Control");
292 resourceInfo.setResourceUUID("9c54e269-122b-4e8a-8b2a-6eac849b441a");
293 resourceInfo.setResourceCustomizationUUID("428a3d73-f962-4cc2-ba62-2483c45d6b12");
294 resourceInfo.setResourceVersion("1.0");
299 * Testing with the service-Svc140-VF-csar.csar.
303 public void treatNotification_ValidVnfResource_ExpectedOutput() {
306 * service UUID/invariantUUID from global metadata in resource-Testvf140-template.yml.
308 String serviceUuid = "28944a37-de3f-46ec-9c60-b57036fbd26d";
309 String serviceInvariantUuid = "9e900d3e-1e2e-4124-a5c2-4345734dc9de";
311 initMockAaiServer(serviceUuid, serviceInvariantUuid);
313 NotificationDataImpl notificationData = new NotificationDataImpl();
314 notificationData.setServiceUUID(serviceUuid);
315 notificationData.setDistributionID(distributionId);
316 notificationData.setServiceInvariantUUID(serviceInvariantUuid);
317 notificationData.setServiceVersion("1.0");
319 ResourceInfoImpl resourceInfo = constructVnfResourceInfo();
320 List<ResourceInfoImpl> resourceInfoList = new ArrayList<>();
321 resourceInfoList.add(resourceInfo);
322 notificationData.setResources(resourceInfoList);
324 ArtifactInfoImpl artifactInfo = constructVnfServiceArtifact();
325 List<ArtifactInfoImpl> artifactInfoList = new ArrayList<>();
326 artifactInfoList.add(artifactInfo);
327 notificationData.setServiceArtifacts(artifactInfoList);
330 asdcController.treatNotification(notificationData);
331 logger.info("Checking the database for VNF ingestion");
334 * Check the tosca csar entity, it should be the same as provided from NotficationData.
336 ToscaCsar toscaCsar = toscaCsarRepository.findById(artifactUuid)
337 .orElseThrow(() -> new EntityNotFoundException("Tosca csar: " + artifactUuid + " not found"));
338 assertEquals("tosca csar UUID", artifactUuid, toscaCsar.getArtifactUUID());
339 assertEquals("tosca csar name", "service-Svc140-VF-csar.csar", toscaCsar.getName());
340 assertEquals("tosca csar version", "1.0", toscaCsar.getVersion());
341 assertNull("tosca csar descrption", toscaCsar.getDescription());
342 assertEquals("tosca csar checksum", "MANUAL_RECORD", toscaCsar.getArtifactChecksum());
343 assertEquals("toscar csar URL", "/download/service-Svc140-VF-csar.csar", toscaCsar.getUrl());
346 * Check the service entity, it should be the same as global metadata information in service-Testservice140-template.yml inside csar.
348 Service service = serviceRepository.findById(serviceUuid)
349 .orElseThrow(() -> new EntityNotFoundException("Service: " + serviceUuid + " not found"));
350 assertEquals("model UUID", serviceUuid, service.getModelUUID());
351 assertEquals("model name", "SVC140", service.getModelName());
352 assertEquals("model invariantUUID", serviceInvariantUuid,
353 service.getModelInvariantUUID());
354 assertEquals("model version", "1.0", service.getModelVersion());
355 assertEquals("description", "SVC140",
356 service.getDescription().trim());
357 assertEquals("tosca csar artifact UUID", artifactUuid, service.getCsar().getArtifactUUID());
358 assertEquals("service type", "ST", service.getServiceType());
359 assertEquals("service role", "Sr", service.getServiceRole());
360 assertEquals("environment context", "General_Revenue-Bearing", service.getEnvironmentContext());
361 assertEquals("service category", "Network Service", service.getCategory());
362 assertNull("workload context", service.getWorkloadContext());
363 assertEquals("resource order", "TestVF140", service.getResourceOrder());
366 * Check VNF resource, it should be the same as metadata in the topology template in service-Testservice140-template.yml
368 * global metadata in the resource-Testservice140-template.yml
370 String vnfResourceKey = "d20d3ea9-2f54-4071-8b5c-fd746dde245e";
371 VnfResource vnfResource = vnfResourceRepository.findById(vnfResourceKey)
372 .orElseThrow(() -> new EntityNotFoundException("VNF resource:" + vnfResourceKey + " not found"));
373 assertEquals("orchestration mode", "HEAT", vnfResource.getOrchestrationMode());
374 assertEquals("Description", "TestPNF140", vnfResource.getDescription().trim());
375 assertEquals("model UUID", vnfResourceKey, vnfResource.getModelUUID());
376 assertEquals("model invariant UUID", "7a4bffa2-fac5-4b8b-b348-0bdf313a1aeb",
377 vnfResource.getModelInvariantUUID());
378 assertEquals("model version", "1.0", vnfResource.getModelVersion());
379 assertEquals("model name", "TestVF140", vnfResource.getModelName());
380 assertEquals("tosca node type", "org.openecomp.resource.vf.Testvf140", vnfResource.getToscaNodeType());
381 assertEquals("resource category", "Application L4+", vnfResource.getCategory());
382 assertEquals("resource sub category", "Database", vnfResource.getSubCategory());
385 * Check VNF resource customization, it should be the same as metadata in the topology template in service-Testservice140-template.yml
387 * global metadata in the resource-Testservice140-template.yml
389 String vnfCustomizationKey = "ca1c8455-8ce2-4a76-a037-3f4cf01cffa0";
390 VnfResourceCustomization vnfCustomization = vnfCustomizationRepository
391 .findById(vnfCustomizationKey).orElseThrow(
392 () -> new EntityNotFoundException(
393 "VNF resource customization: " + vnfCustomizationKey + " not found"));
394 assertEquals("model customizationUUID", vnfCustomizationKey, vnfCustomization.getModelCustomizationUUID());
395 assertEquals("model instance name", "TestVF140 0", vnfCustomization.getModelInstanceName());
396 assertNull("NF type", vnfCustomization.getNfType());
397 assertNull("NF Role", vnfCustomization.getNfRole());
398 assertNull("NF function", vnfCustomization.getNfFunction());
399 assertNull("NF naming code", vnfCustomization.getNfNamingCode());
400 assertEquals("VNF resource model UUID", vnfResourceKey, vnfCustomization.getVnfResources().getModelUUID());
401 assertEquals("Multi stage design", "false", vnfCustomization.getMultiStageDesign());
402 assertNull("resource input", vnfCustomization.getResourceInput());
403 assertEquals("cds blueprint name(sdnc_model_name property)", vnfCustomization.getBlueprintName(),
404 vnfCustomization.getBlueprintName());
405 assertEquals("cds blueprint version(sdnc_model_version property)", vnfCustomization.getBlueprintVersion(),
406 vnfCustomization.getBlueprintVersion());
408 * Check the vnf resource customization with service mapping
410 List<VnfResourceCustomization> vnfCustList = service.getVnfCustomizations();
411 assertEquals("VNF resource customization entity", 1, vnfCustList.size());
412 assertEquals(vnfCustomizationKey, vnfCustList.get(0).getModelCustomizationUUID());
413 } catch (Exception e) {
414 logger.info(e.getMessage(), e);
415 fail(e.getMessage());
419 private ArtifactInfoImpl constructVnfServiceArtifact() {
420 ArtifactInfoImpl artifactInfo = new ArtifactInfoImpl();
421 artifactInfo.setArtifactType(ASDCConfiguration.TOSCA_CSAR);
422 artifactInfo.setArtifactURL("/download/service-Svc140-VF-csar.csar");
423 artifactInfo.setArtifactName("service-Svc140-VF-csar.csar");
424 artifactInfo.setArtifactVersion("1.0");
425 artifactInfo.setArtifactUUID(artifactUuid);
430 * Construct the PnfResourceInfo based on the resource-Testvf140-template.yml from service-Svc140-VF-csar.csar.
432 private ResourceInfoImpl constructVnfResourceInfo() {
433 ResourceInfoImpl resourceInfo = new ResourceInfoImpl();
434 resourceInfo.setResourceInstanceName("TestVF140");
435 resourceInfo.setResourceInvariantUUID("7a4bffa2-fac5-4b8b-b348-0bdf313a1aeb");
436 resourceInfo.setResoucreType("VF");
437 resourceInfo.setCategory("Application L4+");
438 resourceInfo.setSubcategory("Database");
439 resourceInfo.setResourceUUID("d20d3ea9-2f54-4071-8b5c-fd746dde245e");
440 resourceInfo.setResourceCustomizationUUID("ca1c8455-8ce2-4a76-a037-3f4cf01cffa0");
441 resourceInfo.setResourceVersion("1.0");
442 resourceInfo.setArtifacts(Collections.EMPTY_LIST);