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;
62 public class SniroHomingV2Test extends BaseIntegrationTest{
64 private ServiceInstance serviceInstance;
66 private RequestContext requestContext;
68 private Customer customer;
69 ObjectMapper mapper = new ObjectMapper();
71 private static final String RESOURCE_PATH = "__files/BuildingBlocks/SniroHoming/";
74 String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}";
77 public void before() {
78 serviceInstance = setServiceInstance();
79 customer = setCustomer();
80 customer.setGlobalCustomerId("testCustomerId");
81 customer.setSubscriberName("testCustomerName");
82 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
84 requestContext = setRequestContext();
85 requestContext.setMsoRequestId("testRequestId");
86 RequestParameters params = new RequestParameters();
87 params.setaLaCarte(false);
88 params.setSubscriptionServiceType("iptollfree");
89 requestContext.setRequestParameters(params);
92 public void beforeVpnBondingLink(String id){
93 VpnBondingLink bondingLink = new VpnBondingLink();
94 bondingLink.setVpnBondingLinkId("testVpnBondingId" + id);
95 bondingLink.getServiceProxies().add(setServiceProxy("1", "transport"));
96 ServiceProxy sp2 = setServiceProxy("2", "infrastructure");
97 Candidate requiredCandidate = new Candidate();
98 requiredCandidate.setCandidateType(CandidateType.VNF_ID);
99 List<String> c = new ArrayList<String>();
101 requiredCandidate.setCandidates(c);
102 sp2.addRequiredCandidates(requiredCandidate);
103 bondingLink.getServiceProxies().add(sp2);
104 serviceInstance.getVpnBondingLinks().add(bondingLink);
108 public void beforeAllottedResource(){
109 serviceInstance.getAllottedResources().add(setAllottedResource("1"));
110 serviceInstance.getAllottedResources().add(setAllottedResource("2"));
111 serviceInstance.getAllottedResources().add(setAllottedResource("3"));
114 public void beforeVnf(){
118 @Test(expected = Test.None.class)
119 public void testCallSniro_success_1VpnLink() throws BadResponseException, IOException{
120 beforeVpnBondingLink("1");
122 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
123 .willReturn(aResponse().withStatus(200)
124 .withHeader("Content-Type", "application/json")
125 .withBody(mockResponse)));
127 sniroHoming.callSniro(execution);
129 String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest1Vpn.json");
130 request = request.replace("28080", wireMockPort);
132 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
133 verify(sniroClient, times(1)).postDemands(argument.capture());
134 assertEquals(request, argument.getValue().toJsonString());
138 public void testCallSniro_success_3VpnLink() throws JsonProcessingException, BadResponseException{
139 beforeVpnBondingLink("1");
140 beforeVpnBondingLink("2");
141 beforeVpnBondingLink("3");
143 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
144 .willReturn(aResponse().withStatus(200)
145 .withHeader("Content-Type", "application/json")
146 .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, JsonProcessingException{
160 beforeAllottedResource();
162 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
163 .willReturn(aResponse().withStatus(200)
164 .withHeader("Content-Type", "application/json")
165 .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 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
182 .willReturn(aResponse().withStatus(200)
183 .withHeader("Content-Type", "application/json")
184 .withBody(mockResponse)));
186 sniroHoming.callSniro(execution);
188 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
189 verify(sniroClient, times(1)).postDemands(argument.capture());
190 //TODO assertEquals(request, argument.getValue().toJsonString());
194 public void testCallSniro_success_3Allotteds1Vnf() throws JsonProcessingException, BadResponseException{
195 beforeAllottedResource();
198 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
199 .willReturn(aResponse().withStatus(200)
200 .withHeader("Content-Type", "application/json")
201 .withBody(mockResponse)));
203 sniroHoming.callSniro(execution);
205 verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class));
208 @Test(expected = Test.None.class)
209 public void testProcessSolution_success_1VpnLink_1Solution(){
210 beforeVpnBondingLink("1");
212 JSONObject asyncResponse = new JSONObject();
213 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
214 JSONArray solution1 = new JSONArray();
215 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("inventoryType", "service").put("solution", new JSONObject()
216 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
217 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
218 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
219 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
220 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1"))));
221 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("inventoryType", "service").put("solution", new JSONObject()
222 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
223 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
224 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2"))
225 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
226 .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName2")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2"))));
228 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", new JSONArray()));
230 sniroHoming.processSolution(execution, asyncResponse.toString());
232 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
234 assertFalse(si.getVpnBondingLinks().isEmpty());
235 VpnBondingLink link = si.getVpnBondingLinks().get(0);
237 assertFalse(link.getServiceProxies().isEmpty());
239 assertEquals("testServiceInstanceId1", link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
240 assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
241 assertEquals("testVnfHostName1", link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
243 assertEquals("testServiceInstanceId2", link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
244 assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
245 assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
246 assertEquals("testPrimaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
247 assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
248 assertEquals("testSecondaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
249 assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
253 public void testProcessSolution_success_1VpnLink_2Solutions(){
254 beforeVpnBondingLink("1");
256 JSONObject asyncResponse = new JSONObject();
257 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
258 JSONArray solution1 = new JSONArray();
259 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("inventoryType", "service").put("solution", new JSONObject()
260 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
261 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
262 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
263 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
264 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1"))));
265 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("inventoryType", "service").put("solution", new JSONObject()
266 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
267 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
268 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2"))
269 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
270 .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName2")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2"))));
272 JSONArray solution2 = new JSONArray();
273 solution2.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("inventoryType", "service").put("solution", new JSONObject()
274 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId3")))
275 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
276 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName3"))
277 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli3")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
278 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId3")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId3"))));
279 solution2.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("inventoryType", "service").put("solution", new JSONObject()
280 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId4")))
281 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
282 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName4"))
283 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli4")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
284 .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName4")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId4"))));
286 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1).put(solution2)).put("licenseSolutions", new JSONArray()));
288 sniroHoming.processSolution(execution, asyncResponse.toString());
290 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
292 assertFalse(si.getVpnBondingLinks().isEmpty());
293 VpnBondingLink link = si.getVpnBondingLinks().get(0);
294 VpnBondingLink link2 = si.getVpnBondingLinks().get(1);
296 assertFalse(link.getServiceProxies().isEmpty());
298 assertEquals("testServiceInstanceId1", link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
299 assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
300 assertEquals("testVnfHostName1", link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
302 assertEquals("testServiceInstanceId2", link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
303 assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
304 assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
305 assertEquals("testPrimaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
306 assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
307 assertEquals("testSecondaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
308 assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
310 assertNotNull(link2);
311 assertFalse(link2.getServiceProxies().isEmpty());
313 assertEquals("testServiceInstanceId3", link2.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
314 assertNotNull(link2.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
315 assertEquals("testVnfHostName3", link2.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
317 assertEquals("testServiceInstanceId4", link2.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
318 assertNotNull(link2.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
319 assertFalse(link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
320 assertEquals("testPrimaryPnfName4", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
321 assertEquals("primary", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
322 assertEquals("testSecondaryPnfName4", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
323 assertEquals("secondary", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
328 public void testProcessSolution_success_3VpnLink_2Solutions(){
333 public void testProcessSolution_success_3Allotteds_1Solution(){
334 beforeAllottedResource();
336 JSONObject asyncResponse = new JSONObject();
337 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
338 JSONArray solution1 = new JSONArray();
339 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1").put("inventoryType", "service").put("solution", new JSONObject()
340 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
341 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
342 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
343 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
344 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1"))));
345 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2").put("inventoryType", "service").put("solution", new JSONObject()
346 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
347 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
348 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2"))
349 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
350 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2"))));
351 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3").put("inventoryType", "cloud").put("solution", new JSONObject()
352 .put("identifierType", "cloudRegionId").put("identifiers", new JSONArray().put("testCloudRegionId3")))
353 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
354 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
355 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))));
357 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", new JSONArray()));
359 sniroHoming.processSolution(execution, asyncResponse.toString());
361 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
363 assertFalse(si.getAllottedResources().isEmpty());
364 AllottedResource ar = si.getAllottedResources().get(0);
366 assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId());
367 assertNotNull(ar.getParentServiceInstance().getSolutionInfo());
368 assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName());
370 AllottedResource ar2 = si.getAllottedResources().get(1);
372 assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId());
373 assertNotNull(ar2.getParentServiceInstance().getSolutionInfo());
374 assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName());
376 AllottedResource ar3 = si.getAllottedResources().get(2);
378 assertNotNull(ar3.getParentServiceInstance().getSolutionInfo());
379 assertEquals("testCloudRegionId3", ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId());
383 public void testProcessSolution_success_3Allotteds1Vnf_1Solution(){
385 beforeAllottedResource();
387 JSONObject asyncResponse = new JSONObject();
388 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
389 JSONArray solution1 = new JSONArray();
390 JSONArray licenseSolution = new JSONArray();
391 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1").put("inventoryType", "service").put("solution", new JSONObject()
392 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
393 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
394 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
395 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
396 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1"))));
397 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2").put("inventoryType", "service").put("solution", new JSONObject()
398 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
399 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
400 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2"))
401 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
402 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2"))));
403 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3").put("inventoryType", "cloud").put("solution", new JSONObject()
404 .put("identifierType", "cloudRegionId").put("identifiers", new JSONArray().put("testCloudRegionId3")))
405 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
406 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
407 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))));
410 new JSONObject().put("serviceResourceId", "testVnfId1").put("entitlementPoolUUID", new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e").put("j1d563e8-e714-4393-8f99-cc480144a05e"))
411 .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e").put("b1d563e8-e714-4393-8f99-cc480144a05e")));
413 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", licenseSolution));
415 sniroHoming.processSolution(execution, asyncResponse.toString());
417 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
419 assertFalse(si.getAllottedResources().isEmpty());
420 AllottedResource ar = si.getAllottedResources().get(0);
422 assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId());
423 assertNotNull(ar.getParentServiceInstance().getSolutionInfo());
424 assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName());
426 AllottedResource ar2 = si.getAllottedResources().get(1);
428 assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId());
429 assertNotNull(ar2.getParentServiceInstance().getSolutionInfo());
430 assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName());
432 AllottedResource ar3 = si.getAllottedResources().get(2);
434 assertNotNull(ar3.getParentServiceInstance().getSolutionInfo());
435 assertEquals("testCloudRegionId3", ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId());
437 GenericVnf vnf = si.getVnfs().get(0);
439 assertNotNull(vnf.getLicense());
440 assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size());
441 assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0));
446 public void testProcessSolution_success_1Vnf_1Solution(){
449 JSONObject asyncResponse = new JSONObject();
450 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
451 JSONArray licenseSolution = new JSONArray();
454 new JSONObject().put("serviceResourceId", "testVnfId1").put("entitlementPoolUUID", new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e").put("j1d563e8-e714-4393-8f99-cc480144a05e"))
455 .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e").put("b1d563e8-e714-4393-8f99-cc480144a05e")));
457 asyncResponse.put("solutions", new JSONObject().put("licenseSolutions", licenseSolution));
459 sniroHoming.processSolution(execution, asyncResponse.toString());
461 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
463 GenericVnf vnf = si.getVnfs().get(0);
465 assertNotNull(vnf.getLicense());
466 assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size());
467 assertEquals(2, vnf.getLicense().getLicenseKeyGroupUuids().size());
468 assertEquals("f1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getEntitlementPoolUuids().get(0));
469 assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0));
474 @Test(expected = BpmnError.class)
475 public void testCallSniro_error_0Resources() throws BadResponseException, JsonProcessingException{
477 sniroHoming.callSniro(execution);
479 verify(sniroClient, times(0)).postDemands(isA(SniroManagerRequest.class));
482 @Test(expected = BpmnError.class)
483 public void testCallSniro_error_badResponse() throws BadResponseException, JsonProcessingException{
484 beforeAllottedResource();
486 mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}";
487 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
488 .willReturn(aResponse().withStatus(200)
489 .withHeader("Content-Type", "application/json")
490 .withBody(mockResponse)));
492 sniroHoming.callSniro(execution);
494 verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class));