Merge "Create PServer/PInterface Objects in AAI based on openstack's stack resources"
[so.git] / mso-api-handlers / mso-api-handler-infra / src / test / java / org / onap / so / apihandlerinfra / ServiceInstancesTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.apihandlerinfra;
22
23
24 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
25 import static com.github.tomakehurst.wiremock.client.WireMock.get;
26 import static com.github.tomakehurst.wiremock.client.WireMock.post;
27 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
28 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
29 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertFalse;
32 import static org.junit.Assert.assertNotNull;
33 import static org.junit.Assert.assertNull;
34 import static org.junit.Assert.assertThat;
35 import static org.junit.Assert.assertTrue;
36 import static org.onap.logging.filter.base.Constants.HttpHeaders.ONAP_REQUEST_ID;
37 import static org.onap.so.logger.HttpHeadersConstants.REQUESTOR_ID;
38 import static org.onap.logging.filter.base.Constants.HttpHeaders.TRANSACTION_ID;
39 import static org.onap.logging.filter.base.Constants.HttpHeaders.CLIENT_ID;
40 import java.io.File;
41 import java.io.IOException;
42 import java.net.MalformedURLException;
43 import java.net.URL;
44 import java.nio.file.Files;
45 import java.nio.file.Paths;
46 import java.util.List;
47 import java.util.Map;
48 import javax.ws.rs.core.MediaType;
49 import javax.ws.rs.core.Response;
50 import org.apache.http.HttpStatus;
51 import org.junit.Before;
52 import org.junit.Test;
53 import org.mockito.Mockito;
54 import org.onap.logging.ref.slf4j.ONAPLogConstants;
55 import org.onap.so.apihandlerinfra.exceptions.ContactCamundaException;
56 import org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException;
57 import org.onap.so.db.catalog.beans.Service;
58 import org.onap.so.db.catalog.beans.ServiceRecipe;
59 import org.onap.so.db.request.beans.InfraActiveRequests;
60 import org.onap.so.serviceinstancebeans.CloudConfiguration;
61 import org.onap.so.serviceinstancebeans.ModelInfo;
62 import org.onap.so.serviceinstancebeans.ModelType;
63 import org.onap.so.serviceinstancebeans.RequestDetails;
64 import org.onap.so.serviceinstancebeans.RequestError;
65 import org.onap.so.serviceinstancebeans.RequestInfo;
66 import org.onap.so.serviceinstancebeans.RequestParameters;
67 import org.onap.so.serviceinstancebeans.RequestReferences;
68 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
69 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
70 import org.springframework.beans.factory.annotation.Autowired;
71 import org.springframework.beans.factory.annotation.Value;
72 import org.springframework.http.HttpEntity;
73 import org.springframework.http.HttpHeaders;
74 import org.springframework.http.HttpMethod;
75 import org.springframework.http.ResponseEntity;
76 import org.springframework.util.ResourceUtils;
77 import org.springframework.web.util.UriComponentsBuilder;
78 import com.fasterxml.jackson.core.JsonParseException;
79 import com.fasterxml.jackson.core.JsonProcessingException;
80 import com.fasterxml.jackson.databind.DeserializationFeature;
81 import com.fasterxml.jackson.databind.JsonMappingException;
82 import com.fasterxml.jackson.databind.ObjectMapper;
83 import com.github.tomakehurst.wiremock.http.Fault;
84 import ch.qos.logback.classic.spi.ILoggingEvent;
85
86 public class ServiceInstancesTest extends BaseTest {
87
88     private final ObjectMapper mapper = new ObjectMapper();
89     private ObjectMapper errorMapper = new ObjectMapper();
90
91     @Autowired
92     private ServiceInstances servInstances;
93
94     @Autowired
95     private RequestHandlerUtils requestHandlerUtils;
96
97     @Value("${wiremock.server.port}")
98     private String wiremockPort;
99
100     private final String servInstanceuri = "/onap/so/infra/serviceInstantiation/";
101     private final String servInstanceUriPrev7 = "/onap/so/infra/serviceInstances/";
102     private String uri;
103     private URL selfLink;
104     private URL initialUrl;
105     private int initialPort;
106     private HttpHeaders headers;
107
108     @Before
109     public void beforeClass() {
110         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
111         errorMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
112         errorMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
113         // set headers
114         headers = new HttpHeaders();
115         headers.set(ONAPLogConstants.Headers.PARTNER_NAME, "test_name");
116         headers.set(TRANSACTION_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
117         headers.set(ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
118         headers.set(ONAPLogConstants.MDCs.REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
119         headers.set(CLIENT_ID, "VID");
120         headers.set(REQUESTOR_ID, "xxxxxx");
121         try { // generate one-time port number to avoid RANDOM port number later.
122             initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH));
123             initialPort = initialUrl.getPort();
124         } catch (MalformedURLException e) {
125             e.printStackTrace();
126         }
127         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests.*")).willReturn(aResponse()
128                 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_OK)));
129         Mockito.doReturn(null).when(requestsDbClient).getInfraActiveRequestbyRequestId(Mockito.any());
130     }
131
132     public String inputStream(String JsonInput) throws IOException {
133         JsonInput = "src/test/resources/ServiceInstanceTest" + JsonInput;
134         return new String(Files.readAllBytes(Paths.get(JsonInput)));
135     }
136
137     private URL createExpectedSelfLink(String version, String requestId) {
138         System.out.println("createdUrl: " + initialUrl.toString());
139         try {
140             selfLink = new URL(initialUrl.toString().concat("/").concat(version).concat("/").concat(requestId));
141         } catch (MalformedURLException e) {
142             e.printStackTrace();
143         }
144         return selfLink;
145     }
146
147     private String getWiremockResponseForCatalogdb(String file) {
148         try {
149             File resource = ResourceUtils.getFile("classpath:__files/catalogdb/" + file);
150             return new String(Files.readAllBytes(resource.toPath())).replaceAll("localhost:8090",
151                     "localhost:" + wiremockPort);
152         } catch (IOException e) {
153             e.printStackTrace();
154             return null;
155         }
156
157     }
158
159     public ResponseEntity<String> sendRequest(String requestJson, String uriPath, HttpMethod reqMethod,
160             HttpHeaders headers) {
161
162         if (!headers.containsKey(HttpHeaders.ACCEPT)) {
163             headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
164         }
165         if (!headers.containsKey(HttpHeaders.CONTENT_TYPE)) {
166             headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
167         }
168
169         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(uriPath, initialPort));
170
171         HttpEntity<String> request = new HttpEntity<>(requestJson, headers);
172
173         return restTemplate.exchange(builder.toUriString(), reqMethod, request, String.class);
174     }
175
176     public ResponseEntity<String> sendRequest(String requestJson, String uriPath, HttpMethod reqMethod) {
177         return sendRequest(requestJson, uriPath, reqMethod, new HttpHeaders());
178     }
179
180     @Test
181     public void createServiceInstanceVIDDefault() throws IOException {
182         TestAppender.events.clear();
183
184         ServiceRecipe serviceRecipe = new ServiceRecipe();
185         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
186         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
187         serviceRecipe.setAction(Action.createInstance.toString());
188         serviceRecipe.setId(1);
189         serviceRecipe.setRecipeTimeout(180);
190         Service defaultService = new Service();
191         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
192
193
194         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
195                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
196                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
197
198         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
199                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
200                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
201
202         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
203                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
204                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
205
206         // expect
207         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
208         RequestReferences requestReferences = new RequestReferences();
209         requestReferences.setInstanceId("1882939");
210         requestReferences.setRequestSelfLink(createExpectedSelfLink("v5", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
211         expectedResponse.setRequestReferences(requestReferences);
212         uri = servInstanceuri + "v5/serviceInstances";
213         ResponseEntity<String> response =
214                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
215
216         // then
217         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
218         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
219         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
220
221
222
223         for (ILoggingEvent logEvent : TestAppender.events)
224             if (logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.SOAuditLogContainerFilter")
225                     && logEvent.getMarker() != null && logEvent.getMarker().getName().equals("ENTRY")) {
226                 Map<String, String> mdc = logEvent.getMDCPropertyMap();
227                 assertNotNull(mdc.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP));
228                 assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
229                 assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID));
230                 assertEquals("UNKNOWN", mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME));
231                 assertEquals("onap/so/infra/serviceInstantiation/v5/serviceInstances",
232                         mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME));
233                 assertEquals("INPROGRESS", mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
234             } else if (logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.SOAuditLogContainerFilter")
235                     && logEvent.getMarker() != null && logEvent.getMarker().getName().equals("EXIT")) {
236                 Map<String, String> mdc = logEvent.getMDCPropertyMap();
237                 assertNotNull(mdc.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP));
238                 assertNotNull(mdc.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP));
239                 assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
240                 assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID));
241                 assertEquals("202", mdc.get(ONAPLogConstants.MDCs.RESPONSE_CODE));
242                 assertEquals("UNKNOWN", mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME));
243                 assertEquals("onap/so/infra/serviceInstantiation/v5/serviceInstances",
244                         mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME));
245                 assertEquals("COMPLETE", mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
246                 assertNotNull(mdc.get(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION));
247                 assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
248                 assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
249                 assertEquals("5.0.0", response.getHeaders().get("X-LatestVersion").get(0));
250             }
251     }
252
253     @Test
254     public void createServiceInstanceServiceInstancesUri() throws IOException {
255         ServiceRecipe serviceRecipe = new ServiceRecipe();
256         serviceRecipe.setOrchestrationUri("/mso/async/services/CreateGenericALaCarteServiceInstance");
257         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
258         serviceRecipe.setAction(Action.createInstance.toString());
259         serviceRecipe.setId(1);
260         serviceRecipe.setRecipeTimeout(180);
261         Service defaultService = new Service();
262         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
263
264         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/CreateGenericALaCarteServiceInstance"))
265                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
266                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
267
268
269         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
270                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
271                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
272
273         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
274                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
275                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
276         // expect
277         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
278         RequestReferences requestReferences = new RequestReferences();
279         requestReferences.setInstanceId("1882939");
280         requestReferences.setRequestSelfLink(createExpectedSelfLink("v5", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
281         expectedResponse.setRequestReferences(requestReferences);
282         uri = servInstanceuri + "v5";
283         ResponseEntity<String> response =
284                 sendRequest(inputStream("/ServiceInstancePrev7.json"), uri, HttpMethod.POST, headers);
285
286         // then
287         assertEquals(404, response.getStatusCode().value());
288         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
289     }
290
291     @Test
292     public void createServiceInstanceBpelStatusError() throws IOException {
293         ServiceRecipe serviceRecipe = new ServiceRecipe();
294         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
295         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
296         serviceRecipe.setAction(Action.createInstance.toString());
297         serviceRecipe.setId(1);
298         serviceRecipe.setRecipeTimeout(180);
299         Service defaultService = new Service();
300         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
301
302
303         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")).willReturn(aResponse()
304                 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
305                 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_BAD_GATEWAY)));
306
307
308         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
309                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
310                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
311
312         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
313                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
314                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
315
316         uri = servInstanceuri + "v5/serviceInstances";
317         ResponseEntity<String> response =
318                 sendRequest(inputStream("/ServiceInstanceStatusError.json"), uri, HttpMethod.POST);
319
320         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
321     }
322
323     @Test
324     public void createServiceInstanceBadGateway() throws IOException {
325         ServiceRecipe serviceRecipe = new ServiceRecipe();
326         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
327         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
328         serviceRecipe.setAction(Action.createInstance.toString());
329         serviceRecipe.setId(1);
330         serviceRecipe.setRecipeTimeout(180);
331         Service defaultService = new Service();
332         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
333
334         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
335                 .willReturn(aResponse().withStatus(org.apache.http.HttpStatus.SC_BAD_GATEWAY).withBody("{}")));
336
337         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
338                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
339                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
340
341         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
342                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
343                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
344
345         uri = servInstanceuri + "v5/serviceInstances";
346         ResponseEntity<String> response =
347                 sendRequest(inputStream("/ServiceInstanceBadGateway.json"), uri, HttpMethod.POST);
348
349         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
350     }
351
352     @Test
353     public void createServiceInstanceEmptyResponse() throws IOException {
354         ServiceRecipe serviceRecipe = new ServiceRecipe();
355         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
356         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
357         serviceRecipe.setAction(Action.createInstance.toString());
358         serviceRecipe.setId(1);
359         serviceRecipe.setRecipeTimeout(180);
360         Service defaultService = new Service();
361         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
362
363         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
364                 .willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE)));
365
366         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
367                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
368                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
369
370         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
371                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
372                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
373
374         uri = servInstanceuri + "v5/serviceInstances";
375         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceEmpty.json"), uri, HttpMethod.POST);
376
377         assertEquals(Response.Status.BAD_GATEWAY.getStatusCode(), response.getStatusCode().value());
378     }
379
380     @Test
381     public void activateServiceInstanceNoRecipeALaCarte() throws IOException {
382         TestAppender.events.clear();
383         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/activate";
384         HttpHeaders requestIDheaders = new HttpHeaders();
385         requestIDheaders.set(ONAPLogConstants.Headers.REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
386         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceALaCarteTrueNoRecipe.json"), uri,
387                 HttpMethod.POST, requestIDheaders);
388
389         Service defaultService = new Service();
390         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
391
392         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
393                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
394                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
395
396
397         wireMockServer.stubFor(get(urlMatching(
398                 ".*/serviceRecipe/search/findFirstByServiceModelUUIDAndAction?serviceModelUUID=d88da85c-d9e8-4f73-b837-3a72a431622a&action=activateInstance"))
399                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
400                                 .withStatus(HttpStatus.SC_NOT_FOUND)));
401
402         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
403
404         for (ILoggingEvent logEvent : TestAppender.events) {
405             if (logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.SOAuditLogContainerFilter")
406                     && logEvent.getMarker() != null && logEvent.getMarker().getName().equals("ENTRY")) {
407                 Map<String, String> mdc = logEvent.getMDCPropertyMap();
408                 assertEquals("32807a28-1a14-4b88-b7b3-2950918aa76d", mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
409                 assertNotNull(mdc.get("PartnerName"));
410             }
411         }
412     }
413
414     @Test
415     public void activateServiceInstanceNoRecipe() throws IOException {
416         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/activate";
417         Service defaultService = new Service();
418         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
419         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
420                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
421                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
422
423         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search/.*")).willReturn(aResponse()
424                 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_NOT_FOUND)));
425
426         ResponseEntity<String> response =
427                 sendRequest(inputStream("/ServiceInstanceNoRecipe.json"), uri, HttpMethod.POST);
428
429         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
430     }
431
432     @Test
433     public void activateServiceInstance() throws IOException {
434         ServiceRecipe serviceRecipe = new ServiceRecipe();
435         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
436         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
437         serviceRecipe.setAction(Action.createInstance.toString());
438         serviceRecipe.setId(1);
439         serviceRecipe.setRecipeTimeout(180);
440         Service defaultService = new Service();
441         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
442
443         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
444                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
445                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
446
447         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
448                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
449                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
450
451         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
452                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
453                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
454         // expected response
455         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
456         RequestReferences requestReferences = new RequestReferences();
457         requestReferences.setInstanceId("1882939");
458         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
459         expectedResponse.setRequestReferences(requestReferences);
460         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/activate";
461         ResponseEntity<String> response =
462                 sendRequest(inputStream("/ServiceInstanceActivate.json"), uri, HttpMethod.POST, headers);
463
464         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
465         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
466         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
467     }
468
469     @Test
470     public void deactivateServiceInstance() throws IOException {
471
472         ServiceRecipe serviceRecipe = new ServiceRecipe();
473         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
474         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
475         serviceRecipe.setAction(Action.createInstance.toString());
476         serviceRecipe.setId(1);
477         serviceRecipe.setRecipeTimeout(180);
478         Service defaultService = new Service();
479         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
480
481         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
482                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
483                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
484
485         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
486                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
487                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
488
489         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
490                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
491                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
492
493         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
494                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
495                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
496
497         // expected response
498         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
499         RequestReferences requestReferences = new RequestReferences();
500         requestReferences.setInstanceId("1882939");
501         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
502         expectedResponse.setRequestReferences(requestReferences);
503         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/deactivate";
504         ResponseEntity<String> response =
505                 sendRequest(inputStream("/ServiceInstanceDeactivate.json"), uri, HttpMethod.POST, headers);
506
507         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
508         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
509         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
510     }
511
512     @Test
513     public void deleteServiceInstance() throws IOException {
514         ServiceRecipe serviceRecipe = new ServiceRecipe();
515         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
516         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
517         serviceRecipe.setAction(Action.createInstance.toString());
518         serviceRecipe.setId(1);
519         serviceRecipe.setRecipeTimeout(180);
520         Service defaultService = new Service();
521         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
522
523         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
524                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
525                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
526
527         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
528                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
529                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
530
531         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
532                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
533                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
534
535         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
536                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
537                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
538         // expected response
539         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
540         RequestReferences requestReferences = new RequestReferences();
541         requestReferences.setInstanceId("1882939");
542         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
543         expectedResponse.setRequestReferences(requestReferences);
544         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a8868/";
545         ResponseEntity<String> response =
546                 sendRequest(inputStream("/ServiceInstanceDelete.json"), uri, HttpMethod.DELETE, headers);
547
548         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
549         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
550         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
551     }
552
553     @Test
554     public void assignServiceInstance() throws IOException {
555         ServiceRecipe serviceRecipe = new ServiceRecipe();
556         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
557         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
558         serviceRecipe.setAction(Action.createInstance.toString());
559         serviceRecipe.setId(1);
560         serviceRecipe.setRecipeTimeout(180);
561         Service defaultService = new Service();
562         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
563
564         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
565                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
566                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
567
568         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
569                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
570                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
571
572         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
573                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
574                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
575
576         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
577                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
578                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
579         // expected response
580         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
581         RequestReferences requestReferences = new RequestReferences();
582         requestReferences.setInstanceId("1882939");
583         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
584         expectedResponse.setRequestReferences(requestReferences);
585         uri = servInstanceuri + "v7" + "/serviceInstances/assign";
586         ResponseEntity<String> response =
587                 sendRequest(inputStream("/ServiceAssign.json"), uri, HttpMethod.POST, headers);
588
589         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
590         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
591         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
592     }
593
594     @Test
595     public void unassignServiceInstance() throws IOException {
596         ServiceRecipe serviceRecipe = new ServiceRecipe();
597         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
598         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
599         serviceRecipe.setAction(Action.createInstance.toString());
600         serviceRecipe.setId(1);
601         serviceRecipe.setRecipeTimeout(180);
602         Service defaultService = new Service();
603         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
604
605         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
606                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
607                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
608
609         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
610                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
611                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
612
613         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
614                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
615                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
616
617         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
618                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
619                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
620         // expected response
621         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
622         RequestReferences requestReferences = new RequestReferences();
623         requestReferences.setInstanceId("1882939");
624         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
625         expectedResponse.setRequestReferences(requestReferences);
626         uri = servInstanceuri + "v7" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/unassign";
627         ResponseEntity<String> response =
628                 sendRequest(inputStream("/ServiceUnassign.json"), uri, HttpMethod.POST, headers);
629
630         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
631         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
632         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
633     }
634
635     @Test
636     public void createPortConfiguration() throws IOException {
637         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
638                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
639                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
640         // expected response
641         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
642         RequestReferences requestReferences = new RequestReferences();
643         requestReferences.setInstanceId("1882939");
644         requestReferences.setRequestSelfLink(createExpectedSelfLink("v5", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
645         expectedResponse.setRequestReferences(requestReferences);
646         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations";
647         ResponseEntity<String> response =
648                 sendRequest(inputStream("/ServiceInstancePortConfiguration.json"), uri, HttpMethod.POST, headers);
649
650         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
651         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
652         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
653         assertTrue(response.getBody().contains("1882939"));
654     }
655
656     @Test
657     public void createPortConfigurationEmptyProductFamilyId() throws IOException {
658         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations";
659         ResponseEntity<String> response =
660                 sendRequest(inputStream("/ServiceInstanceParseFail.json"), uri, HttpMethod.POST);
661
662         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
663     }
664
665     @Test
666     public void deletePortConfiguration() throws IOException {
667         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
668                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
669                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
670
671         // expected response
672         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
673         RequestReferences requestReferences = new RequestReferences();
674         requestReferences.setInstanceId("1882939");
675         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
676         expectedResponse.setRequestReferences(requestReferences);
677         uri = servInstanceuri + "v7"
678                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970";
679         ResponseEntity<String> response =
680                 sendRequest(inputStream("/ServiceInstance.json"), uri, HttpMethod.DELETE, headers);
681
682         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
683         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
684         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
685     }
686
687     @Test
688     public void enablePort() throws IOException {
689         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
690                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
691                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
692         // expected response
693         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
694         RequestReferences requestReferences = new RequestReferences();
695         requestReferences.setInstanceId("1882939");
696         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
697         expectedResponse.setRequestReferences(requestReferences);
698         uri = servInstanceuri + "v7"
699                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/enablePort";
700         ResponseEntity<String> response =
701                 sendRequest(inputStream("/ServiceInstanceEnablePort.json"), uri, HttpMethod.POST, headers);
702
703         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
704         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
705         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
706     }
707
708     @Test
709     public void disablePort() throws IOException {
710         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
711                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
712                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
713         // expected response
714         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
715         RequestReferences requestReferences = new RequestReferences();
716         requestReferences.setInstanceId("1882939");
717         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
718         expectedResponse.setRequestReferences(requestReferences);
719         uri = servInstanceuri + "v7"
720                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/disablePort";
721         ResponseEntity<String> response =
722                 sendRequest(inputStream("/ServiceInstanceDisablePort.json"), uri, HttpMethod.POST, headers);
723
724         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
725         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
726         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
727     }
728
729     @Test
730     public void activatePort() throws IOException {
731         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
732                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
733                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
734         // expected response
735         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
736         RequestReferences requestReferences = new RequestReferences();
737         requestReferences.setInstanceId("1882939");
738         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
739         expectedResponse.setRequestReferences(requestReferences);
740         uri = servInstanceuri + "v7"
741                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/activate";
742         ResponseEntity<String> response =
743                 sendRequest(inputStream("/ServiceInstanceActivatePort.json"), uri, HttpMethod.POST, headers);
744
745         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
746         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
747         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
748     }
749
750     @Test
751     public void deactivatePort() throws IOException {
752         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
753                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
754                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
755         // expected response
756         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
757         RequestReferences requestReferences = new RequestReferences();
758         requestReferences.setInstanceId("1882939");
759         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
760         expectedResponse.setRequestReferences(requestReferences);
761         uri = servInstanceuri + "v7"
762                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/deactivate";
763         ResponseEntity<String> response =
764                 sendRequest(inputStream("/ServiceInstanceDeactivatePort.json"), uri, HttpMethod.POST, headers);
765
766         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
767         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
768         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
769     }
770
771     @Test
772     public void addRelationships() throws IOException {
773         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
774                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
775                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
776         // expected response
777         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
778         RequestReferences requestReferences = new RequestReferences();
779         requestReferences.setInstanceId("1882939");
780         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
781         expectedResponse.setRequestReferences(requestReferences);
782         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/addRelationships";
783         ResponseEntity<String> response =
784                 sendRequest(inputStream("/AddRelationships.json"), uri, HttpMethod.POST, headers);
785
786         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
787         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
788         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
789     }
790
791     @Test
792     public void removeRelationships() throws IOException {
793         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
794                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
795                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
796         // expected response
797         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
798         RequestReferences requestReferences = new RequestReferences();
799         requestReferences.setInstanceId("1882939");
800         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
801         expectedResponse.setRequestReferences(requestReferences);
802         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/removeRelationships";
803         ResponseEntity<String> response =
804                 sendRequest(inputStream("/RemoveRelationships.json"), uri, HttpMethod.POST, headers);
805
806         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
807         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
808         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
809     }
810
811     @Test
812     public void createVnfInstanceNoALaCarte() throws IOException {
813         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
814                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
815                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
816
817
818         wireMockServer.stubFor(get(urlMatching(
819                 ".*/vnfResourceCustomization/search/findByModelCustomizationUUID[?]MODEL_CUSTOMIZATION_UUID=68dc9a92-214c-11e7-93ae-92361f002671"))
820                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
821                                 .withBody(getWiremockResponseForCatalogdb(
822                                         "vnfResourceCustomization_ReplaceVnf_Response.json"))
823                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
824
825         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/1/vnfResources"))
826                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
827                         .withBody(getWiremockResponseForCatalogdb("vnfResources_ReplaceVnf_Response.json"))
828                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
829
830         wireMockServer.stubFor(get(urlMatching(
831                 ".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]nfRole=GR-API-DEFAULT&action=createInstance"))
832                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
833                                 .withBody(getWiremockResponseForCatalogdb("vnfRecipeReplaceInstance_Response.json"))
834                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
835
836         // expected response
837         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
838         RequestReferences requestReferences = new RequestReferences();
839         requestReferences.setInstanceId("1882939");
840         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
841         expectedResponse.setRequestReferences(requestReferences);
842         uri = servInstanceuri + "v7" + "/serviceInstances/49585b36-2b5a-443a-8b10-c75d34bb5e46/vnfs";
843         ResponseEntity<String> response =
844                 sendRequest(inputStream("/VnfCreateDefault.json"), uri, HttpMethod.POST, headers);
845
846         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
847         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
848         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
849     }
850
851     @Test
852     public void createVnfInstance() throws IOException {
853         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
854                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
855                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
856
857         wireMockServer.stubFor(get(urlMatching(".*/service/5df8b6de-2083-11e7-93ae-92361f002672"))
858                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
859                         .withBody(getWiremockResponseForCatalogdb("serviceVnf_Response.json"))
860                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
861         wireMockServer.stubFor(get(urlMatching(".*/service/5df8b6de-2083-11e7-93ae-92361f002672/vnfCustomizations"))
862                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
863                         .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomizationsList_Response.json"))
864                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
865
866
867         wireMockServer.stubFor(
868                 get(urlMatching(".*/vnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002672/vnfResources"))
869                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
870                                 .withBody(getWiremockResponseForCatalogdb("vnfResourcesCreateVnf_Response.json"))
871                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
872
873         wireMockServer.stubFor(get(urlMatching(
874                 ".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]nfRole=GR-API-DEFAULT&action=createInstance"))
875                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
876                                 .withBody(getWiremockResponseForCatalogdb("vnfRecipeCreateInstance_Response.json"))
877                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
878
879         // expected response
880         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
881         RequestReferences requestReferences = new RequestReferences();
882         requestReferences.setInstanceId("1882939");
883         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
884         expectedResponse.setRequestReferences(requestReferences);
885         uri = servInstanceuri + "v7" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs";
886         ResponseEntity<String> response =
887                 sendRequest(inputStream("/VnfWithServiceRelatedInstance.json"), uri, HttpMethod.POST, headers);
888
889         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
890         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
891         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
892         assertTrue(response.getBody().contains("1882939"));
893     }
894
895     @Test
896     public void createVnfWithServiceRelatedInstanceFail() throws IOException {
897         uri = servInstanceUriPrev7 + "v6" + "/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs";
898         ResponseEntity<String> response =
899                 sendRequest(inputStream("/VnfWithServiceRelatedInstanceFail.json"), uri, HttpMethod.POST);
900
901         assertEquals(404, response.getStatusCode().value());
902     }
903
904     @Test
905     public void createVnfInstanceInvalidVnfResource() throws IOException {
906         uri = servInstanceuri + "v7" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs";
907         ResponseEntity<String> response = sendRequest(inputStream("/NoVnfResource.json"), uri, HttpMethod.POST);
908
909         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
910         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
911         assertEquals("No valid vnfResource is specified", realResponse.getServiceException().getText());
912     }
913
914     @Test
915     public void replaceVnfInstance() throws IOException {
916         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
917                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
918                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
919
920         wireMockServer.stubFor(get(urlMatching(
921                 ".*/vnfResourceCustomization/search/findByModelCustomizationUUID[?]MODEL_CUSTOMIZATION_UUID=68dc9a92-214c-11e7-93ae-92361f002671"))
922                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
923                                 .withBody(getWiremockResponseForCatalogdb(
924                                         "vnfResourceCustomization_ReplaceVnf_Response.json"))
925                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
926
927         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/1/vnfResources"))
928                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
929                         .withBody(getWiremockResponseForCatalogdb("vnfResources_ReplaceVnf_Response.json"))
930                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
931
932         wireMockServer.stubFor(get(urlMatching(
933                 ".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]nfRole=GR-API-DEFAULT&action=replaceInstance"))
934                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
935                                 .withBody(getWiremockResponseForCatalogdb("vnfRecipeReplaceInstance_Response.json"))
936                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
937         // expected response
938         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
939         RequestReferences requestReferences = new RequestReferences();
940         requestReferences.setInstanceId("1882939");
941         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
942         expectedResponse.setRequestReferences(requestReferences);
943         uri = servInstanceuri + "v7"
944                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
945         ResponseEntity<String> response = sendRequest(inputStream("/ReplaceVnf.json"), uri, HttpMethod.POST, headers);
946
947         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
948         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
949         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
950     }
951
952     @Test
953     public void replaceVnfRecreateInstance() throws IOException {
954         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/RecreateInfraVce"))
955                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
956                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
957
958         wireMockServer.stubFor(get(urlMatching(
959                 ".*/vnfResourceCustomization/search/findByModelCustomizationUUID[?]MODEL_CUSTOMIZATION_UUID=68dc9a92-214c-11e7-93ae-92361f002674"))
960                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
961                                 .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomization_Response.json"))
962                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
963
964         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/4/vnfResources"))
965                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
966                         .withBody(getWiremockResponseForCatalogdb("vnfResources_Response.json"))
967                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
968
969         wireMockServer.stubFor(get(urlMatching(
970                 ".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]nfRole=TEST&action=replaceInstance"))
971                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
972                                 .withBody(getWiremockResponseForCatalogdb("vnfRecipe_Response.json"))
973                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
974
975         // expected response
976         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
977         RequestReferences requestReferences = new RequestReferences();
978         requestReferences.setInstanceId("1882939");
979         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
980         expectedResponse.setRequestReferences(requestReferences);
981         uri = servInstanceuri + "v7"
982                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
983         ResponseEntity<String> response =
984                 sendRequest(inputStream("/ReplaceVnfRecreate.json"), uri, HttpMethod.POST, headers);
985         logger.debug(response.getBody());
986
987         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
988         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
989         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
990     }
991
992     @Test
993     public void recreateVnfInstance() throws IOException {
994         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
995                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
996                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
997
998         wireMockServer.stubFor(get(urlMatching(
999                 ".*/vnfResourceCustomization/search/findByModelCustomizationUUID[?]MODEL_CUSTOMIZATION_UUID=68dc9a92-214c-11e7-93ae-92361f002674"))
1000                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1001                                 .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomization_Response"))
1002                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1003
1004         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/4/vnfResources"))
1005                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1006                         .withBody(getWiremockResponseForCatalogdb("vnfResources_Response.json"))
1007                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1008
1009         wireMockServer.stubFor(get(urlMatching(
1010                 ".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]nfRole=GR-API-DEFAULT&action=recreateInstance"))
1011                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1012                                 .withBody(getWiremockResponseForCatalogdb("vnfRecipe_ResponseWorkflowAction.json"))
1013                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1014
1015         // expected response
1016         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1017         RequestReferences requestReferences = new RequestReferences();
1018         requestReferences.setInstanceId("1882939");
1019         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1020         expectedResponse.setRequestReferences(requestReferences);
1021         uri = servInstanceuri + "v7"
1022                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/recreate";
1023         ResponseEntity<String> response = sendRequest(inputStream("/VnfRecreate.json"), uri, HttpMethod.POST, headers);
1024         logger.debug(response.getBody());
1025
1026         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1027         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1028         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1029     }
1030
1031     @Test
1032     public void updateVnfInstance() throws IOException {
1033         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1034                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1035                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1036
1037         wireMockServer.stubFor(get(urlMatching(
1038                 ".*/vnfResourceCustomization/search/findByModelCustomizationUUID[?]MODEL_CUSTOMIZATION_UUID=68dc9a92-214c-11e7-93ae-92361f002674"))
1039                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1040                                 .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomization_Response.json"))
1041                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1042
1043         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/4/vnfResources"))
1044                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1045                         .withBody(getWiremockResponseForCatalogdb("vnfResources_Response.json"))
1046                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1047
1048         wireMockServer.stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction"
1049                 + "[?]nfRole=GR-API-DEFAULT&action=updateInstance"))
1050                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1051                                 .withBody(getWiremockResponseForCatalogdb("UpdateVnfRecipe_Response.json"))
1052                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1053
1054         // expected response
1055         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1056         RequestReferences requestReferences = new RequestReferences();
1057         requestReferences.setInstanceId("1882939");
1058         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1059         expectedResponse.setRequestReferences(requestReferences);
1060         uri = servInstanceuri + "v7"
1061                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1062         ResponseEntity<String> response = sendRequest(inputStream("/UpdateVnf.json"), uri, HttpMethod.PUT, headers);
1063
1064         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1065         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1066         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1067     }
1068
1069     @Test
1070     public void applyUpdatedConfig() throws IOException {
1071         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/VnfConfigUpdate"))
1072                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1073                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1074
1075
1076         wireMockServer.stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction"
1077                 + "[?]nfRole=GR-API-DEFAULT&action=applyUpdatedConfig"))
1078                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1079                                 .withBody(getWiremockResponseForCatalogdb("vnfRecipeApplyUpdatedConfig_Response.json"))
1080                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1081
1082         // expected response
1083         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1084         RequestReferences requestReferences = new RequestReferences();
1085         requestReferences.setInstanceId("1882939");
1086         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1087         expectedResponse.setRequestReferences(requestReferences);
1088         uri = servInstanceuri + "v7"
1089                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/applyUpdatedConfig";
1090         ResponseEntity<String> response =
1091                 sendRequest(inputStream("/ApplyUpdatedConfig.json"), uri, HttpMethod.POST, headers);
1092
1093         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1094         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1095         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1096     }
1097
1098     @Test
1099     public void deleteVnfInstanceV5() throws IOException {
1100         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1101                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1102                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1103
1104         wireMockServer.stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction"
1105                 + "[?]nfRole=GR-API-DEFAULT&action=deleteInstance"))
1106                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1107                                 .withBody(getWiremockResponseForCatalogdb("vnfRecipeDelete_Response.json"))
1108                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1109         // expected response
1110         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1111         RequestReferences requestReferences = new RequestReferences();
1112         requestReferences.setInstanceId("1882939");
1113         requestReferences.setRequestSelfLink(createExpectedSelfLink("v5", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1114         expectedResponse.setRequestReferences(requestReferences);
1115         uri = servInstanceuri + "v5"
1116                 + "/serviceInstances/e446b97d-9c35-437a-95a2-6b4c542c4507/vnfs/49befbfe-fccb-421d-bb4c-0734a43f5ea0";
1117         ResponseEntity<String> response =
1118                 sendRequest(inputStream("/DeleteVnfV5.json"), uri, HttpMethod.DELETE, headers);
1119
1120         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1121         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1122         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1123     }
1124
1125     @Test
1126     public void createVfModuleInstance() throws IOException {
1127         wireMockServer.stubFor(get(urlMatching(
1128                 "/vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc\\?MODEL_CUSTOMIZATION_UUID=cb82ffd8-252a-11e7-93ae-92361f002671"))
1129                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1130                                 .withBody(getWiremockResponseForCatalogdb("vfModuleCustomization_Response.json"))
1131                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1132
1133         wireMockServer.stubFor(get(urlMatching("/vfModule/20c4431c-246d-11e7-93ae-92361f002671"))
1134                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1135                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1136                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1137
1138         wireMockServer.stubFor(get(urlMatching("/vfModuleCustomization/1/vfModule"))
1139                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1140                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1141                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1142
1143         wireMockServer.stubFor(get(urlMatching(
1144                 "/vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc\\?MODEL_CUSTOMIZATION_UUID=20c4431c-246d-11e7-93ae-92361f002671"))
1145                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1146                                 .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1147                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1148
1149         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/CreateVfModuleInfra"))
1150                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1151                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1152
1153         wireMockServer.stubFor(get(urlMatching(
1154                 "/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1155                         + "[?]vfModuleModelUUID=20c4431c-246d-11e7-93ae-92361f002671&vnfComponentType=vfModule&action=createInstance"))
1156                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1157                                         .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipe_Response.json"))
1158                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1159         // expected response
1160         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1161         RequestReferences requestReferences = new RequestReferences();
1162         requestReferences.setInstanceId("1882939");
1163         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1164         expectedResponse.setRequestReferences(requestReferences);
1165         uri = servInstanceuri + "v7"
1166                 + "/serviceInstances/7a88cbeb-0ec8-4765-a271-4f9e90c3da7b/vnfs/cbba721b-4803-4df7-9347-307c9a955426/vfModules";
1167         ResponseEntity<String> response =
1168                 sendRequest(inputStream("/VfModuleWithRelatedInstances.json"), uri, HttpMethod.POST, headers);
1169
1170         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1171         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1172         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1173         assertTrue(response.getBody().contains("1882939"));
1174     }
1175
1176     @Test
1177     public void createVfModuleInstanceNoModelCustomization() throws IOException {
1178         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/CreateVfModuleInfra"))
1179                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1180                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1181
1182         wireMockServer.stubFor(get(urlMatching(".*/vnfResource/fe6478e4-ea33-3346-ac12-ab121484a3fe"))
1183                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1184                         .withBody(getWiremockResponseForCatalogdb("vnfResourceForVfModule_Response.json"))
1185                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1186
1187         wireMockServer
1188                 .stubFor(get(urlMatching(".*/vnfResourceCustomization/search/findByModelInstanceNameAndVnfResources"
1189                         + "[?]MODEL_INSTANCE_NAME=test&VNF_RESOURCE_MODEL_UUID=fe6478e4-ea33-3346-ac12-ab121484a3fe"))
1190                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1191                                         .withBody(getWiremockResponseForCatalogdb(
1192                                                 "vnfResourceCustomizationForVfModule_Response.json"))
1193                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1194
1195         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/3/vfModuleCustomizations"))
1196                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1197                         .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationsPCM_Response.json"))
1198                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1199
1200         wireMockServer.stubFor(get(urlMatching(
1201                 ".*/vfModuleCustomization/search/findFirstByModelCustomizationUUIDAndVfModuleModelUUIDOrderByCreatedDesc[?]"
1202                         + "MODEL_CUSTOMIZATION_UUID=b4ea86b4-253f-11e7-93ae-92361f002672&MODEL_UUID=066de97e-253e-11e7-93ae-92361f002672"))
1203                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1204                                         .withBody(getWiremockResponseForCatalogdb(
1205                                                 "vfModuleCustomizationPCM_Response.json"))
1206                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1207
1208         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/2/vfModule"))
1209                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1210                         .withBody(getWiremockResponseForCatalogdb("vfModulePCM_Response.json"))
1211                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1212
1213         wireMockServer.stubFor(get(urlMatching(".*/vfModule/066de97e-253e-11e7-93ae-92361f002672"))
1214                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1215                         .withBody(getWiremockResponseForCatalogdb("vfModulePCM_Response.json"))
1216                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1217
1218
1219         wireMockServer.stubFor(
1220                 get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVnfComponentTypeAndAction"
1221                         + "[?]vnfComponentType=vfModule&action=createInstance"))
1222                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1223                                         .withBody(getWiremockResponseForCatalogdb(
1224                                                 "vnfComponentRecipeVNF_API_Response.json"))
1225                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1226
1227         // expected response
1228         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1229         RequestReferences requestReferences = new RequestReferences();
1230         requestReferences.setInstanceId("1882939");
1231         requestReferences.setRequestSelfLink(createExpectedSelfLink("v6", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1232         expectedResponse.setRequestReferences(requestReferences);
1233         uri = servInstanceuri + "v6"
1234                 + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules";
1235         ResponseEntity<String> response =
1236                 sendRequest(inputStream("/VfModuleNoModelCustomization.json"), uri, HttpMethod.POST, headers);
1237         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1238         ObjectMapper mapper = new ObjectMapper();
1239         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1240         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1241     }
1242
1243     @Test
1244     public void deleteVfModuleInstanceNoMatchingModelUUD() throws IOException {
1245         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1246                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1247                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1248
1249         wireMockServer.stubFor(get(urlMatching(".*/vnfResource/.*"))
1250                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1251                         .withBody(getWiremockResponseForCatalogdb("vnfResourceForVfModule_Response.json"))
1252                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1253
1254         wireMockServer
1255                 .stubFor(get(urlMatching(".*/vnfResourceCustomization/search/findByModelInstanceNameAndVnfResources.*"))
1256                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1257                                 .withBody(getWiremockResponseForCatalogdb(
1258                                         "vnfResourceCustomizationForVfModule_Response.json"))
1259                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1260
1261         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/3/vfModuleCustomizations"))
1262                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1263                         .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationsPCM_Response.json"))
1264                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1265
1266         wireMockServer.stubFor(get(urlMatching(
1267                 ".*/vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc[?]MODEL_CUSTOMIZATION_UUID=b4ea86b4-253f-11e7-93ae-92361f002672"))
1268                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1269                                 .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationPCM_Response.json"))
1270                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1271
1272         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/2/vfModule"))
1273                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1274                         .withBody(getWiremockResponseForCatalogdb("vfModulePCM_Response.json"))
1275                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1276
1277         wireMockServer.stubFor(get(urlMatching(".*/vfModule/066de97e-253e-11e7-93ae-92361f002672"))
1278                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1279                         .withBody(getWiremockResponseForCatalogdb("vfModulePCM_Response.json"))
1280                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1281
1282         wireMockServer.stubFor(get(urlMatching(
1283                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1284                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=deleteInstance"))
1285                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1286                                         .withBody(getWiremockResponseForCatalogdb(
1287                                                 "vnfComponentRecipeDeleteVfModule_Response.json"))
1288                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1289
1290         // expected response
1291         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1292         RequestReferences requestReferences = new RequestReferences();
1293         requestReferences.setInstanceId("1882939");
1294         requestReferences.setRequestSelfLink(createExpectedSelfLink("v6", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1295         expectedResponse.setRequestReferences(requestReferences);
1296         uri = servInstanceuri + "v6"
1297                 + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1298         ResponseEntity<String> response =
1299                 sendRequest(inputStream("/VfModuleNoMatchingModelUUID.json"), uri, HttpMethod.DELETE, headers);
1300
1301
1302         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1303         ObjectMapper mapper = new ObjectMapper();
1304         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1305         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1306     }
1307
1308     @Test
1309     public void createVfModuleInstanceNoRecipe() throws IOException {
1310
1311         wireMockServer.stubFor(get(urlMatching(".*/vnfResource/fe6478e4-ea33-3346-ac12-ab121484a3fe"))
1312                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1313                         .withBody(getWiremockResponseForCatalogdb("vnfResourceForVfModule_Response.json"))
1314                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1315
1316         wireMockServer
1317                 .stubFor(get(urlMatching(".*/vnfResourceCustomization/search/findByModelInstanceNameAndVnfResources"
1318                         + "[?]MODEL_INSTANCE_NAME=test&VNF_RESOURCE_MODEL_UUID=fe6478e4-ea33-3346-ac12-ab121484a3fe"))
1319                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1320                                         .withBody(getWiremockResponseForCatalogdb(
1321                                                 "vnfResourceCustomizationForVfModule_Response.json"))
1322                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1323
1324         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/3/vfModuleCustomizations"))
1325                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1326                         .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationsPCM_Response.json"))
1327                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1328
1329         wireMockServer.stubFor(
1330                 get(urlMatching(".*/vfModuleCustomization/search/findByModelCustomizationUUIDAndVfModuleModelUUID[?]"
1331                         + "modelCustomizationUUID=b4ea86b4-253f-11e7-93ae-92361f002672&vfModuleModelUUID=066de97e-253e-11e7-93ae-92361f002672"))
1332                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1333                                         .withBody(getWiremockResponseForCatalogdb(
1334                                                 "vfModuleCustomizationPCM_Response.json"))
1335                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1336
1337         uri = servInstanceuri + "v6"
1338                 + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules";
1339         ResponseEntity<String> response =
1340                 sendRequest(inputStream("/VfModuleInvalid.json"), uri, HttpMethod.POST, headers);
1341
1342         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
1343         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
1344         assertEquals("No valid vfModuleCustomization is specified", realResponse.getServiceException().getText());
1345     }
1346
1347     @Test
1348     public void replaceVfModuleInstance() throws IOException {
1349         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1350                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1351                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1352
1353         wireMockServer
1354                 .stubFor(get(urlMatching(".*/vfModule/search/findFirstVfModuleByModelInvariantUUIDAndModelVersion[?]"
1355                         + "modelInvariantUUID=78ca26d0-246d-11e7-93ae-92361f002671&modelVersion=2"))
1356                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1357                                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1358                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1359
1360         wireMockServer.stubFor(get(urlMatching(
1361                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1362                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=replaceInstance"))
1363                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1364                                         .withBody(getWiremockResponseForCatalogdb(
1365                                                 "vnfComponentRecipeDeleteVfModule_Response.json"))
1366                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1367         // expected response
1368         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1369         RequestReferences requestReferences = new RequestReferences();
1370         requestReferences.setInstanceId("1882939");
1371         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1372         expectedResponse.setRequestReferences(requestReferences);
1373         uri = servInstanceuri + "v7"
1374                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
1375         ResponseEntity<String> response =
1376                 sendRequest(inputStream("/ReplaceVfModule.json"), uri, HttpMethod.POST, headers);
1377
1378         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1379         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1380         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1381     }
1382
1383     @Test
1384     public void updateVfModuleInstance() throws IOException {
1385         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1386                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1387                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1388
1389         wireMockServer.stubFor(get(urlMatching(
1390                 ".*/vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc[?]MODEL_CUSTOMIZATION_UUID=cb82ffd8-252a-11e7-93ae-92361f002671"))
1391                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1392                                 .withBody(getWiremockResponseForCatalogdb("vfModuleCustomization_Response.json"))
1393                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1394
1395         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/1/vfModule"))
1396                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1397                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1398                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1399
1400         wireMockServer.stubFor(get(urlMatching(".*/vfModule/20c4431c-246d-11e7-93ae-92361f002671"))
1401                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1402                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1403                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1404
1405         wireMockServer.stubFor(get(urlMatching(
1406                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1407                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=updateInstance"))
1408                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1409                                         .withBody(getWiremockResponseForCatalogdb(
1410                                                 "vnfComponentRecipe_GRAPI_Response.json"))
1411                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1412
1413         // expected response
1414         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1415         RequestReferences requestReferences = new RequestReferences();
1416         requestReferences.setInstanceId("1882939");
1417         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1418         expectedResponse.setRequestReferences(requestReferences);
1419         uri = servInstanceuri + "v7"
1420                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1421         ResponseEntity<String> response =
1422                 sendRequest(inputStream("/UpdateVfModule.json"), uri, HttpMethod.PUT, headers);
1423         logger.debug(response.getBody());
1424
1425         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1426         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1427         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1428     }
1429
1430     @Test
1431     public void createVfModuleNoModelType() throws IOException {
1432         InfraActiveRequests expectedRecord = new InfraActiveRequests();
1433         expectedRecord.setRequestStatus("FAILED");
1434         expectedRecord.setStatusMessage("Error parsing request: No valid modelType is specified");
1435         expectedRecord.setProgress(100L);
1436         expectedRecord.setSource("VID");
1437         expectedRecord.setRequestBody(inputStream("/VfModuleNoModelType.json"));
1438         expectedRecord.setLastModifiedBy("APIH");
1439         expectedRecord.setVfModuleName("testVfModule2");
1440         expectedRecord.setVfModuleModelName("serviceModel");
1441         expectedRecord.setRequestScope("vfModule");
1442         expectedRecord.setRequestAction("createInstance");
1443         expectedRecord.setRequestorId("zz9999");
1444         expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
1445         // VnfType is not sent in this request, should be blank in db
1446         expectedRecord.setVnfType("");
1447         uri = servInstanceuri
1448                 + "v5/serviceInstances/32807a28-1a14-4b88-b7b3-2950918aa76d/vnfs/32807a28-1a14-4b88-b7b3-2950918aa76d/vfModules";
1449
1450         ResponseEntity<String> response =
1451                 sendRequest(inputStream("/VfModuleNoModelType.json"), uri, HttpMethod.POST, headers);
1452         // ActualRecord
1453         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
1454     }
1455
1456     @Test
1457     public void inPlaceSoftwareUpdate() throws IOException {
1458         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/VnfInPlaceUpdate"))
1459                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1460                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1461
1462         wireMockServer.stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]"
1463                 + "nfRole=GR-API-DEFAULT&action=inPlaceSoftwareUpdate"))
1464                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1465                                 .withBody(getWiremockResponseForCatalogdb("vnfRecipeInPlaceUpdate_Response.json"))
1466                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1467
1468         // expected response
1469         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1470         RequestReferences requestReferences = new RequestReferences();
1471         requestReferences.setInstanceId("1882939");
1472         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1473         expectedResponse.setRequestReferences(requestReferences);
1474         uri = servInstanceuri + "v7"
1475                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/inPlaceSoftwareUpdate";
1476         ResponseEntity<String> response =
1477                 sendRequest(inputStream("/InPlaceSoftwareUpdate.json"), uri, HttpMethod.POST, headers);
1478
1479         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1480         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1481         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1482     }
1483
1484     @Test
1485     public void deleteVfModuleInstance() throws IOException {
1486         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1487                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1488                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1489
1490         wireMockServer
1491                 .stubFor(get(urlMatching(".*/vfModule/search/findFirstVfModuleByModelInvariantUUIDAndModelVersion[?]"
1492                         + "modelInvariantUUID=78ca26d0-246d-11e7-93ae-92361f002671&modelVersion=2"))
1493                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1494                                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1495                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1496
1497         wireMockServer.stubFor(get(urlMatching(
1498                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1499                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=deleteInstance"))
1500                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1501                                         .withBody(getWiremockResponseForCatalogdb(
1502                                                 "vnfComponentRecipeDeleteVfModule_Response.json"))
1503                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1504
1505         // expected response
1506         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1507         RequestReferences requestReferences = new RequestReferences();
1508         requestReferences.setInstanceId("1882939");
1509         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1510         expectedResponse.setRequestReferences(requestReferences);
1511         uri = servInstanceuri + "v7"
1512                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1513         ResponseEntity<String> response =
1514                 sendRequest(inputStream("/DeleteVfModule.json"), uri, HttpMethod.DELETE, headers);
1515
1516         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1517         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1518         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1519     }
1520
1521     @Test
1522     public void deleteVfModuleNoModelInvariantId() throws IOException {
1523         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1524                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1525                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1526
1527         wireMockServer.stubFor(get(urlMatching(
1528                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1529                         + "[?]vfModuleModelUUID=VNF-API-DEFAULT&vnfComponentType=vfModule&action=deleteInstance"))
1530                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1531                                         .withBody(getWiremockResponseForCatalogdb(
1532                                                 "vnfComponentRecipeDeleteVfModule_Response.json"))
1533                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1534
1535         // expected response
1536         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1537         RequestReferences requestReferences = new RequestReferences();
1538         requestReferences.setInstanceId("1882939");
1539         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1540         expectedResponse.setRequestReferences(requestReferences);
1541         uri = servInstanceuri + "v7"
1542                 + "/serviceInstances/196b4a84-0858-4317-a1f6-497e2e52ae43/vnfs/36e4f902-ec32-451e-8d53-e3edc19e40a4/vfModules/09f3a38d-933f-450a-8784-9e6c4dec3f72";
1543         ResponseEntity<String> response =
1544                 sendRequest(inputStream("/DeleteVfModuleNoModelInvariantId.json"), uri, HttpMethod.DELETE, headers);
1545
1546         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1547         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1548         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1549     }
1550
1551     @Test
1552     public void deactivateAndCloudDeleteVfModuleInstance() throws IOException {
1553         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1554                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1555                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1556
1557         wireMockServer
1558                 .stubFor(get(urlMatching(".*/vfModule/search/findFirstVfModuleByModelInvariantUUIDAndModelVersion[?]"
1559                         + "modelInvariantUUID=78ca26d0-246d-11e7-93ae-92361f002671&modelVersion=2"))
1560                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1561                                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1562                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1563
1564         wireMockServer.stubFor(get(urlMatching(
1565                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1566                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=deactivateAndCloudDelete"))
1567                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1568                                         .withBody(getWiremockResponseForCatalogdb(
1569                                                 "vnfComponentRecipeDeactivate_Response.json"))
1570                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1571
1572         // expected response
1573         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1574         RequestReferences requestReferences = new RequestReferences();
1575         requestReferences.setInstanceId("1882939");
1576         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1577         expectedResponse.setRequestReferences(requestReferences);
1578         uri = servInstanceuri + "v7"
1579                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000/deactivateAndCloudDelete";
1580         ResponseEntity<String> response =
1581                 sendRequest(inputStream("/DeactivateAndCloudDeleteVfModule.json"), uri, HttpMethod.POST, headers);
1582
1583         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1584         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1585         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1586     }
1587
1588     @Test
1589     public void createVolumeGroupInstance() throws IOException {
1590         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1591                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1592                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1593
1594         wireMockServer.stubFor(get(urlMatching(
1595                 ".*/vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc[?]MODEL_CUSTOMIZATION_UUID=b4ea86b4-253f-11e7-93ae-92361f002671"))
1596                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1597                                 .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationVolGrp_Response.json"))
1598                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1599
1600         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/1/vfModule"))
1601                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1602                         .withBody(getWiremockResponseForCatalogdb("vfModuleVolGroup_Response.json"))
1603                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1604
1605         wireMockServer.stubFor(get(urlMatching(
1606                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1607                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=volumeGroup&action=createInstance"))
1608                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1609                                         .withBody(getWiremockResponseForCatalogdb(
1610                                                 "vnfComponentRecipeVolGrp_GRAPI_Response.json"))
1611                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1612
1613         // expected response
1614         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1615         RequestReferences requestReferences = new RequestReferences();
1616         requestReferences.setInstanceId("1882939");
1617         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1618         expectedResponse.setRequestReferences(requestReferences);
1619         uri = servInstanceuri + "v7"
1620                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups";
1621         ResponseEntity<String> response = sendRequest(inputStream("/VolumeGroup.json"), uri, HttpMethod.POST, headers);
1622
1623         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1624         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1625         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1626         assertTrue(response.getBody().contains("1882939"));
1627     }
1628
1629     @Test
1630     public void updateVolumeGroupInstance() throws IOException {
1631         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1632                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1633                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1634
1635         wireMockServer.stubFor(get(urlMatching(
1636                 ".*/vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc[?]MODEL_CUSTOMIZATION_UUID=b4ea86b4-253f-11e7-93ae-92361f002671"))
1637                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1638                                 .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationVolGrp_Response.json"))
1639                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1640
1641         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/1/vfModule"))
1642                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1643                         .withBody(getWiremockResponseForCatalogdb("vfModuleVolGroup_Response.json"))
1644                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1645
1646         wireMockServer.stubFor(get(urlMatching(
1647                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1648                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=volumeGroup&action=updateInstance"))
1649                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1650                                         .withBody(getWiremockResponseForCatalogdb(
1651                                                 "vnfComponentRecipeVolGrp_GRAPI_Response.json"))
1652                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1653
1654         // expected response
1655         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1656         RequestReferences requestReferences = new RequestReferences();
1657         requestReferences.setInstanceId("1882939");
1658         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1659         expectedResponse.setRequestReferences(requestReferences);
1660         uri = servInstanceuri + "v7"
1661                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1662         ResponseEntity<String> response =
1663                 sendRequest(inputStream("/UpdateVolumeGroup.json"), uri, HttpMethod.PUT, headers);
1664
1665         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1666         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1667         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1668     }
1669
1670     @Test
1671     public void deleteVolumeGroupInstance() throws IOException {
1672         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1673                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1674                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1675
1676         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1677                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1678                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1679
1680         wireMockServer.stubFor(get(urlMatching(
1681                 ".*/vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc[?]MODEL_CUSTOMIZATION_UUID=b4ea86b4-253f-11e7-93ae-92361f002671"))
1682                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1683                                 .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationVolGrp_Response.json"))
1684                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1685
1686         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/1/vfModule"))
1687                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1688                         .withBody(getWiremockResponseForCatalogdb("vfModuleVolGroup_Response.json"))
1689                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1690
1691         wireMockServer.stubFor(get(urlMatching(
1692                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1693                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=volumeGroup&action=deleteInstance"))
1694                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1695                                         .withBody(getWiremockResponseForCatalogdb(
1696                                                 "vnfComponentRecipeVolGrp_GRAPI_Response.json"))
1697                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1698
1699         // expected response
1700         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1701         RequestReferences requestReferences = new RequestReferences();
1702         requestReferences.setInstanceId("1882939");
1703         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1704         expectedResponse.setRequestReferences(requestReferences);
1705         uri = servInstanceuri + "v7"
1706                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1707         ResponseEntity<String> response =
1708                 sendRequest(inputStream("/DeleteVolumeGroup.json"), uri, HttpMethod.DELETE, headers);
1709
1710         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1711         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1712         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1713     }
1714
1715     @Test
1716     public void createNetworkInstance() throws IOException {
1717         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1718                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1719                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1720
1721         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
1722                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1723                         .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json"))
1724                         .withStatus(HttpStatus.SC_OK)));
1725
1726         wireMockServer.stubFor(
1727                 get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource"))
1728                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1729                                 .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json"))
1730                                 .withStatus(HttpStatus.SC_OK)));
1731
1732         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]"
1733                 + "modelName=GR-API-DEFAULT&action=createInstance"))
1734                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1735                                 .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
1736                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1737
1738         // expected response
1739         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1740         RequestReferences requestReferences = new RequestReferences();
1741         requestReferences.setInstanceId("1882939");
1742         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1743         expectedResponse.setRequestReferences(requestReferences);
1744         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1745         ResponseEntity<String> response =
1746                 sendRequest(inputStream("/NetworkCreate.json"), uri, HttpMethod.POST, headers);
1747
1748         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1749         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1750         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1751     }
1752
1753     @Test
1754     public void updateNetworkInstance() throws IOException {
1755         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1756                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1757                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1758
1759         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
1760                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1761                         .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json"))
1762                         .withStatus(HttpStatus.SC_OK)));
1763
1764         wireMockServer.stubFor(
1765                 get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource"))
1766                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1767                                 .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json"))
1768                                 .withStatus(HttpStatus.SC_OK)));
1769
1770         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]"
1771                 + "modelName=GR-API-DEFAULT&action=updateInstance"))
1772                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1773                                 .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
1774                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1775         // expected response
1776         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1777         RequestReferences requestReferences = new RequestReferences();
1778         requestReferences.setInstanceId("1882939");
1779         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1780         expectedResponse.setRequestReferences(requestReferences);
1781         uri = servInstanceuri + "v7"
1782                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1783         ResponseEntity<String> response = sendRequest(inputStream("/UpdateNetwork.json"), uri, HttpMethod.PUT, headers);
1784
1785         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1786         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1787         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1788         assertTrue(response.getBody().contains("1882939"));
1789     }
1790
1791     @Test
1792     public void deleteNetworkInstance() throws IOException {
1793         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1794                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1795                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1796
1797         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
1798                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1799                         .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json"))
1800                         .withStatus(HttpStatus.SC_OK)));
1801
1802         wireMockServer.stubFor(
1803                 get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource"))
1804                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1805                                 .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json"))
1806                                 .withStatus(HttpStatus.SC_OK)));
1807
1808         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]"
1809                 + "modelName=VNF-API-DEFAULT&action=deleteInstance"))
1810                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1811                                 .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
1812                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1813
1814         // expected response
1815         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1816         RequestReferences requestReferences = new RequestReferences();
1817         requestReferences.setInstanceId("1882939");
1818         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1819         expectedResponse.setRequestReferences(requestReferences);
1820         uri = servInstanceuri + "v7"
1821                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1822         ResponseEntity<String> response =
1823                 sendRequest(inputStream("/NetworkInstance.json"), uri, HttpMethod.DELETE, headers);
1824
1825         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1826         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1827         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1828     }
1829
1830     @Test
1831     public void deleteNetworkInstanceNoReqParams() throws IOException {
1832         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1833                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1834                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1835
1836         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]"
1837                 + "modelName=GR-API-DEFAULT&action=deleteInstance"))
1838                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1839                                 .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
1840                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1841
1842
1843         // expected response
1844         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1845         RequestReferences requestReferences = new RequestReferences();
1846         requestReferences.setInstanceId("1882939");
1847         requestReferences.setRequestSelfLink(createExpectedSelfLink("v6", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1848         expectedResponse.setRequestReferences(requestReferences);
1849         uri = servInstanceuri + "v6"
1850                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1851         ResponseEntity<String> response =
1852                 sendRequest(inputStream("/NetworkInstanceNoReqParams.json"), uri, HttpMethod.DELETE, headers);
1853
1854         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1855         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1856         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1857     }
1858
1859     @Test
1860     public void convertJsonToServiceInstanceRequestFail() throws IOException {
1861         // ExpectedRecord
1862         InfraActiveRequests expectedRecord = new InfraActiveRequests();
1863         expectedRecord.setRequestStatus("FAILED");
1864         expectedRecord.setStatusMessage("Error mapping request: ");
1865         expectedRecord.setProgress(100L);
1866         expectedRecord.setRequestBody(inputStream("/ConvertRequestFail.json"));
1867         expectedRecord.setLastModifiedBy("APIH");
1868         expectedRecord.setRequestScope("network");
1869         expectedRecord.setRequestAction("deleteInstance");
1870         expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
1871
1872         uri = servInstanceuri + "v6"
1873                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1874         ResponseEntity<String> response =
1875                 sendRequest(inputStream("/ConvertRequestFail.json"), uri, HttpMethod.DELETE, headers);
1876
1877         // ActualRecord
1878
1879         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
1880     }
1881
1882     @Test
1883     public void convertJsonToServiceInstanceRequestConfigurationFail() throws IOException {
1884         uri = servInstanceuri + "v5"
1885                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/configurations/test/enablePort";
1886         ResponseEntity<String> response = sendRequest(inputStream("/ConvertRequestFail.json"), uri, HttpMethod.POST);
1887
1888         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
1889     }
1890
1891     @Test
1892     public void creatServiceInstanceGRTestApiNoCustomRecipeFound() throws IOException {
1893         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1894                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1895                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1896
1897         ServiceRecipe serviceRecipe = new ServiceRecipe();
1898         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
1899         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
1900         serviceRecipe.setAction(Action.createInstance.toString());
1901         serviceRecipe.setId(1);
1902         serviceRecipe.setRecipeTimeout(180);
1903         Service defaultService = new Service();
1904         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
1905
1906         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
1907                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1908                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
1909
1910         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
1911                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1912                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
1913
1914         uri = servInstanceuri + "v7" + "/serviceInstances";
1915         ResponseEntity<String> response =
1916                 sendRequest(inputStream("/ServiceInstanceMacro.json"), uri, HttpMethod.POST, headers);
1917
1918         // expected response
1919         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1920         RequestReferences requestReferences = new RequestReferences();
1921         requestReferences.setInstanceId("1882939");
1922         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1923         expectedResponse.setRequestReferences(requestReferences);
1924
1925         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1926         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1927         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1928     }
1929
1930     @Test
1931     public void createNetworkInstanceTestApiUndefinedUsePropertiesDefault() throws IOException {
1932         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1933                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1934                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1935
1936         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
1937                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1938                         .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json"))
1939                         .withStatus(HttpStatus.SC_OK)));
1940
1941         wireMockServer.stubFor(
1942                 get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource"))
1943                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1944                                 .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json"))
1945                                 .withStatus(HttpStatus.SC_OK)));
1946
1947         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]"
1948                 + "modelName=GR-API-DEFAULT&action=createInstance"))
1949                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1950                                 .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
1951                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1952
1953         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1954         ResponseEntity<String> response =
1955                 sendRequest(inputStream("/NetworkCreateAlternateInstanceName.json"), uri, HttpMethod.POST, headers);
1956
1957         // expected response
1958         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1959         RequestReferences requestReferences = new RequestReferences();
1960         requestReferences.setInstanceId("1882939");
1961         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1962         expectedResponse.setRequestReferences(requestReferences);
1963
1964         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1965         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1966         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1967     }
1968
1969     @Test
1970     public void createNetworkInstanceTestApiIncorrectUsePropertiesDefault() throws IOException {
1971         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1972                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1973                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1974
1975         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1976         ResponseEntity<String> response =
1977                 sendRequest(inputStream("/NetworkCreateTestApiIncorrect.json"), uri, HttpMethod.POST);
1978
1979         // expected response
1980         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1981         RequestReferences requestReferences = new RequestReferences();
1982         requestReferences.setInstanceId("1882939");
1983         expectedResponse.setRequestReferences(requestReferences);
1984
1985         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
1986     }
1987
1988     @Test
1989     public void createNetworkInstanceTestApiGrApi() throws IOException {
1990         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1991                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1992                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1993
1994         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
1995                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1996                         .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json"))
1997                         .withStatus(HttpStatus.SC_OK)));
1998
1999         wireMockServer.stubFor(
2000                 get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource"))
2001                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2002                                 .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json"))
2003                                 .withStatus(HttpStatus.SC_OK)));
2004
2005         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]"
2006                 + "modelName=GR-API-DEFAULT&action=createInstance"))
2007                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2008                                 .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
2009                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2010
2011         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
2012         ResponseEntity<String> response =
2013                 sendRequest(inputStream("/NetworkCreateTestApiGrApi.json"), uri, HttpMethod.POST, headers);
2014
2015         // expected response
2016         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2017         RequestReferences requestReferences = new RequestReferences();
2018         requestReferences.setInstanceId("1882939");
2019         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2020         expectedResponse.setRequestReferences(requestReferences);
2021
2022         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2023         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2024         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2025     }
2026
2027     @Test
2028     public void createNetworkInstanceTestApiVnfApi() throws IOException {
2029         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/CreateNetworkInstance"))
2030                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2031                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2032
2033         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
2034                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2035                         .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json"))
2036                         .withStatus(HttpStatus.SC_OK)));
2037
2038         wireMockServer.stubFor(
2039                 get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource"))
2040                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2041                                 .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json"))
2042                                 .withStatus(HttpStatus.SC_OK)));
2043
2044         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]"
2045                 + "modelName=VNF-API-DEFAULT&action=createInstance"))
2046                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2047                                 .withBody(getWiremockResponseForCatalogdb("networkRecipeVNF_API_Response.json"))
2048                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2049
2050         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
2051         ResponseEntity<String> response =
2052                 sendRequest(inputStream("/NetworkCreateTestApiVnfApi.json"), uri, HttpMethod.POST, headers);
2053
2054         // expected response
2055         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2056         RequestReferences requestReferences = new RequestReferences();
2057         requestReferences.setInstanceId("1882939");
2058         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2059         expectedResponse.setRequestReferences(requestReferences);
2060
2061         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2062         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2063         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2064     }
2065
2066     @Test
2067     public void activateServiceInstanceRequestStatus() throws IOException {
2068         ServiceRecipe serviceRecipe = new ServiceRecipe();
2069         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
2070         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2071         serviceRecipe.setAction(Action.createInstance.toString());
2072         serviceRecipe.setId(1);
2073         serviceRecipe.setRecipeTimeout(180);
2074         Service defaultService = new Service();
2075         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2076
2077         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2078                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2079                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2080
2081         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
2082                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2083                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2084
2085         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2086                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2087                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
2088
2089         // expect
2090         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2091         RequestReferences requestReferences = new RequestReferences();
2092         requestReferences.setInstanceId("1882939");
2093         requestReferences.setRequestSelfLink(createExpectedSelfLink("v5", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2094         expectedResponse.setRequestReferences(requestReferences);
2095         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7999/activate";
2096         ResponseEntity<String> response =
2097                 sendRequest(inputStream("/ServiceInstancePrev8.json"), uri, HttpMethod.POST, headers);
2098
2099         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2100         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2101         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2102     }
2103
2104     @Test
2105     public void invalidRequestId() throws IOException {
2106         String illegalRequestId = "1234";
2107         HttpHeaders ivalidRequestIdHeaders = new HttpHeaders();
2108         ivalidRequestIdHeaders.set(ONAPLogConstants.Headers.REQUEST_ID, illegalRequestId);
2109         uri = servInstanceuri + "v5/serviceInstances";
2110         ResponseEntity<String> response =
2111                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, ivalidRequestIdHeaders);
2112
2113         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2114         assertTrue(response.getBody().contains("Request Id " + illegalRequestId + " is not a valid UUID"));
2115     }
2116
2117     @Test
2118     public void invalidBPELResponse() throws IOException {
2119
2120         ServiceRecipe serviceRecipe = new ServiceRecipe();
2121         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
2122         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2123         serviceRecipe.setAction(Action.createInstance.toString());
2124         serviceRecipe.setId(1);
2125         serviceRecipe.setRecipeTimeout(180);
2126         Service defaultService = new Service();
2127         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2128
2129         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")).willReturn(aResponse()
2130                 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2131                 .withBodyFile("Camunda/TestResponseInvalid2.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2132
2133         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
2134                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2135                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2136
2137         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2138                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2139                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
2140
2141         uri = servInstanceuri + "v5/serviceInstances";
2142         ResponseEntity<String> response =
2143                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2144
2145         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2146         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2147         assertEquals("Request Failed due to BPEL error with HTTP Status = 202{\"instanceId\": \"1882939\"}",
2148                 realResponse.getServiceException().getText());
2149     }
2150
2151     @Test
2152     public void unauthorizedBPELResponse() throws IOException {
2153
2154         ServiceRecipe serviceRecipe = new ServiceRecipe();
2155         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
2156         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2157         serviceRecipe.setAction(Action.createInstance.toString());
2158         serviceRecipe.setId(1);
2159         serviceRecipe.setRecipeTimeout(180);
2160         Service defaultService = new Service();
2161         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2162
2163         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2164                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2165                         .withBodyFile("Camunda/UnauthorizedResponse.json")
2166                         .withStatus(org.apache.http.HttpStatus.SC_UNAUTHORIZED)));
2167
2168         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
2169                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2170                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2171
2172         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2173                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2174                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
2175
2176         uri = servInstanceuri + "v5/serviceInstances";
2177         ResponseEntity<String> response =
2178                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2179
2180         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2181         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2182         assertEquals("Exception caught mapping Camunda JSON response to object",
2183                 realResponse.getServiceException().getText());
2184     }
2185
2186     @Test
2187     public void invalidBPELResponse2() throws IOException {
2188
2189         ServiceRecipe serviceRecipe = new ServiceRecipe();
2190         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
2191         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2192         serviceRecipe.setAction(Action.createInstance.toString());
2193         serviceRecipe.setId(1);
2194         serviceRecipe.setRecipeTimeout(180);
2195         Service defaultService = new Service();
2196         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2197
2198         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")).willReturn(aResponse()
2199                 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2200                 .withBodyFile("Camunda/TestResponseInvalid.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2201
2202         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
2203                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2204                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2205
2206         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2207                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2208                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
2209         uri = servInstanceuri + "v5/serviceInstances";
2210         ResponseEntity<String> response =
2211                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2212
2213         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2214         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2215         assertTrue(realResponse.getServiceException().getText()
2216                 .contains("<aetgt:ErrorMessage>Exception in create execution list 500"));
2217     }
2218
2219     @Test
2220     public void createMacroServiceInstance() throws IOException {
2221         ServiceRecipe serviceRecipe = new ServiceRecipe();
2222         serviceRecipe.setOrchestrationUri("/mso/async/services/CreateMacroServiceNetworkVnf");
2223         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2224         serviceRecipe.setAction(Action.createInstance.toString());
2225         serviceRecipe.setId(1);
2226         serviceRecipe.setRecipeTimeout(180);
2227         Service defaultService = new Service();
2228         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2229
2230         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/CreateMacroServiceNetworkVnf"))
2231                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2232                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2233
2234         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")).willReturn(aResponse()
2235                 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2236                 .withBodyFile("Camunda/TestResponseInvalid.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2237
2238         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
2239                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2240                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2241
2242         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2243                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2244                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
2245
2246         // expect
2247         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2248         RequestReferences requestReferences = new RequestReferences();
2249         requestReferences.setInstanceId("1882939");
2250         requestReferences.setRequestSelfLink(createExpectedSelfLink("v5", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2251         expectedResponse.setRequestReferences(requestReferences);
2252         uri = servInstanceuri + "v5";
2253         ResponseEntity<String> response =
2254                 sendRequest(inputStream("/MacroServiceInstance.json"), uri, HttpMethod.POST, headers);
2255
2256         // then
2257         assertEquals(404, response.getStatusCode().value());
2258     }
2259
2260     @Test
2261     public void testUserParams() throws IOException {
2262         ObjectMapper mapper = new ObjectMapper();
2263         ServiceInstancesRequest request =
2264                 mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class);
2265         RequestParameters requestParameters = request.getRequestDetails().getRequestParameters();
2266         String userParamsTxt = inputStream("/userParams.txt");
2267
2268         List<Map<String, Object>> userParams = requestHandlerUtils.configureUserParams(requestParameters);
2269         System.out.println(userParams);
2270         assertTrue(userParams.size() > 0);
2271         assertTrue(userParams.get(0).containsKey("name"));
2272         assertTrue(userParams.get(0).containsKey("value"));
2273         assertEquals(userParamsTxt.replaceAll("\\s+", ""), userParams.toString().replaceAll("\\s+", ""));
2274     }
2275
2276     @Test
2277     public void testConfigureCloudConfig() throws IOException {
2278         ObjectMapper mapper = new ObjectMapper();
2279         ServiceInstancesRequest request =
2280                 mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class);
2281         CloudConfiguration cloudConfig =
2282                 requestHandlerUtils.configureCloudConfig(request.getRequestDetails().getRequestParameters());
2283
2284         assertEquals("mdt25b", cloudConfig.getLcpCloudRegionId());
2285         assertEquals("aefb697db6524ddebfe4915591b0a347", cloudConfig.getTenantId());
2286     }
2287
2288     @Test
2289     public void testMapToLegacyRequest() throws IOException {
2290         ObjectMapper mapper = new ObjectMapper();
2291         ServiceInstancesRequest request =
2292                 mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class);
2293         ServiceInstancesRequest expected =
2294                 mapper.readValue(inputStream("/LegacyMacroServiceInstance.json"), ServiceInstancesRequest.class);
2295         requestHandlerUtils.mapToLegacyRequest(request.getRequestDetails());
2296         System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(request));
2297         assertThat(request, sameBeanAs(expected));
2298     }
2299
2300     @Test
2301     public void scaleOutVfModule() throws IOException {
2302         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2303                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2304                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2305
2306         wireMockServer.stubFor(get(urlMatching(
2307                 ".*/vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc[?]MODEL_CUSTOMIZATION_UUID=cb82ffd8-252a-11e7-93ae-92361f002671"))
2308                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2309                                 .withBody(getWiremockResponseForCatalogdb("vfModuleCustomization_Response.json"))
2310                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2311
2312         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/1/vfModule"))
2313                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2314                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
2315                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
2316
2317         wireMockServer.stubFor(get(urlMatching(".*/vfModule/20c4431c-246d-11e7-93ae-92361f002671"))
2318                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2319                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
2320                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
2321
2322
2323         wireMockServer.stubFor(get(urlMatching(
2324                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
2325                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=scaleOut"))
2326                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2327                                         .withBody(getWiremockResponseForCatalogdb(
2328                                                 "vnfComponentRecipeVfModuleScaleOut_Response.json"))
2329                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
2330
2331         wireMockServer.stubFor(get(urlMatching(
2332                 ".*/vfModule/search/findByModelInvariantUUIDOrderByModelVersionDesc[?]modelInvariantUUID=78ca26d0-246d-11e7-93ae-92361f002671"))
2333                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2334                                 .withBody(getWiremockResponseForCatalogdb("vfModulesListByInvariantId_Response.json"))
2335                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2336
2337         // expected response
2338         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2339         RequestReferences requestReferences = new RequestReferences();
2340         requestReferences.setInstanceId("1882939");
2341         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2342         expectedResponse.setRequestReferences(requestReferences);
2343         uri = servInstanceuri + "v7"
2344                 + "/serviceInstances/7a88cbeb-0ec8-4765-a271-4f9e90c3da7b/vnfs/cbba721b-4803-4df7-9347-307c9a955426/vfModules/scaleOut";
2345         ResponseEntity<String> response =
2346                 sendRequest(inputStream("/ScaleOutRequest.json"), uri, HttpMethod.POST, headers);
2347
2348         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2349         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2350         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2351         assertTrue(response.getBody().contains("1882939"));
2352     }
2353
2354     @Test
2355     public void createServiceInstanceBadResponse() throws IOException {
2356         ServiceRecipe serviceRecipe = new ServiceRecipe();
2357         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
2358         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2359         serviceRecipe.setAction(Action.createInstance.toString());
2360         serviceRecipe.setId(1);
2361         serviceRecipe.setRecipeTimeout(180);
2362         Service defaultService = new Service();
2363         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2364
2365         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2366                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2367                         .withBodyFile("Camunda/TestBadResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2368
2369         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
2370                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2371                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2372
2373         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2374                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2375                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
2376
2377         uri = servInstanceuri + "v5/serviceInstances";
2378         ResponseEntity<String> response =
2379                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2380
2381         assertEquals(Response.Status.NOT_ACCEPTABLE.getStatusCode(), response.getStatusCode().value());
2382         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2383         assertEquals("Exception caught mapping Camunda JSON response to object",
2384                 realResponse.getServiceException().getText());
2385     }
2386
2387     @Test
2388     public void createServiceInstanceDuplicateError() throws IOException {
2389         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/checkInstanceNameDuplicate"))
2390                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2391                         .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
2392
2393         uri = servInstanceuri + "v5/serviceInstances";
2394         ResponseEntity<String> response =
2395                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2396
2397         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2398         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2399         assertEquals(
2400                 "Unable to check for duplicate instance due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error",
2401                 realResponse.getServiceException().getText());
2402     }
2403
2404     @Test
2405     public void createServiceInstanceDuplicateHistoryCheck() throws IOException {
2406         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/checkInstanceNameDuplicate"))
2407                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2408                         .withBodyFile("InfraActiveRequests/createInfraActiveRequests.json")
2409                         .withStatus(HttpStatus.SC_ACCEPTED)));
2410         wireMockServer.stubFor(get(
2411                 ("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f"))
2412                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2413                                 .withBodyFile("Camunda/HistoryCheckResponse.json")
2414                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2415
2416         uri = servInstanceuri + "v5/serviceInstances";
2417         ResponseEntity<String> response =
2418                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2419
2420         assertEquals(Response.Status.CONFLICT.getStatusCode(), response.getStatusCode().value());
2421         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2422         assertEquals(
2423                 "Error: Locked instance - This service (testService9) already has a request being worked with a status of UNLOCKED (RequestId - f0a35706-efc4-4e27-80ea-a995d7a2a40f). The existing request must finish or be cleaned up before proceeding.",
2424                 realResponse.getServiceException().getText());
2425     }
2426
2427     @Test
2428     public void createServiceInstanceDuplicateHistoryCheckException() throws IOException {
2429         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/checkInstanceNameDuplicate"))
2430                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2431                         .withBodyFile("InfraActiveRequests/createInfraActiveRequests.json")
2432                         .withStatus(HttpStatus.SC_ACCEPTED)));
2433         wireMockServer.stubFor(get(
2434                 ("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f"))
2435                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2436                                 .withStatus(org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR)));
2437
2438         uri = servInstanceuri + "v5/serviceInstances";
2439         ResponseEntity<String> response =
2440                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2441
2442         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2443         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2444         assertEquals(
2445                 "Unable to get process-instance history from Camunda for requestId: f0a35706-efc4-4e27-80ea-a995d7a2a40f due to error: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error",
2446                 realResponse.getServiceException().getText());
2447     }
2448
2449     @Test
2450     public void createServiceInstanceDuplicate() throws IOException {
2451         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/checkInstanceNameDuplicate"))
2452                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2453                         .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
2454
2455         uri = servInstanceuri + "v5/serviceInstances";
2456         ResponseEntity<String> response =
2457                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2458
2459         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2460         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2461         assertEquals(
2462                 "Unable to check for duplicate instance due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error",
2463                 realResponse.getServiceException().getText());
2464     }
2465
2466     @Test
2467     public void createServiceInstanceSaveError() throws IOException {
2468         ServiceRecipe serviceRecipe = new ServiceRecipe();
2469         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
2470         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2471         serviceRecipe.setAction(Action.createInstance.toString());
2472         serviceRecipe.setId(1);
2473         serviceRecipe.setRecipeTimeout(180);
2474         Service defaultService = new Service();
2475         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2476         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/"))
2477                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2478                         .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
2479         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
2480                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2481                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2482
2483         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2484                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2485                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
2486
2487         uri = servInstanceuri + "v5/serviceInstances";
2488         ResponseEntity<String> response =
2489                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2490
2491         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2492         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2493         assertEquals(
2494                 "Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error",
2495                 realResponse.getServiceException().getText());
2496     }
2497
2498     @Test
2499     public void createPortConfigurationSaveError() throws IOException {
2500         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/"))
2501                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2502                         .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
2503         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
2504                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2505                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2506
2507         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations";
2508         ResponseEntity<String> response =
2509                 sendRequest(inputStream("/ServiceInstancePortConfiguration.json"), uri, HttpMethod.POST, headers);
2510
2511         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2512         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2513         assertEquals(
2514                 "Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error",
2515                 realResponse.getServiceException().getText());
2516     }
2517
2518     @Test
2519     public void createPortConfigDbUpdateError() throws IOException {
2520         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/"))
2521                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2522                         .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
2523
2524         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations";
2525         ResponseEntity<String> response =
2526                 sendRequest(inputStream("/ServiceInstanceParseFail.json"), uri, HttpMethod.POST, headers);
2527
2528         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2529         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2530         assertEquals(
2531                 "Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error",
2532                 realResponse.getServiceException().getText());
2533     }
2534
2535     @Test
2536     public void vnfUpdateWithNetworkInstanceGroup() throws IOException {
2537         TestAppender.events.clear();
2538         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2539                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2540                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2541
2542         wireMockServer.stubFor(get(urlMatching(
2543                 ".*/vnfResourceCustomization/search/findByModelCustomizationUUID[?]MODEL_CUSTOMIZATION_UUID=2ccae1b4-7d9e-46fa-a452-9180ce008d17"))
2544                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2545                                 .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomization_Response.json"))
2546                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2547
2548         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/4/vnfResources"))
2549                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2550                         .withBody(getWiremockResponseForCatalogdb("vnfResources_Response.json"))
2551                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
2552
2553         wireMockServer.stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction"
2554                 + "[?]nfRole=GR-API-DEFAULT&action=updateInstance"))
2555                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2556                                 .withBody(getWiremockResponseForCatalogdb("UpdateVnfRecipe_Response.json"))
2557                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2558         headers.set(ONAPLogConstants.Headers.PARTNER_NAME, "VID");
2559         // expect
2560         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2561         RequestReferences requestReferences = new RequestReferences();
2562         requestReferences.setInstanceId("1882939");
2563         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2564         expectedResponse.setRequestReferences(requestReferences);
2565         uri = servInstanceuri
2566                 + "v7/serviceInstances/e05864f0-ab35-47d0-8be4-56fd9619ba3c/vnfs/f501ce76-a9bc-4601-9837-74fd9f4d5eca";
2567         ResponseEntity<String> response =
2568                 sendRequest(inputStream("/VnfwithNeteworkInstanceGroup.json"), uri, HttpMethod.PUT, headers);
2569         // then
2570         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2571         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2572         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2573         assertEquals(response.getHeaders().get(TRANSACTION_ID).get(0), "32807a28-1a14-4b88-b7b3-2950918aa76d");
2574
2575         for (ILoggingEvent logEvent : TestAppender.events) {
2576             if (logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.SOAuditLogContainerFilter")
2577                     && logEvent.getMarker() != null && logEvent.getMarker().getName().equals("ENTRY")) {
2578                 Map<String, String> mdc = logEvent.getMDCPropertyMap();
2579                 assertEquals("32807a28-1a14-4b88-b7b3-2950918aa76d", mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
2580                 assertEquals("VID", mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME));
2581             }
2582         }
2583     }
2584
2585     @Test
2586     public void createInstanceGroup() throws IOException {
2587         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2588                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2589                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2590
2591         // expect
2592         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2593         RequestReferences requestReferences = new RequestReferences();
2594         requestReferences.setInstanceId("1882939");
2595         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2596         expectedResponse.setRequestReferences(requestReferences);
2597         uri = servInstanceuri + "/v7/instanceGroups";
2598         ResponseEntity<String> response =
2599                 sendRequest(inputStream("/CreateInstanceGroup.json"), uri, HttpMethod.POST, headers);
2600
2601         // then
2602         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2603         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2604         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2605     }
2606
2607     @Test
2608     public void deleteInstanceGroup() throws IOException {
2609         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2610                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2611                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2612
2613         // expect
2614         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2615         RequestReferences requestReferences = new RequestReferences();
2616         requestReferences.setInstanceId("1882939");
2617         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2618         expectedResponse.setRequestReferences(requestReferences);
2619         uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c";
2620         ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE, headers);
2621
2622         // then
2623         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2624         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2625         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2626     }
2627
2628     @Test
2629     public void deleteInstanceGroupNoRequestIdHeader() throws IOException {
2630         uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c";
2631         ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE);
2632         // then
2633         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
2634         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2635         assertEquals(realResponse.getServiceException().getText(), "No valid X-ONAP-RequestID header is specified");
2636     }
2637
2638     @Test
2639     public void deleteInstanceGroupNoPartnerNameHeader() throws IOException {
2640         HttpHeaders noPartnerHeaders = new HttpHeaders();
2641         noPartnerHeaders.set(ONAPLogConstants.Headers.REQUEST_ID, "eca3a1b1-43ab-457e-ab1c-367263d148b4");
2642         noPartnerHeaders.set(REQUESTOR_ID, "xxxxxx");
2643         uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c";
2644         ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE, noPartnerHeaders);
2645         // then
2646         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
2647         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2648         assertEquals(realResponse.getServiceException().getText(), "No valid X-ONAP-PartnerName header is specified");
2649     }
2650
2651     @Test
2652     public void deleteInstanceGroupNoRquestorIdHeader() throws IOException {
2653         HttpHeaders noRequestorIdHheaders = new HttpHeaders();
2654         noRequestorIdHheaders.set(ONAPLogConstants.Headers.REQUEST_ID, "eca3a1b1-43ab-457e-ab1c-367263d148b4");
2655         noRequestorIdHheaders.set(ONAPLogConstants.Headers.PARTNER_NAME, "eca3a1b1-43ab-457e-ab1c-367263d148b4");
2656         // expect
2657         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2658         RequestReferences requestReferences = new RequestReferences();
2659         requestReferences.setInstanceId("1882939");
2660         expectedResponse.setRequestReferences(requestReferences);
2661         uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c";
2662         ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE, noRequestorIdHheaders);
2663
2664         // then
2665         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
2666         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2667         assertEquals(realResponse.getServiceException().getText(), "No valid X-RequestorID header is specified");
2668     }
2669
2670     @Test
2671     public void addMembers() throws IOException {
2672         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2673                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2674                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2675         // expect
2676         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2677         RequestReferences requestReferences = new RequestReferences();
2678         requestReferences.setInstanceId("1882939");
2679         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2680         expectedResponse.setRequestReferences(requestReferences);
2681         uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c/addMembers";
2682         ResponseEntity<String> response = sendRequest(inputStream("/AddMembers.json"), uri, HttpMethod.POST, headers);
2683
2684         // then
2685         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2686         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2687         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2688     }
2689
2690     @Test
2691     public void removeMembers() throws IOException {
2692         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2693                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2694                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2695         // expect
2696         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2697         RequestReferences requestReferences = new RequestReferences();
2698         requestReferences.setInstanceId("1882939");
2699         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2700         expectedResponse.setRequestReferences(requestReferences);
2701         uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c/removeMembers";
2702         ResponseEntity<String> response =
2703                 sendRequest(inputStream("/RemoveMembers.json"), uri, HttpMethod.POST, headers);
2704
2705         // then
2706         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2707         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2708         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2709     }
2710
2711     @Test
2712     public void deleteNetworkInstanceNoCustomizationEntry() throws IOException {
2713         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2714                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2715                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2716
2717         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
2718                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2719                         .withStatus(HttpStatus.SC_NOT_FOUND)));
2720
2721         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]"
2722                 + "modelName=VNF-API-DEFAULT&action=deleteInstance"))
2723                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2724                                 .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
2725                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2726
2727         // expected response
2728         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2729         RequestReferences requestReferences = new RequestReferences();
2730         requestReferences.setInstanceId("1882939");
2731         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2732         expectedResponse.setRequestReferences(requestReferences);
2733         uri = servInstanceuri + "v7"
2734                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
2735         ResponseEntity<String> response =
2736                 sendRequest(inputStream("/NetworkInstance.json"), uri, HttpMethod.DELETE, headers);
2737
2738         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2739         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2740         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2741     }
2742
2743     @Test
2744     public void updateNetworkInstanceNoCustomizationEntry() throws IOException {
2745         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
2746                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2747                         .withStatus(HttpStatus.SC_NOT_FOUND)));
2748
2749         uri = servInstanceuri + "v7"
2750                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
2751         ResponseEntity<String> response = sendRequest(inputStream("/UpdateNetwork.json"), uri, HttpMethod.PUT, headers);
2752
2753         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
2754         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2755         assertEquals(realResponse.getServiceException().getText(),
2756                 "No valid modelCustomizationId for networkResourceCustomization lookup is specified");
2757     }
2758
2759     @Test
2760     public void setServiceTypeTestALaCarte() throws JsonProcessingException {
2761         String requestScope = ModelType.service.toString();
2762         Boolean aLaCarteFlag = true;
2763         ServiceInstancesRequest sir = new ServiceInstancesRequest();
2764         RequestDetails requestDetails = new RequestDetails();
2765         RequestInfo requestInfo = new RequestInfo();
2766         requestInfo.setSource("VID");
2767         requestDetails.setRequestInfo(requestInfo);
2768         sir.setRequestDetails(requestDetails);
2769         Service defaultService = new Service();
2770         defaultService.setServiceType("testServiceTypeALaCarte");
2771
2772         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
2773                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2774                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2775
2776         String serviceType = requestHandlerUtils.getServiceType(requestScope, sir, aLaCarteFlag);
2777         assertEquals(serviceType, "testServiceTypeALaCarte");
2778     }
2779
2780     @Test
2781     public void setServiceTypeTest() throws JsonProcessingException {
2782         String requestScope = ModelType.service.toString();
2783         Boolean aLaCarteFlag = false;
2784         ServiceInstancesRequest sir = new ServiceInstancesRequest();
2785         RequestDetails requestDetails = new RequestDetails();
2786         RequestInfo requestInfo = new RequestInfo();
2787         ModelInfo modelInfo = new ModelInfo();
2788         modelInfo.setModelVersionId("0dd91181-49da-446b-b839-cd959a96f04a");
2789         requestInfo.setSource("VID");
2790         requestDetails.setModelInfo(modelInfo);
2791         requestDetails.setRequestInfo(requestInfo);
2792         sir.setRequestDetails(requestDetails);
2793         Service defaultService = new Service();
2794         defaultService.setServiceType("testServiceType");
2795
2796         wireMockServer.stubFor(get(urlMatching(".*/service/0dd91181-49da-446b-b839-cd959a96f04a"))
2797                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2798                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2799
2800         String serviceType = requestHandlerUtils.getServiceType(requestScope, sir, aLaCarteFlag);
2801         assertEquals(serviceType, "testServiceType");
2802     }
2803
2804     @Test
2805     public void setServiceTypeTestDefault() throws JsonProcessingException {
2806         String requestScope = ModelType.service.toString();
2807         Boolean aLaCarteFlag = false;
2808         ServiceInstancesRequest sir = new ServiceInstancesRequest();
2809         RequestDetails requestDetails = new RequestDetails();
2810         RequestInfo requestInfo = new RequestInfo();
2811         ModelInfo modelInfo = new ModelInfo();
2812         modelInfo.setModelVersionId("0dd91181-49da-446b-b839-cd959a96f04a");
2813         requestInfo.setSource("VID");
2814         requestDetails.setModelInfo(modelInfo);
2815         requestDetails.setRequestInfo(requestInfo);
2816         sir.setRequestDetails(requestDetails);
2817         Service defaultService = new Service();
2818         defaultService.setServiceType("testServiceType");
2819
2820         wireMockServer.stubFor(get(urlMatching(".*/service/0dd91181-49da-446b-b839-cd959a96f04a"))
2821                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2822                         .withStatus(HttpStatus.SC_NOT_FOUND)));
2823         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
2824                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2825                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2826
2827         String serviceType = requestHandlerUtils.getServiceType(requestScope, sir, aLaCarteFlag);
2828         assertEquals(serviceType, "testServiceType");
2829     }
2830
2831     @Test
2832     public void setServiceTypeTestNetwork() throws JsonProcessingException {
2833         String requestScope = ModelType.network.toString();
2834         Boolean aLaCarteFlag = null;
2835         ServiceInstancesRequest sir = new ServiceInstancesRequest();
2836         RequestDetails requestDetails = new RequestDetails();
2837         RequestInfo requestInfo = new RequestInfo();
2838         ModelInfo modelInfo = new ModelInfo();
2839         modelInfo.setModelName("networkModelName");
2840         requestInfo.setSource("VID");
2841         requestDetails.setModelInfo(modelInfo);
2842         requestDetails.setRequestInfo(requestInfo);
2843         sir.setRequestDetails(requestDetails);
2844
2845         String serviceType = requestHandlerUtils.getServiceType(requestScope, sir, aLaCarteFlag);
2846         assertEquals(serviceType, "networkModelName");
2847     }
2848
2849     @Test
2850     public void setServiceInstanceIdInstanceGroupTest() throws JsonParseException, JsonMappingException, IOException {
2851         String requestScope = "instanceGroup";
2852         ServiceInstancesRequest sir =
2853                 mapper.readValue(inputStream("/CreateInstanceGroup.json"), ServiceInstancesRequest.class);
2854         assertEquals("ddcbbf3d-f2c1-4ca0-8852-76a807285efc",
2855                 requestHandlerUtils.setServiceInstanceId(requestScope, sir));
2856     }
2857
2858     @Test
2859     public void setServiceInstanceIdTest() {
2860         String requestScope = "vnf";
2861         ServiceInstancesRequest sir = new ServiceInstancesRequest();
2862         sir.setServiceInstanceId("f0a35706-efc4-4e27-80ea-a995d7a2a40f");
2863         assertEquals("f0a35706-efc4-4e27-80ea-a995d7a2a40f",
2864                 requestHandlerUtils.setServiceInstanceId(requestScope, sir));
2865     }
2866
2867     @Test
2868     public void setServiceInstanceIdReturnNullTest() {
2869         String requestScope = "vnf";
2870         ServiceInstancesRequest sir = new ServiceInstancesRequest();
2871         assertNull(requestHandlerUtils.setServiceInstanceId(requestScope, sir));
2872     }
2873
2874     @Test
2875     public void camundaHistoryCheckTest() throws ContactCamundaException, RequestDbFailureException {
2876         wireMockServer.stubFor(get(
2877                 ("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f"))
2878                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2879                                 .withBodyFile("Camunda/HistoryCheckResponse.json")
2880                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2881
2882         InfraActiveRequests duplicateRecord = new InfraActiveRequests();
2883         duplicateRecord.setRequestId("f0a35706-efc4-4e27-80ea-a995d7a2a40f");
2884         boolean inProgress = false;
2885         inProgress = requestHandlerUtils.camundaHistoryCheck(duplicateRecord, null);
2886         assertTrue(inProgress);
2887     }
2888
2889     @Test
2890     public void camundaHistoryCheckNoneFoundTest() throws ContactCamundaException, RequestDbFailureException {
2891         wireMockServer.stubFor(get(
2892                 ("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f"))
2893                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2894                                 .withBody("[]").withStatus(org.apache.http.HttpStatus.SC_OK)));
2895
2896         InfraActiveRequests duplicateRecord = new InfraActiveRequests();
2897         duplicateRecord.setRequestId("f0a35706-efc4-4e27-80ea-a995d7a2a40f");
2898         boolean inProgress = false;
2899         inProgress = requestHandlerUtils.camundaHistoryCheck(duplicateRecord, null);
2900         assertFalse(inProgress);
2901     }
2902
2903     @Test
2904     public void camundaHistoryCheckNotInProgressTest() throws ContactCamundaException, RequestDbFailureException {
2905         wireMockServer.stubFor(get(
2906                 ("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f"))
2907                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2908                                 .withBodyFile("Camunda/HistoryCheckResponseCompleted.json")
2909                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2910
2911         InfraActiveRequests duplicateRecord = new InfraActiveRequests();
2912         duplicateRecord.setRequestId("f0a35706-efc4-4e27-80ea-a995d7a2a40f");
2913         boolean inProgress = false;
2914         inProgress = requestHandlerUtils.camundaHistoryCheck(duplicateRecord, null);
2915         assertFalse(inProgress);
2916     }
2917
2918     @Test
2919     public void handleReplaceInstance_Test() throws JsonParseException, JsonMappingException, IOException {
2920         String replaceVfModule = inputStream("/ReplaceVfModule.json");
2921         ObjectMapper mapper = new ObjectMapper();
2922         ServiceInstancesRequest sir = mapper.readValue(replaceVfModule, ServiceInstancesRequest.class);
2923         Actions action = servInstances.handleReplaceInstance(Action.replaceInstance, sir);
2924         assertEquals(Action.replaceInstance, action);
2925     }
2926
2927     @Test
2928     public void handleReplaceInstance_retainAssignments_Test()
2929             throws JsonParseException, JsonMappingException, IOException {
2930         String replaceVfModule = inputStream("/ReplaceVfModuleRetainAssignments.json");
2931         ObjectMapper mapper = new ObjectMapper();
2932         ServiceInstancesRequest sir = mapper.readValue(replaceVfModule, ServiceInstancesRequest.class);
2933         Actions action = servInstances.handleReplaceInstance(Action.replaceInstance, sir);
2934         assertEquals(Action.replaceInstanceRetainAssignments, action);
2935     }
2936 }
2937