2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.apihandlerinfra;
24 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
25 import static com.github.tomakehurst.wiremock.client.WireMock.post;
26 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
27 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
28 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
29 import static org.hamcrest.CoreMatchers.containsString;
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertNotNull;
32 import static org.junit.Assert.assertNull;
33 import static org.junit.Assert.assertThat;
34 import static org.junit.Assert.assertTrue;
36 import java.io.IOException;
37 import java.nio.file.Files;
38 import java.nio.file.Paths;
39 import java.util.List;
42 import javax.ws.rs.core.HttpHeaders;
43 import javax.ws.rs.core.MediaType;
44 import javax.ws.rs.core.Response;
46 import org.apache.log4j.MDC;
47 import org.junit.Ignore;
48 import org.junit.Test;
49 import org.onap.so.db.request.beans.InfraActiveRequests;
50 import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository;
51 import org.onap.so.logger.MsoLogger;
52 import org.onap.so.serviceinstancebeans.CloudConfiguration;
53 import org.onap.so.serviceinstancebeans.ModelInfo;
54 import org.onap.so.serviceinstancebeans.RequestError;
55 import org.onap.so.serviceinstancebeans.RequestParameters;
56 import org.onap.so.serviceinstancebeans.RequestReferences;
57 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
58 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
59 import org.springframework.beans.factory.annotation.Autowired;
60 import org.springframework.http.HttpEntity;
61 import org.springframework.http.HttpMethod;
62 import org.springframework.http.ResponseEntity;
63 import org.springframework.web.util.UriComponentsBuilder;
65 import com.fasterxml.jackson.annotation.JsonInclude.Include;
66 import com.fasterxml.jackson.core.JsonParseException;
67 import com.fasterxml.jackson.databind.DeserializationFeature;
68 import com.fasterxml.jackson.databind.JsonMappingException;
69 import com.fasterxml.jackson.databind.ObjectMapper;
70 import com.github.tomakehurst.wiremock.http.Fault;
72 import ch.qos.logback.classic.spi.ILoggingEvent;
75 public class ServiceInstancesTest extends BaseTest{
78 private InfraActiveRequestsRepository iar;
81 private ServiceInstances servInstances;
83 private final String servInstanceuri = "/onap/so/infra/serviceInstantiation/";
84 private final String servInstanceUriPrev7 = "/onap/so/infra/serviceInstances/";
87 public String inputStream(String JsonInput)throws IOException{
88 JsonInput = "src/test/resources/ServiceInstanceTest" + JsonInput;
89 String input = new String(Files.readAllBytes(Paths.get(JsonInput)));
93 public ResponseEntity<String> sendRequest(String requestJson, String uriPath, HttpMethod reqMethod){
94 headers.set("Accept", MediaType.APPLICATION_JSON);
95 headers.set("Content-Type",MediaType.APPLICATION_JSON);
97 UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(uriPath));
99 HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
100 ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(),
101 reqMethod, request, String.class);
107 public void test_mapJSONtoMSOStyle() throws IOException{
108 ObjectMapper mapper = new ObjectMapper();
109 mapper.setSerializationInclusion(Include.NON_NULL);
110 String testRequest= inputStream("/ServiceInstanceDefault.json");
111 String resultString = servInstances.mapJSONtoMSOStyle(testRequest, null, false, null);
112 ServiceInstancesRequest sir = mapper.readValue(resultString, ServiceInstancesRequest.class);
113 ModelInfo modelInfo = sir.getRequestDetails().getModelInfo();
114 assertEquals("f7ce78bb-423b-11e7-93f8-0050569a796",modelInfo.getModelCustomizationUuid());
115 assertEquals("modelInstanceName",modelInfo.getModelInstanceName());
116 assertEquals("f7ce78bb-423b-11e7-93f8-0050569a7965",modelInfo.getModelInvariantUuid());
117 assertEquals("10",modelInfo.getModelUuid());
121 public void createServiceInstanceVIDDefault() throws JsonParseException, JsonMappingException, IOException{
122 TestAppender.events.clear();
123 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
124 .willReturn(aResponse().withHeader("Content-Type", "application/json")
125 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
127 headers.set(MsoLogger.ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
128 headers.set(MsoLogger.CLIENT_ID, "VID");
130 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
131 RequestReferences requestReferences = new RequestReferences();
132 requestReferences.setInstanceId("1882939");
133 expectedResponse.setRequestReferences(requestReferences);
134 uri = servInstanceuri + "v5/serviceInstances";
135 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST);
137 ObjectMapper mapper = new ObjectMapper();
138 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
141 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
142 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
143 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
147 for(ILoggingEvent logEvent : TestAppender.events)
148 if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.jersey.JaxRsFilterLogging") &&
149 logEvent.getMarker().getName().equals("ENTRY")
151 Map<String,String> mdc = logEvent.getMDCPropertyMap();
152 assertNotNull(mdc.get(MsoLogger.BEGINTIME));
153 assertNotNull(mdc.get(MsoLogger.REQUEST_ID));
154 assertNotNull(mdc.get(MsoLogger.INVOCATION_ID));
155 assertEquals("UNKNOWN",mdc.get(MsoLogger.PARTNERNAME));
156 assertEquals("onap/so/infra/serviceInstantiation/v5/serviceInstances",mdc.get(MsoLogger.SERVICE_NAME));
157 assertEquals("INPROGRESS",mdc.get(MsoLogger.STATUSCODE));
158 }else if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.jersey.JaxRsFilterLogging") &&
159 logEvent.getMarker().getName().equals("EXIT")){
160 Map<String,String> mdc = logEvent.getMDCPropertyMap();
161 assertNotNull(mdc.get(MsoLogger.BEGINTIME));
162 assertNotNull(mdc.get(MsoLogger.ENDTIME));
163 assertNotNull(mdc.get(MsoLogger.REQUEST_ID));
164 assertNotNull(mdc.get(MsoLogger.INVOCATION_ID));
165 assertEquals("202",mdc.get(MsoLogger.RESPONSECODE));
166 assertEquals("UNKNOWN",mdc.get(MsoLogger.PARTNERNAME));
167 assertEquals("onap/so/infra/serviceInstantiation/v5/serviceInstances",mdc.get(MsoLogger.SERVICE_NAME));
168 assertEquals("COMPLETE",mdc.get(MsoLogger.STATUSCODE));
169 assertNotNull(mdc.get(MsoLogger.RESPONSEDESC));
170 assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
171 assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
172 assertEquals("5.0.0", response.getHeaders().get("X-LatestVersion").get(0));
176 InfraActiveRequests expectedRecord = new InfraActiveRequests();
177 expectedRecord.setRequestStatus("IN_PROGRESS");
178 expectedRecord.setRequestBody(inputStream("/ServiceInstanceDefault.json"));
179 expectedRecord.setAction("createInstance");
180 expectedRecord.setSource("VID");
181 expectedRecord.setVnfId("1882938");
182 expectedRecord.setLastModifiedBy("APIH");
183 expectedRecord.setServiceInstanceId("1882939");
184 expectedRecord.setServiceInstanceName("testService9");
185 expectedRecord.setRequestScope("service");
186 expectedRecord.setRequestorId("xxxxxx");
187 expectedRecord.setRequestAction("createInstance");
188 expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
191 InfraActiveRequests requestRecord = iar.findOneByRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
192 assertEquals(sameBeanAs(expectedRecord).toString(), sameBeanAs(requestRecord).ignoring("startTime").ignoring("modifyTime").toString());
196 public void createServiceInstanceServiceInstancesUri() throws JsonParseException, JsonMappingException, IOException{
197 stubFor(post(urlPathEqualTo("/mso/async/services/CreateGenericALaCarteServiceInstance"))
198 .willReturn(aResponse().withHeader("Content-Type", "application/json")
199 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
202 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
203 RequestReferences requestReferences = new RequestReferences();
204 requestReferences.setInstanceId("1882939");
205 expectedResponse.setRequestReferences(requestReferences);
206 uri = servInstanceUriPrev7 + "v5";
207 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstancePrev7.json"), uri, HttpMethod.POST);
209 ObjectMapper mapper = new ObjectMapper();
210 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
213 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
214 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
215 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
218 public void createServiceInstanceBpelStatusError() throws JsonParseException, JsonMappingException, IOException{
219 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
220 .willReturn(aResponse().withHeader("Content-Type", "application/json")
221 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_BAD_GATEWAY)));
223 uri = servInstanceuri + "v5/serviceInstances";
224 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceStatusError.json"), uri, HttpMethod.POST);
226 assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
229 public void createServiceInstanceBadGateway() throws JsonParseException, JsonMappingException, IOException{
230 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
231 .willReturn(aResponse().withStatus(org.apache.http.HttpStatus.SC_BAD_GATEWAY).withBody("{}")));
233 uri = servInstanceuri + "v5/serviceInstances";
234 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceBadGateway.json"), uri, HttpMethod.POST);
236 assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
239 public void createServiceInstanceBadData() throws JsonParseException, JsonMappingException, IOException{
240 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
241 .willReturn(aResponse().withStatus(org.apache.http.HttpStatus.SC_BAD_GATEWAY).withBody("{I AM REALLY BAD}")));
243 uri = servInstanceuri + "v5/serviceInstances";
244 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceBadGateway.json"), uri, HttpMethod.POST);
246 assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
249 public void createServiceInstanceEmptyResponse() throws JsonParseException, JsonMappingException, IOException{
250 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
251 .willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE)));
253 uri = servInstanceuri + "v5/serviceInstances";
254 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceEmpty.json"), uri, HttpMethod.POST);
256 assertEquals(Response.Status.BAD_GATEWAY.getStatusCode(), response.getStatusCode().value());
259 public void activateServiceInstanceNoRecipeALaCarte() throws JsonParseException, JsonMappingException, IOException{
260 uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/activate";
261 headers.set("X-ECOMP-RequestID", "32807a28-1a14-4b88-b7b3-2950918aa76d");
262 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceALaCarteTrueNoRecipe.json"), uri, HttpMethod.POST);
265 InfraActiveRequests expectedRecord = new InfraActiveRequests();
266 expectedRecord.setRequestStatus("FAILED");
267 expectedRecord.setAction("activateInstance");
268 expectedRecord.setStatusMessage("Recipe could not be retrieved from catalog DB.");
269 expectedRecord.setProgress(new Long(100));
270 expectedRecord.setSource("VID");
271 expectedRecord.setVnfId("1882938");
272 expectedRecord.setRequestBody(inputStream("/ServiceInstanceALaCarteTrueNoRecipe.json"));
273 expectedRecord.setLastModifiedBy("APIH");
274 expectedRecord.setServiceInstanceId("f7ce78bb-423b-11e7-93f8-0050569a7968");
275 expectedRecord.setServiceInstanceName("testService7");
276 expectedRecord.setRequestScope("service");
277 expectedRecord.setRequestAction("activateInstance");
278 expectedRecord.setRequestorId("xxxxxx");
279 expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
282 InfraActiveRequests requestRecord = iar.findOneByRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
283 assertEquals(sameBeanAs(expectedRecord).toString(), sameBeanAs(requestRecord).ignoring("startTime").ignoring("endTime").ignoring("modifyTime").toString());
284 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
287 public void activateServiceInstanceNoRecipe() throws JsonParseException, JsonMappingException, IOException{
288 uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/activate";
289 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceNoRecipe.json"), uri, HttpMethod.POST);
291 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
294 public void activateServiceInstance() throws JsonParseException, JsonMappingException, IOException{
295 stubFor(post(urlPathEqualTo("/mso/async/services/ActivateInstance"))
296 .willReturn(aResponse().withHeader("Content-Type", "application/json")
297 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
299 headers.set("X-TransactionID", "32807a28-1a14-4b88-b7b3-2950918aa76d");
301 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
302 RequestReferences requestReferences = new RequestReferences();
303 requestReferences.setInstanceId("1882939");
304 expectedResponse.setRequestReferences(requestReferences);
305 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/activate";
306 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceActivate.json"), uri, HttpMethod.POST);
308 ObjectMapper mapper = new ObjectMapper();
309 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
311 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
312 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
313 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
316 public void deactivateServiceInstance() throws JsonParseException, JsonMappingException, IOException{
317 stubFor(post(urlPathEqualTo("/mso/async/services/DeactivateInstance"))
318 .willReturn(aResponse().withHeader("Content-Type", "application/json")
319 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
321 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
322 RequestReferences requestReferences = new RequestReferences();
323 requestReferences.setInstanceId("1882939");
324 expectedResponse.setRequestReferences(requestReferences);
325 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/deactivate";
326 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDeactivate.json"), uri, HttpMethod.POST);
328 ObjectMapper mapper = new ObjectMapper();
329 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
331 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
332 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
333 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
336 public void deleteServiceInstance() throws JsonParseException, JsonMappingException, IOException {
337 stubFor(post(urlPathEqualTo("/mso/async/services/DeleteInstance"))
338 .willReturn(aResponse().withHeader("Content-Type", "application/json")
339 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
341 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
342 RequestReferences requestReferences = new RequestReferences();
343 requestReferences.setInstanceId("1882939");
344 expectedResponse.setRequestReferences(requestReferences);
345 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a8868/";
346 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDelete.json"), uri, HttpMethod.DELETE);
348 ObjectMapper mapper = new ObjectMapper();
349 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
351 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
352 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
353 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
356 public void assignServiceInstance() throws JsonParseException, JsonMappingException, IOException {
357 stubFor(post(urlPathEqualTo("/mso/async/services/AssignServiceInstance"))
358 .willReturn(aResponse().withHeader("Content-Type", "application/json")
359 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
361 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
362 RequestReferences requestReferences = new RequestReferences();
363 requestReferences.setInstanceId("1882939");
364 expectedResponse.setRequestReferences(requestReferences);
365 uri = servInstanceuri + "v7" + "/serviceInstances/assign";
366 ResponseEntity<String> response = sendRequest(inputStream("/ServiceAssign.json"), uri, HttpMethod.POST);
368 ObjectMapper mapper = new ObjectMapper();
369 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
371 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
372 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
373 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
377 public void unassignServiceInstance() throws JsonParseException, JsonMappingException, IOException {
378 stubFor(post(urlPathEqualTo("/mso/async/services/UnassignServiceInstance"))
379 .willReturn(aResponse().withHeader("Content-Type", "application/json")
380 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
382 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
383 RequestReferences requestReferences = new RequestReferences();
384 requestReferences.setInstanceId("1882939");
385 expectedResponse.setRequestReferences(requestReferences);
386 uri = servInstanceuri + "v7" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/unassign";
387 ResponseEntity<String> response = sendRequest(inputStream("/ServiceUnassign.json"), uri, HttpMethod.POST);
389 ObjectMapper mapper = new ObjectMapper();
390 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
392 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
393 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
394 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
397 public void createPortConfiguration() throws JsonParseException, JsonMappingException, IOException {
398 stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
399 .willReturn(aResponse().withHeader("Content-Type", "application/json")
400 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
401 headers.set("X-TransactionID", "32807a28-1a14-4b88-b7b3-2950918aa76d");
403 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
404 RequestReferences requestReferences = new RequestReferences();
405 requestReferences.setInstanceId("1882939");
406 expectedResponse.setRequestReferences(requestReferences);
407 uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations";
408 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstancePortConfiguration.json"), uri, HttpMethod.POST);
410 ObjectMapper mapper = new ObjectMapper();
411 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
413 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
414 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
415 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
416 assertTrue(response.getBody().contains("1882939"));
419 public void createPortConfigurationEmptyProductFamilyId() throws JsonParseException, JsonMappingException, IOException {
420 uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations";
421 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceParseFail.json"), uri, HttpMethod.POST);
423 assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
426 public void deletePortConfiguration() throws JsonParseException, JsonMappingException, IOException {
427 stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
428 .willReturn(aResponse().withHeader("Content-Type", "application/json")
429 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
431 headers.set("X-ECOMP-RequestID", "32807a28-1a14-4b88-b7b3-2950918aa76d");
433 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
434 RequestReferences requestReferences = new RequestReferences();
435 requestReferences.setInstanceId("1882939");
436 expectedResponse.setRequestReferences(requestReferences);
437 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970";
438 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstance.json"), uri, HttpMethod.DELETE);
440 ObjectMapper mapper = new ObjectMapper();
441 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
443 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
444 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
445 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
448 public void enablePort() throws JsonParseException, JsonMappingException, IOException {
449 stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
450 .willReturn(aResponse().withHeader("Content-Type", "application/json")
451 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
453 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
454 RequestReferences requestReferences = new RequestReferences();
455 requestReferences.setInstanceId("1882939");
456 expectedResponse.setRequestReferences(requestReferences);
457 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/enablePort";
458 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceEnablePort.json"), uri, HttpMethod.POST);
460 ObjectMapper mapper = new ObjectMapper();
461 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
463 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
464 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
465 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
468 public void disablePort() throws JsonParseException, JsonMappingException, IOException {
469 stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
470 .willReturn(aResponse().withHeader("Content-Type", "application/json")
471 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
473 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
474 RequestReferences requestReferences = new RequestReferences();
475 requestReferences.setInstanceId("1882939");
476 expectedResponse.setRequestReferences(requestReferences);
477 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/disablePort";
478 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDisablePort.json"), uri, HttpMethod.POST);
480 ObjectMapper mapper = new ObjectMapper();
481 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
483 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
484 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
485 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
488 public void activatePort() throws JsonParseException, JsonMappingException, IOException {
489 stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
490 .willReturn(aResponse().withHeader("Content-Type", "application/json")
491 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
493 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
494 RequestReferences requestReferences = new RequestReferences();
495 requestReferences.setInstanceId("1882939");
496 expectedResponse.setRequestReferences(requestReferences);
497 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/activate";
498 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceActivatePort.json"), uri, HttpMethod.POST);
500 ObjectMapper mapper = new ObjectMapper();
501 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
503 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
504 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
505 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
508 public void deactivatePort() throws JsonParseException, JsonMappingException, IOException {
509 stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
510 .willReturn(aResponse().withHeader("Content-Type", "application/json")
511 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
513 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
514 RequestReferences requestReferences = new RequestReferences();
515 requestReferences.setInstanceId("1882939");
516 expectedResponse.setRequestReferences(requestReferences);
517 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/deactivate";
518 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDeactivatePort.json"), uri, HttpMethod.POST);
520 ObjectMapper mapper = new ObjectMapper();
521 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
523 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
524 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
525 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
528 public void addRelationships() throws JsonParseException, JsonMappingException, IOException {
529 stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
530 .willReturn(aResponse().withHeader("Content-Type", "application/json")
531 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
534 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
535 RequestReferences requestReferences = new RequestReferences();
536 requestReferences.setInstanceId("1882939");
537 expectedResponse.setRequestReferences(requestReferences);
538 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/addRelationships";
539 ResponseEntity<String> response = sendRequest(inputStream("/AddRelationships.json"), uri, HttpMethod.POST);
541 ObjectMapper mapper = new ObjectMapper();
542 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
544 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
545 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
546 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
549 public void removeRelationships() throws JsonParseException, JsonMappingException, IOException {
550 stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
551 .willReturn(aResponse().withHeader("Content-Type", "application/json")
552 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
555 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
556 RequestReferences requestReferences = new RequestReferences();
557 requestReferences.setInstanceId("1882939");
558 expectedResponse.setRequestReferences(requestReferences);
559 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/removeRelationships";
560 ResponseEntity<String> response = sendRequest(inputStream("/RemoveRelationships.json"), uri, HttpMethod.POST);
562 ObjectMapper mapper = new ObjectMapper();
563 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
565 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
566 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
567 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
570 public void createVnfInstanceNoALaCarte() throws JsonParseException, JsonMappingException, IOException {
571 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
572 .willReturn(aResponse().withHeader("Content-Type", "application/json")
573 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
576 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
577 RequestReferences requestReferences = new RequestReferences();
578 requestReferences.setInstanceId("1882939");
579 expectedResponse.setRequestReferences(requestReferences);
580 uri = servInstanceuri + "v7" + "/serviceInstances/49585b36-2b5a-443a-8b10-c75d34bb5e46/vnfs";
581 ResponseEntity<String> response = sendRequest(inputStream("/VnfCreateDefault.json"), uri, HttpMethod.POST);
583 ObjectMapper mapper = new ObjectMapper();
584 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
586 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
587 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
588 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
591 public void createVnfInstance() throws JsonParseException, JsonMappingException, IOException {
592 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
593 .willReturn(aResponse().withHeader("Content-Type", "application/json")
594 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
596 String requestId = "b7a6b76f-2ee2-416c-971b-548472a8c5c3";
597 headers.set(MsoLogger.ONAP_REQUEST_ID, requestId);
599 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
600 RequestReferences requestReferences = new RequestReferences();
601 requestReferences.setInstanceId("1882939");
602 expectedResponse.setRequestReferences(requestReferences);
603 uri = servInstanceuri + "v7" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs";
604 ResponseEntity<String> response = sendRequest(inputStream("/VnfWithServiceRelatedInstance.json"), uri, HttpMethod.POST);
606 ObjectMapper mapper = new ObjectMapper();
607 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
609 InfraActiveRequests record = iar.findOneByRequestId(requestId);
610 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
611 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
612 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
613 assertTrue(response.getBody().contains("1882939"));
614 assertEquals(record.getVnfType(), "vSAMP12/test");
617 public void createVnfWithServiceRelatedInstanceFail() throws JsonParseException, JsonMappingException, IOException {
618 uri = servInstanceUriPrev7 + "v6" + "/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs";
619 ResponseEntity<String> response = sendRequest(inputStream("/VnfWithServiceRelatedInstanceFail.json"), uri, HttpMethod.POST);
621 assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
624 public void createVnfInstanceInvalidVnfResource() throws JsonParseException, JsonMappingException, IOException {
625 uri = servInstanceuri + "v7" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs";
626 ResponseEntity<String> response = sendRequest(inputStream("/NoVnfResource.json"), uri, HttpMethod.POST);
628 ObjectMapper mapper = new ObjectMapper();
629 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
630 mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
632 assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
633 RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
634 assertTrue(realResponse.getServiceException().getText().equals("No valid vnfResource is specified"));
637 public void replaceVnfInstance() throws JsonParseException, JsonMappingException, IOException {
638 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
639 .willReturn(aResponse().withHeader("Content-Type", "application/json")
640 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
643 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
644 RequestReferences requestReferences = new RequestReferences();
645 requestReferences.setInstanceId("1882939");
646 expectedResponse.setRequestReferences(requestReferences);
647 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
648 ResponseEntity<String> response = sendRequest(inputStream("/ReplaceVnf.json"), uri, HttpMethod.POST);
650 ObjectMapper mapper = new ObjectMapper();
651 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
653 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
654 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
655 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
658 public void replaceVnfRecreateInstance() throws JsonParseException, JsonMappingException, IOException {
659 stubFor(post(urlPathEqualTo("/mso/async/services/RecreateInfraVce"))
660 .willReturn(aResponse().withHeader("Content-Type", "application/json")
661 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
664 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
665 RequestReferences requestReferences = new RequestReferences();
666 requestReferences.setInstanceId("1882939");
667 expectedResponse.setRequestReferences(requestReferences);
668 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
669 ResponseEntity<String> response = sendRequest(inputStream("/ReplaceVnfRecreate.json"), uri, HttpMethod.POST);
670 logger.debug(response.getBody());
671 ObjectMapper mapper = new ObjectMapper();
672 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
674 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
675 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
676 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
679 public void updateVnfInstance() throws JsonParseException, JsonMappingException, IOException {
680 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
681 .willReturn(aResponse().withHeader("Content-Type", "application/json")
682 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
685 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
686 RequestReferences requestReferences = new RequestReferences();
687 requestReferences.setInstanceId("1882939");
688 expectedResponse.setRequestReferences(requestReferences);
689 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
690 ResponseEntity<String> response = sendRequest(inputStream("/UpdateVnf.json"), uri, HttpMethod.PUT);
692 ObjectMapper mapper = new ObjectMapper();
693 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
695 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
696 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
697 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
700 public void applyUpdatedConfig() throws JsonParseException, JsonMappingException, IOException {
701 stubFor(post(urlPathEqualTo("/mso/async/services/VnfConfigUpdate"))
702 .willReturn(aResponse().withHeader("Content-Type", "application/json")
703 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
705 String requestId = "b7a6b76f-2ee2-416c-971b-548472a8c5c5";
706 headers.set(MsoLogger.ONAP_REQUEST_ID, requestId);
708 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
709 RequestReferences requestReferences = new RequestReferences();
710 requestReferences.setInstanceId("1882939");
711 expectedResponse.setRequestReferences(requestReferences);
712 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/applyUpdatedConfig";
713 ResponseEntity<String> response = sendRequest(inputStream("/ApplyUpdatedConfig.json"), uri, HttpMethod.POST);
715 ObjectMapper mapper = new ObjectMapper();
716 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
718 InfraActiveRequests record = iar.findOneByRequestId(requestId);
719 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
720 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
721 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
722 assertNull(record.getVnfType());
725 public void deleteVnfInstanceV5() throws JsonParseException, JsonMappingException, IOException {
726 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
727 .willReturn(aResponse().withHeader("Content-Type", "application/json")
728 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
731 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
732 RequestReferences requestReferences = new RequestReferences();
733 requestReferences.setInstanceId("1882939");
734 expectedResponse.setRequestReferences(requestReferences);
735 uri = servInstanceuri + "v5" + "/serviceInstances/e446b97d-9c35-437a-95a2-6b4c542c4507/vnfs/49befbfe-fccb-421d-bb4c-0734a43f5ea0";
736 ResponseEntity<String> response = sendRequest(inputStream("/DeleteVnfV5.json"), uri, HttpMethod.DELETE);
738 ObjectMapper mapper = new ObjectMapper();
739 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
741 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
742 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
743 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
746 public void createVfModuleInstance() throws JsonParseException, JsonMappingException, IOException {
747 stubFor(post(urlPathEqualTo("/mso/async/services/CreateVfModuleInfra"))
748 .willReturn(aResponse().withHeader("Content-Type", "application/json")
749 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
752 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
753 RequestReferences requestReferences = new RequestReferences();
754 requestReferences.setInstanceId("1882939");
755 expectedResponse.setRequestReferences(requestReferences);
756 uri = servInstanceuri + "v7" + "/serviceInstances/7a88cbeb-0ec8-4765-a271-4f9e90c3da7b/vnfs/cbba721b-4803-4df7-9347-307c9a955426/vfModules";
757 ResponseEntity<String> response = sendRequest(inputStream("/VfModuleWithRelatedInstances.json"), uri, HttpMethod.POST);
759 ObjectMapper mapper = new ObjectMapper();
760 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
762 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
763 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
764 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
765 assertTrue(response.getBody().contains("1882939"));
768 public void createVfModuleInstanceNoModelCustomization() throws JsonParseException, JsonMappingException, IOException {
769 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
770 .willReturn(aResponse().withHeader("Content-Type", "application/json")
771 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
774 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
775 RequestReferences requestReferences = new RequestReferences();
776 requestReferences.setInstanceId("1882939");
777 expectedResponse.setRequestReferences(requestReferences);
778 uri = servInstanceuri + "v6" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules";
779 ResponseEntity<String> response = sendRequest(inputStream("/VfModuleNoModelCustomization.json"), uri, HttpMethod.POST);
780 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
781 ObjectMapper mapper = new ObjectMapper();
782 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
783 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
786 public void deleteVfModuleInstanceNoMatchingModelUUD() throws JsonParseException, JsonMappingException, IOException {
787 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
788 .willReturn(aResponse().withHeader("Content-Type", "application/json")
789 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
792 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
793 RequestReferences requestReferences = new RequestReferences();
794 requestReferences.setInstanceId("1882939");
795 expectedResponse.setRequestReferences(requestReferences);
796 uri = servInstanceuri + "v6" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
797 ResponseEntity<String> response = sendRequest(inputStream("/VfModuleNoMatchingModelUUID.json"), uri, HttpMethod.DELETE);
799 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
800 ObjectMapper mapper = new ObjectMapper();
801 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
802 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
805 public void createVfModuleInstanceNoRecipe() throws JsonParseException, JsonMappingException, IOException {
806 uri = servInstanceuri + "v6" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules";
807 ResponseEntity<String> response = sendRequest(inputStream("/VfModuleInvalid.json"), uri, HttpMethod.POST);
809 assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
810 ObjectMapper mapper = new ObjectMapper();
811 mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
812 RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
813 assertTrue(realResponse.getServiceException().getText().equals("No valid vfModuleCustomization is specified"));
816 public void replaceVfModuleInstance() throws JsonParseException, JsonMappingException, IOException {
817 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
818 .willReturn(aResponse().withHeader("Content-Type", "application/json")
819 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
822 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
823 RequestReferences requestReferences = new RequestReferences();
824 requestReferences.setInstanceId("1882939");
825 expectedResponse.setRequestReferences(requestReferences);
826 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
827 ResponseEntity<String> response = sendRequest(inputStream("/ReplaceVfModule.json"), uri, HttpMethod.POST);
829 ObjectMapper mapper = new ObjectMapper();
830 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
832 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
833 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
834 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
837 public void updateVfModuleInstance() throws JsonParseException, JsonMappingException, IOException {
838 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
839 .willReturn(aResponse().withHeader("Content-Type", "application/json")
840 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
843 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
844 RequestReferences requestReferences = new RequestReferences();
845 requestReferences.setInstanceId("1882939");
846 expectedResponse.setRequestReferences(requestReferences);
847 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
848 ResponseEntity<String> response = sendRequest(inputStream("/UpdateVfModule.json"), uri, HttpMethod.PUT);
849 logger.debug(response.getBody());
851 ObjectMapper mapper = new ObjectMapper();
852 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
854 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
855 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
856 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
859 public void createVfModuleNoModelType() throws JsonParseException, JsonMappingException, IOException{
860 headers.set(MsoLogger.ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
861 InfraActiveRequests expectedRecord = new InfraActiveRequests();
862 expectedRecord.setRequestStatus("FAILED");
863 expectedRecord.setAction("createInstance");
864 expectedRecord.setStatusMessage("Error parsing request: No valid modelType is specified");
865 expectedRecord.setProgress(new Long(100));
866 expectedRecord.setSource("VID");
867 expectedRecord.setRequestBody(inputStream("/VfModuleNoModelType.json"));
868 expectedRecord.setLastModifiedBy("APIH");
869 expectedRecord.setVfModuleName("testVfModule2");
870 expectedRecord.setVfModuleModelName("serviceModel");
871 expectedRecord.setRequestScope("vfModule");
872 expectedRecord.setRequestAction("createInstance");
873 expectedRecord.setRequestorId("zz9999");
874 expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
875 //VnfType is not sent in this request, should be blank in db
876 expectedRecord.setVnfType("");
877 uri = servInstanceuri + "v5/serviceInstances/32807a28-1a14-4b88-b7b3-2950918aa76d/vnfs/32807a28-1a14-4b88-b7b3-2950918aa76d/vfModules";
879 ResponseEntity<String> response = sendRequest(inputStream("/VfModuleNoModelType.json"), uri, HttpMethod.POST);
881 InfraActiveRequests requestRecord = iar.findOneByRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
882 assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
883 assertEquals(sameBeanAs(expectedRecord).toString(), sameBeanAs(requestRecord).ignoring("startTime").ignoring("endTime").ignoring("modifyTime").toString());
884 assertNotNull(requestRecord.getStartTime());
885 assertNotNull(requestRecord.getEndTime());
888 public void inPlaceSoftwareUpdate() throws JsonParseException, JsonMappingException, IOException {
889 stubFor(post(urlPathEqualTo("/mso/async/services/VnfInPlaceUpdate"))
890 .willReturn(aResponse().withHeader("Content-Type", "application/json")
891 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
894 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
895 RequestReferences requestReferences = new RequestReferences();
896 requestReferences.setInstanceId("1882939");
897 expectedResponse.setRequestReferences(requestReferences);
898 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/inPlaceSoftwareUpdate";
899 ResponseEntity<String> response = sendRequest(inputStream("/InPlaceSoftwareUpdate.json"), uri, HttpMethod.POST);
901 ObjectMapper mapper = new ObjectMapper();
902 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
904 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
905 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
906 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
910 public void inPlaceSoftwareUpdateDuplicate() throws JsonParseException, JsonMappingException, IOException {
911 stubFor(post(urlPathEqualTo("/mso/async/services/VnfInPlaceUpdate"))
912 .willReturn(aResponse().withHeader("Content-Type", "application/json")
913 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
915 InfraActiveRequests req = new InfraActiveRequests();
916 req.setRequestStatus("IN_PROGRESS");
917 req.setAction("inPlaceSoftwareUpdate");
918 req.setProgress(new Long(10));
919 req.setRequestBody(inputStream("/ServiceInstanceALaCarteTrueNoRecipe.json"));
920 req.setServiceInstanceId("f7ce78bb-423b-11e7-93f8-0050569a7908");
921 req.setVnfId("ff305d54-75b4-431b-adb2-eb6b9e5ff033");
922 req.setRequestScope("vnf");
923 req.setVnfName("duplicateCheck123");
924 req.setRequestAction("inPlaceSoftwareUpdate");
925 req.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
929 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
930 RequestReferences requestReferences = new RequestReferences();
931 requestReferences.setInstanceId("1882939");
932 expectedResponse.setRequestReferences(requestReferences);
933 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7908/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff033/inPlaceSoftwareUpdate";
934 ResponseEntity<String> response = sendRequest(inputStream("/InPlaceSoftwareUpdate2.json"), uri, HttpMethod.POST);
936 ObjectMapper mapper = new ObjectMapper();
937 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
939 assertEquals(Response.Status.CONFLICT.getStatusCode(), response.getStatusCode().value());
941 InfraActiveRequests newRecord = iar.findOneByRequestBody(inputStream("/InPlaceSoftwareUpdate2.json"));
943 assertNotNull(newRecord.getServiceInstanceId());
944 assertNotNull(newRecord.getVnfId());
949 public void deleteVfModuleInstance() throws JsonParseException, JsonMappingException, IOException {
950 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
951 .willReturn(aResponse().withHeader("Content-Type", "application/json")
952 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
955 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
956 RequestReferences requestReferences = new RequestReferences();
957 requestReferences.setInstanceId("1882939");
958 expectedResponse.setRequestReferences(requestReferences);
959 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
960 ResponseEntity<String> response = sendRequest(inputStream("/DeleteVfModule.json"), uri, HttpMethod.DELETE);
962 ObjectMapper mapper = new ObjectMapper();
963 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
965 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
966 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
967 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
970 public void deactivateAndCloudDeleteVfModuleInstance() throws JsonParseException, JsonMappingException, IOException {
971 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
972 .willReturn(aResponse().withHeader("Content-Type", "application/json")
973 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
976 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
977 RequestReferences requestReferences = new RequestReferences();
978 requestReferences.setInstanceId("1882939");
979 expectedResponse.setRequestReferences(requestReferences);
980 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000/deactivateAndCloudDelete";
981 ResponseEntity<String> response = sendRequest(inputStream("/DeactivateAndCloudDeleteVfModule.json"), uri, HttpMethod.POST);
983 ObjectMapper mapper = new ObjectMapper();
984 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
986 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
987 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
988 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
991 public void createVolumeGroupInstance() throws JsonParseException, JsonMappingException, IOException {
992 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
993 .willReturn(aResponse().withHeader("Content-Type", "application/json")
994 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
997 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
998 RequestReferences requestReferences = new RequestReferences();
999 requestReferences.setInstanceId("1882939");
1000 expectedResponse.setRequestReferences(requestReferences);
1001 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups";
1002 ResponseEntity<String> response = sendRequest(inputStream("/VolumeGroup.json"), uri, HttpMethod.POST);
1004 ObjectMapper mapper = new ObjectMapper();
1005 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1007 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1008 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1009 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1010 assertTrue(response.getBody().contains("1882939"));
1013 public void updateVolumeGroupInstance() throws JsonParseException, JsonMappingException, IOException {
1014 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1015 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1016 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1019 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1020 RequestReferences requestReferences = new RequestReferences();
1021 requestReferences.setInstanceId("1882939");
1022 expectedResponse.setRequestReferences(requestReferences);
1023 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1024 ResponseEntity<String> response = sendRequest(inputStream("/UpdateVolumeGroup.json"), uri, HttpMethod.PUT);
1026 ObjectMapper mapper = new ObjectMapper();
1027 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1029 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1030 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1031 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1034 public void deleteVolumeGroupInstance() throws JsonParseException, JsonMappingException, IOException {
1035 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1036 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1037 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1040 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1041 RequestReferences requestReferences = new RequestReferences();
1042 requestReferences.setInstanceId("1882939");
1043 expectedResponse.setRequestReferences(requestReferences);
1044 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1045 ResponseEntity<String> response = sendRequest(inputStream("/DeleteVolumeGroup.json"), uri, HttpMethod.DELETE);
1047 ObjectMapper mapper = new ObjectMapper();
1048 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1050 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1051 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1052 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1055 public void createNetworkInstance() throws JsonParseException, JsonMappingException, IOException {
1056 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1057 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1058 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1060 String requestId = "b7a6b76f-2ee2-416c-971b-548472a8c5c4";
1061 headers.set(MsoLogger.ONAP_REQUEST_ID, requestId);
1063 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1064 RequestReferences requestReferences = new RequestReferences();
1065 requestReferences.setInstanceId("1882939");
1066 expectedResponse.setRequestReferences(requestReferences);
1067 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1068 ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreate.json"), uri, HttpMethod.POST);
1070 ObjectMapper mapper = new ObjectMapper();
1071 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1073 InfraActiveRequests record = iar.findOneByRequestId(requestId);
1074 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1075 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1076 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1077 assertEquals(record.getNetworkType(), "TestNetworkType");
1080 public void updateNetworkInstance() throws JsonParseException, JsonMappingException, IOException {
1081 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1082 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1083 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1086 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1087 RequestReferences requestReferences = new RequestReferences();
1088 requestReferences.setInstanceId("1882939");
1089 expectedResponse.setRequestReferences(requestReferences);
1090 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1091 ResponseEntity<String> response = sendRequest(inputStream("/UpdateNetwork.json"), uri, HttpMethod.PUT);
1093 ObjectMapper mapper = new ObjectMapper();
1094 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1096 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1097 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1098 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1099 assertTrue(response.getBody().contains("1882939"));
1102 public void deleteNetworkInstance() throws JsonParseException, JsonMappingException, IOException {
1103 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1104 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1105 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1108 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1109 RequestReferences requestReferences = new RequestReferences();
1110 requestReferences.setInstanceId("1882939");
1111 expectedResponse.setRequestReferences(requestReferences);
1112 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1113 ResponseEntity<String> response = sendRequest(inputStream("/NetworkInstance.json"), uri, HttpMethod.DELETE);
1115 ObjectMapper mapper = new ObjectMapper();
1116 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1118 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1119 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1120 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1123 public void deleteNetworkInstanceNoReqParams() throws JsonParseException, JsonMappingException, IOException {
1124 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1125 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1126 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1129 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1130 RequestReferences requestReferences = new RequestReferences();
1131 requestReferences.setInstanceId("1882939");
1132 expectedResponse.setRequestReferences(requestReferences);
1133 uri = servInstanceuri + "v6" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1134 ResponseEntity<String> response = sendRequest(inputStream("/NetworkInstanceNoReqParams.json"), uri, HttpMethod.DELETE);
1136 ObjectMapper mapper = new ObjectMapper();
1137 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1139 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1140 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1141 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1144 public void convertJsonToServiceInstanceRequestFail() throws JsonParseException, JsonMappingException, IOException {
1145 headers.set(MsoLogger.ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
1147 InfraActiveRequests expectedRecord = new InfraActiveRequests();
1148 expectedRecord.setRequestStatus("FAILED");
1149 expectedRecord.setStatusMessage("Error mapping request: ");
1150 expectedRecord.setProgress(new Long(100));
1151 expectedRecord.setRequestBody(inputStream("/ConvertRequestFail.json"));
1152 expectedRecord.setLastModifiedBy("APIH");
1153 expectedRecord.setRequestScope("network");
1154 expectedRecord.setRequestAction("deleteInstance");
1155 expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
1157 uri = servInstanceuri + "v6" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1158 ResponseEntity<String> response = sendRequest(inputStream("/ConvertRequestFail.json"), uri, HttpMethod.DELETE);
1161 InfraActiveRequests requestRecord = iar.findOneByRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
1163 assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
1164 assertThat(expectedRecord, sameBeanAs(requestRecord).ignoring("startTime").ignoring("endTime").ignoring("modifyTime").ignoring("statusMessage"));
1165 assertThat(requestRecord.getStatusMessage(), containsString("Error mapping request: "));
1166 assertNotNull(requestRecord.getStartTime());
1167 assertNotNull(requestRecord.getEndTime());
1170 public void convertJsonToServiceInstanceRequestConfigurationFail() throws JsonParseException, JsonMappingException, IOException {
1171 uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/configurations/test/enablePort";
1172 ResponseEntity<String> response = sendRequest(inputStream("/ConvertRequestFail.json"), uri, HttpMethod.POST);
1174 assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
1178 public void creatServiceInstanceGRTestApiNoCustomRecipeFound() throws IOException {
1179 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1180 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1181 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1183 uri = servInstanceuri + "v7" + "/serviceInstances";
1184 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceMacro.json"), uri, HttpMethod.POST);
1187 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1188 RequestReferences requestReferences = new RequestReferences();
1189 requestReferences.setInstanceId("1882939");
1190 expectedResponse.setRequestReferences(requestReferences);
1192 ObjectMapper mapper = new ObjectMapper();
1193 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1195 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1196 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1197 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1201 public void createNetworkInstanceTestApiUndefinedUsePropertiesDefault() throws IOException {
1202 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1203 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1204 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1206 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1207 ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateAlternateInstanceName.json"), uri, HttpMethod.POST);
1210 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1211 RequestReferences requestReferences = new RequestReferences();
1212 requestReferences.setInstanceId("1882939");
1213 expectedResponse.setRequestReferences(requestReferences);
1215 ObjectMapper mapper = new ObjectMapper();
1216 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1218 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1219 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1220 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1224 public void createNetworkInstanceTestApiIncorrectUsePropertiesDefault() throws IOException {
1225 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1226 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1227 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1229 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1230 ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateTestApiIncorrect.json"), uri, HttpMethod.POST);
1233 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1234 RequestReferences requestReferences = new RequestReferences();
1235 requestReferences.setInstanceId("1882939");
1236 expectedResponse.setRequestReferences(requestReferences);
1238 ObjectMapper mapper = new ObjectMapper();
1239 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1241 assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
1245 public void createNetworkInstanceTestApiGrApi() throws IOException {
1246 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1247 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1248 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1250 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1251 ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateTestApiGrApi.json"), uri, HttpMethod.POST);
1254 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1255 RequestReferences requestReferences = new RequestReferences();
1256 requestReferences.setInstanceId("1882939");
1257 expectedResponse.setRequestReferences(requestReferences);
1259 ObjectMapper mapper = new ObjectMapper();
1260 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1262 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1263 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1264 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1268 public void createNetworkInstanceTestApiVnfApi() throws IOException {
1269 stubFor(post(urlPathEqualTo("/mso/async/services/CreateNetworkInstance"))
1270 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1271 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1273 uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1274 ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateTestApiVnfApi.json"), uri, HttpMethod.POST);
1277 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1278 RequestReferences requestReferences = new RequestReferences();
1279 requestReferences.setInstanceId("1882939");
1280 expectedResponse.setRequestReferences(requestReferences);
1282 ObjectMapper mapper = new ObjectMapper();
1283 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1285 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1286 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1287 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1291 public void activateServiceInstanceRequestStatus() throws JsonParseException, JsonMappingException, IOException{
1292 stubFor(post(urlPathEqualTo("/mso/async/services/ActivateInstance"))
1293 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1294 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1295 headers.set("X-ECOMP-RequestID", "32807a28-1a14-4b88-b7b3-2950918aa76d");
1297 InfraActiveRequests expectedRecord = new InfraActiveRequests();
1298 expectedRecord.setRequestStatus("FAILED");
1299 expectedRecord.setAction("activateInstance");
1300 expectedRecord.setStatusMessage("Recipe could not be retrieved from catalog DB.");
1301 expectedRecord.setProgress(new Long(100));
1302 expectedRecord.setSource("VID");
1303 expectedRecord.setRequestBody(inputStream("/ServiceInstanceALaCarteTrueNoRecipe.json"));
1304 expectedRecord.setLastModifiedBy("APIH");
1305 expectedRecord.setServiceInstanceId("f7ce78bb-423b-11e7-93f8-0050569a7999");
1306 expectedRecord.setServiceInstanceName("testService1234");
1307 expectedRecord.setRequestScope("service");
1308 expectedRecord.setRequestAction("activateInstance");
1309 expectedRecord.setRequestorId("xxxxxx");
1310 expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
1313 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1314 RequestReferences requestReferences = new RequestReferences();
1315 requestReferences.setInstanceId("1882939");
1316 expectedResponse.setRequestReferences(requestReferences);
1317 uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7999/activate";
1318 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstancePrev8.json"), uri, HttpMethod.POST);
1320 ObjectMapper mapper = new ObjectMapper();
1321 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1323 InfraActiveRequests requestRecord = iar.findOneByRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
1326 assertEquals(Status.IN_PROGRESS.name(), requestRecord.getRequestStatus());
1327 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1328 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1329 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1333 public void invalidRequestId() throws IOException {
1334 String illegalRequestId = "1234";
1335 headers.set("X-ECOMP-RequestID", illegalRequestId);
1337 uri = servInstanceuri + "v5/serviceInstances";
1338 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST);
1340 assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
1341 assertTrue(response.getBody().contains("Request Id " + illegalRequestId + " is not a valid UUID"));
1344 public void invalidBPELResponse() throws IOException{
1345 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1346 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1347 .withBodyFile("Camunda/TestResponseInvalid2.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1349 uri = servInstanceuri + "v5/serviceInstances";
1350 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST);
1352 ObjectMapper mapper = new ObjectMapper();
1353 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1354 mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
1356 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1357 RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
1358 assertEquals("Request Failed due to BPEL error with HTTP Status = 202{\"instanceId\": \"1882939\"}", realResponse.getServiceException().getText());
1362 public void invalidBPELResponse2() throws IOException{
1363 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1364 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1365 .withBodyFile("Camunda/TestResponseInvalid.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1367 uri = servInstanceuri + "v5/serviceInstances";
1368 ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST);
1370 ObjectMapper mapper = new ObjectMapper();
1371 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1372 mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
1374 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1375 RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
1376 assertTrue(realResponse.getServiceException().getText().contains("<aetgt:ErrorMessage>Exception in create execution list 500"));
1380 public void createMacroServiceInstance() throws JsonParseException, JsonMappingException, IOException{
1381 stubFor(post(urlPathEqualTo("/mso/async/services/CreateMacroServiceNetworkVnf"))
1382 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1383 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1386 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1387 RequestReferences requestReferences = new RequestReferences();
1388 requestReferences.setInstanceId("1882939");
1389 expectedResponse.setRequestReferences(requestReferences);
1390 uri = servInstanceUriPrev7 + "v5";
1391 ResponseEntity<String> response = sendRequest(inputStream("/MacroServiceInstance.json"), uri, HttpMethod.POST);
1393 ObjectMapper mapper = new ObjectMapper();
1394 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1397 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1398 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1399 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1403 public void testUserParams() throws JsonParseException, JsonMappingException, IOException {
1404 ObjectMapper mapper = new ObjectMapper();
1405 ServiceInstancesRequest request = mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class);
1406 RequestParameters requestParameters = request.getRequestDetails().getRequestParameters();
1407 String userParamsTxt = inputStream("/userParams.txt");
1409 List<Map<String, Object>> userParams = servInstances.configureUserParams(requestParameters);
1410 System.out.println(userParams);
1411 assertTrue(userParams.size() > 0);
1412 assertTrue(userParams.get(0).containsKey("name"));
1413 assertTrue(userParams.get(0).containsKey("value"));
1414 assertTrue(userParamsTxt.replaceAll("\\s+","").equals(userParams.toString().replaceAll("\\s+","")));
1418 public void testConfigureCloudConfig() throws IOException {
1419 ObjectMapper mapper = new ObjectMapper();
1420 ServiceInstancesRequest request = mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class);
1421 CloudConfiguration cloudConfig = servInstances.configureCloudConfig(request.getRequestDetails().getRequestParameters());
1423 assertEquals("mdt25b", cloudConfig.getLcpCloudRegionId());
1424 assertEquals("aefb697db6524ddebfe4915591b0a347", cloudConfig.getTenantId());
1428 public void testMapToLegacyRequest() throws IOException {
1429 ObjectMapper mapper = new ObjectMapper();
1430 ServiceInstancesRequest request = mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class);
1431 ServiceInstancesRequest expected = mapper.readValue(inputStream("/LegacyMacroServiceInstance.json"), ServiceInstancesRequest.class);
1432 servInstances.mapToLegacyRequest(request.getRequestDetails());
1433 System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(request));
1434 assertThat(request, sameBeanAs(expected));
1437 public void scaleOutVfModule() throws JsonParseException, JsonMappingException, IOException {
1438 stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1439 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1440 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1443 ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1444 RequestReferences requestReferences = new RequestReferences();
1445 requestReferences.setInstanceId("1882939");
1446 expectedResponse.setRequestReferences(requestReferences);
1447 uri = servInstanceuri + "v7" + "/serviceInstances/7a88cbeb-0ec8-4765-a271-4f9e90c3da7b/vnfs/cbba721b-4803-4df7-9347-307c9a955426/vfModules/scaleOut";
1448 ResponseEntity<String> response = sendRequest(inputStream("/ScaleOutRequest.json"), uri, HttpMethod.POST);
1450 ObjectMapper mapper = new ObjectMapper();
1451 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1453 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1454 ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1455 assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1456 assertTrue(response.getBody().contains("1882939"));