Update Logging
[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                 customer.getServiceSubscription().getServiceInstances().add(serviceInstancePend);
115                 gBBInput.setCustomer(customer);
116
117                 ServiceInstance extractServPend = extractPojos.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, "abc");
118                 assertEquals(extractServPend.getServiceInstanceId(), serviceInstancePend.getServiceInstanceId());
119                 GenericVnf extractVnfPend = extractPojos.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, "abc");
120                 assertEquals(extractVnfPend.getVnfId(), vnfPend.getVnfId());
121                 L3Network extractNetworkPend = extractPojos.extractByKey(execution, ResourceKey.NETWORK_ID, "abc");
122                 assertEquals(extractNetworkPend.getNetworkId(), networkPend.getNetworkId());
123                 VolumeGroup extractVolumeGroupPend = extractPojos.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, "abc");
124                 assertEquals(extractVolumeGroupPend.getVolumeGroupId(), volumeGroupPend.getVolumeGroupId());
125                 AllottedResource extractallotedResourcePend = extractPojos.extractByKey(execution,
126                                 ResourceKey.ALLOTTED_RESOURCE_ID, "abc");
127                 assertEquals(extractallotedResourcePend.getId(), allotedResourcePend.getId());
128                 Configuration extractConfigurationPend = extractPojos.extractByKey(execution, ResourceKey.CONFIGURATION_ID,
129                                 "abc");
130                 assertEquals(extractConfigurationPend.getConfigurationId(), configurationPend.getConfigurationId());
131                 VpnBinding extractVpnBinding = extractPojos.extractByKey(execution, ResourceKey.VPN_ID, "abc");
132                 assertEquals(extractVpnBinding.getVpnId(), vpnBinding.getVpnId());
133                 
134                 VfModule extractVfModulePend = extractPojos.extractByKey(execution, ResourceKey.VF_MODULE_ID, "abc");
135                 assertEquals(extractVfModulePend.getVfModuleId(), vfModulePend.getVfModuleId());
136
137                 VpnBondingLink extractVpnBondingLinkPend = extractPojos.extractByKey(execution, ResourceKey.VPN_BONDING_LINK_ID, "testVpnBondingLink");
138                 assertEquals(extractVpnBondingLinkPend.getVpnBondingLinkId(), vpnBondingLinkPend.getVpnBondingLinkId());
139         }
140
141         @Test
142         public void siError() throws BBObjectNotFoundException {
143                 expectedException.expect(BBObjectNotFoundException.class);
144
145                 Customer customer = new Customer();
146                 customer.setServiceSubscription(new ServiceSubscription());
147                 ServiceInstance serviceInstance = new ServiceInstance();
148                 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
149                 gBBInput.setCustomer(customer);
150
151                 extractPojos.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, "abc");
152         }
153
154         @Test
155         public void vnfError() throws BBObjectNotFoundException {
156                 expectedException.expect(BBObjectNotFoundException.class);
157
158                 Customer customer = new Customer();
159                 customer.setServiceSubscription(new ServiceSubscription());
160                 ServiceInstance serviceInstance = new ServiceInstance();
161                 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
162                 gBBInput.setCustomer(customer);
163                 extractPojos.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, "bbb");
164         }
165
166         @Test
167         public void vfModuleError() throws BBObjectNotFoundException {
168                 expectedException.expect(BBObjectNotFoundException.class);
169
170                 Customer customer = new Customer();
171                 customer.setServiceSubscription(new ServiceSubscription());
172                 ServiceInstance serviceInstance = new ServiceInstance();
173                 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
174                 gBBInput.setCustomer(customer);
175                 extractPojos.extractByKey(execution, ResourceKey.VF_MODULE_ID, "bbb");
176         }
177         
178         @Test
179         public void configurationError() throws BBObjectNotFoundException {
180                 expectedException.expect(BBObjectNotFoundException.class);
181
182                 Customer customer = new Customer();
183                 customer.setServiceSubscription(new ServiceSubscription());
184                 ServiceInstance serviceInstance = new ServiceInstance();
185                 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
186                 gBBInput.setCustomer(customer);
187                 extractPojos.extractByKey(execution, ResourceKey.CONFIGURATION_ID, "bbb");
188         }
189         @Test
190         public void allotedError() throws BBObjectNotFoundException {
191                 expectedException.expect(BBObjectNotFoundException.class);
192
193                 Customer customer = new Customer();
194                 customer.setServiceSubscription(new ServiceSubscription());
195                 ServiceInstance serviceInstance = new ServiceInstance();
196                 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
197                 gBBInput.setCustomer(customer);
198                 extractPojos.extractByKey(execution, ResourceKey.ALLOTTED_RESOURCE_ID, "bbb");
199         }
200         @Test
201         public void vpnBindingError() throws BBObjectNotFoundException {
202                 expectedException.expect(BBObjectNotFoundException.class);
203                 Customer customer = new Customer();
204                 customer.setServiceSubscription(new ServiceSubscription());
205                 ServiceInstance serviceInstance = new ServiceInstance();
206                 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
207                 gBBInput.setCustomer(customer);
208                 extractPojos.extractByKey(execution, ResourceKey.VPN_ID, "bbb");
209         }
210
211         @Test
212         public void vpnBondingLinkError() throws BBObjectNotFoundException {
213                 expectedException.expect(BBObjectNotFoundException.class);
214                 Customer customer = new Customer();
215                 customer.setServiceSubscription(new ServiceSubscription());
216                 ServiceInstance serviceInstance = new ServiceInstance();
217                 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
218                 gBBInput.setCustomer(customer);
219                 extractPojos.extractByKey(execution, ResourceKey.VPN_BONDING_LINK_ID, "bbb");
220         }
221 }