5de0903d6524f6064cf4ee0bbd8cda6acf7c059e
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / onap / so / bpmn / servicedecomposition / ExtractPojosForBBTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.bpmn.servicedecomposition;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.util.HashMap;
26 import java.util.List;
27
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;
41
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;
47         
48         @Rule
49         public ExpectedException expectedException = ExpectedException.none();
50         
51         @Before
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);
59         }
60         
61         @Test
62         public void get() throws BBObjectNotFoundException {
63                 ServiceInstance serviceInstancePend = new ServiceInstance();
64                 serviceInstancePend.setServiceInstanceId("abc");
65                 lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, serviceInstancePend.getServiceInstanceId());
66
67                 VpnBondingLink vpnBondingLinkPend = new VpnBondingLink();
68                 vpnBondingLinkPend.setVpnBondingLinkId("testVpnBondingLink");
69                 serviceInstancePend.getVpnBondingLinks().add(vpnBondingLinkPend);
70                 lookupKeyMap.put(ResourceKey.VPN_BONDING_LINK_ID, vpnBondingLinkPend.getVpnBondingLinkId());
71
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());
78
79                 List<GenericVnf> vnfsPend = serviceInstancePend.getVnfs();
80                 GenericVnf vnfPend = new GenericVnf();
81                 vnfPend.setVnfId("abc");
82                 lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnfPend.getVnfId());
83
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());
90
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());
96
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());
102
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());
108                 
109                 Configuration configurationPend = new Configuration();
110                 configurationPend.setConfigurationId("abc");
111                 serviceInstancePend.getConfigurations().add(configurationPend);
112                 lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, configurationPend.getConfigurationId());
113
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());
119                                 
120                 customer.getServiceSubscription().getServiceInstances().add(serviceInstancePend);
121                 gBBInput.setCustomer(customer);
122
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());
138                 
139                 VfModule extractVfModulePend = extractPojos.extractByKey(execution, ResourceKey.VF_MODULE_ID);
140                 assertEquals(extractVfModulePend.getVfModuleId(), vfModulePend.getVfModuleId());
141
142                 VpnBondingLink extractVpnBondingLinkPend = extractPojos.extractByKey(execution, ResourceKey.VPN_BONDING_LINK_ID);
143                 assertEquals(extractVpnBondingLinkPend.getVpnBondingLinkId(), vpnBondingLinkPend.getVpnBondingLinkId());
144                 
145                 InstanceGroup extractInstanceGroupPend = extractPojos.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID);
146                 assertEquals(instanceGroupPend.getId(), extractInstanceGroupPend.getId());
147         }
148
149         @Test
150         public void siError() throws BBObjectNotFoundException {
151                 expectedException.expect(BBObjectNotFoundException.class);
152
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);
158
159                 extractPojos.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
160         }
161
162         @Test
163         public void vnfError() throws BBObjectNotFoundException {
164                 expectedException.expect(BBObjectNotFoundException.class);
165
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);
172         }
173
174         @Test
175         public void vfModuleError() throws BBObjectNotFoundException {
176                 expectedException.expect(BBObjectNotFoundException.class);
177
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);
184         }
185         
186         @Test
187         public void configurationError() throws BBObjectNotFoundException {
188                 expectedException.expect(BBObjectNotFoundException.class);
189
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);
196         }
197         @Test
198         public void allotedError() throws BBObjectNotFoundException {
199                 expectedException.expect(BBObjectNotFoundException.class);
200
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);
207         }
208         @Test
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);
217         }
218
219         @Test
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);
228         }
229 }