2 * ============LICENSE_START======================================================= Copyright (C) 2019 Nordix
3 * Foundation. ================================================================================ Licensed under the
4 * Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may
5 * obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
9 * either express or implied. See the License for the specific language governing permissions and limitations under the
12 * SPDX-License-Identifier: Apache-2.0 ============LICENSE_END=========================================================
15 package org.onap.so.asdc.client;
17 import static com.github.tomakehurst.wiremock.client.WireMock.ok;
18 import static com.github.tomakehurst.wiremock.client.WireMock.post;
19 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertNull;
23 import static org.junit.Assert.fail;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.List;
27 import java.util.Optional;
28 import java.util.UUID;
29 import javax.persistence.EntityNotFoundException;
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Ignore;
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.rules.TestName;
36 import org.onap.so.asdc.BaseTest;
37 import org.onap.so.asdc.client.exceptions.ASDCControllerException;
38 import org.onap.so.asdc.client.test.emulators.ArtifactInfoImpl;
39 import org.onap.so.asdc.client.test.emulators.DistributionClientEmulator;
40 import org.onap.so.asdc.client.test.emulators.NotificationDataImpl;
41 import org.onap.so.asdc.client.test.emulators.ResourceInfoImpl;
42 import org.onap.so.db.catalog.beans.PnfResource;
43 import org.onap.so.db.catalog.beans.PnfResourceCustomization;
44 import org.onap.so.db.catalog.beans.Service;
45 import org.onap.so.db.catalog.beans.ToscaCsar;
46 import org.onap.so.db.catalog.beans.VnfResource;
47 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
48 import org.onap.so.db.catalog.data.repository.PnfCustomizationRepository;
49 import org.onap.so.db.catalog.data.repository.PnfResourceRepository;
50 import org.onap.so.db.catalog.data.repository.ServiceRepository;
51 import org.onap.so.db.catalog.data.repository.ToscaCsarRepository;
52 import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository;
53 import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
54 import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus;
55 import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository;
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
58 import org.springframework.beans.factory.annotation.Autowired;
59 import org.springframework.transaction.annotation.Transactional;
62 * This is used to run some basic integration test(BIT) for ASDC controller. It will test the csar install and all the
63 * testing csar files are located underneath src/main/resources/download folder,
65 * PNF csar: service-Testservice140-csar.csar VNF csar: service-Svc140-VF-csar.csar
68 public class ASDCControllerITTest extends BaseTest {
70 private Logger logger = LoggerFactory.getLogger(ASDCControllerITTest.class);
73 public TestName testName = new TestName();
75 private String serviceUuid;
76 private String serviceInvariantUuid;
79 * Random UUID served as distribution UUID.
81 private String distributionId;
82 private String artifactUuid;
85 private ASDCController asdcController;
88 private PnfResourceRepository pnfResourceRepository;
91 private PnfCustomizationRepository pnfCustomizationRepository;
94 private VnfResourceRepository vnfResourceRepository;
97 private VnfCustomizationRepository vnfCustomizationRepository;
100 private ToscaCsarRepository toscaCsarRepository;
103 private ServiceRepository serviceRepository;
106 protected WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository;
108 private DistributionClientEmulator distributionClient;
111 public void setUp() {
112 distributionId = UUID.randomUUID().toString();
113 artifactUuid = UUID.randomUUID().toString();
114 logger.info("Using distributionId: {}, artifactUUID: {} for testcase: {}", distributionId, artifactUuid,
115 testName.getMethodName());
117 distributionClient = new DistributionClientEmulator();
118 distributionClient.setResourcePath("src/test/resources");
119 asdcController.setDistributionClient(distributionClient);
121 asdcController.initASDC();
122 } catch (ASDCControllerException e) {
123 logger.error(e.getMessage(), e);
124 fail(e.getMessage());
129 public void shutDown() {
131 asdcController.closeASDC();
132 } catch (ASDCControllerException e) {
133 logger.error(e.getMessage(), e);
134 fail(e.getMessage());
139 * Mock the AAI using wireshark.
141 private void initMockAaiServer(final String serviceUuid, final String serviceInvariantUuid) {
142 String modelEndpoint = "/aai/v15/service-design-and-creation/models/model/" + serviceInvariantUuid
143 + "/model-vers/model-ver/" + serviceUuid + "?depth=0";
145 wireMockServer.stubFor(post(urlEqualTo(modelEndpoint)).willReturn(ok()));
149 * Test with service-Testservice140-csar.csar.
152 public void treatNotification_ValidPnfResource_ExpectedOutput() {
155 * service UUID/invariantUUID from global metadata in service-Testservice140-template.yml.
157 String serviceUuid = "efaea486-561f-4159-9191-a8d3cb346728";
158 String serviceInvariantUuid = "f2edfbf4-bb0a-4fe7-a57a-71362d4b0b23";
160 initMockAaiServer(serviceUuid, serviceInvariantUuid);
162 NotificationDataImpl notificationData = new NotificationDataImpl();
163 notificationData.setServiceUUID(serviceUuid);
164 notificationData.setDistributionID(distributionId);
165 notificationData.setServiceInvariantUUID(serviceInvariantUuid);
166 notificationData.setServiceVersion("1.0");
168 ResourceInfoImpl resourceInfo = constructPnfResourceInfo();
169 List<ResourceInfoImpl> resourceInfoList = new ArrayList<>();
170 resourceInfoList.add(resourceInfo);
171 notificationData.setResources(resourceInfoList);
173 ArtifactInfoImpl artifactInfo = constructPnfServiceArtifact();
174 List<ArtifactInfoImpl> artifactInfoList = new ArrayList<>();
175 artifactInfoList.add(artifactInfo);
176 notificationData.setServiceArtifacts(artifactInfoList);
179 asdcController.treatNotification(notificationData);
180 logger.info("Checking the database for PNF ingestion");
183 * Check the tosca csar entity, it should be the same as provided from NotficationData.
185 ToscaCsar toscaCsar = toscaCsarRepository.findById(artifactUuid)
186 .orElseThrow(() -> new EntityNotFoundException("Tosca csar: " + artifactUuid + " not found"));
187 assertEquals("tosca csar UUID", artifactUuid, toscaCsar.getArtifactUUID());
188 assertEquals("tosca csar name", "service-Testservice140-csar.csar", toscaCsar.getName());
189 assertEquals("tosca csar version", "1.0", toscaCsar.getVersion());
190 assertNull("tosca csar descrption", toscaCsar.getDescription());
191 assertEquals("tosca csar checksum", "MANUAL_RECORD", toscaCsar.getArtifactChecksum());
192 assertEquals("toscar csar URL", "/download/service-Testservice140-csar.csar", toscaCsar.getUrl());
195 * Check the service entity, it should be the same as global metadata information in
196 * 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
217 * service-Testservice140-template.yml OR global metadata in the resource-Test140pnf-template.yml
219 String pnfResourceKey = "9c54e269-122b-4e8a-8b2a-6eac849b441a";
220 PnfResource pnfResource = pnfResourceRepository.findById(pnfResourceKey)
221 .orElseThrow(() -> new EntityNotFoundException("PNF resource:" + pnfResourceKey + " not found"));
222 assertNull("orchestration mode", pnfResource.getOrchestrationMode());
223 assertEquals("Description", "Oracle", pnfResource.getDescription().trim());
224 assertEquals("model UUID", pnfResourceKey, pnfResource.getModelUUID());
225 assertEquals("model invariant UUID", "d832a027-75f3-455d-9de4-f02fcdee7e7e",
226 pnfResource.getModelInvariantUUID());
227 assertEquals("model version", "1.0", pnfResource.getModelVersion());
228 assertEquals("model name", "Test140PNF", pnfResource.getModelName());
229 assertEquals("tosca node type", "org.openecomp.resource.pnf.Test140pnf", pnfResource.getToscaNodeType());
230 assertEquals("resource category", "Application L4+", pnfResource.getCategory());
231 assertEquals("resource sub category", "Call Control", pnfResource.getSubCategory());
234 * Check PNF resource customization, it should be the same as metadata in the topology template in
235 * service-Testservice140-template.yml OR global metadata in the resource-Test140pnf-template.yml
237 String pnfCustomizationKey = "428a3d73-f962-4cc2-ba62-2483c45d6b12";
238 PnfResourceCustomization pnfCustomization = pnfCustomizationRepository.findById(pnfCustomizationKey)
239 .orElseThrow(() -> new EntityNotFoundException(
240 "PNF resource customization: " + pnfCustomizationKey + " not found"));
241 assertEquals("model customizationUUID", pnfCustomizationKey, pnfCustomization.getModelCustomizationUUID());
242 assertEquals("model instance name", "Test140PNF 0", pnfCustomization.getModelInstanceName());
243 assertEquals("NF type", "", pnfCustomization.getNfType());
244 assertEquals("NF Role", "nf", pnfCustomization.getNfRole());
245 assertEquals("NF function", "nf", pnfCustomization.getNfFunction());
246 assertEquals("NF naming code", "", pnfCustomization.getNfNamingCode());
247 assertEquals("PNF resource model UUID", pnfResourceKey, pnfCustomization.getPnfResources().getModelUUID());
248 assertEquals("Multi stage design", "", pnfCustomization.getMultiStageDesign());
249 assertNull("resource input", pnfCustomization.getResourceInput());
250 assertEquals("cds blueprint name(sdnc_model_name property)", pnfCustomization.getBlueprintName(),
251 pnfCustomization.getBlueprintName());
252 assertEquals("cds blueprint version(sdnc_model_version property)", pnfCustomization.getBlueprintVersion(),
253 pnfCustomization.getBlueprintVersion());
256 * Check the pnf resource customization with service mapping
258 List<PnfResourceCustomization> pnfCustList = service.getPnfCustomizations();
259 assertEquals("PNF resource customization entity", 1, pnfCustList.size());
260 assertEquals(pnfCustomizationKey, pnfCustList.get(0).getModelCustomizationUUID());
263 * Check the watchdog for component distribution status
265 List<WatchdogComponentDistributionStatus> distributionList =
266 watchdogCDStatusRepository.findByDistributionId(this.distributionId);
267 assertNotNull(distributionList);
268 assertEquals(1, distributionList.size());
269 WatchdogComponentDistributionStatus distributionStatus = distributionList.get(0);
270 assertEquals("COMPONENT_DONE_OK", distributionStatus.getComponentDistributionStatus());
271 assertEquals("SO", distributionStatus.getComponentName());
274 } catch (Exception e) {
275 logger.info(e.getMessage(), e);
276 fail(e.getMessage());
280 private ArtifactInfoImpl constructPnfServiceArtifact() {
281 ArtifactInfoImpl artifactInfo = new ArtifactInfoImpl();
282 artifactInfo.setArtifactType(ASDCConfiguration.TOSCA_CSAR);
283 artifactInfo.setArtifactURL("/download/service-Testservice140-csar.csar");
284 artifactInfo.setArtifactName("service-Testservice140-csar.csar");
285 artifactInfo.setArtifactVersion("1.0");
286 artifactInfo.setArtifactUUID(artifactUuid);
291 * Construct the PnfResourceInfo based on the resource-Test140Pnf-template.yml from
292 * service-Testservice140-csar.csar.
294 private ResourceInfoImpl constructPnfResourceInfo() {
295 ResourceInfoImpl resourceInfo = new ResourceInfoImpl();
296 resourceInfo.setResourceInstanceName("Test140PNF");
297 resourceInfo.setResourceInvariantUUID("d832a027-75f3-455d-9de4-f02fcdee7e7e");
298 resourceInfo.setResoucreType("PNF");
299 resourceInfo.setCategory("Application L4+");
300 resourceInfo.setSubcategory("Call Control");
301 resourceInfo.setResourceUUID("9c54e269-122b-4e8a-8b2a-6eac849b441a");
302 resourceInfo.setResourceCustomizationUUID("428a3d73-f962-4cc2-ba62-2483c45d6b12");
303 resourceInfo.setResourceVersion("1.0");
308 * Testing with the service-Svc140-VF-csar.csar.
312 public void treatNotification_ValidVnfResource_ExpectedOutput() {
315 * service UUID/invariantUUID from global metadata in resource-Testvf140-template.yml.
317 String serviceUuid = "28944a37-de3f-46ec-9c60-b57036fbd26d";
318 String serviceInvariantUuid = "9e900d3e-1e2e-4124-a5c2-4345734dc9de";
320 initMockAaiServer(serviceUuid, serviceInvariantUuid);
322 NotificationDataImpl notificationData = new NotificationDataImpl();
323 notificationData.setServiceUUID(serviceUuid);
324 notificationData.setDistributionID(distributionId);
325 notificationData.setServiceInvariantUUID(serviceInvariantUuid);
326 notificationData.setServiceVersion("1.0");
328 ResourceInfoImpl resourceInfo = constructVnfResourceInfo();
329 List<ResourceInfoImpl> resourceInfoList = new ArrayList<>();
330 resourceInfoList.add(resourceInfo);
331 notificationData.setResources(resourceInfoList);
333 ArtifactInfoImpl artifactInfo = constructVnfServiceArtifact();
334 List<ArtifactInfoImpl> artifactInfoList = new ArrayList<>();
335 artifactInfoList.add(artifactInfo);
336 notificationData.setServiceArtifacts(artifactInfoList);
339 asdcController.treatNotification(notificationData);
340 logger.info("Checking the database for VNF ingestion");
343 * Check the tosca csar entity, it should be the same as provided from NotficationData.
345 ToscaCsar toscaCsar = toscaCsarRepository.findById(artifactUuid)
346 .orElseThrow(() -> new EntityNotFoundException("Tosca csar: " + artifactUuid + " not found"));
347 assertEquals("tosca csar UUID", artifactUuid, toscaCsar.getArtifactUUID());
348 assertEquals("tosca csar name", "service-Svc140-VF-csar.csar", toscaCsar.getName());
349 assertEquals("tosca csar version", "1.0", toscaCsar.getVersion());
350 assertNull("tosca csar descrption", toscaCsar.getDescription());
351 assertEquals("tosca csar checksum", "MANUAL_RECORD", toscaCsar.getArtifactChecksum());
352 assertEquals("toscar csar URL", "/download/service-Svc140-VF-csar.csar", toscaCsar.getUrl());
355 * Check the service entity, it should be the same as global metadata information in
356 * service-Testservice140-template.yml inside csar.
358 Service service = serviceRepository.findById(serviceUuid)
359 .orElseThrow(() -> new EntityNotFoundException("Service: " + serviceUuid + " not found"));
360 assertEquals("model UUID", serviceUuid, service.getModelUUID());
361 assertEquals("model name", "SVC140", service.getModelName());
362 assertEquals("model invariantUUID", serviceInvariantUuid, service.getModelInvariantUUID());
363 assertEquals("model version", "1.0", service.getModelVersion());
364 assertEquals("description", "SVC140", service.getDescription().trim());
365 assertEquals("tosca csar artifact UUID", artifactUuid, service.getCsar().getArtifactUUID());
366 assertEquals("service type", "ST", service.getServiceType());
367 assertEquals("service role", "Sr", service.getServiceRole());
368 assertEquals("environment context", "General_Revenue-Bearing", service.getEnvironmentContext());
369 assertEquals("service category", "Network Service", service.getCategory());
370 assertNull("workload context", service.getWorkloadContext());
371 assertEquals("resource order", "TestVF140", service.getResourceOrder());
374 * Check VNF resource, it should be the same as metadata in the topology template in
375 * service-Testservice140-template.yml OR global metadata in the resource-Testservice140-template.yml
377 String vnfResourceKey = "d20d3ea9-2f54-4071-8b5c-fd746dde245e";
378 VnfResource vnfResource = vnfResourceRepository.findById(vnfResourceKey)
379 .orElseThrow(() -> new EntityNotFoundException("VNF resource:" + vnfResourceKey + " not found"));
380 assertEquals("orchestration mode", "HEAT", vnfResource.getOrchestrationMode());
381 assertEquals("Description", "TestPNF140", vnfResource.getDescription().trim());
382 assertEquals("model UUID", vnfResourceKey, vnfResource.getModelUUID());
383 assertEquals("model invariant UUID", "7a4bffa2-fac5-4b8b-b348-0bdf313a1aeb",
384 vnfResource.getModelInvariantUUID());
385 assertEquals("model version", "1.0", vnfResource.getModelVersion());
386 assertEquals("model name", "TestVF140", vnfResource.getModelName());
387 assertEquals("tosca node type", "org.openecomp.resource.vf.Testvf140", vnfResource.getToscaNodeType());
388 assertEquals("resource category", "Application L4+", vnfResource.getCategory());
389 assertEquals("resource sub category", "Database", vnfResource.getSubCategory());
392 * Check VNF resource customization, it should be the same as metadata in the topology template in
393 * service-Testservice140-template.yml OR global metadata in the resource-Testservice140-template.yml
395 String vnfCustomizationKey = "ca1c8455-8ce2-4a76-a037-3f4cf01cffa0";
396 VnfResourceCustomization vnfCustomization =
397 Optional.ofNullable(vnfCustomizationRepository.findOneByModelCustomizationUUID(vnfCustomizationKey))
398 .orElseThrow(() -> new EntityNotFoundException(
399 "VNF resource customization: " + vnfCustomizationKey + " not found"));
400 assertEquals("model customizationUUID", vnfCustomizationKey, vnfCustomization.getModelCustomizationUUID());
401 assertEquals("model instance name", "TestVF140 0", vnfCustomization.getModelInstanceName());
402 assertNull("NF type", vnfCustomization.getNfType());
403 assertNull("NF Role", vnfCustomization.getNfRole());
404 assertNull("NF function", vnfCustomization.getNfFunction());
405 assertNull("NF naming code", vnfCustomization.getNfNamingCode());
406 assertEquals("VNF resource model UUID", vnfResourceKey, vnfCustomization.getVnfResources().getModelUUID());
407 assertEquals("Multi stage design", "false", vnfCustomization.getMultiStageDesign());
408 assertNull("resource input", vnfCustomization.getResourceInput());
409 assertEquals("cds blueprint name(sdnc_model_name property)", vnfCustomization.getBlueprintName(),
410 vnfCustomization.getBlueprintName());
411 assertEquals("cds blueprint version(sdnc_model_version property)", vnfCustomization.getBlueprintVersion(),
412 vnfCustomization.getBlueprintVersion());
414 * Check the vnf resource customization with service mapping
416 List<VnfResourceCustomization> vnfCustList = service.getVnfCustomizations();
417 assertEquals("VNF resource customization entity", 1, vnfCustList.size());
418 assertEquals(vnfCustomizationKey, vnfCustList.get(0).getModelCustomizationUUID());
421 * Check the watchdog for component distribution status
423 List<WatchdogComponentDistributionStatus> distributionList =
424 watchdogCDStatusRepository.findByDistributionId(this.distributionId);
425 assertNotNull(distributionList);
426 assertEquals(1, distributionList.size());
427 WatchdogComponentDistributionStatus distributionStatus = distributionList.get(0);
428 assertEquals("COMPONENT_DONE_OK", distributionStatus.getComponentDistributionStatus());
429 assertEquals("SO", distributionStatus.getComponentName());
430 } catch (Exception e) {
431 logger.info(e.getMessage(), e);
432 fail(e.getMessage());
436 private ArtifactInfoImpl constructVnfServiceArtifact() {
437 ArtifactInfoImpl artifactInfo = new ArtifactInfoImpl();
438 artifactInfo.setArtifactType(ASDCConfiguration.TOSCA_CSAR);
439 artifactInfo.setArtifactURL("/download/service-Svc140-VF-csar.csar");
440 artifactInfo.setArtifactName("service-Svc140-VF-csar.csar");
441 artifactInfo.setArtifactVersion("1.0");
442 artifactInfo.setArtifactUUID(artifactUuid);
447 * Construct the PnfResourceInfo based on the resource-Testvf140-template.yml from service-Svc140-VF-csar.csar.
449 private ResourceInfoImpl constructVnfResourceInfo() {
450 ResourceInfoImpl resourceInfo = new ResourceInfoImpl();
451 resourceInfo.setResourceInstanceName("TestVF140");
452 resourceInfo.setResourceInvariantUUID("7a4bffa2-fac5-4b8b-b348-0bdf313a1aeb");
453 resourceInfo.setResoucreType("VF");
454 resourceInfo.setCategory("Application L4+");
455 resourceInfo.setSubcategory("Database");
456 resourceInfo.setResourceUUID("d20d3ea9-2f54-4071-8b5c-fd746dde245e");
457 resourceInfo.setResourceCustomizationUUID("ca1c8455-8ce2-4a76-a037-3f4cf01cffa0");
458 resourceInfo.setResourceVersion("1.0");
459 resourceInfo.setArtifacts(Collections.EMPTY_LIST);