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