2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Modifications Copyright (c) 2021 Nokia
10 * ================================================================================
11 * Modifications Copyright (c) 2020 Tech Mahindra
12 * ================================================================================
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
17 * http://www.apache.org/licenses/LICENSE-2.0
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 * ============LICENSE_END=========================================================
27 package org.onap.so.bpmn.infrastructure.workflow.tasks;
29 import org.junit.Test;
30 import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys;
31 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
32 import org.onap.so.db.catalog.beans.macro.OrchestrationFlow;
33 import java.util.ArrayList;
34 import java.util.List;
35 import static org.junit.Assert.assertEquals;
36 import static org.junit.Assert.assertNotNull;
37 import static org.junit.Assert.fail;
39 public class ExecuteBuildingBlockBuilderTest {
41 final private ExecuteBuildingBlockBuilder executeBBBuilder = new ExecuteBuildingBlockBuilder();
44 public void sortVfModulesByBaseFirstTest() {
45 List<Resource> resources = new ArrayList<>();
46 Resource resource1 = new Resource(WorkflowType.VFMODULE, "111", false);
47 resource1.setBaseVfModule(false);
48 resources.add(resource1);
49 Resource resource2 = new Resource(WorkflowType.VFMODULE, "222", false);
50 resource2.setBaseVfModule(false);
51 resources.add(resource2);
52 Resource resource3 = new Resource(WorkflowType.VFMODULE, "333", false);
53 resource3.setBaseVfModule(true);
54 resources.add(resource3);
56 List<Resource> result = executeBBBuilder.sortVfModulesByBaseFirst(resources);
57 assertEquals("333", result.get(0).getResourceId());
58 assertEquals("222", result.get(1).getResourceId());
59 assertEquals("111", result.get(2).getResourceId());
63 public void sortVfModulesByBaseLastTest() {
64 List<Resource> resources = new ArrayList<>();
65 Resource resource1 = new Resource(WorkflowType.VFMODULE, "111", false);
66 resource1.setBaseVfModule(true);
67 resources.add(resource1);
68 Resource resource2 = new Resource(WorkflowType.VFMODULE, "222", false);
69 resource2.setBaseVfModule(false);
70 resources.add(resource2);
71 Resource resource3 = new Resource(WorkflowType.VFMODULE, "333", false);
72 resource3.setBaseVfModule(false);
73 resources.add(resource3);
74 List<Resource> result = executeBBBuilder.sortVfModulesByBaseLast(resources);
75 assertEquals("333", result.get(0).getResourceId());
76 assertEquals("222", result.get(1).getResourceId());
77 assertEquals("111", result.get(2).getResourceId());
81 public void verifyLackOfNullPointerExceptionForNullResource() {
82 ExecuteBuildingBlock result = null;
84 result = executeBBBuilder.buildExecuteBuildingBlock(new OrchestrationFlow(), null, null, null, null, null,
85 false, null, null, null, false, null, null, true, null);
86 } catch (NullPointerException e) {
87 fail("NullPointerException should not be thrown when 'resource' is null");
89 assertNotNull(result);
93 public void getConfigurationResourceKeysTest() {
94 String vnfcName = "vnfc";
95 String vfModuleCustomizationId = "1a2b3c4e5d";
96 String cvnfModuleCustomizationId = "2b1a3c";
97 String vnfCustomizationId = "zz12aa";
99 Resource resource = new Resource(WorkflowType.SERVICE, "123", true);
101 resource.setCvnfModuleCustomizationId(vfModuleCustomizationId);
102 resource.setCvnfModuleCustomizationId(cvnfModuleCustomizationId);
103 resource.setVnfCustomizationId(vnfCustomizationId);
105 ConfigurationResourceKeys confResourceKeys = executeBBBuilder.getConfigurationResourceKeys(resource, vnfcName);
107 assertNotNull(confResourceKeys);
108 assertEquals(vnfcName, confResourceKeys.getVnfcName());
109 assertEquals(cvnfModuleCustomizationId, confResourceKeys.getCvnfcCustomizationUUID());
110 assertEquals(vnfCustomizationId, confResourceKeys.getVnfResourceCustomizationUUID());