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