2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.so.bpmn.servicedecomposition;
23 import static org.junit.Assert.assertEquals;
24 import java.util.HashMap;
25 import java.util.List;
26 import org.camunda.bpm.engine.impl.pvm.runtime.ExecutionImpl;
27 import org.junit.Before;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.rules.ExpectedException;
31 import org.onap.so.bpmn.common.BuildingBlockExecution;
32 import org.onap.so.bpmn.common.DelegateExecutionImpl;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.*;
34 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
35 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
36 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
37 import org.onap.so.client.exception.BBObjectNotFoundException;
38 import org.onap.so.BaseTest;
40 public class ExtractPojosForBBTest extends BaseTest {
41 ExtractPojosForBB extractPojos = new ExtractPojosForBB();
42 private BuildingBlockExecution execution;
43 private GeneralBuildingBlock gBBInput;
44 private HashMap<ResourceKey, String> lookupKeyMap;
47 public ExpectedException expectedException = ExpectedException.none();
50 public void before() {
51 execution = new DelegateExecutionImpl(new ExecutionImpl());
52 execution.setVariable("testProcessKey", "AAICreateTasksTests");
53 gBBInput = new GeneralBuildingBlock();
54 execution.setVariable("gBBInput", gBBInput);
55 lookupKeyMap = new HashMap<>();
56 execution.setVariable("lookupKeyMap", lookupKeyMap);
60 public void get() throws BBObjectNotFoundException {
61 ServiceInstance serviceInstancePend = new ServiceInstance();
62 serviceInstancePend.setServiceInstanceId("abc");
63 lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, serviceInstancePend.getServiceInstanceId());
65 VpnBondingLink vpnBondingLinkPend = new VpnBondingLink();
66 vpnBondingLinkPend.setVpnBondingLinkId("testVpnBondingLink");
67 serviceInstancePend.getVpnBondingLinks().add(vpnBondingLinkPend);
68 lookupKeyMap.put(ResourceKey.VPN_BONDING_LINK_ID, vpnBondingLinkPend.getVpnBondingLinkId());
70 Customer customer = new Customer();
71 customer.setServiceSubscription(new ServiceSubscription());
72 VpnBinding vpnBinding = new VpnBinding();
73 vpnBinding.setVpnId("abc");
74 customer.getVpnBindings().add(vpnBinding);
75 lookupKeyMap.put(ResourceKey.VPN_ID, vpnBinding.getVpnId());
77 List<GenericVnf> vnfsPend = serviceInstancePend.getVnfs();
78 GenericVnf vnfPend = new GenericVnf();
79 vnfPend.setVnfId("abc");
80 lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnfPend.getVnfId());
82 List<VfModule> vfModulesPend = vnfPend.getVfModules();
83 VfModule vfModulePend = new VfModule();
84 vfModulePend.setVfModuleId("abc");
85 vfModulesPend.add(vfModulePend);
86 vnfsPend.add(vnfPend);
87 lookupKeyMap.put(ResourceKey.VF_MODULE_ID, vfModulePend.getVfModuleId());
89 List<L3Network> networksPend = serviceInstancePend.getNetworks();
90 L3Network networkPend = new L3Network();
91 networkPend.setNetworkId("abc");
92 networksPend.add(networkPend);
93 lookupKeyMap.put(ResourceKey.NETWORK_ID, networkPend.getNetworkId());
95 List<VolumeGroup> volumeGroupsPend = serviceInstancePend.getVnfs().get(0).getVolumeGroups();
96 VolumeGroup volumeGroupPend = new VolumeGroup();
97 volumeGroupPend.setVolumeGroupId("abc");
98 volumeGroupsPend.add(volumeGroupPend);
99 lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, volumeGroupPend.getVolumeGroupId());
101 List<AllottedResource> allotedResourcesPend = serviceInstancePend.getAllottedResources();
102 AllottedResource allotedResourcePend = new AllottedResource();
103 allotedResourcePend.setId("abc");
104 allotedResourcesPend.add(allotedResourcePend);
105 lookupKeyMap.put(ResourceKey.ALLOTTED_RESOURCE_ID, allotedResourcePend.getId());
107 Configuration configurationPend = new Configuration();
108 configurationPend.setConfigurationId("abc");
109 serviceInstancePend.getConfigurations().add(configurationPend);
110 lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, configurationPend.getConfigurationId());
112 List<InstanceGroup> instanceGroupsPend = serviceInstancePend.getInstanceGroups();
113 InstanceGroup instanceGroupPend = new InstanceGroup();
114 instanceGroupPend.setId("test-instance-group-1");
115 instanceGroupsPend.add(instanceGroupPend);
116 lookupKeyMap.put(ResourceKey.INSTANCE_GROUP_ID, instanceGroupPend.getId());
118 customer.getServiceSubscription().getServiceInstances().add(serviceInstancePend);
119 gBBInput.setCustomer(customer);
121 ServiceInstance extractServPend = extractPojos.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
122 assertEquals(extractServPend.getServiceInstanceId(), serviceInstancePend.getServiceInstanceId());
123 GenericVnf extractVnfPend = extractPojos.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
124 assertEquals(extractVnfPend.getVnfId(), vnfPend.getVnfId());
125 L3Network extractNetworkPend = extractPojos.extractByKey(execution, ResourceKey.NETWORK_ID);
126 assertEquals(extractNetworkPend.getNetworkId(), networkPend.getNetworkId());
127 VolumeGroup extractVolumeGroupPend = extractPojos.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
128 assertEquals(extractVolumeGroupPend.getVolumeGroupId(), volumeGroupPend.getVolumeGroupId());
129 AllottedResource extractallotedResourcePend =
130 extractPojos.extractByKey(execution, ResourceKey.ALLOTTED_RESOURCE_ID);
131 assertEquals(extractallotedResourcePend.getId(), allotedResourcePend.getId());
132 Configuration extractConfigurationPend = extractPojos.extractByKey(execution, ResourceKey.CONFIGURATION_ID);
133 assertEquals(extractConfigurationPend.getConfigurationId(), configurationPend.getConfigurationId());
134 VpnBinding extractVpnBinding = extractPojos.extractByKey(execution, ResourceKey.VPN_ID);
135 assertEquals(extractVpnBinding.getVpnId(), vpnBinding.getVpnId());
137 VfModule extractVfModulePend = extractPojos.extractByKey(execution, ResourceKey.VF_MODULE_ID);
138 assertEquals(extractVfModulePend.getVfModuleId(), vfModulePend.getVfModuleId());
140 VpnBondingLink extractVpnBondingLinkPend =
141 extractPojos.extractByKey(execution, ResourceKey.VPN_BONDING_LINK_ID);
142 assertEquals(extractVpnBondingLinkPend.getVpnBondingLinkId(), vpnBondingLinkPend.getVpnBondingLinkId());
144 InstanceGroup extractInstanceGroupPend = extractPojos.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID);
145 assertEquals(instanceGroupPend.getId(), extractInstanceGroupPend.getId());
149 public void siError() throws BBObjectNotFoundException {
150 expectedException.expect(BBObjectNotFoundException.class);
152 Customer customer = new Customer();
153 customer.setServiceSubscription(new ServiceSubscription());
154 ServiceInstance serviceInstance = new ServiceInstance();
155 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
156 gBBInput.setCustomer(customer);
158 extractPojos.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
162 public void vnfError() throws BBObjectNotFoundException {
163 expectedException.expect(BBObjectNotFoundException.class);
165 Customer customer = new Customer();
166 customer.setServiceSubscription(new ServiceSubscription());
167 ServiceInstance serviceInstance = new ServiceInstance();
168 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
169 gBBInput.setCustomer(customer);
170 extractPojos.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
174 public void vfModuleError() throws BBObjectNotFoundException {
175 expectedException.expect(BBObjectNotFoundException.class);
177 Customer customer = new Customer();
178 customer.setServiceSubscription(new ServiceSubscription());
179 ServiceInstance serviceInstance = new ServiceInstance();
180 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
181 gBBInput.setCustomer(customer);
182 extractPojos.extractByKey(execution, ResourceKey.VF_MODULE_ID);
186 public void configurationError() throws BBObjectNotFoundException {
187 expectedException.expect(BBObjectNotFoundException.class);
189 Customer customer = new Customer();
190 customer.setServiceSubscription(new ServiceSubscription());
191 ServiceInstance serviceInstance = new ServiceInstance();
192 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
193 gBBInput.setCustomer(customer);
194 extractPojos.extractByKey(execution, ResourceKey.CONFIGURATION_ID);
198 public void allotedError() throws BBObjectNotFoundException {
199 expectedException.expect(BBObjectNotFoundException.class);
201 Customer customer = new Customer();
202 customer.setServiceSubscription(new ServiceSubscription());
203 ServiceInstance serviceInstance = new ServiceInstance();
204 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
205 gBBInput.setCustomer(customer);
206 extractPojos.extractByKey(execution, ResourceKey.ALLOTTED_RESOURCE_ID);
210 public void vpnBindingError() throws BBObjectNotFoundException {
211 expectedException.expect(BBObjectNotFoundException.class);
212 Customer customer = new Customer();
213 customer.setServiceSubscription(new ServiceSubscription());
214 ServiceInstance serviceInstance = new ServiceInstance();
215 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
216 gBBInput.setCustomer(customer);
217 extractPojos.extractByKey(execution, ResourceKey.VPN_ID);
221 public void vpnBondingLinkError() throws BBObjectNotFoundException {
222 expectedException.expect(BBObjectNotFoundException.class);
223 Customer customer = new Customer();
224 customer.setServiceSubscription(new ServiceSubscription());
225 ServiceInstance serviceInstance = new ServiceInstance();
226 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
227 gBBInput.setCustomer(customer);
228 extractPojos.extractByKey(execution, ResourceKey.VPN_BONDING_LINK_ID);
232 public void getServiceInstanceWithNoCustomer() throws BBObjectNotFoundException {
233 ServiceInstance serviceInstancePend = new ServiceInstance();
234 serviceInstancePend.setServiceInstanceId("abc");
235 lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, serviceInstancePend.getServiceInstanceId());
236 Customer customer = new Customer();
237 gBBInput.setCustomer(customer);
238 gBBInput.setServiceInstance(serviceInstancePend);
239 ServiceInstance extractServPend = extractPojos.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
240 assertEquals(extractServPend.getServiceInstanceId(), serviceInstancePend.getServiceInstanceId());