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.stubFor;
26 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertNotNull;
30 import static org.mockito.ArgumentMatchers.isA;
31 import static org.mockito.Mockito.times;
32 import static org.mockito.Mockito.verify;
34 import java.io.IOException;
35 import java.util.ArrayList;
36 import java.util.List;
38 import org.camunda.bpm.engine.delegate.BpmnError;
39 import org.json.JSONArray;
40 import org.json.JSONObject;
41 import org.junit.Before;
42 import org.junit.Test;
43 import org.mockito.ArgumentCaptor;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBondingLink;
50 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
51 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters;
52 import org.onap.so.bpmn.servicedecomposition.homingobjects.Candidate;
53 import org.onap.so.bpmn.servicedecomposition.homingobjects.CandidateType;
54 import org.onap.so.client.exception.BadResponseException;
55 import org.onap.so.client.sniro.beans.SniroManagerRequest;
56 import org.onap.so.BaseIntegrationTest;
57 import com.fasterxml.jackson.core.JsonProcessingException;
58 import com.fasterxml.jackson.databind.ObjectMapper;
60 public class SniroHomingV2IT extends BaseIntegrationTest{
62 private ServiceInstance serviceInstance;
64 private RequestContext requestContext;
66 private Customer customer;
67 ObjectMapper mapper = new ObjectMapper();
69 private static final String RESOURCE_PATH = "__files/BuildingBlocks/SniroHoming/";
72 String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}";
75 public void before() {
76 serviceInstance = setServiceInstance();
77 customer = setCustomer();
78 customer.setGlobalCustomerId("testCustomerId");
79 customer.setSubscriberName("testCustomerName");
80 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
82 requestContext = setRequestContext();
83 requestContext.setMsoRequestId("testRequestId");
84 RequestParameters params = new RequestParameters();
85 params.setaLaCarte(false);
86 params.setSubscriptionServiceType("testSubscriptionServiceType");
87 requestContext.setRequestParameters(params);
90 public void beforeVpnBondingLink(String id){
91 VpnBondingLink bondingLink = new VpnBondingLink();
92 bondingLink.setVpnBondingLinkId("testVpnBondingId" + id);
93 bondingLink.getServiceProxies().add(setServiceProxy("1", "transport"));
94 ServiceProxy sp2 = setServiceProxy("2", "infrastructure");
95 Candidate requiredCandidate = new Candidate();
96 requiredCandidate.setIdentifierType(CandidateType.VNF_ID);
97 List<String> c = new ArrayList<String>();
99 requiredCandidate.setIdentifiers(c);
100 sp2.addRequiredCandidates(requiredCandidate);
101 bondingLink.getServiceProxies().add(sp2);
102 serviceInstance.getVpnBondingLinks().add(bondingLink);
106 public void beforeAllottedResource(){
107 serviceInstance.getAllottedResources().add(setAllottedResource("1"));
108 serviceInstance.getAllottedResources().add(setAllottedResource("2"));
109 serviceInstance.getAllottedResources().add(setAllottedResource("3"));
112 public void beforeVnf(){
116 @Test(expected = Test.None.class)
117 public void testCallSniro_success_1VpnLink() throws BadResponseException, IOException{
118 beforeVpnBondingLink("1");
120 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
121 .willReturn(aResponse().withStatus(200)
122 .withHeader("Content-Type", "application/json")
123 .withBody(mockResponse)));
125 sniroHoming.callSniro(execution);
127 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest1Vpn.json");
128 request = request.replace("28080", wireMockPort);
130 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
131 verify(sniroClient, times(1)).postDemands(argument.capture());
132 assertEquals(request, argument.getValue().toJsonString());
136 public void testCallSniro_success_3VpnLink() throws JsonProcessingException, BadResponseException{
137 beforeVpnBondingLink("1");
138 beforeVpnBondingLink("2");
139 beforeVpnBondingLink("3");
141 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
142 .willReturn(aResponse().withStatus(200)
143 .withHeader("Content-Type", "application/json")
144 .withBody(mockResponse)));
146 sniroHoming.callSniro(execution);
148 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest3Vpn.json");
149 request = request.replace("28080", wireMockPort);
151 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
152 verify(sniroClient, times(1)).postDemands(argument.capture());
153 assertEquals(request, argument.getValue().toJsonString());
157 public void testCallSniro_success_3Allotteds() throws BadResponseException, JsonProcessingException{
158 beforeAllottedResource();
160 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
161 .willReturn(aResponse().withStatus(200)
162 .withHeader("Content-Type", "application/json")
163 .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 JsonProcessingException, BadResponseException{
179 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
180 .willReturn(aResponse().withStatus(200)
181 .withHeader("Content-Type", "application/json")
182 .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 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
197 .willReturn(aResponse().withStatus(200)
198 .withHeader("Content-Type", "application/json")
199 .withBody(mockResponse)));
201 sniroHoming.callSniro(execution);
203 verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class));
206 @Test(expected = Test.None.class)
207 public void testProcessSolution_success_1VpnLink_1Solution(){
208 beforeVpnBondingLink("1");
210 JSONObject asyncResponse = new JSONObject();
211 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
212 JSONArray solution1 = new JSONArray();
213 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("solution", new JSONObject()
214 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
215 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
216 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
217 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
218 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1"))));
219 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("solution", new JSONObject()
220 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
221 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
222 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2"))
223 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
224 .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName2")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2"))));
226 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", new JSONArray()));
228 sniroHoming.processSolution(execution, asyncResponse.toString());
230 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
232 assertFalse(si.getVpnBondingLinks().isEmpty());
233 VpnBondingLink link = si.getVpnBondingLinks().get(0);
235 assertFalse(link.getServiceProxies().isEmpty());
237 assertEquals("testServiceInstanceId1", link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
238 assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
239 assertEquals("testVnfHostName1", link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
241 assertEquals("testServiceInstanceId2", link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
242 assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
243 assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
244 assertEquals("testPrimaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
245 assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
246 assertEquals("testSecondaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
247 assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
251 public void testProcessSolution_success_1VpnLink_2Solutions(){
252 beforeVpnBondingLink("1");
254 JSONObject asyncResponse = new JSONObject();
255 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
256 JSONArray solution1 = new JSONArray();
257 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("solution", new JSONObject()
258 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
259 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
260 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
261 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
262 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1"))));
263 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("solution", new JSONObject()
264 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
265 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
266 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2"))
267 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
268 .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName2")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2"))));
270 JSONArray solution2 = new JSONArray();
271 solution2.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("solution", new JSONObject()
272 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId3")))
273 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
274 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName3"))
275 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli3")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
276 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId3")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId3"))));
277 solution2.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("solution", new JSONObject()
278 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId4")))
279 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
280 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName4"))
281 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli4")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
282 .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName4")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId4"))));
284 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1).put(solution2)).put("licenseSolutions", new JSONArray()));
286 sniroHoming.processSolution(execution, asyncResponse.toString());
288 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
290 assertFalse(si.getVpnBondingLinks().isEmpty());
291 VpnBondingLink link = si.getVpnBondingLinks().get(0);
292 VpnBondingLink link2 = si.getVpnBondingLinks().get(1);
294 assertFalse(link.getServiceProxies().isEmpty());
296 assertEquals("testServiceInstanceId1", link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
297 assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
298 assertEquals("testVnfHostName1", link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
300 assertEquals("testServiceInstanceId2", link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
301 assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
302 assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
303 assertEquals("testPrimaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
304 assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
305 assertEquals("testSecondaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
306 assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
308 assertNotNull(link2);
309 assertFalse(link2.getServiceProxies().isEmpty());
311 assertEquals("testServiceInstanceId3", link2.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
312 assertNotNull(link2.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
313 assertEquals("testVnfHostName3", link2.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
315 assertEquals("testServiceInstanceId4", link2.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
316 assertNotNull(link2.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
317 assertFalse(link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
318 assertEquals("testPrimaryPnfName4", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
319 assertEquals("primary", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
320 assertEquals("testSecondaryPnfName4", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
321 assertEquals("secondary", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
326 public void testProcessSolution_success_3VpnLink_2Solutions(){
331 public void testProcessSolution_success_3Allotteds_1Solution(){
332 beforeAllottedResource();
334 JSONObject asyncResponse = new JSONObject();
335 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
336 JSONArray solution1 = new JSONArray();
337 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1").put("solution", new JSONObject()
338 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
339 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
340 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
341 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
342 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1"))));
343 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2").put("solution", new JSONObject()
344 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
345 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
346 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2"))
347 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
348 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2"))));
349 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3").put("solution", new JSONObject()
350 .put("identifierType", "cloudRegionId").put("identifiers", new JSONArray().put("testCloudRegionId3")))
351 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
352 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
353 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))));
355 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", new JSONArray()));
357 sniroHoming.processSolution(execution, asyncResponse.toString());
359 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
361 assertFalse(si.getAllottedResources().isEmpty());
362 AllottedResource ar = si.getAllottedResources().get(0);
364 assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId());
365 assertNotNull(ar.getParentServiceInstance().getSolutionInfo());
366 assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName());
368 AllottedResource ar2 = si.getAllottedResources().get(1);
370 assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId());
371 assertNotNull(ar2.getParentServiceInstance().getSolutionInfo());
372 assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName());
374 AllottedResource ar3 = si.getAllottedResources().get(2);
376 assertNotNull(ar3.getParentServiceInstance().getSolutionInfo());
377 assertEquals("testCloudRegionId3", ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId());
381 public void testProcessSolution_success_3Allotteds1Vnf_1Solution(){
383 beforeAllottedResource();
385 JSONObject asyncResponse = new JSONObject();
386 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
387 JSONArray solution1 = new JSONArray();
388 JSONArray licenseSolution = new JSONArray();
389 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1").put("solution", new JSONObject()
390 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
391 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
392 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
393 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
394 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1"))));
395 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2").put("solution", new JSONObject()
396 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
397 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
398 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2"))
399 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
400 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2"))));
401 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3").put("solution", new JSONObject()
402 .put("identifierType", "cloudRegionId").put("identifiers", new JSONArray().put("testCloudRegionId3")))
403 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
404 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
405 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))));
408 new JSONObject().put("serviceResourceId", "testVnfId1").put("entitlementPoolUUID", new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e").put("j1d563e8-e714-4393-8f99-cc480144a05e"))
409 .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e").put("b1d563e8-e714-4393-8f99-cc480144a05e")));
411 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", licenseSolution));
413 sniroHoming.processSolution(execution, asyncResponse.toString());
415 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
417 assertFalse(si.getAllottedResources().isEmpty());
418 AllottedResource ar = si.getAllottedResources().get(0);
420 assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId());
421 assertNotNull(ar.getParentServiceInstance().getSolutionInfo());
422 assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName());
424 AllottedResource ar2 = si.getAllottedResources().get(1);
426 assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId());
427 assertNotNull(ar2.getParentServiceInstance().getSolutionInfo());
428 assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName());
430 AllottedResource ar3 = si.getAllottedResources().get(2);
432 assertNotNull(ar3.getParentServiceInstance().getSolutionInfo());
433 assertEquals("testCloudRegionId3", ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId());
435 GenericVnf vnf = si.getVnfs().get(0);
437 assertNotNull(vnf.getLicense());
438 assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size());
439 assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0));
444 public void testProcessSolution_success_1Vnf_1Solution(){
447 JSONObject asyncResponse = new JSONObject();
448 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
449 JSONArray licenseSolution = new JSONArray();
452 new JSONObject().put("serviceResourceId", "testVnfId1").put("entitlementPoolUUID", new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e").put("j1d563e8-e714-4393-8f99-cc480144a05e"))
453 .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e").put("b1d563e8-e714-4393-8f99-cc480144a05e")));
455 asyncResponse.put("solutions", new JSONObject().put("licenseSolutions", licenseSolution));
457 sniroHoming.processSolution(execution, asyncResponse.toString());
459 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
461 GenericVnf vnf = si.getVnfs().get(0);
463 assertNotNull(vnf.getLicense());
464 assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size());
465 assertEquals(2, vnf.getLicense().getLicenseKeyGroupUuids().size());
466 assertEquals("f1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getEntitlementPoolUuids().get(0));
467 assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0));
472 @Test(expected = BpmnError.class)
473 public void testCallSniro_error_0Resources() throws BadResponseException, JsonProcessingException{
475 sniroHoming.callSniro(execution);
477 verify(sniroClient, times(0)).postDemands(isA(SniroManagerRequest.class));
480 @Test(expected = BpmnError.class)
481 public void testCallSniro_error_badResponse() throws BadResponseException, JsonProcessingException{
482 beforeAllottedResource();
484 mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}";
485 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
486 .willReturn(aResponse().withStatus(200)
487 .withHeader("Content-Type", "application/json")
488 .withBody(mockResponse)));
490 sniroHoming.callSniro(execution);
492 verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class));