Merge "SOL003 Adapter Package Management - Notify"
[so.git] / mso-api-handlers / mso-api-handler-infra / src / test / java / org / onap / so / apihandlerinfra / ServiceInstancesTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.apihandlerinfra;
22
23
24 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
25 import static com.github.tomakehurst.wiremock.client.WireMock.get;
26 import static com.github.tomakehurst.wiremock.client.WireMock.post;
27 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
28 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
29 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertFalse;
32 import static org.junit.Assert.assertNull;
33 import static org.junit.Assert.assertThat;
34 import static org.junit.Assert.assertTrue;
35 import static org.onap.logging.filter.base.Constants.HttpHeaders.ONAP_PARTNER_NAME;
36 import static org.onap.logging.filter.base.Constants.HttpHeaders.ONAP_REQUEST_ID;
37 import static org.onap.logging.filter.base.Constants.HttpHeaders.TRANSACTION_ID;
38 import static org.onap.so.logger.HttpHeadersConstants.REQUESTOR_ID;
39 import java.io.File;
40 import java.io.IOException;
41 import java.net.MalformedURLException;
42 import java.net.URL;
43 import java.nio.file.Files;
44 import java.nio.file.Paths;
45 import java.util.List;
46 import java.util.Map;
47 import javax.ws.rs.core.MediaType;
48 import javax.ws.rs.core.Response;
49 import org.apache.http.HttpStatus;
50 import org.junit.Before;
51 import org.junit.Test;
52 import org.mockito.Mockito;
53 import org.onap.logging.ref.slf4j.ONAPLogConstants;
54 import org.onap.so.apihandlerinfra.exceptions.ContactCamundaException;
55 import org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException;
56 import org.onap.so.db.catalog.beans.Service;
57 import org.onap.so.db.catalog.beans.ServiceRecipe;
58 import org.onap.so.db.request.beans.InfraActiveRequests;
59 import org.onap.so.serviceinstancebeans.CloudConfiguration;
60 import org.onap.so.serviceinstancebeans.ModelInfo;
61 import org.onap.so.serviceinstancebeans.ModelType;
62 import org.onap.so.serviceinstancebeans.RequestDetails;
63 import org.onap.so.serviceinstancebeans.RequestError;
64 import org.onap.so.serviceinstancebeans.RequestInfo;
65 import org.onap.so.serviceinstancebeans.RequestParameters;
66 import org.onap.so.serviceinstancebeans.RequestReferences;
67 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
68 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
69 import org.springframework.beans.factory.annotation.Autowired;
70 import org.springframework.beans.factory.annotation.Value;
71 import org.springframework.http.HttpEntity;
72 import org.springframework.http.HttpHeaders;
73 import org.springframework.http.HttpMethod;
74 import org.springframework.http.ResponseEntity;
75 import org.springframework.util.ResourceUtils;
76 import org.springframework.web.util.UriComponentsBuilder;
77 import com.fasterxml.jackson.core.JsonParseException;
78 import com.fasterxml.jackson.core.JsonProcessingException;
79 import com.fasterxml.jackson.databind.DeserializationFeature;
80 import com.fasterxml.jackson.databind.JsonMappingException;
81 import com.fasterxml.jackson.databind.ObjectMapper;
82 import com.github.tomakehurst.wiremock.http.Fault;
83
84 public class ServiceInstancesTest extends BaseTest {
85
86     private final ObjectMapper mapper = new ObjectMapper();
87
88     @Autowired
89     private ServiceInstances servInstances;
90
91     @Autowired
92     private RequestHandlerUtils requestHandlerUtils;
93
94     @Value("${wiremock.server.port}")
95     private String wiremockPort;
96
97     private final String servInstanceuri = "/onap/so/infra/serviceInstantiation/";
98     private final String servInstanceUriPrev7 = "/onap/so/infra/serviceInstances/";
99     private String uri;
100     private URL selfLink;
101     private URL initialUrl;
102     private int initialPort;
103     private HttpHeaders headers;
104
105     @Before
106     public void beforeClass() {
107         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
108         // set headers
109         headers = new HttpHeaders();
110         headers.set(ONAPLogConstants.Headers.PARTNER_NAME, "test_name");
111         headers.set(TRANSACTION_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
112         headers.set(ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
113         headers.set(ONAPLogConstants.MDCs.REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
114         headers.set(ONAP_PARTNER_NAME, "VID");
115         headers.set(REQUESTOR_ID, "xxxxxx");
116         try { // generate one-time port number to avoid RANDOM port number later.
117             initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH));
118             initialPort = initialUrl.getPort();
119         } catch (MalformedURLException e) {
120             e.printStackTrace();
121         }
122         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/")).willReturn(aResponse()
123                 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_OK)));
124         Mockito.doReturn(null).when(requestsDbClient).getInfraActiveRequestbyRequestId(Mockito.any());
125     }
126
127     public String inputStream(String JsonInput) throws IOException {
128         JsonInput = "src/test/resources/ServiceInstanceTest" + JsonInput;
129         return new String(Files.readAllBytes(Paths.get(JsonInput)));
130     }
131
132     private URL createExpectedSelfLink(String version, String requestId) {
133         System.out.println("createdUrl: " + initialUrl.toString());
134         try {
135             selfLink = new URL(initialUrl.toString().concat("/").concat(version).concat("/").concat(requestId));
136         } catch (MalformedURLException e) {
137             e.printStackTrace();
138         }
139         return selfLink;
140     }
141
142     private String getWiremockResponseForCatalogdb(String file) {
143         try {
144             File resource = ResourceUtils.getFile("classpath:__files/catalogdb/" + file);
145             return new String(Files.readAllBytes(resource.toPath())).replaceAll("localhost:8090",
146                     "localhost:" + wiremockPort);
147         } catch (IOException e) {
148             e.printStackTrace();
149             return null;
150         }
151
152     }
153
154     public ResponseEntity<String> sendRequest(String requestJson, String uriPath, HttpMethod reqMethod,
155             HttpHeaders headers) {
156
157         if (!headers.containsKey(HttpHeaders.ACCEPT)) {
158             headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
159         }
160         if (!headers.containsKey(HttpHeaders.CONTENT_TYPE)) {
161             headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
162         }
163
164         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(uriPath, initialPort));
165
166         HttpEntity<String> request = new HttpEntity<>(requestJson, headers);
167
168         return restTemplate.exchange(builder.toUriString(), reqMethod, request, String.class);
169     }
170
171     public ResponseEntity<String> sendRequest(String requestJson, String uriPath, HttpMethod reqMethod) {
172         return sendRequest(requestJson, uriPath, reqMethod, new HttpHeaders());
173     }
174
175     @Test
176     public void createServiceInstanceVIDDefault() throws IOException {
177         TestAppender.events.clear();
178
179         ServiceRecipe serviceRecipe = new ServiceRecipe();
180         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
181         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
182         serviceRecipe.setAction(Action.createInstance.toString());
183         serviceRecipe.setId(1);
184         serviceRecipe.setRecipeTimeout(180);
185         Service defaultService = new Service();
186         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
187
188
189         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
190                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
191                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
192
193         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
194                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
195                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
196
197         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
198                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
199                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
200
201         // expect
202         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
203         RequestReferences requestReferences = new RequestReferences();
204         requestReferences.setInstanceId("1882939");
205         requestReferences.setRequestSelfLink(createExpectedSelfLink("v5", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
206         expectedResponse.setRequestReferences(requestReferences);
207         uri = servInstanceuri + "v5/serviceInstances";
208         ResponseEntity<String> response =
209                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
210
211         // then
212         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
213         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
214         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
215     }
216
217     @Test
218     public void createServiceInstanceServiceInstancesUri() throws IOException {
219         ServiceRecipe serviceRecipe = new ServiceRecipe();
220         serviceRecipe.setOrchestrationUri("/mso/async/services/CreateGenericALaCarteServiceInstance");
221         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
222         serviceRecipe.setAction(Action.createInstance.toString());
223         serviceRecipe.setId(1);
224         serviceRecipe.setRecipeTimeout(180);
225         Service defaultService = new Service();
226         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
227
228         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/CreateGenericALaCarteServiceInstance"))
229                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
230                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
231
232
233         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
234                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
235                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
236
237         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
238                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
239                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
240         // expect
241         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
242         RequestReferences requestReferences = new RequestReferences();
243         requestReferences.setInstanceId("1882939");
244         requestReferences.setRequestSelfLink(createExpectedSelfLink("v5", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
245         expectedResponse.setRequestReferences(requestReferences);
246         uri = servInstanceuri + "v5";
247         ResponseEntity<String> response =
248                 sendRequest(inputStream("/ServiceInstancePrev7.json"), uri, HttpMethod.POST, headers);
249
250         // then
251         assertEquals(404, response.getStatusCode().value());
252         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
253     }
254
255     @Test
256     public void createServiceInstanceBpelStatusError() throws IOException {
257         ServiceRecipe serviceRecipe = new ServiceRecipe();
258         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
259         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
260         serviceRecipe.setAction(Action.createInstance.toString());
261         serviceRecipe.setId(1);
262         serviceRecipe.setRecipeTimeout(180);
263         Service defaultService = new Service();
264         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
265
266
267         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")).willReturn(aResponse()
268                 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
269                 .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_BAD_GATEWAY)));
270
271
272         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
273                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
274                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
275
276         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
277                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
278                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
279
280         uri = servInstanceuri + "v5/serviceInstances";
281         ResponseEntity<String> response =
282                 sendRequest(inputStream("/ServiceInstanceStatusError.json"), uri, HttpMethod.POST);
283
284         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
285     }
286
287     @Test
288     public void createServiceInstanceBadGateway() throws IOException {
289         ServiceRecipe serviceRecipe = new ServiceRecipe();
290         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
291         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
292         serviceRecipe.setAction(Action.createInstance.toString());
293         serviceRecipe.setId(1);
294         serviceRecipe.setRecipeTimeout(180);
295         Service defaultService = new Service();
296         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
297
298         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
299                 .willReturn(aResponse().withStatus(org.apache.http.HttpStatus.SC_BAD_GATEWAY).withBody("{}")));
300
301         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
302                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
303                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
304
305         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
306                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
307                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
308
309         uri = servInstanceuri + "v5/serviceInstances";
310         ResponseEntity<String> response =
311                 sendRequest(inputStream("/ServiceInstanceBadGateway.json"), uri, HttpMethod.POST);
312
313         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
314     }
315
316     @Test
317     public void createServiceInstanceEmptyResponse() throws IOException {
318         ServiceRecipe serviceRecipe = new ServiceRecipe();
319         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
320         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
321         serviceRecipe.setAction(Action.createInstance.toString());
322         serviceRecipe.setId(1);
323         serviceRecipe.setRecipeTimeout(180);
324         Service defaultService = new Service();
325         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
326
327         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
328                 .willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE)));
329
330         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
331                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
332                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
333
334         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
335                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
336                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
337
338         uri = servInstanceuri + "v5/serviceInstances";
339         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceEmpty.json"), uri, HttpMethod.POST);
340
341         assertEquals(Response.Status.BAD_GATEWAY.getStatusCode(), response.getStatusCode().value());
342     }
343
344     @Test
345     public void activateServiceInstanceNoRecipeALaCarte() throws IOException {
346         TestAppender.events.clear();
347         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/activate";
348         HttpHeaders requestIDheaders = new HttpHeaders();
349         requestIDheaders.set(ONAPLogConstants.Headers.REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
350         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceALaCarteTrueNoRecipe.json"), uri,
351                 HttpMethod.POST, requestIDheaders);
352
353         Service defaultService = new Service();
354         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
355
356         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
357                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
358                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
359
360
361         wireMockServer.stubFor(get(urlMatching(
362                 ".*/serviceRecipe/search/findFirstByServiceModelUUIDAndAction?serviceModelUUID=d88da85c-d9e8-4f73-b837-3a72a431622a&action=activateInstance"))
363                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
364                                 .withStatus(HttpStatus.SC_NOT_FOUND)));
365
366         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
367     }
368
369     @Test
370     public void activateServiceInstanceNoRecipe() throws IOException {
371         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/activate";
372         Service defaultService = new Service();
373         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
374         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
375                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
376                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
377
378         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search/.*")).willReturn(aResponse()
379                 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_NOT_FOUND)));
380
381         ResponseEntity<String> response =
382                 sendRequest(inputStream("/ServiceInstanceNoRecipe.json"), uri, HttpMethod.POST);
383
384         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
385     }
386
387     @Test
388     public void activateServiceInstance() throws IOException {
389         ServiceRecipe serviceRecipe = new ServiceRecipe();
390         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
391         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
392         serviceRecipe.setAction(Action.createInstance.toString());
393         serviceRecipe.setId(1);
394         serviceRecipe.setRecipeTimeout(180);
395         Service defaultService = new Service();
396         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
397
398         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
399                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
400                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
401
402         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
403                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
404                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
405
406         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
407                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
408                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
409         // expected response
410         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
411         RequestReferences requestReferences = new RequestReferences();
412         requestReferences.setInstanceId("1882939");
413         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
414         expectedResponse.setRequestReferences(requestReferences);
415         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/activate";
416         ResponseEntity<String> response =
417                 sendRequest(inputStream("/ServiceInstanceActivate.json"), uri, HttpMethod.POST, headers);
418
419         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
420         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
421         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
422     }
423
424     @Test
425     public void deactivateServiceInstance() throws IOException {
426
427         ServiceRecipe serviceRecipe = new ServiceRecipe();
428         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
429         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
430         serviceRecipe.setAction(Action.createInstance.toString());
431         serviceRecipe.setId(1);
432         serviceRecipe.setRecipeTimeout(180);
433         Service defaultService = new Service();
434         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
435
436         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
437                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
438                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
439
440         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
441                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
442                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
443
444         wireMockServer.stubFor(get(urlMatching(".*/service-design-and-creation/services/service/.*"))
445                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
446                         .withBodyFile("/aai/ServiceFromAAI.json").withStatus(HttpStatus.SC_OK)));
447
448         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
449                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
450                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
451
452         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
453                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
454                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
455
456         // expected response
457         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
458         RequestReferences requestReferences = new RequestReferences();
459         requestReferences.setInstanceId("1882939");
460         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
461         expectedResponse.setRequestReferences(requestReferences);
462         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/deactivate";
463         ResponseEntity<String> response =
464                 sendRequest(inputStream("/ServiceInstanceDeactivate.json"), uri, HttpMethod.POST, headers);
465
466         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
467         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
468         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
469     }
470
471     @Test
472     public void deleteServiceInstance() throws IOException {
473         ServiceRecipe serviceRecipe = new ServiceRecipe();
474         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
475         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
476         serviceRecipe.setAction(Action.createInstance.toString());
477         serviceRecipe.setId(1);
478         serviceRecipe.setRecipeTimeout(180);
479         Service defaultService = new Service();
480         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
481
482         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
483                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
484                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
485
486         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
487                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
488                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
489
490         wireMockServer.stubFor(get(urlMatching(".*/service-design-and-creation/services/service/.*"))
491                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
492                         .withBodyFile("/aai/ServiceFromAAI.json").withStatus(HttpStatus.SC_OK)));
493
494         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
495                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
496                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
497
498         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
499                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
500                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
501         // expected response
502         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
503         RequestReferences requestReferences = new RequestReferences();
504         requestReferences.setInstanceId("1882939");
505         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
506         expectedResponse.setRequestReferences(requestReferences);
507         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a8868/";
508         ResponseEntity<String> response =
509                 sendRequest(inputStream("/ServiceInstanceDelete.json"), uri, HttpMethod.DELETE, headers);
510
511         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
512         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
513         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
514     }
515
516     @Test
517     public void assignServiceInstance() throws IOException {
518         ServiceRecipe serviceRecipe = new ServiceRecipe();
519         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
520         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
521         serviceRecipe.setAction(Action.createInstance.toString());
522         serviceRecipe.setId(1);
523         serviceRecipe.setRecipeTimeout(180);
524         Service defaultService = new Service();
525         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
526
527         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
528                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
529                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
530
531         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
532                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
533                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
534
535         wireMockServer.stubFor(get(urlMatching(".*/service-design-and-creation/services/service/.*"))
536                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
537                         .withBodyFile("/aai/ServiceFromAAI.json").withStatus(HttpStatus.SC_OK)));
538
539         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
540                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
541                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
542
543         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
544                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
545                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
546         // expected response
547         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
548         RequestReferences requestReferences = new RequestReferences();
549         requestReferences.setInstanceId("1882939");
550         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
551         expectedResponse.setRequestReferences(requestReferences);
552         uri = servInstanceuri + "v7" + "/serviceInstances/assign";
553         ResponseEntity<String> response =
554                 sendRequest(inputStream("/ServiceAssign.json"), uri, HttpMethod.POST, headers);
555
556         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
557         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
558         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
559     }
560
561     @Test
562     public void unassignServiceInstance() throws IOException {
563         ServiceRecipe serviceRecipe = new ServiceRecipe();
564         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
565         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
566         serviceRecipe.setAction(Action.createInstance.toString());
567         serviceRecipe.setId(1);
568         serviceRecipe.setRecipeTimeout(180);
569         Service defaultService = new Service();
570         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
571
572         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
573                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
574                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
575
576         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
577                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
578                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
579
580         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
581                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
582                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
583
584         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
585                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
586                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
587         // expected response
588         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
589         RequestReferences requestReferences = new RequestReferences();
590         requestReferences.setInstanceId("1882939");
591         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
592         expectedResponse.setRequestReferences(requestReferences);
593         uri = servInstanceuri + "v7" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/unassign";
594         ResponseEntity<String> response =
595                 sendRequest(inputStream("/ServiceUnassign.json"), uri, HttpMethod.POST, headers);
596
597         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
598         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
599         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
600     }
601
602     @Test
603     public void createPortConfiguration() throws IOException {
604         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
605                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
606                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
607         // expected response
608         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
609         RequestReferences requestReferences = new RequestReferences();
610         requestReferences.setInstanceId("1882939");
611         requestReferences.setRequestSelfLink(createExpectedSelfLink("v5", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
612         expectedResponse.setRequestReferences(requestReferences);
613         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations";
614         ResponseEntity<String> response =
615                 sendRequest(inputStream("/ServiceInstancePortConfiguration.json"), uri, HttpMethod.POST, headers);
616
617         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
618         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
619         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
620         assertTrue(response.getBody().contains("1882939"));
621     }
622
623     @Test
624     public void createPortConfigurationEmptyProductFamilyId() throws IOException {
625         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations";
626         ResponseEntity<String> response =
627                 sendRequest(inputStream("/ServiceInstanceParseFail.json"), uri, HttpMethod.POST);
628
629         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
630     }
631
632     @Test
633     public void deletePortConfiguration() throws IOException {
634         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
635                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
636                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
637
638         // expected response
639         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
640         RequestReferences requestReferences = new RequestReferences();
641         requestReferences.setInstanceId("1882939");
642         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
643         expectedResponse.setRequestReferences(requestReferences);
644         uri = servInstanceuri + "v7"
645                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970";
646         ResponseEntity<String> response =
647                 sendRequest(inputStream("/ServiceInstance.json"), uri, HttpMethod.DELETE, headers);
648
649         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
650         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
651         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
652     }
653
654     @Test
655     public void enablePort() throws IOException {
656         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
657                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
658                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
659         // expected response
660         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
661         RequestReferences requestReferences = new RequestReferences();
662         requestReferences.setInstanceId("1882939");
663         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
664         expectedResponse.setRequestReferences(requestReferences);
665         uri = servInstanceuri + "v7"
666                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/enablePort";
667         ResponseEntity<String> response =
668                 sendRequest(inputStream("/ServiceInstanceEnablePort.json"), uri, HttpMethod.POST, headers);
669
670         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
671         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
672         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
673     }
674
675     @Test
676     public void disablePort() throws IOException {
677         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
678                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
679                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
680         // expected response
681         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
682         RequestReferences requestReferences = new RequestReferences();
683         requestReferences.setInstanceId("1882939");
684         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
685         expectedResponse.setRequestReferences(requestReferences);
686         uri = servInstanceuri + "v7"
687                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/disablePort";
688         ResponseEntity<String> response =
689                 sendRequest(inputStream("/ServiceInstanceDisablePort.json"), uri, HttpMethod.POST, headers);
690
691         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
692         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
693         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
694     }
695
696     @Test
697     public void activatePort() throws IOException {
698         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
699                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
700                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
701         // expected response
702         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
703         RequestReferences requestReferences = new RequestReferences();
704         requestReferences.setInstanceId("1882939");
705         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
706         expectedResponse.setRequestReferences(requestReferences);
707         uri = servInstanceuri + "v7"
708                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/activate";
709         ResponseEntity<String> response =
710                 sendRequest(inputStream("/ServiceInstanceActivatePort.json"), uri, HttpMethod.POST, headers);
711
712         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
713         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
714         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
715     }
716
717     @Test
718     public void deactivatePort() throws IOException {
719         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
720                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
721                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
722         // expected response
723         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
724         RequestReferences requestReferences = new RequestReferences();
725         requestReferences.setInstanceId("1882939");
726         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
727         expectedResponse.setRequestReferences(requestReferences);
728         uri = servInstanceuri + "v7"
729                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/deactivate";
730         ResponseEntity<String> response =
731                 sendRequest(inputStream("/ServiceInstanceDeactivatePort.json"), uri, HttpMethod.POST, headers);
732
733         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
734         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
735         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
736     }
737
738     @Test
739     public void addRelationships() throws IOException {
740         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
741                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
742                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
743         // expected response
744         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
745         RequestReferences requestReferences = new RequestReferences();
746         requestReferences.setInstanceId("1882939");
747         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
748         expectedResponse.setRequestReferences(requestReferences);
749         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/addRelationships";
750         ResponseEntity<String> response =
751                 sendRequest(inputStream("/AddRelationships.json"), uri, HttpMethod.POST, headers);
752
753         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
754         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
755         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
756     }
757
758     @Test
759     public void removeRelationships() throws IOException {
760         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
761                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
762                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
763         // expected response
764         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
765         RequestReferences requestReferences = new RequestReferences();
766         requestReferences.setInstanceId("1882939");
767         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
768         expectedResponse.setRequestReferences(requestReferences);
769         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/removeRelationships";
770         ResponseEntity<String> response =
771                 sendRequest(inputStream("/RemoveRelationships.json"), uri, HttpMethod.POST, headers);
772
773         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
774         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
775         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
776     }
777
778     @Test
779     public void createVnfInstanceNoALaCarte() throws IOException {
780         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
781                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
782                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
783
784
785         wireMockServer.stubFor(get(urlMatching(
786                 ".*/vnfResourceCustomization/search/findByModelCustomizationUUID[?]MODEL_CUSTOMIZATION_UUID=68dc9a92-214c-11e7-93ae-92361f002671"))
787                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
788                                 .withBody(getWiremockResponseForCatalogdb(
789                                         "vnfResourceCustomization_ReplaceVnf_Response.json"))
790                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
791
792         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/1/vnfResources"))
793                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
794                         .withBody(getWiremockResponseForCatalogdb("vnfResources_ReplaceVnf_Response.json"))
795                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
796
797         wireMockServer.stubFor(get(urlMatching(
798                 ".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]nfRole=GR-API-DEFAULT&action=createInstance"))
799                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
800                                 .withBody(getWiremockResponseForCatalogdb("vnfRecipeReplaceInstance_Response.json"))
801                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
802
803         // expected response
804         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
805         RequestReferences requestReferences = new RequestReferences();
806         requestReferences.setInstanceId("1882939");
807         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
808         expectedResponse.setRequestReferences(requestReferences);
809         uri = servInstanceuri + "v7" + "/serviceInstances/49585b36-2b5a-443a-8b10-c75d34bb5e46/vnfs";
810         ResponseEntity<String> response =
811                 sendRequest(inputStream("/VnfCreateDefault.json"), uri, HttpMethod.POST, headers);
812
813         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
814         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
815         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
816     }
817
818     @Test
819     public void createVnfInstance() throws IOException {
820         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
821                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
822                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
823
824         wireMockServer.stubFor(get(urlMatching(".*/service/5df8b6de-2083-11e7-93ae-92361f002672"))
825                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
826                         .withBody(getWiremockResponseForCatalogdb("serviceVnf_Response.json"))
827                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
828         wireMockServer.stubFor(get(urlMatching(".*/service/5df8b6de-2083-11e7-93ae-92361f002672/vnfCustomizations"))
829                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
830                         .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomizationsList_Response.json"))
831                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
832
833
834         wireMockServer.stubFor(
835                 get(urlMatching(".*/vnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002672/vnfResources"))
836                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
837                                 .withBody(getWiremockResponseForCatalogdb("vnfResourcesCreateVnf_Response.json"))
838                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
839
840         wireMockServer.stubFor(get(urlMatching(
841                 ".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]nfRole=GR-API-DEFAULT&action=createInstance"))
842                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
843                                 .withBody(getWiremockResponseForCatalogdb("vnfRecipeCreateInstance_Response.json"))
844                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
845
846         // expected response
847         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
848         RequestReferences requestReferences = new RequestReferences();
849         requestReferences.setInstanceId("1882939");
850         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
851         expectedResponse.setRequestReferences(requestReferences);
852         uri = servInstanceuri + "v7" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs";
853         ResponseEntity<String> response =
854                 sendRequest(inputStream("/VnfWithServiceRelatedInstance.json"), uri, HttpMethod.POST, headers);
855
856         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
857         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
858         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
859         assertTrue(response.getBody().contains("1882939"));
860     }
861
862     @Test
863     public void createVnfWithServiceRelatedInstanceFail() throws IOException {
864         uri = servInstanceUriPrev7 + "v6" + "/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs";
865         ResponseEntity<String> response =
866                 sendRequest(inputStream("/VnfWithServiceRelatedInstanceFail.json"), uri, HttpMethod.POST);
867
868         assertEquals(404, response.getStatusCode().value());
869     }
870
871     @Test
872     public void createVnfInstanceInvalidVnfResource() throws IOException {
873         uri = servInstanceuri + "v7" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs";
874         ResponseEntity<String> response = sendRequest(inputStream("/NoVnfResource.json"), uri, HttpMethod.POST);
875
876         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
877         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
878         assertEquals("No valid vnfResource is specified", realResponse.getServiceException().getText());
879     }
880
881     @Test
882     public void replaceVnfInstance() throws IOException {
883         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
884                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
885                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
886
887         wireMockServer.stubFor(get(urlMatching(
888                 ".*/vnfResourceCustomization/search/findByModelCustomizationUUID[?]MODEL_CUSTOMIZATION_UUID=68dc9a92-214c-11e7-93ae-92361f002671"))
889                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
890                                 .withBody(getWiremockResponseForCatalogdb(
891                                         "vnfResourceCustomization_ReplaceVnf_Response.json"))
892                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
893
894         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/1/vnfResources"))
895                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
896                         .withBody(getWiremockResponseForCatalogdb("vnfResources_ReplaceVnf_Response.json"))
897                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
898
899         wireMockServer.stubFor(get(urlMatching(
900                 ".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]nfRole=GR-API-DEFAULT&action=replaceInstance"))
901                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
902                                 .withBody(getWiremockResponseForCatalogdb("vnfRecipeReplaceInstance_Response.json"))
903                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
904         // expected response
905         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
906         RequestReferences requestReferences = new RequestReferences();
907         requestReferences.setInstanceId("1882939");
908         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
909         expectedResponse.setRequestReferences(requestReferences);
910         uri = servInstanceuri + "v7"
911                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
912         ResponseEntity<String> response = sendRequest(inputStream("/ReplaceVnf.json"), uri, HttpMethod.POST, headers);
913
914         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
915         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
916         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
917     }
918
919     @Test
920     public void replaceVnfInstanceNoCloudConfig() throws IOException {
921         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/v1/getInfraActiveRequests.*"))
922                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
923                         .withBodyFile("infra/VnfLookup.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
924         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
925                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
926                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
927         wireMockServer.stubFor(get(urlMatching(
928                 ".*/vnfResourceCustomization/search/findByModelCustomizationUUID[?]MODEL_CUSTOMIZATION_UUID=68dc9a92-214c-11e7-93ae-92361f002671"))
929                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
930                                 .withBody(getWiremockResponseForCatalogdb(
931                                         "vnfResourceCustomization_ReplaceVnf_Response.json"))
932                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
933         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/1/vnfResources"))
934                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
935                         .withBody(getWiremockResponseForCatalogdb("vnfResources_ReplaceVnf_Response.json"))
936                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
937         wireMockServer.stubFor(get(urlMatching(
938                 ".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]nfRole=GR-API-DEFAULT&action=replaceInstance"))
939                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
940                                 .withBody(getWiremockResponseForCatalogdb("vnfRecipeReplaceInstance_Response.json"))
941                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
942         // expected response
943         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
944         RequestReferences requestReferences = new RequestReferences();
945         requestReferences.setInstanceId("1882939");
946         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
947         expectedResponse.setRequestReferences(requestReferences);
948         uri = servInstanceuri + "v7"
949                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
950         ResponseEntity<String> response =
951                 sendRequest(inputStream("/ReplaceVnfNoCloudConfig.json"), uri, HttpMethod.POST, headers);
952
953         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
954         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
955         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
956     }
957
958     @Test
959     public void replaceVnfRecreateInstance() throws IOException {
960         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/RecreateInfraVce"))
961                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
962                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
963
964         wireMockServer.stubFor(get(urlMatching(
965                 ".*/vnfResourceCustomization/search/findByModelCustomizationUUID[?]MODEL_CUSTOMIZATION_UUID=68dc9a92-214c-11e7-93ae-92361f002674"))
966                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
967                                 .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomization_Response.json"))
968                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
969
970         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/4/vnfResources"))
971                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
972                         .withBody(getWiremockResponseForCatalogdb("vnfResources_Response.json"))
973                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
974
975         wireMockServer.stubFor(get(urlMatching(
976                 ".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]nfRole=TEST&action=replaceInstance"))
977                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
978                                 .withBody(getWiremockResponseForCatalogdb("vnfRecipe_Response.json"))
979                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
980
981         // expected response
982         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
983         RequestReferences requestReferences = new RequestReferences();
984         requestReferences.setInstanceId("1882939");
985         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
986         expectedResponse.setRequestReferences(requestReferences);
987         uri = servInstanceuri + "v7"
988                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
989         ResponseEntity<String> response =
990                 sendRequest(inputStream("/ReplaceVnfRecreate.json"), uri, HttpMethod.POST, headers);
991         logger.debug(response.getBody());
992
993         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
994         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
995         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
996     }
997
998     @Test
999     public void recreateVnfInstance() throws IOException {
1000         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1001                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1002                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1003
1004         wireMockServer.stubFor(get(urlMatching(
1005                 ".*/vnfResourceCustomization/search/findByModelCustomizationUUID[?]MODEL_CUSTOMIZATION_UUID=68dc9a92-214c-11e7-93ae-92361f002674"))
1006                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1007                                 .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomization_Response"))
1008                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1009
1010         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/4/vnfResources"))
1011                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1012                         .withBody(getWiremockResponseForCatalogdb("vnfResources_Response.json"))
1013                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1014
1015         wireMockServer.stubFor(get(urlMatching(
1016                 ".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]nfRole=GR-API-DEFAULT&action=recreateInstance"))
1017                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1018                                 .withBody(getWiremockResponseForCatalogdb("vnfRecipe_ResponseWorkflowAction.json"))
1019                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1020
1021         // expected response
1022         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1023         RequestReferences requestReferences = new RequestReferences();
1024         requestReferences.setInstanceId("1882939");
1025         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1026         expectedResponse.setRequestReferences(requestReferences);
1027         uri = servInstanceuri + "v7"
1028                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/recreate";
1029         ResponseEntity<String> response = sendRequest(inputStream("/VnfRecreate.json"), uri, HttpMethod.POST, headers);
1030         logger.debug(response.getBody());
1031
1032         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1033         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1034         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1035     }
1036
1037     @Test
1038     public void updateVnfInstance() throws IOException {
1039         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1040                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1041                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1042
1043         wireMockServer.stubFor(get(urlMatching(
1044                 ".*/vnfResourceCustomization/search/findByModelCustomizationUUID[?]MODEL_CUSTOMIZATION_UUID=68dc9a92-214c-11e7-93ae-92361f002674"))
1045                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1046                                 .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomization_Response.json"))
1047                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1048
1049         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/4/vnfResources"))
1050                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1051                         .withBody(getWiremockResponseForCatalogdb("vnfResources_Response.json"))
1052                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1053
1054         wireMockServer.stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction"
1055                 + "[?]nfRole=GR-API-DEFAULT&action=updateInstance"))
1056                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1057                                 .withBody(getWiremockResponseForCatalogdb("UpdateVnfRecipe_Response.json"))
1058                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1059
1060         // expected response
1061         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1062         RequestReferences requestReferences = new RequestReferences();
1063         requestReferences.setInstanceId("1882939");
1064         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1065         expectedResponse.setRequestReferences(requestReferences);
1066         uri = servInstanceuri + "v7"
1067                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1068         ResponseEntity<String> response = sendRequest(inputStream("/UpdateVnf.json"), uri, HttpMethod.PUT, headers);
1069
1070         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1071         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1072         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1073     }
1074
1075     @Test
1076     public void applyUpdatedConfig() throws IOException {
1077         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/VnfConfigUpdate"))
1078                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1079                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1080
1081
1082         wireMockServer.stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction"
1083                 + "[?]nfRole=GR-API-DEFAULT&action=applyUpdatedConfig"))
1084                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1085                                 .withBody(getWiremockResponseForCatalogdb("vnfRecipeApplyUpdatedConfig_Response.json"))
1086                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1087
1088         // expected response
1089         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1090         RequestReferences requestReferences = new RequestReferences();
1091         requestReferences.setInstanceId("1882939");
1092         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1093         expectedResponse.setRequestReferences(requestReferences);
1094         uri = servInstanceuri + "v7"
1095                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/applyUpdatedConfig";
1096         ResponseEntity<String> response =
1097                 sendRequest(inputStream("/ApplyUpdatedConfig.json"), uri, HttpMethod.POST, headers);
1098
1099         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1100         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1101         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1102     }
1103
1104     @Test
1105     public void deleteVnfInstanceV5() throws IOException {
1106         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1107                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1108                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1109
1110         wireMockServer.stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction"
1111                 + "[?]nfRole=GR-API-DEFAULT&action=deleteInstance"))
1112                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1113                                 .withBody(getWiremockResponseForCatalogdb("vnfRecipeDelete_Response.json"))
1114                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1115         // expected response
1116         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1117         RequestReferences requestReferences = new RequestReferences();
1118         requestReferences.setInstanceId("1882939");
1119         requestReferences.setRequestSelfLink(createExpectedSelfLink("v5", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1120         expectedResponse.setRequestReferences(requestReferences);
1121         uri = servInstanceuri + "v5"
1122                 + "/serviceInstances/e446b97d-9c35-437a-95a2-6b4c542c4507/vnfs/49befbfe-fccb-421d-bb4c-0734a43f5ea0";
1123         ResponseEntity<String> response =
1124                 sendRequest(inputStream("/DeleteVnfV5.json"), uri, HttpMethod.DELETE, headers);
1125
1126         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1127         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1128         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1129     }
1130
1131     @Test
1132     public void createVfModuleInstance() throws IOException {
1133         wireMockServer.stubFor(get(urlMatching(
1134                 "/vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc\\?MODEL_CUSTOMIZATION_UUID=cb82ffd8-252a-11e7-93ae-92361f002671"))
1135                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1136                                 .withBody(getWiremockResponseForCatalogdb("vfModuleCustomization_Response.json"))
1137                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1138
1139         wireMockServer.stubFor(get(urlMatching("/vfModule/20c4431c-246d-11e7-93ae-92361f002671"))
1140                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1141                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1142                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1143
1144         wireMockServer.stubFor(get(urlMatching("/vfModuleCustomization/1/vfModule"))
1145                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1146                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1147                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1148
1149         wireMockServer.stubFor(get(urlMatching(
1150                 "/vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc\\?MODEL_CUSTOMIZATION_UUID=20c4431c-246d-11e7-93ae-92361f002671"))
1151                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1152                                 .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1153                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1154
1155         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/CreateVfModuleInfra"))
1156                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1157                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1158
1159         wireMockServer.stubFor(get(urlMatching(
1160                 "/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1161                         + "[?]vfModuleModelUUID=20c4431c-246d-11e7-93ae-92361f002671&vnfComponentType=vfModule&action=createInstance"))
1162                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1163                                         .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipe_Response.json"))
1164                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1165         // expected response
1166         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1167         RequestReferences requestReferences = new RequestReferences();
1168         requestReferences.setInstanceId("1882939");
1169         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1170         expectedResponse.setRequestReferences(requestReferences);
1171         uri = servInstanceuri + "v7"
1172                 + "/serviceInstances/7a88cbeb-0ec8-4765-a271-4f9e90c3da7b/vnfs/cbba721b-4803-4df7-9347-307c9a955426/vfModules";
1173         ResponseEntity<String> response =
1174                 sendRequest(inputStream("/VfModuleWithRelatedInstances.json"), uri, HttpMethod.POST, headers);
1175
1176         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1177         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1178         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1179         assertTrue(response.getBody().contains("1882939"));
1180     }
1181
1182     @Test
1183     public void createVfModuleInstanceNoModelCustomization() throws IOException {
1184         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/CreateVfModuleInfra"))
1185                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1186                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1187
1188         wireMockServer.stubFor(get(urlMatching(".*/vnfResource/fe6478e4-ea33-3346-ac12-ab121484a3fe"))
1189                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1190                         .withBody(getWiremockResponseForCatalogdb("vnfResourceForVfModule_Response.json"))
1191                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1192
1193         wireMockServer
1194                 .stubFor(get(urlMatching(".*/vnfResourceCustomization/search/findByModelInstanceNameAndVnfResources"
1195                         + "[?]MODEL_INSTANCE_NAME=test&VNF_RESOURCE_MODEL_UUID=fe6478e4-ea33-3346-ac12-ab121484a3fe"))
1196                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1197                                         .withBody(getWiremockResponseForCatalogdb(
1198                                                 "vnfResourceCustomizationForVfModule_Response.json"))
1199                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1200
1201         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/3/vfModuleCustomizations"))
1202                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1203                         .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationsPCM_Response.json"))
1204                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1205
1206         wireMockServer.stubFor(get(urlMatching(
1207                 ".*/vfModuleCustomization/search/findFirstByModelCustomizationUUIDAndVfModuleModelUUIDOrderByCreatedDesc[?]"
1208                         + "MODEL_CUSTOMIZATION_UUID=b4ea86b4-253f-11e7-93ae-92361f002672&MODEL_UUID=066de97e-253e-11e7-93ae-92361f002672"))
1209                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1210                                         .withBody(getWiremockResponseForCatalogdb(
1211                                                 "vfModuleCustomizationPCM_Response.json"))
1212                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1213
1214         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/2/vfModule"))
1215                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1216                         .withBody(getWiremockResponseForCatalogdb("vfModulePCM_Response.json"))
1217                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1218
1219         wireMockServer.stubFor(get(urlMatching(".*/vfModule/066de97e-253e-11e7-93ae-92361f002672"))
1220                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1221                         .withBody(getWiremockResponseForCatalogdb("vfModulePCM_Response.json"))
1222                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1223
1224
1225         wireMockServer.stubFor(
1226                 get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVnfComponentTypeAndAction"
1227                         + "[?]vnfComponentType=vfModule&action=createInstance"))
1228                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1229                                         .withBody(getWiremockResponseForCatalogdb(
1230                                                 "vnfComponentRecipeVNF_API_Response.json"))
1231                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1232
1233         // expected response
1234         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1235         RequestReferences requestReferences = new RequestReferences();
1236         requestReferences.setInstanceId("1882939");
1237         requestReferences.setRequestSelfLink(createExpectedSelfLink("v6", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1238         expectedResponse.setRequestReferences(requestReferences);
1239         uri = servInstanceuri + "v6"
1240                 + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules";
1241         ResponseEntity<String> response =
1242                 sendRequest(inputStream("/VfModuleNoModelCustomization.json"), uri, HttpMethod.POST, headers);
1243         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1244         ObjectMapper mapper = new ObjectMapper();
1245         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1246         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1247     }
1248
1249     @Test
1250     public void deleteVfModuleInstanceNoMatchingModelUUD() throws IOException {
1251         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1252                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1253                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1254
1255         wireMockServer.stubFor(get(urlMatching(".*/vnfResource/.*"))
1256                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1257                         .withBody(getWiremockResponseForCatalogdb("vnfResourceForVfModule_Response.json"))
1258                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1259
1260         wireMockServer
1261                 .stubFor(get(urlMatching(".*/vnfResourceCustomization/search/findByModelInstanceNameAndVnfResources.*"))
1262                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1263                                 .withBody(getWiremockResponseForCatalogdb(
1264                                         "vnfResourceCustomizationForVfModule_Response.json"))
1265                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1266
1267         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/3/vfModuleCustomizations"))
1268                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1269                         .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationsPCM_Response.json"))
1270                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1271
1272         wireMockServer.stubFor(get(urlMatching(
1273                 ".*/vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc[?]MODEL_CUSTOMIZATION_UUID=b4ea86b4-253f-11e7-93ae-92361f002672"))
1274                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1275                                 .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationPCM_Response.json"))
1276                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1277
1278         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/2/vfModule"))
1279                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1280                         .withBody(getWiremockResponseForCatalogdb("vfModulePCM_Response.json"))
1281                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1282
1283         wireMockServer.stubFor(get(urlMatching(".*/vfModule/066de97e-253e-11e7-93ae-92361f002672"))
1284                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1285                         .withBody(getWiremockResponseForCatalogdb("vfModulePCM_Response.json"))
1286                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1287
1288         wireMockServer.stubFor(get(urlMatching(
1289                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1290                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=deleteInstance"))
1291                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1292                                         .withBody(getWiremockResponseForCatalogdb(
1293                                                 "vnfComponentRecipeDeleteVfModule_Response.json"))
1294                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1295
1296         // expected response
1297         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1298         RequestReferences requestReferences = new RequestReferences();
1299         requestReferences.setInstanceId("1882939");
1300         requestReferences.setRequestSelfLink(createExpectedSelfLink("v6", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1301         expectedResponse.setRequestReferences(requestReferences);
1302         uri = servInstanceuri + "v6"
1303                 + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1304         ResponseEntity<String> response =
1305                 sendRequest(inputStream("/VfModuleNoMatchingModelUUID.json"), uri, HttpMethod.DELETE, headers);
1306
1307
1308         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1309         ObjectMapper mapper = new ObjectMapper();
1310         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1311         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1312     }
1313
1314     @Test
1315     public void createVfModuleInstanceNoRecipe() throws IOException {
1316
1317         wireMockServer.stubFor(get(urlMatching(".*/vnfResource/fe6478e4-ea33-3346-ac12-ab121484a3fe"))
1318                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1319                         .withBody(getWiremockResponseForCatalogdb("vnfResourceForVfModule_Response.json"))
1320                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1321
1322         wireMockServer
1323                 .stubFor(get(urlMatching(".*/vnfResourceCustomization/search/findByModelInstanceNameAndVnfResources"
1324                         + "[?]MODEL_INSTANCE_NAME=test&VNF_RESOURCE_MODEL_UUID=fe6478e4-ea33-3346-ac12-ab121484a3fe"))
1325                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1326                                         .withBody(getWiremockResponseForCatalogdb(
1327                                                 "vnfResourceCustomizationForVfModule_Response.json"))
1328                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1329
1330         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/3/vfModuleCustomizations"))
1331                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1332                         .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationsPCM_Response.json"))
1333                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1334
1335         wireMockServer.stubFor(
1336                 get(urlMatching(".*/vfModuleCustomization/search/findByModelCustomizationUUIDAndVfModuleModelUUID[?]"
1337                         + "modelCustomizationUUID=b4ea86b4-253f-11e7-93ae-92361f002672&vfModuleModelUUID=066de97e-253e-11e7-93ae-92361f002672"))
1338                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1339                                         .withBody(getWiremockResponseForCatalogdb(
1340                                                 "vfModuleCustomizationPCM_Response.json"))
1341                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1342
1343         uri = servInstanceuri + "v6"
1344                 + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules";
1345         ResponseEntity<String> response =
1346                 sendRequest(inputStream("/VfModuleInvalid.json"), uri, HttpMethod.POST, headers);
1347
1348         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
1349         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
1350         assertEquals("No valid vfModuleCustomization is specified", realResponse.getServiceException().getText());
1351     }
1352
1353     @Test
1354     public void replaceVfModuleInstance() throws IOException {
1355         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1356                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1357                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1358
1359         wireMockServer
1360                 .stubFor(get(urlMatching(".*/vfModule/search/findFirstVfModuleByModelInvariantUUIDAndModelVersion[?]"
1361                         + "modelInvariantUUID=78ca26d0-246d-11e7-93ae-92361f002671&modelVersion=2"))
1362                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1363                                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1364                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1365
1366         wireMockServer.stubFor(get(urlMatching(
1367                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1368                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=replaceInstance"))
1369                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1370                                         .withBody(getWiremockResponseForCatalogdb(
1371                                                 "vnfComponentRecipeDeleteVfModule_Response.json"))
1372                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1373         // expected response
1374         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1375         RequestReferences requestReferences = new RequestReferences();
1376         requestReferences.setInstanceId("1882939");
1377         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1378         expectedResponse.setRequestReferences(requestReferences);
1379         uri = servInstanceuri + "v7"
1380                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
1381         ResponseEntity<String> response =
1382                 sendRequest(inputStream("/ReplaceVfModule.json"), uri, HttpMethod.POST, headers);
1383
1384         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1385         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1386         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1387     }
1388
1389     @Test
1390     public void replaceVfModuleInstanceNoCloudConfigurationTest() throws IOException {
1391         wireMockServer.stubFor(
1392                 get(urlPathEqualTo("/aai/v19/network/generic-vnfs/generic-vnf/ff305d54-75b4-431b-adb2-eb6b9e5ff000"))
1393                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1394                                 .withBodyFile("infra/Vnf.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1395         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1396                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1397                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1398         wireMockServer
1399                 .stubFor(get(urlMatching(".*/vfModule/search/findFirstVfModuleByModelInvariantUUIDAndModelVersion[?]"
1400                         + "modelInvariantUUID=78ca26d0-246d-11e7-93ae-92361f002671&modelVersion=2"))
1401                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1402                                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1403                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1404         wireMockServer.stubFor(get(urlMatching(
1405                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1406                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=replaceInstance"))
1407                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1408                                         .withBody(getWiremockResponseForCatalogdb(
1409                                                 "vnfComponentRecipeDeleteVfModule_Response.json"))
1410                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1411         // expected response
1412         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1413         RequestReferences requestReferences = new RequestReferences();
1414         requestReferences.setInstanceId("1882939");
1415         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1416         expectedResponse.setRequestReferences(requestReferences);
1417         uri = servInstanceuri + "v7"
1418                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
1419         ResponseEntity<String> response =
1420                 sendRequest(inputStream("/ReplaceVfModuleNoCloudConfig.json"), uri, HttpMethod.POST, headers);
1421
1422         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1423         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1424         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1425     }
1426
1427     @Test
1428     public void updateVfModuleInstance() throws IOException {
1429         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1430                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1431                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1432
1433         wireMockServer.stubFor(get(urlMatching(
1434                 ".*/vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc[?]MODEL_CUSTOMIZATION_UUID=cb82ffd8-252a-11e7-93ae-92361f002671"))
1435                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1436                                 .withBody(getWiremockResponseForCatalogdb("vfModuleCustomization_Response.json"))
1437                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1438
1439         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/1/vfModule"))
1440                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1441                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1442                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1443
1444         wireMockServer.stubFor(get(urlMatching(".*/vfModule/20c4431c-246d-11e7-93ae-92361f002671"))
1445                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1446                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1447                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1448
1449         wireMockServer.stubFor(get(urlMatching(
1450                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1451                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=updateInstance"))
1452                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1453                                         .withBody(getWiremockResponseForCatalogdb(
1454                                                 "vnfComponentRecipe_GRAPI_Response.json"))
1455                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1456
1457         // expected response
1458         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1459         RequestReferences requestReferences = new RequestReferences();
1460         requestReferences.setInstanceId("1882939");
1461         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1462         expectedResponse.setRequestReferences(requestReferences);
1463         uri = servInstanceuri + "v7"
1464                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1465         ResponseEntity<String> response =
1466                 sendRequest(inputStream("/UpdateVfModule.json"), uri, HttpMethod.PUT, headers);
1467         logger.debug(response.getBody());
1468
1469         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1470         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1471         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1472     }
1473
1474     @Test
1475     public void createVfModuleNoModelType() throws IOException {
1476         InfraActiveRequests expectedRecord = new InfraActiveRequests();
1477         expectedRecord.setRequestStatus("FAILED");
1478         expectedRecord.setStatusMessage("Error parsing request: No valid modelType is specified");
1479         expectedRecord.setProgress(100L);
1480         expectedRecord.setSource("VID");
1481         expectedRecord.setRequestBody(inputStream("/VfModuleNoModelType.json"));
1482         expectedRecord.setLastModifiedBy("APIH");
1483         expectedRecord.setVfModuleName("testVfModule2");
1484         expectedRecord.setVfModuleModelName("serviceModel");
1485         expectedRecord.setRequestScope("vfModule");
1486         expectedRecord.setRequestAction("createInstance");
1487         expectedRecord.setRequestorId("zz9999");
1488         expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
1489         // VnfType is not sent in this request, should be blank in db
1490         expectedRecord.setVnfType("");
1491         uri = servInstanceuri
1492                 + "v5/serviceInstances/32807a28-1a14-4b88-b7b3-2950918aa76d/vnfs/32807a28-1a14-4b88-b7b3-2950918aa76d/vfModules";
1493
1494         ResponseEntity<String> response =
1495                 sendRequest(inputStream("/VfModuleNoModelType.json"), uri, HttpMethod.POST, headers);
1496         // ActualRecord
1497         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
1498     }
1499
1500     @Test
1501     public void inPlaceSoftwareUpdate() throws IOException {
1502         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/VnfInPlaceUpdate"))
1503                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1504                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1505
1506         wireMockServer.stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]"
1507                 + "nfRole=GR-API-DEFAULT&action=inPlaceSoftwareUpdate"))
1508                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1509                                 .withBody(getWiremockResponseForCatalogdb("vnfRecipeInPlaceUpdate_Response.json"))
1510                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1511
1512         // expected response
1513         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1514         RequestReferences requestReferences = new RequestReferences();
1515         requestReferences.setInstanceId("1882939");
1516         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1517         expectedResponse.setRequestReferences(requestReferences);
1518         uri = servInstanceuri + "v7"
1519                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/inPlaceSoftwareUpdate";
1520         ResponseEntity<String> response =
1521                 sendRequest(inputStream("/InPlaceSoftwareUpdate.json"), uri, HttpMethod.POST, headers);
1522
1523         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1524         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1525         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1526     }
1527
1528     @Test
1529     public void deleteVfModuleInstance() throws IOException {
1530         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1531                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1532                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1533
1534         wireMockServer
1535                 .stubFor(get(urlMatching(".*/vfModule/search/findFirstVfModuleByModelInvariantUUIDAndModelVersion[?]"
1536                         + "modelInvariantUUID=78ca26d0-246d-11e7-93ae-92361f002671&modelVersion=2"))
1537                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1538                                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1539                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1540
1541         wireMockServer.stubFor(get(urlMatching(
1542                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1543                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=deleteInstance"))
1544                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1545                                         .withBody(getWiremockResponseForCatalogdb(
1546                                                 "vnfComponentRecipeDeleteVfModule_Response.json"))
1547                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1548
1549         // expected response
1550         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1551         RequestReferences requestReferences = new RequestReferences();
1552         requestReferences.setInstanceId("1882939");
1553         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1554         expectedResponse.setRequestReferences(requestReferences);
1555         uri = servInstanceuri + "v7"
1556                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1557         ResponseEntity<String> response =
1558                 sendRequest(inputStream("/DeleteVfModule.json"), uri, HttpMethod.DELETE, headers);
1559
1560         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1561         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1562         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1563     }
1564
1565     @Test
1566     public void deleteVfModuleNoModelInvariantId() throws IOException {
1567         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1568                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1569                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1570
1571         wireMockServer.stubFor(get(urlMatching(
1572                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1573                         + "[?]vfModuleModelUUID=VNF-API-DEFAULT&vnfComponentType=vfModule&action=deleteInstance"))
1574                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1575                                         .withBody(getWiremockResponseForCatalogdb(
1576                                                 "vnfComponentRecipeDeleteVfModule_Response.json"))
1577                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1578
1579         // expected response
1580         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1581         RequestReferences requestReferences = new RequestReferences();
1582         requestReferences.setInstanceId("1882939");
1583         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1584         expectedResponse.setRequestReferences(requestReferences);
1585         uri = servInstanceuri + "v7"
1586                 + "/serviceInstances/196b4a84-0858-4317-a1f6-497e2e52ae43/vnfs/36e4f902-ec32-451e-8d53-e3edc19e40a4/vfModules/09f3a38d-933f-450a-8784-9e6c4dec3f72";
1587         ResponseEntity<String> response =
1588                 sendRequest(inputStream("/DeleteVfModuleNoModelInvariantId.json"), uri, HttpMethod.DELETE, headers);
1589
1590         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1591         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1592         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1593     }
1594
1595     @Test
1596     public void deactivateAndCloudDeleteVfModuleInstance() throws IOException {
1597         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1598                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1599                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1600
1601         wireMockServer
1602                 .stubFor(get(urlMatching(".*/vfModule/search/findFirstVfModuleByModelInvariantUUIDAndModelVersion[?]"
1603                         + "modelInvariantUUID=78ca26d0-246d-11e7-93ae-92361f002671&modelVersion=2"))
1604                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1605                                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1606                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1607
1608         wireMockServer.stubFor(get(urlMatching(
1609                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1610                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=deactivateAndCloudDelete"))
1611                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1612                                         .withBody(getWiremockResponseForCatalogdb(
1613                                                 "vnfComponentRecipeDeactivate_Response.json"))
1614                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1615
1616         // expected response
1617         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1618         RequestReferences requestReferences = new RequestReferences();
1619         requestReferences.setInstanceId("1882939");
1620         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1621         expectedResponse.setRequestReferences(requestReferences);
1622         uri = servInstanceuri + "v7"
1623                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000/deactivateAndCloudDelete";
1624         ResponseEntity<String> response =
1625                 sendRequest(inputStream("/DeactivateAndCloudDeleteVfModule.json"), uri, HttpMethod.POST, headers);
1626
1627         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1628         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1629         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1630     }
1631
1632     @Test
1633     public void createVolumeGroupInstance() throws IOException {
1634         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1635                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1636                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1637
1638         wireMockServer.stubFor(get(urlMatching(
1639                 ".*/vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc[?]MODEL_CUSTOMIZATION_UUID=b4ea86b4-253f-11e7-93ae-92361f002671"))
1640                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1641                                 .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationVolGrp_Response.json"))
1642                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1643
1644         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/1/vfModule"))
1645                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1646                         .withBody(getWiremockResponseForCatalogdb("vfModuleVolGroup_Response.json"))
1647                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1648
1649         wireMockServer.stubFor(get(urlMatching(
1650                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1651                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=volumeGroup&action=createInstance"))
1652                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1653                                         .withBody(getWiremockResponseForCatalogdb(
1654                                                 "vnfComponentRecipeVolGrp_GRAPI_Response.json"))
1655                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1656
1657         // expected response
1658         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1659         RequestReferences requestReferences = new RequestReferences();
1660         requestReferences.setInstanceId("1882939");
1661         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1662         expectedResponse.setRequestReferences(requestReferences);
1663         uri = servInstanceuri + "v7"
1664                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups";
1665         ResponseEntity<String> response = sendRequest(inputStream("/VolumeGroup.json"), uri, HttpMethod.POST, headers);
1666
1667         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1668         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1669         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1670         assertTrue(response.getBody().contains("1882939"));
1671     }
1672
1673     @Test
1674     public void updateVolumeGroupInstance() throws IOException {
1675         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1676                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1677                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1678
1679         wireMockServer.stubFor(get(urlMatching(
1680                 ".*/vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc[?]MODEL_CUSTOMIZATION_UUID=b4ea86b4-253f-11e7-93ae-92361f002671"))
1681                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1682                                 .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationVolGrp_Response.json"))
1683                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1684
1685         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/1/vfModule"))
1686                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1687                         .withBody(getWiremockResponseForCatalogdb("vfModuleVolGroup_Response.json"))
1688                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1689
1690         wireMockServer.stubFor(get(urlMatching(
1691                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1692                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=volumeGroup&action=updateInstance"))
1693                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1694                                         .withBody(getWiremockResponseForCatalogdb(
1695                                                 "vnfComponentRecipeVolGrp_GRAPI_Response.json"))
1696                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1697
1698         // expected response
1699         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1700         RequestReferences requestReferences = new RequestReferences();
1701         requestReferences.setInstanceId("1882939");
1702         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1703         expectedResponse.setRequestReferences(requestReferences);
1704         uri = servInstanceuri + "v7"
1705                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1706         ResponseEntity<String> response =
1707                 sendRequest(inputStream("/UpdateVolumeGroup.json"), uri, HttpMethod.PUT, headers);
1708
1709         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1710         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1711         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1712     }
1713
1714     @Test
1715     public void deleteVolumeGroupInstance() throws IOException {
1716         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1717                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1718                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1719
1720         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1721                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1722                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1723
1724         wireMockServer.stubFor(get(urlMatching(
1725                 ".*/vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc[?]MODEL_CUSTOMIZATION_UUID=b4ea86b4-253f-11e7-93ae-92361f002671"))
1726                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1727                                 .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationVolGrp_Response.json"))
1728                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1729
1730         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/1/vfModule"))
1731                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1732                         .withBody(getWiremockResponseForCatalogdb("vfModuleVolGroup_Response.json"))
1733                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1734
1735         wireMockServer.stubFor(get(urlMatching(
1736                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
1737                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=volumeGroup&action=deleteInstance"))
1738                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1739                                         .withBody(getWiremockResponseForCatalogdb(
1740                                                 "vnfComponentRecipeVolGrp_GRAPI_Response.json"))
1741                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1742
1743         // expected response
1744         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1745         RequestReferences requestReferences = new RequestReferences();
1746         requestReferences.setInstanceId("1882939");
1747         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1748         expectedResponse.setRequestReferences(requestReferences);
1749         uri = servInstanceuri + "v7"
1750                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1751         ResponseEntity<String> response =
1752                 sendRequest(inputStream("/DeleteVolumeGroup.json"), uri, HttpMethod.DELETE, headers);
1753
1754         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1755         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1756         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1757     }
1758
1759     @Test
1760     public void createNetworkInstance() throws IOException {
1761         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1762                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1763                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1764
1765         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
1766                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1767                         .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json"))
1768                         .withStatus(HttpStatus.SC_OK)));
1769
1770         wireMockServer.stubFor(
1771                 get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource"))
1772                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1773                                 .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json"))
1774                                 .withStatus(HttpStatus.SC_OK)));
1775
1776         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]"
1777                 + "modelName=GR-API-DEFAULT&action=createInstance"))
1778                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1779                                 .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
1780                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1781
1782         // expected response
1783         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1784         RequestReferences requestReferences = new RequestReferences();
1785         requestReferences.setInstanceId("1882939");
1786         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1787         expectedResponse.setRequestReferences(requestReferences);
1788         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1789         ResponseEntity<String> response =
1790                 sendRequest(inputStream("/NetworkCreate.json"), uri, HttpMethod.POST, headers);
1791
1792         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1793         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1794         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1795     }
1796
1797     @Test
1798     public void updateNetworkInstance() throws IOException {
1799         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1800                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1801                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1802
1803         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
1804                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1805                         .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json"))
1806                         .withStatus(HttpStatus.SC_OK)));
1807
1808         wireMockServer.stubFor(
1809                 get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource"))
1810                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1811                                 .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json"))
1812                                 .withStatus(HttpStatus.SC_OK)));
1813
1814         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]"
1815                 + "modelName=GR-API-DEFAULT&action=updateInstance"))
1816                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1817                                 .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
1818                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1819         // expected response
1820         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1821         RequestReferences requestReferences = new RequestReferences();
1822         requestReferences.setInstanceId("1882939");
1823         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1824         expectedResponse.setRequestReferences(requestReferences);
1825         uri = servInstanceuri + "v7"
1826                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1827         ResponseEntity<String> response = sendRequest(inputStream("/UpdateNetwork.json"), uri, HttpMethod.PUT, headers);
1828
1829         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1830         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1831         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1832         assertTrue(response.getBody().contains("1882939"));
1833     }
1834
1835     @Test
1836     public void deleteNetworkInstance() throws IOException {
1837         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1838                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1839                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1840
1841         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
1842                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1843                         .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json"))
1844                         .withStatus(HttpStatus.SC_OK)));
1845
1846         wireMockServer.stubFor(
1847                 get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource"))
1848                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1849                                 .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json"))
1850                                 .withStatus(HttpStatus.SC_OK)));
1851
1852         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]"
1853                 + "modelName=VNF-API-DEFAULT&action=deleteInstance"))
1854                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1855                                 .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
1856                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1857
1858         // expected response
1859         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1860         RequestReferences requestReferences = new RequestReferences();
1861         requestReferences.setInstanceId("1882939");
1862         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1863         expectedResponse.setRequestReferences(requestReferences);
1864         uri = servInstanceuri + "v7"
1865                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1866         ResponseEntity<String> response =
1867                 sendRequest(inputStream("/NetworkInstance.json"), uri, HttpMethod.DELETE, headers);
1868
1869         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1870         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1871         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1872     }
1873
1874     @Test
1875     public void deleteNetworkInstanceNoReqParams() throws IOException {
1876         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1877                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1878                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1879
1880         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]"
1881                 + "modelName=GR-API-DEFAULT&action=deleteInstance"))
1882                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1883                                 .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
1884                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
1885
1886
1887         // expected response
1888         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1889         RequestReferences requestReferences = new RequestReferences();
1890         requestReferences.setInstanceId("1882939");
1891         requestReferences.setRequestSelfLink(createExpectedSelfLink("v6", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1892         expectedResponse.setRequestReferences(requestReferences);
1893         uri = servInstanceuri + "v6"
1894                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1895         ResponseEntity<String> response =
1896                 sendRequest(inputStream("/NetworkInstanceNoReqParams.json"), uri, HttpMethod.DELETE, headers);
1897
1898         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1899         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1900         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1901     }
1902
1903     @Test
1904     public void convertJsonToServiceInstanceRequestFail() throws IOException {
1905         // ExpectedRecord
1906         InfraActiveRequests expectedRecord = new InfraActiveRequests();
1907         expectedRecord.setRequestStatus("FAILED");
1908         expectedRecord.setStatusMessage("Error mapping request: ");
1909         expectedRecord.setProgress(100L);
1910         expectedRecord.setRequestBody(inputStream("/ConvertRequestFail.json"));
1911         expectedRecord.setLastModifiedBy("APIH");
1912         expectedRecord.setRequestScope("network");
1913         expectedRecord.setRequestAction("deleteInstance");
1914         expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
1915
1916         uri = servInstanceuri + "v6"
1917                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1918         ResponseEntity<String> response =
1919                 sendRequest(inputStream("/ConvertRequestFail.json"), uri, HttpMethod.DELETE, headers);
1920
1921         // ActualRecord
1922
1923         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
1924     }
1925
1926     @Test
1927     public void convertJsonToServiceInstanceRequestConfigurationFail() throws IOException {
1928         uri = servInstanceuri + "v5"
1929                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/configurations/test/enablePort";
1930         ResponseEntity<String> response = sendRequest(inputStream("/ConvertRequestFail.json"), uri, HttpMethod.POST);
1931
1932         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
1933     }
1934
1935     @Test
1936     public void creatServiceInstanceGRTestApiNoCustomRecipeFound() throws IOException {
1937         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1938                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1939                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1940
1941         ServiceRecipe serviceRecipe = new ServiceRecipe();
1942         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
1943         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
1944         serviceRecipe.setAction(Action.createInstance.toString());
1945         serviceRecipe.setId(1);
1946         serviceRecipe.setRecipeTimeout(180);
1947         Service defaultService = new Service();
1948         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
1949
1950         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
1951                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1952                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
1953
1954         wireMockServer.stubFor(get(urlMatching(".*/service-design-and-creation/services/service/.*"))
1955                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1956                         .withBodyFile("/aai/ServiceFromAAI.json").withStatus(HttpStatus.SC_OK)));
1957
1958         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
1959                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1960                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
1961
1962         uri = servInstanceuri + "v7" + "/serviceInstances";
1963         ResponseEntity<String> response =
1964                 sendRequest(inputStream("/ServiceInstanceMacro.json"), uri, HttpMethod.POST, headers);
1965
1966         // expected response
1967         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1968         RequestReferences requestReferences = new RequestReferences();
1969         requestReferences.setInstanceId("1882939");
1970         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
1971         expectedResponse.setRequestReferences(requestReferences);
1972
1973         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1974         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1975         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
1976     }
1977
1978     @Test
1979     public void createNetworkInstanceTestApiUndefinedUsePropertiesDefault() throws IOException {
1980         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1981                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1982                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1983
1984         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
1985                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1986                         .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json"))
1987                         .withStatus(HttpStatus.SC_OK)));
1988
1989         wireMockServer.stubFor(
1990                 get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource"))
1991                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1992                                 .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json"))
1993                                 .withStatus(HttpStatus.SC_OK)));
1994
1995         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]"
1996                 + "modelName=GR-API-DEFAULT&action=createInstance"))
1997                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1998                                 .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
1999                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2000
2001         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
2002         ResponseEntity<String> response =
2003                 sendRequest(inputStream("/NetworkCreateAlternateInstanceName.json"), uri, HttpMethod.POST, headers);
2004
2005         // expected response
2006         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2007         RequestReferences requestReferences = new RequestReferences();
2008         requestReferences.setInstanceId("1882939");
2009         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2010         expectedResponse.setRequestReferences(requestReferences);
2011
2012         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2013         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2014         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2015     }
2016
2017     @Test
2018     public void createNetworkInstanceTestApiIncorrectUsePropertiesDefault() throws IOException {
2019         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2020                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2021                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2022
2023         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
2024         ResponseEntity<String> response =
2025                 sendRequest(inputStream("/NetworkCreateTestApiIncorrect.json"), uri, HttpMethod.POST);
2026
2027         // expected response
2028         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2029         RequestReferences requestReferences = new RequestReferences();
2030         requestReferences.setInstanceId("1882939");
2031         expectedResponse.setRequestReferences(requestReferences);
2032
2033         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2034     }
2035
2036     @Test
2037     public void createNetworkInstanceTestApiGrApi() throws IOException {
2038         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2039                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2040                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2041
2042         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
2043                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2044                         .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json"))
2045                         .withStatus(HttpStatus.SC_OK)));
2046
2047         wireMockServer.stubFor(
2048                 get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource"))
2049                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2050                                 .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json"))
2051                                 .withStatus(HttpStatus.SC_OK)));
2052
2053         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]"
2054                 + "modelName=GR-API-DEFAULT&action=createInstance"))
2055                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2056                                 .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
2057                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2058
2059         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
2060         ResponseEntity<String> response =
2061                 sendRequest(inputStream("/NetworkCreateTestApiGrApi.json"), uri, HttpMethod.POST, headers);
2062
2063         // expected response
2064         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2065         RequestReferences requestReferences = new RequestReferences();
2066         requestReferences.setInstanceId("1882939");
2067         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2068         expectedResponse.setRequestReferences(requestReferences);
2069
2070         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2071         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2072         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2073     }
2074
2075     @Test
2076     public void createNetworkInstanceTestApiVnfApi() throws IOException {
2077         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/CreateNetworkInstance"))
2078                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2079                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2080
2081         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
2082                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2083                         .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json"))
2084                         .withStatus(HttpStatus.SC_OK)));
2085
2086         wireMockServer.stubFor(
2087                 get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource"))
2088                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2089                                 .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json"))
2090                                 .withStatus(HttpStatus.SC_OK)));
2091
2092         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]"
2093                 + "modelName=VNF-API-DEFAULT&action=createInstance"))
2094                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2095                                 .withBody(getWiremockResponseForCatalogdb("networkRecipeVNF_API_Response.json"))
2096                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2097
2098         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
2099         ResponseEntity<String> response =
2100                 sendRequest(inputStream("/NetworkCreateTestApiVnfApi.json"), uri, HttpMethod.POST, headers);
2101
2102         // expected response
2103         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2104         RequestReferences requestReferences = new RequestReferences();
2105         requestReferences.setInstanceId("1882939");
2106         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2107         expectedResponse.setRequestReferences(requestReferences);
2108
2109         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2110         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2111         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2112     }
2113
2114     @Test
2115     public void activateServiceInstanceRequestStatus() throws IOException {
2116         ServiceRecipe serviceRecipe = new ServiceRecipe();
2117         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
2118         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2119         serviceRecipe.setAction(Action.createInstance.toString());
2120         serviceRecipe.setId(1);
2121         serviceRecipe.setRecipeTimeout(180);
2122         Service defaultService = new Service();
2123         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2124
2125         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2126                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2127                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2128
2129         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
2130                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2131                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2132
2133         wireMockServer.stubFor(get(urlMatching(".*/service-design-and-creation/services/service/.*"))
2134                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2135                         .withBodyFile("/aai/ServiceFromAAI.json").withStatus(HttpStatus.SC_OK)));
2136
2137         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2138                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2139                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
2140
2141         // expect
2142         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2143         RequestReferences requestReferences = new RequestReferences();
2144         requestReferences.setInstanceId("1882939");
2145         requestReferences.setRequestSelfLink(createExpectedSelfLink("v5", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2146         expectedResponse.setRequestReferences(requestReferences);
2147         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7999/activate";
2148         ResponseEntity<String> response =
2149                 sendRequest(inputStream("/ServiceInstancePrev8.json"), uri, HttpMethod.POST, headers);
2150
2151         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2152         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2153         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2154     }
2155
2156     @Test
2157     public void invalidRequestId() throws IOException {
2158         String illegalRequestId = "1234";
2159         HttpHeaders ivalidRequestIdHeaders = new HttpHeaders();
2160         ivalidRequestIdHeaders.set(ONAPLogConstants.Headers.REQUEST_ID, illegalRequestId);
2161         uri = servInstanceuri + "v5/serviceInstances";
2162         ResponseEntity<String> response =
2163                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, ivalidRequestIdHeaders);
2164
2165         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2166         assertTrue(response.getBody().contains("Request Id " + illegalRequestId + " is not a valid UUID"));
2167     }
2168
2169     @Test
2170     public void invalidBPELResponse() throws IOException {
2171
2172         ServiceRecipe serviceRecipe = new ServiceRecipe();
2173         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
2174         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2175         serviceRecipe.setAction(Action.createInstance.toString());
2176         serviceRecipe.setId(1);
2177         serviceRecipe.setRecipeTimeout(180);
2178         Service defaultService = new Service();
2179         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2180
2181         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")).willReturn(aResponse()
2182                 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2183                 .withBodyFile("Camunda/TestResponseInvalid2.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2184
2185         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
2186                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2187                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2188
2189         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2190                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2191                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
2192
2193         uri = servInstanceuri + "v5/serviceInstances";
2194         ResponseEntity<String> response =
2195                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2196
2197         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2198         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
2199         assertEquals("Request Failed due to BPEL error with HTTP Status = 202{\"instanceId\": \"1882939\"}",
2200                 realResponse.getServiceException().getText());
2201     }
2202
2203     @Test
2204     public void unauthorizedBPELResponse() throws IOException {
2205
2206         ServiceRecipe serviceRecipe = new ServiceRecipe();
2207         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
2208         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2209         serviceRecipe.setAction(Action.createInstance.toString());
2210         serviceRecipe.setId(1);
2211         serviceRecipe.setRecipeTimeout(180);
2212         Service defaultService = new Service();
2213         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2214
2215         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2216                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2217                         .withBodyFile("Camunda/UnauthorizedResponse.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("Exception caught mapping Camunda JSON response to object",
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.NOT_ACCEPTABLE.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