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.mockito.ArgumentMatchers.isA;
28 import static org.mockito.Mockito.times;
29 import static org.mockito.Mockito.verify;
30 import java.util.ArrayList;
31 import java.util.List;
32 import org.camunda.bpm.engine.delegate.BpmnError;
33 import org.json.JSONArray;
34 import org.json.JSONObject;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.mockito.ArgumentCaptor;
38 import org.onap.so.BaseIntegrationTest;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBondingLink;
45 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
46 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters;
47 import org.onap.so.bpmn.servicedecomposition.homingobjects.Candidate;
48 import org.onap.so.bpmn.servicedecomposition.homingobjects.CandidateType;
49 import org.onap.so.client.exception.BadResponseException;
50 import org.onap.so.client.sniro.beans.SniroManagerRequest;
51 import com.fasterxml.jackson.databind.ObjectMapper;
53 public class SniroHomingV2IT extends BaseIntegrationTest {
55 private ServiceInstance serviceInstance;
57 private RequestContext requestContext;
59 private Customer customer;
60 ObjectMapper mapper = new ObjectMapper();
62 private static final String RESOURCE_PATH = "__files/BuildingBlocks/SniroHoming/";
66 "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}";
69 public void before() {
70 serviceInstance = setServiceInstance();
71 customer = setCustomer();
72 customer.setGlobalCustomerId("testCustomerId");
73 customer.setSubscriberName("testCustomerName");
74 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
76 requestContext = setRequestContext();
77 requestContext.setMsoRequestId("testRequestId");
78 RequestParameters params = new RequestParameters();
79 params.setaLaCarte(false);
80 params.setSubscriptionServiceType("testSubscriptionServiceType");
81 requestContext.setRequestParameters(params);
84 public void beforeVpnBondingLink(String id) {
85 VpnBondingLink bondingLink = new VpnBondingLink();
86 bondingLink.setVpnBondingLinkId("testVpnBondingId" + id);
87 bondingLink.getServiceProxies().add(setServiceProxy("1", "transport"));
88 ServiceProxy sp2 = setServiceProxy("2", "infrastructure");
89 Candidate requiredCandidate = new Candidate();
90 requiredCandidate.setIdentifierType(CandidateType.VNF_ID);
91 List<String> c = new ArrayList<String>();
93 requiredCandidate.setIdentifiers(c);
94 sp2.addRequiredCandidates(requiredCandidate);
95 bondingLink.getServiceProxies().add(sp2);
96 serviceInstance.getVpnBondingLinks().add(bondingLink);
100 public void beforeAllottedResource() {
101 serviceInstance.getAllottedResources().add(setAllottedResource("1"));
102 serviceInstance.getAllottedResources().add(setAllottedResource("2"));
103 serviceInstance.getAllottedResources().add(setAllottedResource("3"));
106 public void beforeServiceProxy() {
107 ServiceProxy sp = setServiceProxy("1", "infrastructure");
108 Candidate filteringAttributes = new Candidate();
109 filteringAttributes.setIdentifierType(CandidateType.CLOUD_REGION_ID);
110 List<String> c = new ArrayList<String>();
111 c.add("testCloudRegionId");
112 filteringAttributes.setCloudOwner("att");
113 filteringAttributes.setIdentifiers(c);
114 sp.getFilteringAttributes().add(filteringAttributes);
115 serviceInstance.getServiceProxies().add(sp);
118 public void beforeVnf() {
122 @Test(expected = Test.None.class)
123 public void testCallSniro_success_1VpnLink() throws BadResponseException {
124 beforeVpnBondingLink("1");
126 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
127 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
129 sniroHoming.callSniro(execution);
131 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest1Vpn.json");
132 request = request.replace("28080", wireMockPort);
134 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
135 verify(sniroClient, times(1)).postDemands(argument.capture());
136 assertEquals(request, argument.getValue().toJsonString());
140 public void testCallSniro_success_3VpnLink() throws BadResponseException {
141 beforeVpnBondingLink("1");
142 beforeVpnBondingLink("2");
143 beforeVpnBondingLink("3");
145 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
146 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
148 sniroHoming.callSniro(execution);
150 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest3Vpn.json");
151 request = request.replace("28080", wireMockPort);
153 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
154 verify(sniroClient, times(1)).postDemands(argument.capture());
155 assertEquals(request, argument.getValue().toJsonString());
159 public void testCallSniro_success_3Allotteds() throws BadResponseException {
160 beforeAllottedResource();
162 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
163 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
165 sniroHoming.callSniro(execution);
167 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest3AR.json");
168 request = request.replace("28080", wireMockPort);
170 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
171 verify(sniroClient, times(1)).postDemands(argument.capture());
172 assertEquals(request, argument.getValue().toJsonString());
176 public void testCallSniro_success_1Vnf() throws BadResponseException {
179 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
180 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
182 sniroHoming.callSniro(execution);
184 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
185 verify(sniroClient, times(1)).postDemands(argument.capture());
186 // TODO assertEquals(request, argument.getValue().toJsonString());
190 public void testCallSniro_success_3Allotteds1Vnf() throws BadResponseException {
191 beforeAllottedResource();
194 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
195 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
197 sniroHoming.callSniro(execution);
199 verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class));
203 public void testCallSniro_success_1ServiceProxy() throws BadResponseException {
204 beforeServiceProxy();
206 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
207 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
209 sniroHoming.callSniro(execution);
211 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest1SP.json");
212 request = request.replace("28080", wireMockPort);
214 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
215 verify(sniroClient, times(1)).postDemands(argument.capture());
216 assertEquals(request, argument.getValue().toJsonString());
219 @Test(expected = Test.None.class)
220 public void testProcessSolution_success_1VpnLink_1Solution() {
221 beforeVpnBondingLink("1");
223 JSONObject asyncResponse = new JSONObject();
224 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
226 JSONArray solution1 = new JSONArray();
227 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1")
229 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
230 new JSONArray().put("testServiceInstanceId1")))
231 .put("assignmentInfo",
232 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
233 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
234 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
235 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1"))
236 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
237 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1"))
238 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1"))));
239 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2")
241 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
242 new JSONArray().put("testServiceInstanceId2")))
243 .put("assignmentInfo",
244 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
245 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
246 .put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2"))
247 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
248 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
249 .put(new JSONObject().put("key", "secondaryPnfName").put("value",
250 "testSecondaryPnfName2"))
251 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2"))));
253 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1))
254 .put("licenseSolutions", new JSONArray()));
256 sniroHoming.processSolution(execution, asyncResponse.toString());
259 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
261 assertFalse(si.getVpnBondingLinks().isEmpty());
262 VpnBondingLink link = si.getVpnBondingLinks().get(0);
264 assertFalse(link.getServiceProxies().isEmpty());
266 assertEquals("testServiceInstanceId1",
267 link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
268 assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
269 assertEquals("testVnfHostName1",
270 link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
272 assertEquals("testServiceInstanceId2",
273 link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
274 assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
275 assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
276 assertEquals("testPrimaryPnfName2",
277 link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
278 assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
279 assertEquals("testSecondaryPnfName2",
280 link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
281 assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
285 public void testProcessSolution_success_1VpnLink_2Solutions() {
286 beforeVpnBondingLink("1");
288 JSONObject asyncResponse = new JSONObject();
289 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
291 JSONArray solution1 = new JSONArray();
292 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1")
294 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
295 new JSONArray().put("testServiceInstanceId1")))
296 .put("assignmentInfo",
297 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
298 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
299 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
300 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1"))
301 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
302 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1"))
303 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1"))));
304 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2")
306 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
307 new JSONArray().put("testServiceInstanceId2")))
308 .put("assignmentInfo",
309 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
310 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
311 .put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2"))
312 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
313 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
314 .put(new JSONObject().put("key", "secondaryPnfName").put("value",
315 "testSecondaryPnfName2"))
316 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2"))));
318 JSONArray solution2 = new JSONArray();
319 solution2.put(new JSONObject().put("serviceResourceId", "testProxyId1")
321 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
322 new JSONArray().put("testServiceInstanceId3")))
323 .put("assignmentInfo",
324 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
325 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
326 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName3"))
327 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli3"))
328 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
329 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId3"))
330 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId3"))));
331 solution2.put(new JSONObject().put("serviceResourceId", "testProxyId2")
333 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
334 new JSONArray().put("testServiceInstanceId4")))
335 .put("assignmentInfo",
336 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
337 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
338 .put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName4"))
339 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli4"))
340 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
341 .put(new JSONObject().put("key", "secondaryPnfName").put("value",
342 "testSecondaryPnfName4"))
343 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId4"))));
345 asyncResponse.put("solutions",
346 new JSONObject().put("placementSolutions", new JSONArray().put(solution1).put(solution2))
347 .put("licenseSolutions", new JSONArray()));
349 sniroHoming.processSolution(execution, asyncResponse.toString());
352 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
354 assertFalse(si.getVpnBondingLinks().isEmpty());
355 VpnBondingLink link = si.getVpnBondingLinks().get(0);
356 VpnBondingLink link2 = si.getVpnBondingLinks().get(1);
358 assertFalse(link.getServiceProxies().isEmpty());
360 assertEquals("testServiceInstanceId1",
361 link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
362 assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
363 assertEquals("testVnfHostName1",
364 link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
366 assertEquals("testServiceInstanceId2",
367 link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
368 assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
369 assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
370 assertEquals("testPrimaryPnfName2",
371 link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
372 assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
373 assertEquals("testSecondaryPnfName2",
374 link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
375 assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
377 assertNotNull(link2);
378 assertFalse(link2.getServiceProxies().isEmpty());
380 assertEquals("testServiceInstanceId3",
381 link2.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
382 assertNotNull(link2.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
383 assertEquals("testVnfHostName3",
384 link2.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
386 assertEquals("testServiceInstanceId4",
387 link2.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
388 assertNotNull(link2.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
389 assertFalse(link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
390 assertEquals("testPrimaryPnfName4",
391 link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
392 assertEquals("primary", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
393 assertEquals("testSecondaryPnfName4",
394 link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
395 assertEquals("secondary",
396 link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
401 public void testProcessSolution_success_3VpnLink_2Solutions() {
406 public void testProcessSolution_success_3Allotteds_1Solution() {
407 beforeAllottedResource();
409 JSONObject asyncResponse = new JSONObject();
410 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
412 JSONArray solution1 = new JSONArray();
413 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1")
415 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
416 new JSONArray().put("testServiceInstanceId1")))
417 .put("assignmentInfo",
418 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
419 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
420 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
421 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1"))
422 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
423 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1"))
424 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1"))));
425 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2")
427 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
428 new JSONArray().put("testServiceInstanceId2")))
429 .put("assignmentInfo",
430 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
431 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
432 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2"))
433 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
434 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
435 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1"))
436 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2"))));
437 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3")
439 new JSONObject().put("identifierType", "cloudRegionId").put("identifiers",
440 new JSONArray().put("testCloudRegionId3")))
441 .put("assignmentInfo",
442 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
443 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
444 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
445 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))));
447 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1))
448 .put("licenseSolutions", new JSONArray()));
450 sniroHoming.processSolution(execution, asyncResponse.toString());
453 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
455 assertFalse(si.getAllottedResources().isEmpty());
456 AllottedResource ar = si.getAllottedResources().get(0);
458 assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId());
459 assertNotNull(ar.getParentServiceInstance().getSolutionInfo());
460 assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName());
462 AllottedResource ar2 = si.getAllottedResources().get(1);
464 assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId());
465 assertNotNull(ar2.getParentServiceInstance().getSolutionInfo());
466 assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName());
468 AllottedResource ar3 = si.getAllottedResources().get(2);
470 assertNotNull(ar3.getParentServiceInstance().getSolutionInfo());
471 assertEquals("testCloudRegionId3",
472 ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId());
476 public void testProcessSolution_success_3Allotteds1Vnf_1Solution() {
478 beforeAllottedResource();
480 JSONObject asyncResponse = new JSONObject();
481 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
483 JSONArray solution1 = new JSONArray();
484 JSONArray licenseSolution = new JSONArray();
485 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1")
487 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
488 new JSONArray().put("testServiceInstanceId1")))
489 .put("assignmentInfo",
490 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
491 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
492 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
493 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1"))
494 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
495 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1"))
496 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1"))));
497 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2")
499 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
500 new JSONArray().put("testServiceInstanceId2")))
501 .put("assignmentInfo",
502 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
503 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
504 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2"))
505 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
506 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
507 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1"))
508 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2"))));
509 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3")
511 new JSONObject().put("identifierType", "cloudRegionId").put("identifiers",
512 new JSONArray().put("testCloudRegionId3")))
513 .put("assignmentInfo",
514 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
515 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
516 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
517 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))));
519 licenseSolution.put(new JSONObject().put("serviceResourceId", "testVnfId1")
520 .put("entitlementPoolUUID",
521 new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e")
522 .put("j1d563e8-e714-4393-8f99-cc480144a05e"))
523 .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e")
524 .put("b1d563e8-e714-4393-8f99-cc480144a05e")));
526 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1))
527 .put("licenseSolutions", licenseSolution));
529 sniroHoming.processSolution(execution, asyncResponse.toString());
532 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
534 assertFalse(si.getAllottedResources().isEmpty());
535 AllottedResource ar = si.getAllottedResources().get(0);
537 assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId());
538 assertNotNull(ar.getParentServiceInstance().getSolutionInfo());
539 assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName());
541 AllottedResource ar2 = si.getAllottedResources().get(1);
543 assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId());
544 assertNotNull(ar2.getParentServiceInstance().getSolutionInfo());
545 assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName());
547 AllottedResource ar3 = si.getAllottedResources().get(2);
549 assertNotNull(ar3.getParentServiceInstance().getSolutionInfo());
550 assertEquals("testCloudRegionId3",
551 ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId());
553 GenericVnf vnf = si.getVnfs().get(0);
555 assertNotNull(vnf.getLicense());
556 assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size());
557 assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0));
562 public void testProcessSolution_success_1Vnf_1Solution() {
565 JSONObject asyncResponse = new JSONObject();
566 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
568 JSONArray licenseSolution = new JSONArray();
570 licenseSolution.put(new JSONObject().put("serviceResourceId", "testVnfId1")
571 .put("entitlementPoolUUID",
572 new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e")
573 .put("j1d563e8-e714-4393-8f99-cc480144a05e"))
574 .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e")
575 .put("b1d563e8-e714-4393-8f99-cc480144a05e")));
577 asyncResponse.put("solutions", new JSONObject().put("licenseSolutions", licenseSolution));
579 sniroHoming.processSolution(execution, asyncResponse.toString());
582 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
584 GenericVnf vnf = si.getVnfs().get(0);
586 assertNotNull(vnf.getLicense());
587 assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size());
588 assertEquals(2, vnf.getLicense().getLicenseKeyGroupUuids().size());
589 assertEquals("f1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getEntitlementPoolUuids().get(0));
590 assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0));
594 public void testProcessSolution_success_1ServiceProxy_1Solutions() {
595 beforeServiceProxy();
597 JSONObject asyncResponse = new JSONObject();
598 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
600 JSONArray solution1 = new JSONArray();
602 .put(new JSONObject()
603 .put("serviceResourceId", "testProxyId1").put(
606 .put("identifierType", "serviceInstanceId")
607 .put("identifiers", new JSONArray().put("testServiceInstanceId1")))
608 .put("assignmentInfo",
609 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
610 .put(new JSONObject().put("key", "cloudOwner").put("value", ""))
611 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1"))
612 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
613 .put(new JSONObject().put("key", "cloudRegionId").put("value", ""))
614 .put(new JSONObject().put("key", "primaryPnfName").put("value",
615 "testPrimaryPnfName"))
616 .put(new JSONObject().put("key", "secondaryPnfName").put("value",
617 "testSecondaryPnfName"))));
619 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1))
620 .put("licenseSolutions", new JSONArray()));
622 sniroHoming.processSolution(execution, asyncResponse.toString());
625 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
627 ServiceProxy sp = si.getServiceProxies().get(0);
629 assertNotNull(sp.getServiceInstance());
631 assertEquals("testServiceInstanceId1", sp.getServiceInstance().getServiceInstanceId());
632 assertNotNull(sp.getServiceInstance().getSolutionInfo());
634 assertFalse(sp.getServiceInstance().getPnfs().isEmpty());
635 assertEquals("testPrimaryPnfName", sp.getServiceInstance().getPnfs().get(0).getPnfName());
636 assertEquals("primary", sp.getServiceInstance().getPnfs().get(0).getRole());
637 assertEquals("testSecondaryPnfName", sp.getServiceInstance().getPnfs().get(1).getPnfName());
638 assertEquals("secondary", sp.getServiceInstance().getPnfs().get(1).getRole());
642 @Test(expected = BpmnError.class)
643 public void testCallSniro_error_0Resources() throws BadResponseException {
645 sniroHoming.callSniro(execution);
647 verify(sniroClient, times(0)).postDemands(isA(SniroManagerRequest.class));
650 @Test(expected = BpmnError.class)
651 public void testCallSniro_error_badResponse() throws BadResponseException {
652 beforeAllottedResource();
655 "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}";
656 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
657 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
659 sniroHoming.callSniro(execution);
661 verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class));