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