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.Ignore;
43 import org.junit.Test;
44 import org.mockito.ArgumentCaptor;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy;
50 import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBondingLink;
51 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
52 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters;
53 import org.onap.so.bpmn.servicedecomposition.homingobjects.Candidate;
54 import org.onap.so.bpmn.servicedecomposition.homingobjects.CandidateType;
55 import org.onap.so.client.exception.BadResponseException;
56 import org.onap.so.client.sniro.beans.SniroManagerRequest;
57 import org.onap.so.BaseIntegrationTest;
58 import com.fasterxml.jackson.core.JsonProcessingException;
59 import com.fasterxml.jackson.databind.ObjectMapper;
61 public class SniroHomingV2IT extends BaseIntegrationTest{
63 private ServiceInstance serviceInstance;
65 private RequestContext requestContext;
67 private Customer customer;
68 ObjectMapper mapper = new ObjectMapper();
70 private static final String RESOURCE_PATH = "__files/BuildingBlocks/SniroHoming/";
73 String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}";
76 public void before() {
77 serviceInstance = setServiceInstance();
78 customer = setCustomer();
79 customer.setGlobalCustomerId("testCustomerId");
80 customer.setSubscriberName("testCustomerName");
81 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
83 requestContext = setRequestContext();
84 requestContext.setMsoRequestId("testRequestId");
85 RequestParameters params = new RequestParameters();
86 params.setaLaCarte(false);
87 params.setSubscriptionServiceType("iptollfree");
88 requestContext.setRequestParameters(params);
91 public void beforeVpnBondingLink(String id){
92 VpnBondingLink bondingLink = new VpnBondingLink();
93 bondingLink.setVpnBondingLinkId("testVpnBondingId" + id);
94 bondingLink.getServiceProxies().add(setServiceProxy("1", "transport"));
95 ServiceProxy sp2 = setServiceProxy("2", "infrastructure");
96 Candidate requiredCandidate = new Candidate();
97 requiredCandidate.setCandidateType(CandidateType.VNF_ID);
98 List<String> c = new ArrayList<String>();
100 requiredCandidate.setCandidates(c);
101 sp2.addRequiredCandidates(requiredCandidate);
102 bondingLink.getServiceProxies().add(sp2);
103 serviceInstance.getVpnBondingLinks().add(bondingLink);
107 public void beforeAllottedResource(){
108 serviceInstance.getAllottedResources().add(setAllottedResource("1"));
109 serviceInstance.getAllottedResources().add(setAllottedResource("2"));
110 serviceInstance.getAllottedResources().add(setAllottedResource("3"));
113 public void beforeVnf(){
117 @Test(expected = Test.None.class)
118 public void testCallSniro_success_1VpnLink() throws BadResponseException, IOException{
119 beforeVpnBondingLink("1");
121 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
122 .willReturn(aResponse().withStatus(200)
123 .withHeader("Content-Type", "application/json")
124 .withBody(mockResponse)));
126 sniroHoming.callSniro(execution);
128 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest1Vpn.json");
129 request = request.replace("28080", wireMockPort);
131 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
132 verify(sniroClient, times(1)).postDemands(argument.capture());
133 assertEquals(request, argument.getValue().toJsonString());
137 public void testCallSniro_success_3VpnLink() throws JsonProcessingException, BadResponseException{
138 beforeVpnBondingLink("1");
139 beforeVpnBondingLink("2");
140 beforeVpnBondingLink("3");
142 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
143 .willReturn(aResponse().withStatus(200)
144 .withHeader("Content-Type", "application/json")
145 .withBody(mockResponse)));
147 sniroHoming.callSniro(execution);
149 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest3Vpn.json");
150 request = request.replace("28080", wireMockPort);
152 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
153 verify(sniroClient, times(1)).postDemands(argument.capture());
154 assertEquals(request, argument.getValue().toJsonString());
158 public void testCallSniro_success_3Allotteds() throws BadResponseException, JsonProcessingException{
159 beforeAllottedResource();
161 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
162 .willReturn(aResponse().withStatus(200)
163 .withHeader("Content-Type", "application/json")
164 .withBody(mockResponse)));
166 sniroHoming.callSniro(execution);
168 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest3AR.json");
169 request = request.replace("28080", wireMockPort);
171 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
172 verify(sniroClient, times(1)).postDemands(argument.capture());
173 assertEquals(request, argument.getValue().toJsonString());
177 public void testCallSniro_success_1Vnf() throws JsonProcessingException, BadResponseException{
180 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
181 .willReturn(aResponse().withStatus(200)
182 .withHeader("Content-Type", "application/json")
183 .withBody(mockResponse)));
185 sniroHoming.callSniro(execution);
187 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
188 verify(sniroClient, times(1)).postDemands(argument.capture());
189 //TODO assertEquals(request, argument.getValue().toJsonString());
193 public void testCallSniro_success_3Allotteds1Vnf() throws JsonProcessingException, BadResponseException{
194 beforeAllottedResource();
197 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
198 .willReturn(aResponse().withStatus(200)
199 .withHeader("Content-Type", "application/json")
200 .withBody(mockResponse)));
202 sniroHoming.callSniro(execution);
204 verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class));
207 @Test(expected = Test.None.class)
208 public void testProcessSolution_success_1VpnLink_1Solution(){
209 beforeVpnBondingLink("1");
211 JSONObject asyncResponse = new JSONObject();
212 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
213 JSONArray solution1 = new JSONArray();
214 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("inventoryType", "service").put("solution", new JSONObject()
215 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
216 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
217 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
218 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
219 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1"))));
220 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("inventoryType", "service").put("solution", new JSONObject()
221 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
222 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
223 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2"))
224 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
225 .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName2")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2"))));
227 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", new JSONArray()));
229 sniroHoming.processSolution(execution, asyncResponse.toString());
231 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
233 assertFalse(si.getVpnBondingLinks().isEmpty());
234 VpnBondingLink link = si.getVpnBondingLinks().get(0);
236 assertFalse(link.getServiceProxies().isEmpty());
238 assertEquals("testServiceInstanceId1", link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
239 assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
240 assertEquals("testVnfHostName1", link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
242 assertEquals("testServiceInstanceId2", link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
243 assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
244 assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
245 assertEquals("testPrimaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
246 assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
247 assertEquals("testSecondaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
248 assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
252 public void testProcessSolution_success_1VpnLink_2Solutions(){
253 beforeVpnBondingLink("1");
255 JSONObject asyncResponse = new JSONObject();
256 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
257 JSONArray solution1 = new JSONArray();
258 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("inventoryType", "service").put("solution", new JSONObject()
259 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
260 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
261 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
262 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
263 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1"))));
264 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("inventoryType", "service").put("solution", new JSONObject()
265 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
266 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
267 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2"))
268 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
269 .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName2")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2"))));
271 JSONArray solution2 = new JSONArray();
272 solution2.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("inventoryType", "service").put("solution", new JSONObject()
273 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId3")))
274 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
275 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName3"))
276 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli3")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
277 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId3")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId3"))));
278 solution2.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("inventoryType", "service").put("solution", new JSONObject()
279 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId4")))
280 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
281 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName4"))
282 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli4")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
283 .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName4")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId4"))));
285 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1).put(solution2)).put("licenseSolutions", new JSONArray()));
287 sniroHoming.processSolution(execution, asyncResponse.toString());
289 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
291 assertFalse(si.getVpnBondingLinks().isEmpty());
292 VpnBondingLink link = si.getVpnBondingLinks().get(0);
293 VpnBondingLink link2 = si.getVpnBondingLinks().get(1);
295 assertFalse(link.getServiceProxies().isEmpty());
297 assertEquals("testServiceInstanceId1", link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
298 assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
299 assertEquals("testVnfHostName1", link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
301 assertEquals("testServiceInstanceId2", link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
302 assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
303 assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
304 assertEquals("testPrimaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
305 assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
306 assertEquals("testSecondaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
307 assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
309 assertNotNull(link2);
310 assertFalse(link2.getServiceProxies().isEmpty());
312 assertEquals("testServiceInstanceId3", link2.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
313 assertNotNull(link2.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
314 assertEquals("testVnfHostName3", link2.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
316 assertEquals("testServiceInstanceId4", link2.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
317 assertNotNull(link2.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
318 assertFalse(link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
319 assertEquals("testPrimaryPnfName4", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
320 assertEquals("primary", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
321 assertEquals("testSecondaryPnfName4", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
322 assertEquals("secondary", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
327 public void testProcessSolution_success_3VpnLink_2Solutions(){
332 public void testProcessSolution_success_3Allotteds_1Solution(){
333 beforeAllottedResource();
335 JSONObject asyncResponse = new JSONObject();
336 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
337 JSONArray solution1 = new JSONArray();
338 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1").put("inventoryType", "service").put("solution", new JSONObject()
339 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
340 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
341 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
342 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
343 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1"))));
344 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2").put("inventoryType", "service").put("solution", new JSONObject()
345 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
346 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
347 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2"))
348 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
349 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2"))));
350 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3").put("inventoryType", "cloud").put("solution", new JSONObject()
351 .put("identifierType", "cloudRegionId").put("identifiers", new JSONArray().put("testCloudRegionId3")))
352 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
353 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
354 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))));
356 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", new JSONArray()));
358 sniroHoming.processSolution(execution, asyncResponse.toString());
360 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
362 assertFalse(si.getAllottedResources().isEmpty());
363 AllottedResource ar = si.getAllottedResources().get(0);
365 assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId());
366 assertNotNull(ar.getParentServiceInstance().getSolutionInfo());
367 assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName());
369 AllottedResource ar2 = si.getAllottedResources().get(1);
371 assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId());
372 assertNotNull(ar2.getParentServiceInstance().getSolutionInfo());
373 assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName());
375 AllottedResource ar3 = si.getAllottedResources().get(2);
377 assertNotNull(ar3.getParentServiceInstance().getSolutionInfo());
378 assertEquals("testCloudRegionId3", ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId());
382 public void testProcessSolution_success_3Allotteds1Vnf_1Solution(){
384 beforeAllottedResource();
386 JSONObject asyncResponse = new JSONObject();
387 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
388 JSONArray solution1 = new JSONArray();
389 JSONArray licenseSolution = new JSONArray();
390 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1").put("inventoryType", "service").put("solution", new JSONObject()
391 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
392 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
393 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
394 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
395 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1"))));
396 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2").put("inventoryType", "service").put("solution", new JSONObject()
397 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
398 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
399 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2"))
400 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
401 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2"))));
402 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3").put("inventoryType", "cloud").put("solution", new JSONObject()
403 .put("identifierType", "cloudRegionId").put("identifiers", new JSONArray().put("testCloudRegionId3")))
404 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
405 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
406 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))));
409 new JSONObject().put("serviceResourceId", "testVnfId1").put("entitlementPoolUUID", new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e").put("j1d563e8-e714-4393-8f99-cc480144a05e"))
410 .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e").put("b1d563e8-e714-4393-8f99-cc480144a05e")));
412 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", licenseSolution));
414 sniroHoming.processSolution(execution, asyncResponse.toString());
416 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
418 assertFalse(si.getAllottedResources().isEmpty());
419 AllottedResource ar = si.getAllottedResources().get(0);
421 assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId());
422 assertNotNull(ar.getParentServiceInstance().getSolutionInfo());
423 assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName());
425 AllottedResource ar2 = si.getAllottedResources().get(1);
427 assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId());
428 assertNotNull(ar2.getParentServiceInstance().getSolutionInfo());
429 assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName());
431 AllottedResource ar3 = si.getAllottedResources().get(2);
433 assertNotNull(ar3.getParentServiceInstance().getSolutionInfo());
434 assertEquals("testCloudRegionId3", ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId());
436 GenericVnf vnf = si.getVnfs().get(0);
438 assertNotNull(vnf.getLicense());
439 assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size());
440 assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0));
445 public void testProcessSolution_success_1Vnf_1Solution(){
448 JSONObject asyncResponse = new JSONObject();
449 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
450 JSONArray licenseSolution = new JSONArray();
453 new JSONObject().put("serviceResourceId", "testVnfId1").put("entitlementPoolUUID", new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e").put("j1d563e8-e714-4393-8f99-cc480144a05e"))
454 .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e").put("b1d563e8-e714-4393-8f99-cc480144a05e")));
456 asyncResponse.put("solutions", new JSONObject().put("licenseSolutions", licenseSolution));
458 sniroHoming.processSolution(execution, asyncResponse.toString());
460 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
462 GenericVnf vnf = si.getVnfs().get(0);
464 assertNotNull(vnf.getLicense());
465 assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size());
466 assertEquals(2, vnf.getLicense().getLicenseKeyGroupUuids().size());
467 assertEquals("f1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getEntitlementPoolUuids().get(0));
468 assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0));
473 @Test(expected = BpmnError.class)
474 public void testCallSniro_error_0Resources() throws BadResponseException, JsonProcessingException{
476 sniroHoming.callSniro(execution);
478 verify(sniroClient, times(0)).postDemands(isA(SniroManagerRequest.class));
481 @Test(expected = BpmnError.class)
482 public void testCallSniro_error_badResponse() throws BadResponseException, JsonProcessingException{
483 beforeAllottedResource();
485 mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}";
486 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
487 .willReturn(aResponse().withStatus(200)
488 .withHeader("Content-Type", "application/json")
489 .withBody(mockResponse)));
491 sniroHoming.callSniro(execution);
493 verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class));