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.*;
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 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
58 public class SniroHomingV2IT extends BaseIntegrationTest {
60 private ServiceInstance serviceInstance;
62 private RequestContext requestContext;
64 private Customer customer;
65 ObjectMapper mapper = new ObjectMapper();
67 private static final String RESOURCE_PATH = "__files/BuildingBlocks/SniroHoming/";
71 "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}";
74 public void before() {
75 serviceInstance = setServiceInstance();
76 customer = setCustomer();
77 customer.setGlobalCustomerId("testCustomerId");
78 customer.setSubscriberName("testCustomerName");
79 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
81 requestContext = setRequestContext();
82 requestContext.setMsoRequestId("testRequestId");
83 RequestParameters params = new RequestParameters();
84 params.setaLaCarte(false);
85 params.setSubscriptionServiceType("testSubscriptionServiceType");
86 requestContext.setRequestParameters(params);
89 public void beforeVpnBondingLink(String id) {
90 VpnBondingLink bondingLink = new VpnBondingLink();
91 bondingLink.setVpnBondingLinkId("testVpnBondingId" + id);
92 bondingLink.getServiceProxies().add(setServiceProxy("1", "transport"));
93 ServiceProxy sp2 = setServiceProxy("2", "infrastructure");
94 Candidate requiredCandidate = new Candidate();
95 requiredCandidate.setIdentifierType(CandidateType.VNF_ID);
96 List<String> c = new ArrayList<String>();
98 requiredCandidate.setIdentifiers(c);
99 sp2.addRequiredCandidates(requiredCandidate);
100 bondingLink.getServiceProxies().add(sp2);
101 serviceInstance.getVpnBondingLinks().add(bondingLink);
105 public void beforeAllottedResource() {
106 serviceInstance.getAllottedResources().add(setAllottedResource("1"));
107 serviceInstance.getAllottedResources().add(setAllottedResource("2"));
108 serviceInstance.getAllottedResources().add(setAllottedResource("3"));
111 public void beforeServiceProxy() {
112 ServiceProxy sp = setServiceProxy("1", "infrastructure");
113 Candidate requiredCandidate = new Candidate();
114 requiredCandidate.setIdentifierType(CandidateType.CLOUD_REGION_ID);
115 List<String> c = new ArrayList<String>();
116 c.add("testCloudRegionId");
117 requiredCandidate.setCloudOwner("att");
118 requiredCandidate.setIdentifiers(c);
119 sp.addRequiredCandidates(requiredCandidate);
120 serviceInstance.getServiceProxies().add(sp);
123 public void beforeVnf() {
127 @Test(expected = Test.None.class)
128 public void testCallSniro_success_1VpnLink() throws BadResponseException, IOException {
129 beforeVpnBondingLink("1");
131 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
132 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
134 sniroHoming.callSniro(execution);
136 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest1Vpn.json");
137 request = request.replace("28080", wireMockPort);
139 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
140 verify(sniroClient, times(1)).postDemands(argument.capture());
141 assertEquals(request, argument.getValue().toJsonString());
145 public void testCallSniro_success_3VpnLink() throws JsonProcessingException, BadResponseException {
146 beforeVpnBondingLink("1");
147 beforeVpnBondingLink("2");
148 beforeVpnBondingLink("3");
150 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
151 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
153 sniroHoming.callSniro(execution);
155 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest3Vpn.json");
156 request = request.replace("28080", wireMockPort);
158 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
159 verify(sniroClient, times(1)).postDemands(argument.capture());
160 assertEquals(request, argument.getValue().toJsonString());
164 public void testCallSniro_success_3Allotteds() throws BadResponseException, JsonProcessingException {
165 beforeAllottedResource();
167 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
168 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
170 sniroHoming.callSniro(execution);
172 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest3AR.json");
173 request = request.replace("28080", wireMockPort);
175 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
176 verify(sniroClient, times(1)).postDemands(argument.capture());
177 assertEquals(request, argument.getValue().toJsonString());
181 public void testCallSniro_success_1Vnf() throws JsonProcessingException, BadResponseException {
184 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
185 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
187 sniroHoming.callSniro(execution);
189 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
190 verify(sniroClient, times(1)).postDemands(argument.capture());
191 // TODO assertEquals(request, argument.getValue().toJsonString());
195 public void testCallSniro_success_3Allotteds1Vnf() throws JsonProcessingException, BadResponseException {
196 beforeAllottedResource();
199 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
200 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
202 sniroHoming.callSniro(execution);
204 verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class));
208 public void testCallSniro_success_1ServiceProxy() throws JsonProcessingException, BadResponseException {
209 beforeServiceProxy();
211 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
212 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
214 sniroHoming.callSniro(execution);
216 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest1SP.json");
217 request = request.replace("28080", wireMockPort);
219 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
220 verify(sniroClient, times(1)).postDemands(argument.capture());
221 assertEquals(request, argument.getValue().toJsonString());
224 @Test(expected = Test.None.class)
225 public void testProcessSolution_success_1VpnLink_1Solution() {
226 beforeVpnBondingLink("1");
228 JSONObject asyncResponse = new JSONObject();
229 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
231 JSONArray solution1 = new JSONArray();
232 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1")
234 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
235 new JSONArray().put("testServiceInstanceId1")))
236 .put("assignmentInfo",
237 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
238 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
239 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
240 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1"))
241 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
242 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1"))
243 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1"))));
244 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2")
246 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
247 new JSONArray().put("testServiceInstanceId2")))
248 .put("assignmentInfo",
249 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
250 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
251 .put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2"))
252 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
253 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
254 .put(new JSONObject().put("key", "secondaryPnfName").put("value",
255 "testSecondaryPnfName2"))
256 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2"))));
258 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1))
259 .put("licenseSolutions", new JSONArray()));
261 sniroHoming.processSolution(execution, asyncResponse.toString());
264 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
266 assertFalse(si.getVpnBondingLinks().isEmpty());
267 VpnBondingLink link = si.getVpnBondingLinks().get(0);
269 assertFalse(link.getServiceProxies().isEmpty());
271 assertEquals("testServiceInstanceId1",
272 link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
273 assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
274 assertEquals("testVnfHostName1",
275 link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
277 assertEquals("testServiceInstanceId2",
278 link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
279 assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
280 assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
281 assertEquals("testPrimaryPnfName2",
282 link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
283 assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
284 assertEquals("testSecondaryPnfName2",
285 link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
286 assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
290 public void testProcessSolution_success_1VpnLink_2Solutions() {
291 beforeVpnBondingLink("1");
293 JSONObject asyncResponse = new JSONObject();
294 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
296 JSONArray solution1 = new JSONArray();
297 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1")
299 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
300 new JSONArray().put("testServiceInstanceId1")))
301 .put("assignmentInfo",
302 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
303 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
304 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
305 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1"))
306 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
307 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1"))
308 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1"))));
309 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2")
311 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
312 new JSONArray().put("testServiceInstanceId2")))
313 .put("assignmentInfo",
314 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
315 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
316 .put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2"))
317 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
318 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
319 .put(new JSONObject().put("key", "secondaryPnfName").put("value",
320 "testSecondaryPnfName2"))
321 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2"))));
323 JSONArray solution2 = new JSONArray();
324 solution2.put(new JSONObject().put("serviceResourceId", "testProxyId1")
326 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
327 new JSONArray().put("testServiceInstanceId3")))
328 .put("assignmentInfo",
329 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
330 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
331 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName3"))
332 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli3"))
333 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
334 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId3"))
335 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId3"))));
336 solution2.put(new JSONObject().put("serviceResourceId", "testProxyId2")
338 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
339 new JSONArray().put("testServiceInstanceId4")))
340 .put("assignmentInfo",
341 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
342 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
343 .put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName4"))
344 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli4"))
345 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
346 .put(new JSONObject().put("key", "secondaryPnfName").put("value",
347 "testSecondaryPnfName4"))
348 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId4"))));
350 asyncResponse.put("solutions",
351 new JSONObject().put("placementSolutions", new JSONArray().put(solution1).put(solution2))
352 .put("licenseSolutions", new JSONArray()));
354 sniroHoming.processSolution(execution, asyncResponse.toString());
357 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
359 assertFalse(si.getVpnBondingLinks().isEmpty());
360 VpnBondingLink link = si.getVpnBondingLinks().get(0);
361 VpnBondingLink link2 = si.getVpnBondingLinks().get(1);
363 assertFalse(link.getServiceProxies().isEmpty());
365 assertEquals("testServiceInstanceId1",
366 link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
367 assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
368 assertEquals("testVnfHostName1",
369 link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
371 assertEquals("testServiceInstanceId2",
372 link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
373 assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
374 assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
375 assertEquals("testPrimaryPnfName2",
376 link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
377 assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
378 assertEquals("testSecondaryPnfName2",
379 link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
380 assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
382 assertNotNull(link2);
383 assertFalse(link2.getServiceProxies().isEmpty());
385 assertEquals("testServiceInstanceId3",
386 link2.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
387 assertNotNull(link2.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
388 assertEquals("testVnfHostName3",
389 link2.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
391 assertEquals("testServiceInstanceId4",
392 link2.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
393 assertNotNull(link2.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
394 assertFalse(link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
395 assertEquals("testPrimaryPnfName4",
396 link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
397 assertEquals("primary", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
398 assertEquals("testSecondaryPnfName4",
399 link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
400 assertEquals("secondary",
401 link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
406 public void testProcessSolution_success_3VpnLink_2Solutions() {
411 public void testProcessSolution_success_3Allotteds_1Solution() {
412 beforeAllottedResource();
414 JSONObject asyncResponse = new JSONObject();
415 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
417 JSONArray solution1 = new JSONArray();
418 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1")
420 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
421 new JSONArray().put("testServiceInstanceId1")))
422 .put("assignmentInfo",
423 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
424 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
425 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
426 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1"))
427 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
428 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1"))
429 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1"))));
430 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2")
432 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
433 new JSONArray().put("testServiceInstanceId2")))
434 .put("assignmentInfo",
435 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
436 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
437 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2"))
438 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
439 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
440 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1"))
441 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2"))));
442 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3")
444 new JSONObject().put("identifierType", "cloudRegionId").put("identifiers",
445 new JSONArray().put("testCloudRegionId3")))
446 .put("assignmentInfo",
447 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
448 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
449 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
450 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))));
452 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1))
453 .put("licenseSolutions", new JSONArray()));
455 sniroHoming.processSolution(execution, asyncResponse.toString());
458 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
460 assertFalse(si.getAllottedResources().isEmpty());
461 AllottedResource ar = si.getAllottedResources().get(0);
463 assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId());
464 assertNotNull(ar.getParentServiceInstance().getSolutionInfo());
465 assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName());
467 AllottedResource ar2 = si.getAllottedResources().get(1);
469 assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId());
470 assertNotNull(ar2.getParentServiceInstance().getSolutionInfo());
471 assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName());
473 AllottedResource ar3 = si.getAllottedResources().get(2);
475 assertNotNull(ar3.getParentServiceInstance().getSolutionInfo());
476 assertEquals("testCloudRegionId3",
477 ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId());
481 public void testProcessSolution_success_3Allotteds1Vnf_1Solution() {
483 beforeAllottedResource();
485 JSONObject asyncResponse = new JSONObject();
486 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
488 JSONArray solution1 = new JSONArray();
489 JSONArray licenseSolution = new JSONArray();
490 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1")
492 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
493 new JSONArray().put("testServiceInstanceId1")))
494 .put("assignmentInfo",
495 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
496 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
497 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
498 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1"))
499 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
500 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1"))
501 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1"))));
502 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2")
504 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
505 new JSONArray().put("testServiceInstanceId2")))
506 .put("assignmentInfo",
507 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
508 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
509 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2"))
510 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
511 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
512 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1"))
513 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2"))));
514 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3")
516 new JSONObject().put("identifierType", "cloudRegionId").put("identifiers",
517 new JSONArray().put("testCloudRegionId3")))
518 .put("assignmentInfo",
519 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
520 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
521 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
522 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))));
524 licenseSolution.put(new JSONObject().put("serviceResourceId", "testVnfId1")
525 .put("entitlementPoolUUID",
526 new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e")
527 .put("j1d563e8-e714-4393-8f99-cc480144a05e"))
528 .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e")
529 .put("b1d563e8-e714-4393-8f99-cc480144a05e")));
531 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1))
532 .put("licenseSolutions", licenseSolution));
534 sniroHoming.processSolution(execution, asyncResponse.toString());
537 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
539 assertFalse(si.getAllottedResources().isEmpty());
540 AllottedResource ar = si.getAllottedResources().get(0);
542 assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId());
543 assertNotNull(ar.getParentServiceInstance().getSolutionInfo());
544 assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName());
546 AllottedResource ar2 = si.getAllottedResources().get(1);
548 assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId());
549 assertNotNull(ar2.getParentServiceInstance().getSolutionInfo());
550 assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName());
552 AllottedResource ar3 = si.getAllottedResources().get(2);
554 assertNotNull(ar3.getParentServiceInstance().getSolutionInfo());
555 assertEquals("testCloudRegionId3",
556 ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId());
558 GenericVnf vnf = si.getVnfs().get(0);
560 assertNotNull(vnf.getLicense());
561 assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size());
562 assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0));
567 public void testProcessSolution_success_1Vnf_1Solution() {
570 JSONObject asyncResponse = new JSONObject();
571 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
573 JSONArray licenseSolution = new JSONArray();
575 licenseSolution.put(new JSONObject().put("serviceResourceId", "testVnfId1")
576 .put("entitlementPoolUUID",
577 new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e")
578 .put("j1d563e8-e714-4393-8f99-cc480144a05e"))
579 .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e")
580 .put("b1d563e8-e714-4393-8f99-cc480144a05e")));
582 asyncResponse.put("solutions", new JSONObject().put("licenseSolutions", licenseSolution));
584 sniroHoming.processSolution(execution, asyncResponse.toString());
587 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
589 GenericVnf vnf = si.getVnfs().get(0);
591 assertNotNull(vnf.getLicense());
592 assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size());
593 assertEquals(2, vnf.getLicense().getLicenseKeyGroupUuids().size());
594 assertEquals("f1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getEntitlementPoolUuids().get(0));
595 assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0));
599 public void testProcessSolution_success_1ServiceProxy_1Solutions() {
600 beforeServiceProxy();
602 JSONObject asyncResponse = new JSONObject();
603 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
605 JSONArray solution1 = new JSONArray();
607 .put(new JSONObject()
608 .put("serviceResourceId", "testProxyId1").put(
611 .put("identifierType", "serviceInstanceId")
612 .put("identifiers", new JSONArray().put("testServiceInstanceId1")))
613 .put("assignmentInfo",
614 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
615 .put(new JSONObject().put("key", "cloudOwner").put("value", ""))
616 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1"))
617 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
618 .put(new JSONObject().put("key", "cloudRegionId").put("value", ""))
619 .put(new JSONObject().put("key", "primaryPnfName").put("value",
620 "testPrimaryPnfName"))
621 .put(new JSONObject().put("key", "secondaryPnfName").put("value",
622 "testSecondaryPnfName"))));
624 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1))
625 .put("licenseSolutions", new JSONArray()));
627 sniroHoming.processSolution(execution, asyncResponse.toString());
630 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
632 ServiceProxy sp = si.getServiceProxies().get(0);
634 assertNotNull(sp.getServiceInstance());
636 assertEquals("testServiceInstanceId1", sp.getServiceInstance().getServiceInstanceId());
637 assertNotNull(sp.getServiceInstance().getSolutionInfo());
639 assertFalse(sp.getServiceInstance().getPnfs().isEmpty());
640 assertEquals("testPrimaryPnfName", sp.getServiceInstance().getPnfs().get(0).getPnfName());
641 assertEquals("primary", sp.getServiceInstance().getPnfs().get(0).getRole());
642 assertEquals("testSecondaryPnfName", sp.getServiceInstance().getPnfs().get(1).getPnfName());
643 assertEquals("secondary", sp.getServiceInstance().getPnfs().get(1).getRole());
647 @Test(expected = BpmnError.class)
648 public void testCallSniro_error_0Resources() throws BadResponseException, JsonProcessingException {
650 sniroHoming.callSniro(execution);
652 verify(sniroClient, times(0)).postDemands(isA(SniroManagerRequest.class));
655 @Test(expected = BpmnError.class)
656 public void testCallSniro_error_badResponse() throws BadResponseException, JsonProcessingException {
657 beforeAllottedResource();
660 "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}";
661 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
662 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
664 sniroHoming.callSniro(execution);
666 verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class));