bed591500ad47158e3e29b33160bd878335715a2
[so.git] / bpmn / so-bpmn-building-blocks / src / test / java / org / onap / so / bpmn / buildingblock / SniroHomingV2Test.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 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.buildingblock;
22
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.post;
25 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
26 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertNotNull;
30 import static org.mockito.Matchers.isA;
31 import static org.mockito.Mockito.times;
32 import static org.mockito.Mockito.verify;
33
34 import java.io.IOException;
35 import java.util.ArrayList;
36 import java.util.List;
37
38 import org.camunda.bpm.engine.delegate.BpmnError;
39 import org.json.JSONArray;
40 import org.json.JSONObject;
41 import org.junit.Before;
42 import org.junit.Test;
43 import org.mockito.ArgumentCaptor;
44 import org.onap.so.BaseTest;
45 import org.onap.so.bpmn.mock.FileUtil;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
50 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy;
51 import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBondingLink;
52 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
53 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters;
54 import org.onap.so.bpmn.servicedecomposition.homingobjects.Candidate;
55 import org.onap.so.bpmn.servicedecomposition.homingobjects.CandidateType;
56 import org.onap.so.client.exception.BadResponseException;
57 import org.onap.so.client.sniro.beans.SniroManagerRequest;
58
59 import com.fasterxml.jackson.core.JsonProcessingException;
60 import com.fasterxml.jackson.databind.ObjectMapper;
61
62
63 public class SniroHomingV2Test extends BaseTest{
64
65         private ServiceInstance serviceInstance;
66
67         private RequestContext requestContext;
68
69         private Customer customer;
70         ObjectMapper mapper = new ObjectMapper();
71
72         private static final String RESOURCE_PATH = "__files/BuildingBlocks/SniroHoming/";
73
74
75     String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}";
76
77         @Before
78         public void before() {
79                 serviceInstance = setServiceInstance();
80                 customer = setCustomer();
81                 customer.setGlobalCustomerId("testCustomerId");
82                 customer.setSubscriberName("testCustomerName");
83                 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
84
85                 requestContext = setRequestContext();
86                 requestContext.setMsoRequestId("testRequestId");
87                 RequestParameters params = new RequestParameters();
88                 params.setaLaCarte(false);
89                 params.setSubscriptionServiceType("iptollfree");
90                 requestContext.setRequestParameters(params);
91         }
92
93         public void beforeVpnBondingLink(String id){
94                 VpnBondingLink bondingLink = new VpnBondingLink();
95                 bondingLink.setVpnBondingLinkId("testVpnBondingId" + id);
96                 bondingLink.getServiceProxies().add(setServiceProxy("1", "transport"));
97                 ServiceProxy sp2 = setServiceProxy("2", "infrastructure");
98                 Candidate requiredCandidate = new Candidate();
99                 requiredCandidate.setCandidateType(CandidateType.VNF_ID);
100                 List<String> c = new ArrayList<String>();
101                 c.add("testVnfId");
102                 requiredCandidate.setCandidates(c);
103                 sp2.addRequiredCandidates(requiredCandidate);
104                 bondingLink.getServiceProxies().add(sp2);
105                 serviceInstance.getVpnBondingLinks().add(bondingLink);
106
107         }
108
109         public void beforeAllottedResource(){
110                 serviceInstance.getAllottedResources().add(setAllottedResource("1"));
111                 serviceInstance.getAllottedResources().add(setAllottedResource("2"));
112                 serviceInstance.getAllottedResources().add(setAllottedResource("3"));
113         }
114
115         public void beforeVnf(){
116                 setGenericVnf();
117         }
118
119     @Test(expected = Test.None.class)
120         public void testCallSniro_success_1VpnLink() throws BadResponseException, IOException{
121         beforeVpnBondingLink("1");
122
123         stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
124                         .willReturn(aResponse().withStatus(200)
125                 .withHeader("Content-Type", "application/json")
126                 .withBody(mockResponse)));
127
128                 sniroHoming.callSniro(execution);
129
130                 String request = FileUtil.readResourceFile(RESOURCE_PATH + "SniroManagerRequest1Vpn.json");
131                 request = request.replace("28080", wireMockPort);
132
133                 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
134                 verify(sniroClient, times(1)).postDemands(argument.capture());
135                 assertEquals(request, argument.getValue().toJsonString());
136         }
137
138         @Test
139         public void testCallSniro_success_3VpnLink() throws JsonProcessingException, BadResponseException{
140         beforeVpnBondingLink("1");
141         beforeVpnBondingLink("2");
142         beforeVpnBondingLink("3");
143
144         stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
145                         .willReturn(aResponse().withStatus(200)
146                 .withHeader("Content-Type", "application/json")
147                 .withBody(mockResponse)));
148
149                 sniroHoming.callSniro(execution);
150
151                 String request = FileUtil.readResourceFile(RESOURCE_PATH + "SniroManagerRequest3Vpn.json");
152                 request = request.replace("28080", wireMockPort);
153
154                 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
155                 verify(sniroClient, times(1)).postDemands(argument.capture());
156                 assertEquals(request, argument.getValue().toJsonString());
157         }
158
159         @Test
160         public void testCallSniro_success_3Allotteds() throws BadResponseException, JsonProcessingException{
161                 beforeAllottedResource();
162
163         stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
164                         .willReturn(aResponse().withStatus(200)
165                 .withHeader("Content-Type", "application/json")
166                 .withBody(mockResponse)));
167
168                 sniroHoming.callSniro(execution);
169
170                 String request = FileUtil.readResourceFile(RESOURCE_PATH + "SniroManagerRequest3AR.json");
171                 request = request.replace("28080", wireMockPort);
172
173                 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
174                 verify(sniroClient, times(1)).postDemands(argument.capture());
175                 assertEquals(request, argument.getValue().toJsonString());
176         }
177
178         @Test
179         public void testCallSniro_success_1Vnf() throws JsonProcessingException, BadResponseException{
180                 beforeVnf();
181
182         stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
183                         .willReturn(aResponse().withStatus(200)
184                 .withHeader("Content-Type", "application/json")
185                 .withBody(mockResponse)));
186
187                 sniroHoming.callSniro(execution);
188
189                 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
190                 verify(sniroClient, times(1)).postDemands(argument.capture());
191                 //TODO assertEquals(request, argument.getValue().toJsonString());
192         }
193
194         @Test
195         public void testCallSniro_success_3Allotteds1Vnf() throws JsonProcessingException, BadResponseException{
196                 beforeAllottedResource();
197                 beforeVnf();
198
199         stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
200                         .willReturn(aResponse().withStatus(200)
201                 .withHeader("Content-Type", "application/json")
202                 .withBody(mockResponse)));
203
204                 sniroHoming.callSniro(execution);
205
206                 verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class));
207         }
208
209         @Test(expected = Test.None.class)
210         public void testProcessSolution_success_1VpnLink_1Solution(){
211         beforeVpnBondingLink("1");
212
213                 JSONObject asyncResponse = new JSONObject();
214                 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
215                 JSONArray solution1 = new JSONArray();
216                 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("inventoryType", "service").put("solution", new JSONObject()
217                                 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
218                                 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
219                                                 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
220                                                 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
221                                                 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1"))));
222                 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("inventoryType", "service").put("solution", new JSONObject()
223                                 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
224                                 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
225                                                 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2"))
226                                                 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
227                                                 .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName2")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2"))));
228
229                 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", new JSONArray()));
230
231                 sniroHoming.processSolution(execution, asyncResponse.toString());
232
233                 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
234
235                 assertFalse(si.getVpnBondingLinks().isEmpty());
236                 VpnBondingLink link = si.getVpnBondingLinks().get(0);
237                 assertNotNull(link);
238                 assertFalse(link.getServiceProxies().isEmpty());
239
240                 assertEquals("testServiceInstanceId1", link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
241                 assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
242                 assertEquals("testVnfHostName1", link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
243
244                 assertEquals("testServiceInstanceId2", link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
245                 assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
246                 assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
247                 assertEquals("testPrimaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
248                 assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
249                 assertEquals("testSecondaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
250                 assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
251         }
252
253         @Test
254         public void testProcessSolution_success_1VpnLink_2Solutions(){
255         beforeVpnBondingLink("1");
256
257                 JSONObject asyncResponse = new JSONObject();
258                 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
259                 JSONArray solution1 = new JSONArray();
260                 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("inventoryType", "service").put("solution", new JSONObject()
261                                 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
262                                 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
263                                                 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
264                                                 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
265                                                 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1"))));
266                 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("inventoryType", "service").put("solution", new JSONObject()
267                                 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
268                                 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
269                                                 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2"))
270                                                 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
271                                                 .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName2")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2"))));
272
273                 JSONArray solution2 = new JSONArray();
274                 solution2.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("inventoryType", "service").put("solution", new JSONObject()
275                                 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId3")))
276                                 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
277                                                 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName3"))
278                                                 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli3")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
279                                                 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId3")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId3"))));
280                 solution2.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("inventoryType", "service").put("solution", new JSONObject()
281                                 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId4")))
282                                 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
283                                                 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName4"))
284                                                 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli4")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
285                                                 .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName4")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId4"))));
286
287                 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1).put(solution2)).put("licenseSolutions", new JSONArray()));
288
289                 sniroHoming.processSolution(execution, asyncResponse.toString());
290
291                 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
292
293                 assertFalse(si.getVpnBondingLinks().isEmpty());
294                 VpnBondingLink link = si.getVpnBondingLinks().get(0);
295                 VpnBondingLink link2 = si.getVpnBondingLinks().get(1);
296                 assertNotNull(link);
297                 assertFalse(link.getServiceProxies().isEmpty());
298
299                 assertEquals("testServiceInstanceId1", link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
300                 assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
301                 assertEquals("testVnfHostName1", link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
302
303                 assertEquals("testServiceInstanceId2", link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
304                 assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
305                 assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
306                 assertEquals("testPrimaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
307                 assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
308                 assertEquals("testSecondaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
309                 assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
310
311                 assertNotNull(link2);
312                 assertFalse(link2.getServiceProxies().isEmpty());
313
314                 assertEquals("testServiceInstanceId3", link2.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
315                 assertNotNull(link2.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
316                 assertEquals("testVnfHostName3", link2.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
317
318                 assertEquals("testServiceInstanceId4", link2.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
319                 assertNotNull(link2.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
320                 assertFalse(link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
321                 assertEquals("testPrimaryPnfName4", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
322                 assertEquals("primary", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
323                 assertEquals("testSecondaryPnfName4", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
324                 assertEquals("secondary", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
325
326         }
327
328         @Test
329         public void testProcessSolution_success_3VpnLink_2Solutions(){
330                 //TODO
331         }
332
333         @Test
334         public void testProcessSolution_success_3Allotteds_1Solution(){
335                 beforeAllottedResource();
336
337                 JSONObject asyncResponse = new JSONObject();
338                 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
339                 JSONArray solution1 = new JSONArray();
340                 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1").put("inventoryType", "service").put("solution", new JSONObject()
341                                 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
342                                 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
343                                                 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
344                                                 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
345                                                 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1"))));
346                 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2").put("inventoryType", "service").put("solution", new JSONObject()
347                                 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
348                                 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
349                                                 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2"))
350                                                 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
351                                                 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2"))));
352                 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3").put("inventoryType", "cloud").put("solution", new JSONObject()
353                                 .put("identifierType", "cloudRegionId").put("identifiers", new JSONArray().put("testCloudRegionId3")))
354                                 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
355                                                 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
356                                                 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))));
357
358                 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", new JSONArray()));
359
360                 sniroHoming.processSolution(execution, asyncResponse.toString());
361
362                 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
363
364                 assertFalse(si.getAllottedResources().isEmpty());
365                 AllottedResource ar = si.getAllottedResources().get(0);
366                 assertNotNull(ar);
367                 assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId());
368                 assertNotNull(ar.getParentServiceInstance().getSolutionInfo());
369                 assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName());
370
371                 AllottedResource ar2 = si.getAllottedResources().get(1);
372                 assertNotNull(ar2);
373                 assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId());
374                 assertNotNull(ar2.getParentServiceInstance().getSolutionInfo());
375                 assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName());
376
377                 AllottedResource ar3 = si.getAllottedResources().get(2);
378                 assertNotNull(ar3);
379                 assertNotNull(ar3.getParentServiceInstance().getSolutionInfo());
380                 assertEquals("testCloudRegionId3", ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId());
381         }
382
383         @Test
384         public void testProcessSolution_success_3Allotteds1Vnf_1Solution(){
385                 beforeVnf();
386                 beforeAllottedResource();
387
388                 JSONObject asyncResponse = new JSONObject();
389                 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
390                 JSONArray solution1 = new JSONArray();
391                 JSONArray licenseSolution = new JSONArray();
392                 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1").put("inventoryType", "service").put("solution", new JSONObject()
393                                 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
394                                 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
395                                                 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
396                                                 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
397                                                 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1"))));
398                 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2").put("inventoryType", "service").put("solution", new JSONObject()
399                                 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
400                                 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
401                                                 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2"))
402                                                 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
403                                                 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2"))));
404                 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3").put("inventoryType", "cloud").put("solution", new JSONObject()
405                                 .put("identifierType", "cloudRegionId").put("identifiers", new JSONArray().put("testCloudRegionId3")))
406                                 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
407                                                 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
408                                                 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))));
409
410                 licenseSolution.put(
411                                 new JSONObject().put("serviceResourceId", "testVnfId1").put("entitlementPoolUUID", new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e").put("j1d563e8-e714-4393-8f99-cc480144a05e"))
412                                                 .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e").put("b1d563e8-e714-4393-8f99-cc480144a05e")));
413
414                 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", licenseSolution));
415
416                 sniroHoming.processSolution(execution, asyncResponse.toString());
417
418                 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
419
420                 assertFalse(si.getAllottedResources().isEmpty());
421                 AllottedResource ar = si.getAllottedResources().get(0);
422                 assertNotNull(ar);
423                 assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId());
424                 assertNotNull(ar.getParentServiceInstance().getSolutionInfo());
425                 assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName());
426
427                 AllottedResource ar2 = si.getAllottedResources().get(1);
428                 assertNotNull(ar2);
429                 assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId());
430                 assertNotNull(ar2.getParentServiceInstance().getSolutionInfo());
431                 assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName());
432
433                 AllottedResource ar3 = si.getAllottedResources().get(2);
434                 assertNotNull(ar3);
435                 assertNotNull(ar3.getParentServiceInstance().getSolutionInfo());
436                 assertEquals("testCloudRegionId3", ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId());
437
438                 GenericVnf vnf = si.getVnfs().get(0);
439                 assertNotNull(vnf);
440                 assertNotNull(vnf.getLicense());
441                 assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size());
442                 assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0));
443
444         }
445
446         @Test
447         public void testProcessSolution_success_1Vnf_1Solution(){
448                 beforeVnf();
449
450                 JSONObject asyncResponse = new JSONObject();
451                 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
452                 JSONArray licenseSolution = new JSONArray();
453
454                 licenseSolution.put(
455                                 new JSONObject().put("serviceResourceId", "testVnfId1").put("entitlementPoolUUID", new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e").put("j1d563e8-e714-4393-8f99-cc480144a05e"))
456                                                 .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e").put("b1d563e8-e714-4393-8f99-cc480144a05e")));
457
458                 asyncResponse.put("solutions", new JSONObject().put("licenseSolutions", licenseSolution));
459
460                 sniroHoming.processSolution(execution, asyncResponse.toString());
461
462                 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
463
464                 GenericVnf vnf = si.getVnfs().get(0);
465                 assertNotNull(vnf);
466                 assertNotNull(vnf.getLicense());
467                 assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size());
468                 assertEquals(2, vnf.getLicense().getLicenseKeyGroupUuids().size());
469                 assertEquals("f1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getEntitlementPoolUuids().get(0));
470                 assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0));
471
472
473         }
474
475         @Test(expected = BpmnError.class)
476         public void testCallSniro_error_0Resources() throws BadResponseException, JsonProcessingException{
477
478                 sniroHoming.callSniro(execution);
479
480                 verify(sniroClient, times(0)).postDemands(isA(SniroManagerRequest.class));
481         }
482
483         @Test(expected = BpmnError.class)
484         public void testCallSniro_error_badResponse() throws BadResponseException, JsonProcessingException{
485                 beforeAllottedResource();
486
487                 mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}";
488                 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
489                                 .willReturn(aResponse().withStatus(200)
490                                                 .withHeader("Content-Type", "application/json")
491                                                 .withBody(mockResponse)));
492
493                 sniroHoming.callSniro(execution);
494
495                 verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class));
496         }
497
498 }