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.buildingblock;
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.Matchers.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.BaseTest;
45 import org.onap.so.bpmn.mock.FileUtil;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
50 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy;
51 import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBondingLink;
52 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
53 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters;
54 import org.onap.so.bpmn.servicedecomposition.homingobjects.Candidate;
55 import org.onap.so.bpmn.servicedecomposition.homingobjects.CandidateType;
56 import org.onap.so.client.exception.BadResponseException;
57 import org.onap.so.client.sniro.beans.SniroManagerRequest;
59 import com.fasterxml.jackson.core.JsonProcessingException;
60 import com.fasterxml.jackson.databind.ObjectMapper;
63 public class SniroHomingV2Test extends BaseTest{
65 private ServiceInstance serviceInstance;
67 private RequestContext requestContext;
69 private Customer customer;
70 ObjectMapper mapper = new ObjectMapper();
72 private static final String RESOURCE_PATH = "__files/BuildingBlocks/SniroHoming/";
75 String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}";
78 public void before() {
79 serviceInstance = setServiceInstance();
80 customer = setCustomer();
81 customer.setGlobalCustomerId("testCustomerId");
82 customer.setSubscriberName("testCustomerName");
83 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
85 requestContext = setRequestContext();
86 requestContext.setMsoRequestId("testRequestId");
87 RequestParameters params = new RequestParameters();
88 params.setaLaCarte(false);
89 params.setSubscriptionServiceType("iptollfree");
90 requestContext.setRequestParameters(params);
93 public void beforeVpnBondingLink(String id){
94 VpnBondingLink bondingLink = new VpnBondingLink();
95 bondingLink.setVpnBondingLinkId("testVpnBondingId" + id);
96 bondingLink.getServiceProxies().add(setServiceProxy("1", "transport"));
97 ServiceProxy sp2 = setServiceProxy("2", "infrastructure");
98 Candidate requiredCandidate = new Candidate();
99 requiredCandidate.setCandidateType(CandidateType.VNF_ID);
100 List<String> c = new ArrayList<String>();
102 requiredCandidate.setCandidates(c);
103 sp2.addRequiredCandidates(requiredCandidate);
104 bondingLink.getServiceProxies().add(sp2);
105 serviceInstance.getVpnBondingLinks().add(bondingLink);
109 public void beforeAllottedResource(){
110 serviceInstance.getAllottedResources().add(setAllottedResource("1"));
111 serviceInstance.getAllottedResources().add(setAllottedResource("2"));
112 serviceInstance.getAllottedResources().add(setAllottedResource("3"));
115 public void beforeVnf(){
119 @Test(expected = Test.None.class)
120 public void testCallSniro_success_1VpnLink() throws BadResponseException, IOException{
121 beforeVpnBondingLink("1");
123 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
124 .willReturn(aResponse().withStatus(200)
125 .withHeader("Content-Type", "application/json")
126 .withBody(mockResponse)));
128 sniroHoming.callSniro(execution);
130 String request = FileUtil.readResourceFile(RESOURCE_PATH + "SniroManagerRequest1Vpn.json");
131 request = request.replace("28080", wireMockPort);
133 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
134 verify(sniroClient, times(1)).postDemands(argument.capture());
135 assertEquals(request, argument.getValue().toJsonString());
139 public void testCallSniro_success_3VpnLink() throws JsonProcessingException, BadResponseException{
140 beforeVpnBondingLink("1");
141 beforeVpnBondingLink("2");
142 beforeVpnBondingLink("3");
144 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
145 .willReturn(aResponse().withStatus(200)
146 .withHeader("Content-Type", "application/json")
147 .withBody(mockResponse)));
149 sniroHoming.callSniro(execution);
151 String request = FileUtil.readResourceFile(RESOURCE_PATH + "SniroManagerRequest3Vpn.json");
152 request = request.replace("28080", wireMockPort);
154 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
155 verify(sniroClient, times(1)).postDemands(argument.capture());
156 assertEquals(request, argument.getValue().toJsonString());
160 public void testCallSniro_success_3Allotteds() throws BadResponseException, JsonProcessingException{
161 beforeAllottedResource();
163 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
164 .willReturn(aResponse().withStatus(200)
165 .withHeader("Content-Type", "application/json")
166 .withBody(mockResponse)));
168 sniroHoming.callSniro(execution);
170 String request = FileUtil.readResourceFile(RESOURCE_PATH + "SniroManagerRequest3AR.json");
171 request = request.replace("28080", wireMockPort);
173 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
174 verify(sniroClient, times(1)).postDemands(argument.capture());
175 assertEquals(request, argument.getValue().toJsonString());
179 public void testCallSniro_success_1Vnf() throws JsonProcessingException, BadResponseException{
182 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
183 .willReturn(aResponse().withStatus(200)
184 .withHeader("Content-Type", "application/json")
185 .withBody(mockResponse)));
187 sniroHoming.callSniro(execution);
189 ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class);
190 verify(sniroClient, times(1)).postDemands(argument.capture());
191 //TODO assertEquals(request, argument.getValue().toJsonString());
195 public void testCallSniro_success_3Allotteds1Vnf() throws JsonProcessingException, BadResponseException{
196 beforeAllottedResource();
199 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
200 .willReturn(aResponse().withStatus(200)
201 .withHeader("Content-Type", "application/json")
202 .withBody(mockResponse)));
204 sniroHoming.callSniro(execution);
206 verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class));
209 @Test(expected = Test.None.class)
210 public void testProcessSolution_success_1VpnLink_1Solution(){
211 beforeVpnBondingLink("1");
213 JSONObject asyncResponse = new JSONObject();
214 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
215 JSONArray solution1 = new JSONArray();
216 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("inventoryType", "service").put("solution", new JSONObject()
217 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
218 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
219 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
220 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
221 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1"))));
222 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("inventoryType", "service").put("solution", new JSONObject()
223 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
224 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
225 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2"))
226 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
227 .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName2")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2"))));
229 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", new JSONArray()));
231 sniroHoming.processSolution(execution, asyncResponse.toString());
233 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
235 assertFalse(si.getVpnBondingLinks().isEmpty());
236 VpnBondingLink link = si.getVpnBondingLinks().get(0);
238 assertFalse(link.getServiceProxies().isEmpty());
240 assertEquals("testServiceInstanceId1", link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
241 assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
242 assertEquals("testVnfHostName1", link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
244 assertEquals("testServiceInstanceId2", link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
245 assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
246 assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
247 assertEquals("testPrimaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
248 assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
249 assertEquals("testSecondaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
250 assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
254 public void testProcessSolution_success_1VpnLink_2Solutions(){
255 beforeVpnBondingLink("1");
257 JSONObject asyncResponse = new JSONObject();
258 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
259 JSONArray solution1 = new JSONArray();
260 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("inventoryType", "service").put("solution", new JSONObject()
261 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
262 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
263 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
264 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
265 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1"))));
266 solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("inventoryType", "service").put("solution", new JSONObject()
267 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
268 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
269 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2"))
270 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
271 .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName2")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2"))));
273 JSONArray solution2 = new JSONArray();
274 solution2.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("inventoryType", "service").put("solution", new JSONObject()
275 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId3")))
276 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
277 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName3"))
278 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli3")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
279 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId3")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId3"))));
280 solution2.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("inventoryType", "service").put("solution", new JSONObject()
281 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId4")))
282 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False"))
283 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName4"))
284 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli4")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
285 .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName4")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId4"))));
287 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1).put(solution2)).put("licenseSolutions", new JSONArray()));
289 sniroHoming.processSolution(execution, asyncResponse.toString());
291 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
293 assertFalse(si.getVpnBondingLinks().isEmpty());
294 VpnBondingLink link = si.getVpnBondingLinks().get(0);
295 VpnBondingLink link2 = si.getVpnBondingLinks().get(1);
297 assertFalse(link.getServiceProxies().isEmpty());
299 assertEquals("testServiceInstanceId1", link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
300 assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
301 assertEquals("testVnfHostName1", link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
303 assertEquals("testServiceInstanceId2", link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
304 assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
305 assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
306 assertEquals("testPrimaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
307 assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
308 assertEquals("testSecondaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
309 assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
311 assertNotNull(link2);
312 assertFalse(link2.getServiceProxies().isEmpty());
314 assertEquals("testServiceInstanceId3", link2.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId());
315 assertNotNull(link2.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo());
316 assertEquals("testVnfHostName3", link2.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName());
318 assertEquals("testServiceInstanceId4", link2.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId());
319 assertNotNull(link2.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo());
320 assertFalse(link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty());
321 assertEquals("testPrimaryPnfName4", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName());
322 assertEquals("primary", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole());
323 assertEquals("testSecondaryPnfName4", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName());
324 assertEquals("secondary", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole());
329 public void testProcessSolution_success_3VpnLink_2Solutions(){
334 public void testProcessSolution_success_3Allotteds_1Solution(){
335 beforeAllottedResource();
337 JSONObject asyncResponse = new JSONObject();
338 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
339 JSONArray solution1 = new JSONArray();
340 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1").put("inventoryType", "service").put("solution", new JSONObject()
341 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
342 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
343 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
344 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
345 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1"))));
346 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2").put("inventoryType", "service").put("solution", new JSONObject()
347 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
348 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
349 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2"))
350 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
351 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2"))));
352 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3").put("inventoryType", "cloud").put("solution", new JSONObject()
353 .put("identifierType", "cloudRegionId").put("identifiers", new JSONArray().put("testCloudRegionId3")))
354 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
355 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic"))
356 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))));
358 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", new JSONArray()));
360 sniroHoming.processSolution(execution, asyncResponse.toString());
362 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
364 assertFalse(si.getAllottedResources().isEmpty());
365 AllottedResource ar = si.getAllottedResources().get(0);
367 assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId());
368 assertNotNull(ar.getParentServiceInstance().getSolutionInfo());
369 assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName());
371 AllottedResource ar2 = si.getAllottedResources().get(1);
373 assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId());
374 assertNotNull(ar2.getParentServiceInstance().getSolutionInfo());
375 assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName());
377 AllottedResource ar3 = si.getAllottedResources().get(2);
379 assertNotNull(ar3.getParentServiceInstance().getSolutionInfo());
380 assertEquals("testCloudRegionId3", ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId());
384 public void testProcessSolution_success_3Allotteds1Vnf_1Solution(){
386 beforeAllottedResource();
388 JSONObject asyncResponse = new JSONObject();
389 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
390 JSONArray solution1 = new JSONArray();
391 JSONArray licenseSolution = new JSONArray();
392 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1").put("inventoryType", "service").put("solution", new JSONObject()
393 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1")))
394 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
395 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1"))
396 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
397 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1"))));
398 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2").put("inventoryType", "service").put("solution", new JSONObject()
399 .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2")))
400 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
401 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2"))
402 .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3"))
403 .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2"))));
404 solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3").put("inventoryType", "cloud").put("solution", new JSONObject()
405 .put("identifierType", "cloudRegionId").put("identifiers", new JSONArray().put("testCloudRegionId3")))
406 .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True"))
407 .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2"))
408 .put(new JSONObject().put("key", "aicVersion").put("value", "3"))));
411 new JSONObject().put("serviceResourceId", "testVnfId1").put("entitlementPoolUUID", new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e").put("j1d563e8-e714-4393-8f99-cc480144a05e"))
412 .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e").put("b1d563e8-e714-4393-8f99-cc480144a05e")));
414 asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", licenseSolution));
416 sniroHoming.processSolution(execution, asyncResponse.toString());
418 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
420 assertFalse(si.getAllottedResources().isEmpty());
421 AllottedResource ar = si.getAllottedResources().get(0);
423 assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId());
424 assertNotNull(ar.getParentServiceInstance().getSolutionInfo());
425 assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName());
427 AllottedResource ar2 = si.getAllottedResources().get(1);
429 assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId());
430 assertNotNull(ar2.getParentServiceInstance().getSolutionInfo());
431 assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName());
433 AllottedResource ar3 = si.getAllottedResources().get(2);
435 assertNotNull(ar3.getParentServiceInstance().getSolutionInfo());
436 assertEquals("testCloudRegionId3", ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId());
438 GenericVnf vnf = si.getVnfs().get(0);
440 assertNotNull(vnf.getLicense());
441 assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size());
442 assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0));
447 public void testProcessSolution_success_1Vnf_1Solution(){
450 JSONObject asyncResponse = new JSONObject();
451 asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed");
452 JSONArray licenseSolution = new JSONArray();
455 new JSONObject().put("serviceResourceId", "testVnfId1").put("entitlementPoolUUID", new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e").put("j1d563e8-e714-4393-8f99-cc480144a05e"))
456 .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e").put("b1d563e8-e714-4393-8f99-cc480144a05e")));
458 asyncResponse.put("solutions", new JSONObject().put("licenseSolutions", licenseSolution));
460 sniroHoming.processSolution(execution, asyncResponse.toString());
462 ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
464 GenericVnf vnf = si.getVnfs().get(0);
466 assertNotNull(vnf.getLicense());
467 assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size());
468 assertEquals(2, vnf.getLicense().getLicenseKeyGroupUuids().size());
469 assertEquals("f1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getEntitlementPoolUuids().get(0));
470 assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0));
475 @Test(expected = BpmnError.class)
476 public void testCallSniro_error_0Resources() throws BadResponseException, JsonProcessingException{
478 sniroHoming.callSniro(execution);
480 verify(sniroClient, times(0)).postDemands(isA(SniroManagerRequest.class));
483 @Test(expected = BpmnError.class)
484 public void testCallSniro_error_badResponse() throws BadResponseException, JsonProcessingException{
485 beforeAllottedResource();
487 mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}";
488 stubFor(post(urlEqualTo("/sniro/api/placement/v2"))
489 .willReturn(aResponse().withStatus(200)
490 .withHeader("Content-Type", "application/json")
491 .withBody(mockResponse)));
493 sniroHoming.callSniro(execution);
495 verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class));