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