Change serviceInstance CM retrieval
[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 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;
39
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;
45
46     @Rule
47     public ExpectedException expectedException = ExpectedException.none();
48
49     @Before
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);
57     }
58
59     @Test
60     public void get() throws BBObjectNotFoundException {
61         ServiceInstance serviceInstancePend = new ServiceInstance();
62         serviceInstancePend.setServiceInstanceId("abc");
63         lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, serviceInstancePend.getServiceInstanceId());
64
65         VpnBondingLink vpnBondingLinkPend = new VpnBondingLink();
66         vpnBondingLinkPend.setVpnBondingLinkId("testVpnBondingLink");
67         serviceInstancePend.getVpnBondingLinks().add(vpnBondingLinkPend);
68         lookupKeyMap.put(ResourceKey.VPN_BONDING_LINK_ID, vpnBondingLinkPend.getVpnBondingLinkId());
69
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());
76
77         List<GenericVnf> vnfsPend = serviceInstancePend.getVnfs();
78         GenericVnf vnfPend = new GenericVnf();
79         vnfPend.setVnfId("abc");
80         lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnfPend.getVnfId());
81
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());
88
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());
94
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());
100
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());
106
107         Configuration configurationPend = new Configuration();
108         configurationPend.setConfigurationId("abc");
109         serviceInstancePend.getConfigurations().add(configurationPend);
110         lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, configurationPend.getConfigurationId());
111
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());
117
118         customer.getServiceSubscription().getServiceInstances().add(serviceInstancePend);
119         gBBInput.setCustomer(customer);
120
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());
136
137         VfModule extractVfModulePend = extractPojos.extractByKey(execution, ResourceKey.VF_MODULE_ID);
138         assertEquals(extractVfModulePend.getVfModuleId(), vfModulePend.getVfModuleId());
139
140         VpnBondingLink extractVpnBondingLinkPend =
141                 extractPojos.extractByKey(execution, ResourceKey.VPN_BONDING_LINK_ID);
142         assertEquals(extractVpnBondingLinkPend.getVpnBondingLinkId(), vpnBondingLinkPend.getVpnBondingLinkId());
143
144         InstanceGroup extractInstanceGroupPend = extractPojos.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID);
145         assertEquals(instanceGroupPend.getId(), extractInstanceGroupPend.getId());
146     }
147
148     @Test
149     public void siError() throws BBObjectNotFoundException {
150         expectedException.expect(BBObjectNotFoundException.class);
151
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);
157
158         extractPojos.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
159     }
160
161     @Test
162     public void vnfError() throws BBObjectNotFoundException {
163         expectedException.expect(BBObjectNotFoundException.class);
164
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);
171     }
172
173     @Test
174     public void vfModuleError() throws BBObjectNotFoundException {
175         expectedException.expect(BBObjectNotFoundException.class);
176
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);
183     }
184
185     @Test
186     public void configurationError() throws BBObjectNotFoundException {
187         expectedException.expect(BBObjectNotFoundException.class);
188
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);
195     }
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
209     @Test
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);
218     }
219
220     @Test
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);
229     }
230
231     @Test
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());
241     }
242 }