2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
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;
57 public class SniroHomingV2IT extends BaseIntegrationTest {
59 private ServiceInstance serviceInstance;
61 private RequestContext requestContext;
63 private Customer customer;
64 ObjectMapper mapper = new ObjectMapper();
66 private static final String RESOURCE_PATH = "__files/BuildingBlocks/SniroHoming/";
70 "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}";
73 public void before() {
74 serviceInstance = setServiceInstance();
75 customer = setCustomer();
76 customer.setGlobalCustomerId("testCustomerId");
77 customer.setSubscriberName("testCustomerName");
78 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
80 requestContext = setRequestContext();
81 requestContext.setMsoRequestId("testRequestId");
82 RequestParameters params = new RequestParameters();
83 params.setaLaCarte(false);
84 params.setSubscriptionServiceType("testSubscriptionServiceType");
85 requestContext.setRequestParameters(params);
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>();
97 requiredCandidate.setIdentifiers(c);
98 sp2.addRequiredCandidates(requiredCandidate);
99 bondingLink.getServiceProxies().add(sp2);
100 serviceInstance.getVpnBondingLinks().add(bondingLink);
104 public void beforeAllottedResource() {
105 serviceInstance.getAllottedResources().add(setAllottedResource("1"));
106 serviceInstance.getAllottedResources().add(setAllottedResource("2"));
107 serviceInstance.getAllottedResources().add(setAllottedResource("3"));
110 public void beforeVnf() {
114 @Test(expected = Test.None.class)
115 public void testCallSniro_success_1VpnLink() throws BadResponseException, IOException {
116 beforeVpnBondingLink("1");
118 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
119 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
121 sniroHoming.callSniro(execution);
123 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest1Vpn.json");
124 request = request.replace("28080", wireMockPort);
126 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
127 verify(sniroClient, times(1)).postDemands(argument.capture());
128 assertEquals(request, argument.getValue().toJsonString());
132 public void testCallSniro_success_3VpnLink() throws JsonProcessingException, BadResponseException {
133 beforeVpnBondingLink("1");
134 beforeVpnBondingLink("2");
135 beforeVpnBondingLink("3");
137 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
138 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
140 sniroHoming.callSniro(execution);
142 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest3Vpn.json");
143 request = request.replace("28080", wireMockPort);
145 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
146 verify(sniroClient, times(1)).postDemands(argument.capture());
147 assertEquals(request, argument.getValue().toJsonString());
151 public void testCallSniro_success_3Allotteds() throws BadResponseException, JsonProcessingException {
152 beforeAllottedResource();
154 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
155 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
157 sniroHoming.callSniro(execution);
159 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest3AR.json");
160 request = request.replace("28080", wireMockPort);
162 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
163 verify(sniroClient, times(1)).postDemands(argument.capture());
164 assertEquals(request, argument.getValue().toJsonString());
168 public void testCallSniro_success_1Vnf() throws JsonProcessingException, BadResponseException {
171 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
172 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
174 sniroHoming.callSniro(execution);
176 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
177 verify(sniroClient, times(1)).postDemands(argument.capture());
178 // TODO assertEquals(request, argument.getValue().toJsonString());
182 public void testCallSniro_success_3Allotteds1Vnf() throws JsonProcessingException, BadResponseException {
183 beforeAllottedResource();
186 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
187 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
189 sniroHoming.callSniro(execution);
191 verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class));
194 @Test(expected = Test.None.class)
195 public void testProcessSolution_success_1VpnLink_1Solution() {
196 beforeVpnBondingLink("1");
198 JSONObject asyncResponse = new JSONObject();
199 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
201 JSONArray solution1 = new JSONArray();
202 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1")
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")
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"))));
228 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1))
229 .put("licenseSolutions", new JSONArray()));
231 sniroHoming.processSolution(execution, asyncResponse.toString());
234 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
236 assertFalse(si.getVpnBondingLinks().isEmpty());
237 VpnBondingLink link = si.getVpnBondingLinks().get(0);
239 assertFalse(link.getServiceProxies().isEmpty());
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());
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());
260 public void testProcessSolution_success_1VpnLink_2Solutions() {
261 beforeVpnBondingLink("1");
263 JSONObject asyncResponse = new JSONObject();
264 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
266 JSONArray solution1 = new JSONArray();
267 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1")
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")
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"))));
293 JSONArray solution2 = new JSONArray();
294 solution2.put(new JSONObject().put("serviceResourceId", "testProxyId1")
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")
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"))));
320 asyncResponse.put("solutions",
321 new JSONObject().put("placementSolutions", new JSONArray().put(solution1).put(solution2))
322 .put("licenseSolutions", new JSONArray()));
324 sniroHoming.processSolution(execution, asyncResponse.toString());
327 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
329 assertFalse(si.getVpnBondingLinks().isEmpty());
330 VpnBondingLink link = si.getVpnBondingLinks().get(0);
331 VpnBondingLink link2 = si.getVpnBondingLinks().get(1);
333 assertFalse(link.getServiceProxies().isEmpty());
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());
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());
352 assertNotNull(link2);
353 assertFalse(link2.getServiceProxies().isEmpty());
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());
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());
376 public void testProcessSolution_success_3VpnLink_2Solutions() {
381 public void testProcessSolution_success_3Allotteds_1Solution() {
382 beforeAllottedResource();
384 JSONObject asyncResponse = new JSONObject();
385 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
387 JSONArray solution1 = new JSONArray();
388 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1")
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")
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")
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"))));
422 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1))
423 .put("licenseSolutions", new JSONArray()));
425 sniroHoming.processSolution(execution, asyncResponse.toString());
428 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
430 assertFalse(si.getAllottedResources().isEmpty());
431 AllottedResource ar = si.getAllottedResources().get(0);
433 assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId());
434 assertNotNull(ar.getParentServiceInstance().getSolutionInfo());
435 assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName());
437 AllottedResource ar2 = si.getAllottedResources().get(1);
439 assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId());
440 assertNotNull(ar2.getParentServiceInstance().getSolutionInfo());
441 assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName());
443 AllottedResource ar3 = si.getAllottedResources().get(2);
445 assertNotNull(ar3.getParentServiceInstance().getSolutionInfo());
446 assertEquals("testCloudRegionId3",
447 ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId());
451 public void testProcessSolution_success_3Allotteds1Vnf_1Solution() {
453 beforeAllottedResource();
455 JSONObject asyncResponse = new JSONObject();
456 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
458 JSONArray solution1 = new JSONArray();
459 JSONArray licenseSolution = new JSONArray();
460 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1")
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")
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")
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"))));
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")));
501 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1))
502 .put("licenseSolutions", licenseSolution));
504 sniroHoming.processSolution(execution, asyncResponse.toString());
507 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
509 assertFalse(si.getAllottedResources().isEmpty());
510 AllottedResource ar = si.getAllottedResources().get(0);
512 assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId());
513 assertNotNull(ar.getParentServiceInstance().getSolutionInfo());
514 assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName());
516 AllottedResource ar2 = si.getAllottedResources().get(1);
518 assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId());
519 assertNotNull(ar2.getParentServiceInstance().getSolutionInfo());
520 assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName());
522 AllottedResource ar3 = si.getAllottedResources().get(2);
524 assertNotNull(ar3.getParentServiceInstance().getSolutionInfo());
525 assertEquals("testCloudRegionId3",
526 ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId());
528 GenericVnf vnf = si.getVnfs().get(0);
530 assertNotNull(vnf.getLicense());
531 assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size());
532 assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0));
537 public void testProcessSolution_success_1Vnf_1Solution() {
540 JSONObject asyncResponse = new JSONObject();
541 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
543 JSONArray licenseSolution = new JSONArray();
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")));
552 asyncResponse.put("solutions", new JSONObject().put("licenseSolutions", licenseSolution));
554 sniroHoming.processSolution(execution, asyncResponse.toString());
557 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
559 GenericVnf vnf = si.getVnfs().get(0);
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));
570 @Test(expected = BpmnError.class)
571 public void testCallSniro_error_0Resources() throws BadResponseException, JsonProcessingException {
573 sniroHoming.callSniro(execution);
575 verify(sniroClient, times(0)).postDemands(isA(SniroManagerRequest.class));
578 @Test(expected = BpmnError.class)
579 public void testCallSniro_error_badResponse() throws BadResponseException, JsonProcessingException {
580 beforeAllottedResource();
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)));
587 sniroHoming.callSniro(execution);
589 verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class));