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