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.io.IOException;
31 import java.util.ArrayList;
32 import java.util.List;
33 import org.camunda.bpm.engine.delegate.BpmnError;
34 import org.json.JSONArray;
35 import org.json.JSONObject;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.mockito.ArgumentCaptor;
39 import org.onap.so.BaseIntegrationTest;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBondingLink;
46 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
47 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters;
48 import org.onap.so.bpmn.servicedecomposition.homingobjects.Candidate;
49 import org.onap.so.bpmn.servicedecomposition.homingobjects.CandidateType;
50 import org.onap.so.client.exception.BadResponseException;
51 import org.onap.so.client.sniro.beans.SniroManagerRequest;
52 import com.fasterxml.jackson.core.JsonProcessingException;
53 import com.fasterxml.jackson.databind.ObjectMapper;
55 public class SniroHomingV2IT extends BaseIntegrationTest {
57 private ServiceInstance serviceInstance;
59 private RequestContext requestContext;
61 private Customer customer;
62 ObjectMapper mapper = new ObjectMapper();
64 private static final String RESOURCE_PATH = "__files/BuildingBlocks/SniroHoming/";
68 "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}";
71 public void before() {
72 serviceInstance = setServiceInstance();
73 customer = setCustomer();
74 customer.setGlobalCustomerId("testCustomerId");
75 customer.setSubscriberName("testCustomerName");
76 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
78 requestContext = setRequestContext();
79 requestContext.setMsoRequestId("testRequestId");
80 RequestParameters params = new RequestParameters();
81 params.setaLaCarte(false);
82 params.setSubscriptionServiceType("testSubscriptionServiceType");
83 requestContext.setRequestParameters(params);
86 public void beforeVpnBondingLink(String id) {
87 VpnBondingLink bondingLink = new VpnBondingLink();
88 bondingLink.setVpnBondingLinkId("testVpnBondingId" + id);
89 bondingLink.getServiceProxies().add(setServiceProxy("1", "transport"));
90 ServiceProxy sp2 = setServiceProxy("2", "infrastructure");
91 Candidate requiredCandidate = new Candidate();
92 requiredCandidate.setIdentifierType(CandidateType.VNF_ID);
93 List<String> c = new ArrayList<String>();
95 requiredCandidate.setIdentifiers(c);
96 sp2.addRequiredCandidates(requiredCandidate);
97 bondingLink.getServiceProxies().add(sp2);
98 serviceInstance.getVpnBondingLinks().add(bondingLink);
102 public void beforeAllottedResource() {
103 serviceInstance.getAllottedResources().add(setAllottedResource("1"));
104 serviceInstance.getAllottedResources().add(setAllottedResource("2"));
105 serviceInstance.getAllottedResources().add(setAllottedResource("3"));
108 public void beforeServiceProxy() {
109 ServiceProxy sp = setServiceProxy("1", "infrastructure");
110 Candidate filteringAttributes = new Candidate();
111 filteringAttributes.setIdentifierType(CandidateType.CLOUD_REGION_ID);
112 List<String> c = new ArrayList<String>();
113 c.add("testCloudRegionId");
114 filteringAttributes.setCloudOwner("att");
115 filteringAttributes.setIdentifiers(c);
116 sp.getFilteringAttributes().add(filteringAttributes);
117 serviceInstance.getServiceProxies().add(sp);
120 public void beforeVnf() {
124 @Test(expected = Test.None.class)
125 public void testCallSniro_success_1VpnLink() throws BadResponseException, IOException {
126 beforeVpnBondingLink("1");
128 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
129 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
131 sniroHoming.callSniro(execution);
133 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest1Vpn.json");
134 request = request.replace("28080", wireMockPort);
136 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
137 verify(sniroClient, times(1)).postDemands(argument.capture());
138 assertEquals(request, argument.getValue().toJsonString());
142 public void testCallSniro_success_3VpnLink() throws JsonProcessingException, BadResponseException {
143 beforeVpnBondingLink("1");
144 beforeVpnBondingLink("2");
145 beforeVpnBondingLink("3");
147 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
148 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
150 sniroHoming.callSniro(execution);
152 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest3Vpn.json");
153 request = request.replace("28080", wireMockPort);
155 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
156 verify(sniroClient, times(1)).postDemands(argument.capture());
157 assertEquals(request, argument.getValue().toJsonString());
161 public void testCallSniro_success_3Allotteds() throws BadResponseException, JsonProcessingException {
162 beforeAllottedResource();
164 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
165 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
167 sniroHoming.callSniro(execution);
169 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest3AR.json");
170 request = request.replace("28080", wireMockPort);
172 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
173 verify(sniroClient, times(1)).postDemands(argument.capture());
174 assertEquals(request, argument.getValue().toJsonString());
178 public void testCallSniro_success_1Vnf() throws JsonProcessingException, BadResponseException {
181 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
182 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
184 sniroHoming.callSniro(execution);
186 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
187 verify(sniroClient, times(1)).postDemands(argument.capture());
188 // TODO assertEquals(request, argument.getValue().toJsonString());
192 public void testCallSniro_success_3Allotteds1Vnf() throws JsonProcessingException, BadResponseException {
193 beforeAllottedResource();
196 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
197 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
199 sniroHoming.callSniro(execution);
201 verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class));
205 public void testCallSniro_success_1ServiceProxy() throws JsonProcessingException, BadResponseException {
206 beforeServiceProxy();
208 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
209 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
211 sniroHoming.callSniro(execution);
213 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest1SP.json");
214 request = request.replace("28080", wireMockPort);
216 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
217 verify(sniroClient, times(1)).postDemands(argument.capture());
218 assertEquals(request, argument.getValue().toJsonString());
221 @Test(expected = Test.None.class)
222 public void testProcessSolution_success_1VpnLink_1Solution() {
223 beforeVpnBondingLink("1");
225 JSONObject asyncResponse = new JSONObject();
226 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
228 JSONArray solution1 = new JSONArray();
229 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1")
231 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
232 new JSONArray().put("testServiceInstanceId1")))
233 .put("assignmentInfo",
234 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
235 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
236 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
237 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1"))
238 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
239 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1"))
240 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1"))));
241 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2")
243 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
244 new JSONArray().put("testServiceInstanceId2")))
245 .put("assignmentInfo",
246 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
247 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
248 .put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2"))
249 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
250 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
251 .put(new JSONObject().put("key", "secondaryPnfName").put("value",
252 "testSecondaryPnfName2"))
253 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2"))));
255 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1))
256 .put("licenseSolutions", new JSONArray()));
258 sniroHoming.processSolution(execution, asyncResponse.toString());
261 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
263 assertFalse(si.getVpnBondingLinks().isEmpty());
264 VpnBondingLink link = si.getVpnBondingLinks().get(0);
266 assertFalse(link.getServiceProxies().isEmpty());
268 assertEquals("testServiceInstanceId1",
269 link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
270 assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
271 assertEquals("testVnfHostName1",
272 link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
274 assertEquals("testServiceInstanceId2",
275 link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
276 assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
277 assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
278 assertEquals("testPrimaryPnfName2",
279 link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
280 assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
281 assertEquals("testSecondaryPnfName2",
282 link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
283 assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
287 public void testProcessSolution_success_1VpnLink_2Solutions() {
288 beforeVpnBondingLink("1");
290 JSONObject asyncResponse = new JSONObject();
291 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
293 JSONArray solution1 = new JSONArray();
294 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1")
296 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
297 new JSONArray().put("testServiceInstanceId1")))
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", "testVnfHostName1"))
302 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1"))
303 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
304 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1"))
305 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1"))));
306 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2")
308 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
309 new JSONArray().put("testServiceInstanceId2")))
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", "testPrimaryPnfName2"))
314 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
315 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
316 .put(new JSONObject().put("key", "secondaryPnfName").put("value",
317 "testSecondaryPnfName2"))
318 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2"))));
320 JSONArray solution2 = new JSONArray();
321 solution2.put(new JSONObject().put("serviceResourceId", "testProxyId1")
323 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
324 new JSONArray().put("testServiceInstanceId3")))
325 .put("assignmentInfo",
326 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
327 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
328 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName3"))
329 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli3"))
330 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
331 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId3"))
332 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId3"))));
333 solution2.put(new JSONObject().put("serviceResourceId", "testProxyId2")
335 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
336 new JSONArray().put("testServiceInstanceId4")))
337 .put("assignmentInfo",
338 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
339 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
340 .put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName4"))
341 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli4"))
342 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
343 .put(new JSONObject().put("key", "secondaryPnfName").put("value",
344 "testSecondaryPnfName4"))
345 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId4"))));
347 asyncResponse.put("solutions",
348 new JSONObject().put("placementSolutions", new JSONArray().put(solution1).put(solution2))
349 .put("licenseSolutions", new JSONArray()));
351 sniroHoming.processSolution(execution, asyncResponse.toString());
354 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
356 assertFalse(si.getVpnBondingLinks().isEmpty());
357 VpnBondingLink link = si.getVpnBondingLinks().get(0);
358 VpnBondingLink link2 = si.getVpnBondingLinks().get(1);
360 assertFalse(link.getServiceProxies().isEmpty());
362 assertEquals("testServiceInstanceId1",
363 link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
364 assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
365 assertEquals("testVnfHostName1",
366 link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
368 assertEquals("testServiceInstanceId2",
369 link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
370 assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
371 assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
372 assertEquals("testPrimaryPnfName2",
373 link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
374 assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
375 assertEquals("testSecondaryPnfName2",
376 link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
377 assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
379 assertNotNull(link2);
380 assertFalse(link2.getServiceProxies().isEmpty());
382 assertEquals("testServiceInstanceId3",
383 link2.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
384 assertNotNull(link2.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
385 assertEquals("testVnfHostName3",
386 link2.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
388 assertEquals("testServiceInstanceId4",
389 link2.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
390 assertNotNull(link2.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
391 assertFalse(link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
392 assertEquals("testPrimaryPnfName4",
393 link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
394 assertEquals("primary", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
395 assertEquals("testSecondaryPnfName4",
396 link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
397 assertEquals("secondary",
398 link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
403 public void testProcessSolution_success_3VpnLink_2Solutions() {
408 public void testProcessSolution_success_3Allotteds_1Solution() {
409 beforeAllottedResource();
411 JSONObject asyncResponse = new JSONObject();
412 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
414 JSONArray solution1 = new JSONArray();
415 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1")
417 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
418 new JSONArray().put("testServiceInstanceId1")))
419 .put("assignmentInfo",
420 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
421 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
422 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
423 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1"))
424 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
425 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1"))
426 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1"))));
427 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2")
429 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
430 new JSONArray().put("testServiceInstanceId2")))
431 .put("assignmentInfo",
432 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
433 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
434 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2"))
435 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
436 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
437 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1"))
438 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2"))));
439 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3")
441 new JSONObject().put("identifierType", "cloudRegionId").put("identifiers",
442 new JSONArray().put("testCloudRegionId3")))
443 .put("assignmentInfo",
444 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
445 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
446 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
447 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))));
449 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1))
450 .put("licenseSolutions", new JSONArray()));
452 sniroHoming.processSolution(execution, asyncResponse.toString());
455 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
457 assertFalse(si.getAllottedResources().isEmpty());
458 AllottedResource ar = si.getAllottedResources().get(0);
460 assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId());
461 assertNotNull(ar.getParentServiceInstance().getSolutionInfo());
462 assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName());
464 AllottedResource ar2 = si.getAllottedResources().get(1);
466 assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId());
467 assertNotNull(ar2.getParentServiceInstance().getSolutionInfo());
468 assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName());
470 AllottedResource ar3 = si.getAllottedResources().get(2);
472 assertNotNull(ar3.getParentServiceInstance().getSolutionInfo());
473 assertEquals("testCloudRegionId3",
474 ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId());
478 public void testProcessSolution_success_3Allotteds1Vnf_1Solution() {
480 beforeAllottedResource();
482 JSONObject asyncResponse = new JSONObject();
483 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
485 JSONArray solution1 = new JSONArray();
486 JSONArray licenseSolution = new JSONArray();
487 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1")
489 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
490 new JSONArray().put("testServiceInstanceId1")))
491 .put("assignmentInfo",
492 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
493 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
494 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
495 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1"))
496 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
497 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1"))
498 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1"))));
499 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2")
501 new JSONObject().put("identifierType", "serviceInstanceId").put("identifiers",
502 new JSONArray().put("testServiceInstanceId2")))
503 .put("assignmentInfo",
504 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
505 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
506 .put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2"))
507 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
508 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
509 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1"))
510 .put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2"))));
511 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3")
513 new JSONObject().put("identifierType", "cloudRegionId").put("identifiers",
514 new JSONArray().put("testCloudRegionId3")))
515 .put("assignmentInfo",
516 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
517 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
518 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
519 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))));
521 licenseSolution.put(new JSONObject().put("serviceResourceId", "testVnfId1")
522 .put("entitlementPoolUUID",
523 new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e")
524 .put("j1d563e8-e714-4393-8f99-cc480144a05e"))
525 .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e")
526 .put("b1d563e8-e714-4393-8f99-cc480144a05e")));
528 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1))
529 .put("licenseSolutions", licenseSolution));
531 sniroHoming.processSolution(execution, asyncResponse.toString());
534 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
536 assertFalse(si.getAllottedResources().isEmpty());
537 AllottedResource ar = si.getAllottedResources().get(0);
539 assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId());
540 assertNotNull(ar.getParentServiceInstance().getSolutionInfo());
541 assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName());
543 AllottedResource ar2 = si.getAllottedResources().get(1);
545 assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId());
546 assertNotNull(ar2.getParentServiceInstance().getSolutionInfo());
547 assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName());
549 AllottedResource ar3 = si.getAllottedResources().get(2);
551 assertNotNull(ar3.getParentServiceInstance().getSolutionInfo());
552 assertEquals("testCloudRegionId3",
553 ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId());
555 GenericVnf vnf = si.getVnfs().get(0);
557 assertNotNull(vnf.getLicense());
558 assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size());
559 assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0));
564 public void testProcessSolution_success_1Vnf_1Solution() {
567 JSONObject asyncResponse = new JSONObject();
568 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
570 JSONArray licenseSolution = new JSONArray();
572 licenseSolution.put(new JSONObject().put("serviceResourceId", "testVnfId1")
573 .put("entitlementPoolUUID",
574 new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e")
575 .put("j1d563e8-e714-4393-8f99-cc480144a05e"))
576 .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e")
577 .put("b1d563e8-e714-4393-8f99-cc480144a05e")));
579 asyncResponse.put("solutions", new JSONObject().put("licenseSolutions", licenseSolution));
581 sniroHoming.processSolution(execution, asyncResponse.toString());
584 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
586 GenericVnf vnf = si.getVnfs().get(0);
588 assertNotNull(vnf.getLicense());
589 assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size());
590 assertEquals(2, vnf.getLicense().getLicenseKeyGroupUuids().size());
591 assertEquals("f1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getEntitlementPoolUuids().get(0));
592 assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0));
596 public void testProcessSolution_success_1ServiceProxy_1Solutions() {
597 beforeServiceProxy();
599 JSONObject asyncResponse = new JSONObject();
600 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState",
602 JSONArray solution1 = new JSONArray();
604 .put(new JSONObject()
605 .put("serviceResourceId", "testProxyId1").put(
608 .put("identifierType", "serviceInstanceId")
609 .put("identifiers", new JSONArray().put("testServiceInstanceId1")))
610 .put("assignmentInfo",
611 new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
612 .put(new JSONObject().put("key", "cloudOwner").put("value", ""))
613 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1"))
614 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))
615 .put(new JSONObject().put("key", "cloudRegionId").put("value", ""))
616 .put(new JSONObject().put("key", "primaryPnfName").put("value",
617 "testPrimaryPnfName"))
618 .put(new JSONObject().put("key", "secondaryPnfName").put("value",
619 "testSecondaryPnfName"))));
621 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1))
622 .put("licenseSolutions", new JSONArray()));
624 sniroHoming.processSolution(execution, asyncResponse.toString());
627 execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
629 ServiceProxy sp = si.getServiceProxies().get(0);
631 assertNotNull(sp.getServiceInstance());
633 assertEquals("testServiceInstanceId1", sp.getServiceInstance().getServiceInstanceId());
634 assertNotNull(sp.getServiceInstance().getSolutionInfo());
636 assertFalse(sp.getServiceInstance().getPnfs().isEmpty());
637 assertEquals("testPrimaryPnfName", sp.getServiceInstance().getPnfs().get(0).getPnfName());
638 assertEquals("primary", sp.getServiceInstance().getPnfs().get(0).getRole());
639 assertEquals("testSecondaryPnfName", sp.getServiceInstance().getPnfs().get(1).getPnfName());
640 assertEquals("secondary", sp.getServiceInstance().getPnfs().get(1).getRole());
644 @Test(expected = BpmnError.class)
645 public void testCallSniro_error_0Resources() throws BadResponseException, JsonProcessingException {
647 sniroHoming.callSniro(execution);
649 verify(sniroClient, times(0)).postDemands(isA(SniroManagerRequest.class));
652 @Test(expected = BpmnError.class)
653 public void testCallSniro_error_badResponse() throws BadResponseException, JsonProcessingException {
654 beforeAllottedResource();
657 "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}";
658 wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn(
659 aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
661 sniroHoming.callSniro(execution);
663 verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class));