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;
25 import java.util.HashMap;
26 import java.util.List;
28 import org.camunda.bpm.engine.impl.pvm.runtime.ExecutionImpl;
29 import org.junit.Before;
30 import org.junit.Rule;
31 import org.junit.Test;
32 import org.junit.rules.ExpectedException;
33 import org.onap.so.bpmn.common.BuildingBlockExecution;
34 import org.onap.so.bpmn.common.DelegateExecutionImpl;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.*;
36 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
37 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
38 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
39 import org.onap.so.client.exception.BBObjectNotFoundException;
40 import org.onap.so.BaseTest;
42 public class ExtractPojosForBBTest extends BaseTest{
43 ExtractPojosForBB extractPojos = new ExtractPojosForBB();
44 private BuildingBlockExecution execution;
45 private GeneralBuildingBlock gBBInput;
46 private HashMap<ResourceKey, String> lookupKeyMap;
49 public ExpectedException expectedException = ExpectedException.none();
52 public void before() {
53 execution = new DelegateExecutionImpl(new ExecutionImpl());
54 execution.setVariable("testProcessKey", "AAICreateTasksTests");
55 gBBInput = new GeneralBuildingBlock();
56 execution.setVariable("gBBInput", gBBInput);
57 lookupKeyMap = new HashMap<>();
58 execution.setVariable("lookupKeyMap", lookupKeyMap);
62 public void get() throws BBObjectNotFoundException {
63 ServiceInstance serviceInstancePend = new ServiceInstance();
64 serviceInstancePend.setServiceInstanceId("abc");
65 lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, serviceInstancePend.getServiceInstanceId());
67 VpnBondingLink vpnBondingLinkPend = new VpnBondingLink();
68 vpnBondingLinkPend.setVpnBondingLinkId("testVpnBondingLink");
69 serviceInstancePend.getVpnBondingLinks().add(vpnBondingLinkPend);
70 lookupKeyMap.put(ResourceKey.VPN_BONDING_LINK_ID, vpnBondingLinkPend.getVpnBondingLinkId());
72 Customer customer = new Customer();
73 customer.setServiceSubscription(new ServiceSubscription());
74 VpnBinding vpnBinding = new VpnBinding();
75 vpnBinding.setVpnId("abc");
76 customer.getVpnBindings().add(vpnBinding);
77 lookupKeyMap.put(ResourceKey.VPN_ID, vpnBinding.getVpnId());
79 List<GenericVnf> vnfsPend = serviceInstancePend.getVnfs();
80 GenericVnf vnfPend = new GenericVnf();
81 vnfPend.setVnfId("abc");
82 lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnfPend.getVnfId());
84 List<VfModule> vfModulesPend = vnfPend.getVfModules();
85 VfModule vfModulePend = new VfModule();
86 vfModulePend.setVfModuleId("abc");
87 vfModulesPend.add(vfModulePend);
88 vnfsPend.add(vnfPend);
89 lookupKeyMap.put(ResourceKey.VF_MODULE_ID, vfModulePend.getVfModuleId());
91 List<L3Network> networksPend = serviceInstancePend.getNetworks();
92 L3Network networkPend = new L3Network();
93 networkPend.setNetworkId("abc");
94 networksPend.add(networkPend);
95 lookupKeyMap.put(ResourceKey.NETWORK_ID, networkPend.getNetworkId());
97 List<VolumeGroup> volumeGroupsPend = serviceInstancePend.getVnfs().get(0).getVolumeGroups();
98 VolumeGroup volumeGroupPend = new VolumeGroup();
99 volumeGroupPend.setVolumeGroupId("abc");
100 volumeGroupsPend.add(volumeGroupPend);
101 lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, volumeGroupPend.getVolumeGroupId());
103 List<AllottedResource> allotedResourcesPend = serviceInstancePend.getAllottedResources();
104 AllottedResource allotedResourcePend = new AllottedResource();
105 allotedResourcePend.setId("abc");
106 allotedResourcesPend.add(allotedResourcePend);
107 lookupKeyMap.put(ResourceKey.ALLOTTED_RESOURCE_ID, allotedResourcePend.getId());
109 Configuration configurationPend = new Configuration();
110 configurationPend.setConfigurationId("abc");
111 serviceInstancePend.getConfigurations().add(configurationPend);
112 lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, configurationPend.getConfigurationId());
114 List<InstanceGroup> instanceGroupsPend = serviceInstancePend.getInstanceGroups();
115 InstanceGroup instanceGroupPend = new InstanceGroup();
116 instanceGroupPend.setId("test-instance-group-1");
117 instanceGroupsPend.add(instanceGroupPend);
118 lookupKeyMap.put(ResourceKey.INSTANCE_GROUP_ID, instanceGroupPend.getId());
120 customer.getServiceSubscription().getServiceInstances().add(serviceInstancePend);
121 gBBInput.setCustomer(customer);
123 ServiceInstance extractServPend = extractPojos.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
124 assertEquals(extractServPend.getServiceInstanceId(), serviceInstancePend.getServiceInstanceId());
125 GenericVnf extractVnfPend = extractPojos.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
126 assertEquals(extractVnfPend.getVnfId(), vnfPend.getVnfId());
127 L3Network extractNetworkPend = extractPojos.extractByKey(execution, ResourceKey.NETWORK_ID);
128 assertEquals(extractNetworkPend.getNetworkId(), networkPend.getNetworkId());
129 VolumeGroup extractVolumeGroupPend = extractPojos.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
130 assertEquals(extractVolumeGroupPend.getVolumeGroupId(), volumeGroupPend.getVolumeGroupId());
131 AllottedResource extractallotedResourcePend = extractPojos.extractByKey(execution,
132 ResourceKey.ALLOTTED_RESOURCE_ID);
133 assertEquals(extractallotedResourcePend.getId(), allotedResourcePend.getId());
134 Configuration extractConfigurationPend = extractPojos.extractByKey(execution, ResourceKey.CONFIGURATION_ID);
135 assertEquals(extractConfigurationPend.getConfigurationId(), configurationPend.getConfigurationId());
136 VpnBinding extractVpnBinding = extractPojos.extractByKey(execution, ResourceKey.VPN_ID);
137 assertEquals(extractVpnBinding.getVpnId(), vpnBinding.getVpnId());
139 VfModule extractVfModulePend = extractPojos.extractByKey(execution, ResourceKey.VF_MODULE_ID);
140 assertEquals(extractVfModulePend.getVfModuleId(), vfModulePend.getVfModuleId());
142 VpnBondingLink extractVpnBondingLinkPend = extractPojos.extractByKey(execution, ResourceKey.VPN_BONDING_LINK_ID);
143 assertEquals(extractVpnBondingLinkPend.getVpnBondingLinkId(), vpnBondingLinkPend.getVpnBondingLinkId());
145 InstanceGroup extractInstanceGroupPend = extractPojos.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID);
146 assertEquals(instanceGroupPend.getId(), extractInstanceGroupPend.getId());
150 public void siError() throws BBObjectNotFoundException {
151 expectedException.expect(BBObjectNotFoundException.class);
153 Customer customer = new Customer();
154 customer.setServiceSubscription(new ServiceSubscription());
155 ServiceInstance serviceInstance = new ServiceInstance();
156 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
157 gBBInput.setCustomer(customer);
159 extractPojos.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
163 public void vnfError() throws BBObjectNotFoundException {
164 expectedException.expect(BBObjectNotFoundException.class);
166 Customer customer = new Customer();
167 customer.setServiceSubscription(new ServiceSubscription());
168 ServiceInstance serviceInstance = new ServiceInstance();
169 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
170 gBBInput.setCustomer(customer);
171 extractPojos.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
175 public void vfModuleError() throws BBObjectNotFoundException {
176 expectedException.expect(BBObjectNotFoundException.class);
178 Customer customer = new Customer();
179 customer.setServiceSubscription(new ServiceSubscription());
180 ServiceInstance serviceInstance = new ServiceInstance();
181 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
182 gBBInput.setCustomer(customer);
183 extractPojos.extractByKey(execution, ResourceKey.VF_MODULE_ID);
187 public void configurationError() throws BBObjectNotFoundException {
188 expectedException.expect(BBObjectNotFoundException.class);
190 Customer customer = new Customer();
191 customer.setServiceSubscription(new ServiceSubscription());
192 ServiceInstance serviceInstance = new ServiceInstance();
193 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
194 gBBInput.setCustomer(customer);
195 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);
209 public void vpnBindingError() throws BBObjectNotFoundException {
210 expectedException.expect(BBObjectNotFoundException.class);
211 Customer customer = new Customer();
212 customer.setServiceSubscription(new ServiceSubscription());
213 ServiceInstance serviceInstance = new ServiceInstance();
214 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
215 gBBInput.setCustomer(customer);
216 extractPojos.extractByKey(execution, ResourceKey.VPN_ID);
220 public void vpnBondingLinkError() throws BBObjectNotFoundException {
221 expectedException.expect(BBObjectNotFoundException.class);
222 Customer customer = new Customer();
223 customer.setServiceSubscription(new ServiceSubscription());
224 ServiceInstance serviceInstance = new ServiceInstance();
225 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
226 gBBInput.setCustomer(customer);
227 extractPojos.extractByKey(execution, ResourceKey.VPN_BONDING_LINK_ID);