Merge "refactor camunda client in apih"
[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                         .withStatus(org.apache.http.HttpStatus.SC_UNAUTHORIZED)));
2218
2219         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
2220                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2221                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2222
2223         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2224                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2225                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
2226
2227         uri = servInstanceuri + "v5/serviceInstances";
2228         ResponseEntity<String> response =
2229                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2230
2231         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2232         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
2233         assertEquals("Request Failed due to BPEL error with HTTP Status = 401 UNAUTHORIZED",
2234                 realResponse.getServiceException().getText());
2235     }
2236
2237     @Test
2238     public void invalidBPELResponse2() throws IOException {
2239
2240         ServiceRecipe serviceRecipe = new ServiceRecipe();
2241         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
2242         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2243         serviceRecipe.setAction(Action.createInstance.toString());
2244         serviceRecipe.setId(1);
2245         serviceRecipe.setRecipeTimeout(180);
2246         Service defaultService = new Service();
2247         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2248
2249         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")).willReturn(aResponse()
2250                 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2251                 .withBodyFile("Camunda/TestResponseInvalid.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2252
2253         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
2254                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2255                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2256
2257         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2258                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2259                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
2260         uri = servInstanceuri + "v5/serviceInstances";
2261         ResponseEntity<String> response =
2262                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2263
2264         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2265         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
2266         assertTrue(realResponse.getServiceException().getText()
2267                 .contains("<aetgt:ErrorMessage>Exception in create execution list 500"));
2268     }
2269
2270     @Test
2271     public void createMacroServiceInstance() throws IOException {
2272         ServiceRecipe serviceRecipe = new ServiceRecipe();
2273         serviceRecipe.setOrchestrationUri("/mso/async/services/CreateMacroServiceNetworkVnf");
2274         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2275         serviceRecipe.setAction(Action.createInstance.toString());
2276         serviceRecipe.setId(1);
2277         serviceRecipe.setRecipeTimeout(180);
2278         Service defaultService = new Service();
2279         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2280
2281         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/CreateMacroServiceNetworkVnf"))
2282                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2283                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2284
2285         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")).willReturn(aResponse()
2286                 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2287                 .withBodyFile("Camunda/TestResponseInvalid.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2288
2289         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
2290                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2291                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2292
2293         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2294                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2295                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
2296
2297         // expect
2298         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2299         RequestReferences requestReferences = new RequestReferences();
2300         requestReferences.setInstanceId("1882939");
2301         requestReferences.setRequestSelfLink(createExpectedSelfLink("v5", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2302         expectedResponse.setRequestReferences(requestReferences);
2303         uri = servInstanceuri + "v5";
2304         ResponseEntity<String> response =
2305                 sendRequest(inputStream("/MacroServiceInstance.json"), uri, HttpMethod.POST, headers);
2306
2307         // then
2308         assertEquals(404, response.getStatusCode().value());
2309     }
2310
2311     @Test
2312     public void testUserParams() throws IOException {
2313         ObjectMapper mapper = new ObjectMapper();
2314         ServiceInstancesRequest request =
2315                 mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class);
2316         RequestParameters requestParameters = request.getRequestDetails().getRequestParameters();
2317         String userParamsTxt = inputStream("/userParams.txt");
2318
2319         List<Map<String, Object>> userParams = requestHandlerUtils.configureUserParams(requestParameters);
2320         System.out.println(userParams);
2321         assertTrue(userParams.size() > 0);
2322         assertTrue(userParams.get(0).containsKey("name"));
2323         assertTrue(userParams.get(0).containsKey("value"));
2324         assertEquals(userParamsTxt.replaceAll("\\s+", ""), userParams.toString().replaceAll("\\s+", ""));
2325     }
2326
2327     @Test
2328     public void testConfigureCloudConfig() throws IOException {
2329         ObjectMapper mapper = new ObjectMapper();
2330         ServiceInstancesRequest request =
2331                 mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class);
2332         CloudConfiguration cloudConfig =
2333                 requestHandlerUtils.configureCloudConfig(request.getRequestDetails().getRequestParameters());
2334
2335         assertEquals("mdt25b", cloudConfig.getLcpCloudRegionId());
2336         assertEquals("aefb697db6524ddebfe4915591b0a347", cloudConfig.getTenantId());
2337     }
2338
2339     @Test
2340     public void testMapToLegacyRequest() throws IOException {
2341         ObjectMapper mapper = new ObjectMapper();
2342         ServiceInstancesRequest request =
2343                 mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class);
2344         ServiceInstancesRequest expected =
2345                 mapper.readValue(inputStream("/LegacyMacroServiceInstance.json"), ServiceInstancesRequest.class);
2346         requestHandlerUtils.mapToLegacyRequest(request.getRequestDetails());
2347         System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(request));
2348         assertThat(request, sameBeanAs(expected));
2349     }
2350
2351     @Test
2352     public void scaleOutVfModule() throws IOException {
2353         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2354                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2355                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2356
2357         wireMockServer.stubFor(get(urlMatching(
2358                 ".*/vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc[?]MODEL_CUSTOMIZATION_UUID=cb82ffd8-252a-11e7-93ae-92361f002671"))
2359                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2360                                 .withBody(getWiremockResponseForCatalogdb("vfModuleCustomization_Response.json"))
2361                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2362
2363         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/1/vfModule"))
2364                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2365                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
2366                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
2367
2368         wireMockServer.stubFor(get(urlMatching(".*/vfModule/20c4431c-246d-11e7-93ae-92361f002671"))
2369                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2370                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
2371                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
2372
2373
2374         wireMockServer.stubFor(get(urlMatching(
2375                 ".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction"
2376                         + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=scaleOut"))
2377                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2378                                         .withBody(getWiremockResponseForCatalogdb(
2379                                                 "vnfComponentRecipeVfModuleScaleOut_Response.json"))
2380                                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
2381
2382         wireMockServer.stubFor(get(urlMatching(
2383                 ".*/vfModule/search/findByModelInvariantUUIDOrderByModelVersionDesc[?]modelInvariantUUID=78ca26d0-246d-11e7-93ae-92361f002671"))
2384                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2385                                 .withBody(getWiremockResponseForCatalogdb("vfModulesListByInvariantId_Response.json"))
2386                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2387
2388         // expected response
2389         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2390         RequestReferences requestReferences = new RequestReferences();
2391         requestReferences.setInstanceId("1882939");
2392         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2393         expectedResponse.setRequestReferences(requestReferences);
2394         uri = servInstanceuri + "v7"
2395                 + "/serviceInstances/7a88cbeb-0ec8-4765-a271-4f9e90c3da7b/vnfs/cbba721b-4803-4df7-9347-307c9a955426/vfModules/scaleOut";
2396         ResponseEntity<String> response =
2397                 sendRequest(inputStream("/ScaleOutRequest.json"), uri, HttpMethod.POST, headers);
2398
2399         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2400         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2401         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2402         assertTrue(response.getBody().contains("1882939"));
2403     }
2404
2405     @Test
2406     public void createServiceInstanceBadResponse() throws IOException {
2407         ServiceRecipe serviceRecipe = new ServiceRecipe();
2408         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
2409         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2410         serviceRecipe.setAction(Action.createInstance.toString());
2411         serviceRecipe.setId(1);
2412         serviceRecipe.setRecipeTimeout(180);
2413         Service defaultService = new Service();
2414         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2415
2416         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2417                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2418                         .withBodyFile("Camunda/TestBadResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2419
2420         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
2421                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2422                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2423
2424         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2425                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2426                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
2427
2428         uri = servInstanceuri + "v5/serviceInstances";
2429         ResponseEntity<String> response =
2430                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2431
2432         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2433         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
2434         assertEquals("Exception caught mapping Camunda JSON response to object",
2435                 realResponse.getServiceException().getText());
2436     }
2437
2438     @Test
2439     public void createServiceInstanceDuplicateError() throws IOException {
2440         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/checkInstanceNameDuplicate"))
2441                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2442                         .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
2443
2444         uri = servInstanceuri + "v5/serviceInstances";
2445         ResponseEntity<String> response =
2446                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2447
2448         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2449         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
2450         assertEquals(
2451                 "Unable to check for duplicate instance due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error",
2452                 realResponse.getServiceException().getText());
2453     }
2454
2455     @Test
2456     public void createServiceInstanceDuplicateHistoryCheck() throws IOException {
2457         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/checkInstanceNameDuplicate"))
2458                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2459                         .withBodyFile("InfraActiveRequests/createInfraActiveRequests.json")
2460                         .withStatus(HttpStatus.SC_ACCEPTED)));
2461         wireMockServer.stubFor(get(
2462                 ("/sobpmnengine/history/process-instance?processInstanceBusinessKey=f0a35706-efc4-4e27-80ea-a995d7a2a40f&active=true&maxResults=1"))
2463                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2464                                 .withBodyFile("Camunda/HistoryCheckResponse.json")
2465                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2466
2467         uri = servInstanceuri + "v5/serviceInstances";
2468         ResponseEntity<String> response =
2469                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2470
2471         assertEquals(Response.Status.CONFLICT.getStatusCode(), response.getStatusCode().value());
2472         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
2473         assertEquals(
2474                 "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.",
2475                 realResponse.getServiceException().getText());
2476     }
2477
2478     @Test
2479     public void createServiceInstanceDuplicateHistoryCheckException() throws IOException {
2480         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/checkInstanceNameDuplicate"))
2481                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2482                         .withBodyFile("InfraActiveRequests/createInfraActiveRequests.json")
2483                         .withStatus(HttpStatus.SC_ACCEPTED)));
2484         wireMockServer.stubFor(get(
2485                 ("/sobpmnengine/history/process-instance?processInstanceBusinessKey=f0a35706-efc4-4e27-80ea-a995d7a2a40f&active=true&maxResults=1"))
2486                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2487                                 .withStatus(org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR)));
2488
2489         uri = servInstanceuri + "v5/serviceInstances";
2490         ResponseEntity<String> response =
2491                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2492
2493         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2494         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
2495         assertEquals(
2496                 "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",
2497                 realResponse.getServiceException().getText());
2498     }
2499
2500     @Test
2501     public void createServiceInstanceDuplicate() throws IOException {
2502         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/checkInstanceNameDuplicate"))
2503                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2504                         .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
2505
2506         uri = servInstanceuri + "v5/serviceInstances";
2507         ResponseEntity<String> response =
2508                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2509
2510         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2511         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
2512         assertEquals(
2513                 "Unable to check for duplicate instance due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error",
2514                 realResponse.getServiceException().getText());
2515     }
2516
2517     @Test
2518     public void createServiceInstanceSaveError() throws IOException {
2519         ServiceRecipe serviceRecipe = new ServiceRecipe();
2520         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
2521         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2522         serviceRecipe.setAction(Action.createInstance.toString());
2523         serviceRecipe.setId(1);
2524         serviceRecipe.setRecipeTimeout(180);
2525         Service defaultService = new Service();
2526         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2527         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/"))
2528                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2529                         .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
2530         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
2531                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2532                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2533
2534         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2535                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2536                         .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
2537
2538         uri = servInstanceuri + "v5/serviceInstances";
2539         ResponseEntity<String> response =
2540                 sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2541
2542         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2543         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
2544         assertEquals(
2545                 "Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error",
2546                 realResponse.getServiceException().getText());
2547     }
2548
2549     @Test
2550     public void createPortConfigurationSaveError() throws IOException {
2551         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/"))
2552                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2553                         .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
2554         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
2555                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2556                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2557
2558         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations";
2559         ResponseEntity<String> response =
2560                 sendRequest(inputStream("/ServiceInstancePortConfiguration.json"), uri, HttpMethod.POST, headers);
2561
2562         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2563         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
2564         assertEquals(
2565                 "Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error",
2566                 realResponse.getServiceException().getText());
2567     }
2568
2569     @Test
2570     public void createPortConfigDbUpdateError() throws IOException {
2571         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/"))
2572                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2573                         .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
2574
2575         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations";
2576         ResponseEntity<String> response =
2577                 sendRequest(inputStream("/ServiceInstanceParseFail.json"), uri, HttpMethod.POST, headers);
2578
2579         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2580         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
2581         assertEquals(
2582                 "Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Server Error",
2583                 realResponse.getServiceException().getText());
2584     }
2585
2586     @Test
2587     public void vnfUpdateWithNetworkInstanceGroup() throws IOException {
2588         TestAppender.events.clear();
2589         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2590                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2591                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2592
2593         wireMockServer.stubFor(get(urlMatching(
2594                 ".*/vnfResourceCustomization/search/findByModelCustomizationUUID[?]MODEL_CUSTOMIZATION_UUID=2ccae1b4-7d9e-46fa-a452-9180ce008d17"))
2595                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2596                                 .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomization_Response.json"))
2597                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2598
2599         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/4/vnfResources"))
2600                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2601                         .withBody(getWiremockResponseForCatalogdb("vnfResources_Response.json"))
2602                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
2603
2604         wireMockServer.stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction"
2605                 + "[?]nfRole=GR-API-DEFAULT&action=updateInstance"))
2606                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2607                                 .withBody(getWiremockResponseForCatalogdb("UpdateVnfRecipe_Response.json"))
2608                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2609         headers.set(ONAPLogConstants.Headers.PARTNER_NAME, "VID");
2610         // expect
2611         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2612         RequestReferences requestReferences = new RequestReferences();
2613         requestReferences.setInstanceId("1882939");
2614         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2615         expectedResponse.setRequestReferences(requestReferences);
2616         uri = servInstanceuri
2617                 + "v7/serviceInstances/e05864f0-ab35-47d0-8be4-56fd9619ba3c/vnfs/f501ce76-a9bc-4601-9837-74fd9f4d5eca";
2618         ResponseEntity<String> response =
2619                 sendRequest(inputStream("/VnfwithNeteworkInstanceGroup.json"), uri, HttpMethod.PUT, headers);
2620         // then
2621         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2622         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2623         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2624         assertEquals(response.getHeaders().get(TRANSACTION_ID).get(0), "32807a28-1a14-4b88-b7b3-2950918aa76d");
2625     }
2626
2627     @Test
2628     public void createInstanceGroup() throws IOException {
2629         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2630                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2631                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2632
2633         // expect
2634         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2635         RequestReferences requestReferences = new RequestReferences();
2636         requestReferences.setInstanceId("1882939");
2637         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2638         expectedResponse.setRequestReferences(requestReferences);
2639         uri = servInstanceuri + "/v7/instanceGroups";
2640         ResponseEntity<String> response =
2641                 sendRequest(inputStream("/CreateInstanceGroup.json"), uri, HttpMethod.POST, headers);
2642
2643         // then
2644         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2645         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2646         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2647     }
2648
2649     @Test
2650     public void deleteInstanceGroup() throws IOException {
2651         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2652                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2653                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2654
2655         // expect
2656         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2657         RequestReferences requestReferences = new RequestReferences();
2658         requestReferences.setInstanceId("1882939");
2659         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2660         expectedResponse.setRequestReferences(requestReferences);
2661         uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c";
2662         ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE, headers);
2663
2664         // then
2665         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2666         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2667         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2668     }
2669
2670     @Test
2671     public void deleteInstanceGroupNoRequestIdHeader() throws IOException {
2672         uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c";
2673         ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE);
2674         // then
2675         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
2676         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
2677         assertEquals(realResponse.getServiceException().getText(), "No valid X-ONAP-RequestID header is specified");
2678     }
2679
2680     @Test
2681     public void deleteInstanceGroupNoPartnerNameHeader() throws IOException {
2682         HttpHeaders noPartnerHeaders = new HttpHeaders();
2683         noPartnerHeaders.set(ONAPLogConstants.Headers.REQUEST_ID, "eca3a1b1-43ab-457e-ab1c-367263d148b4");
2684         noPartnerHeaders.set(REQUESTOR_ID, "xxxxxx");
2685         uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c";
2686         ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE, noPartnerHeaders);
2687         // then
2688         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
2689         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
2690         assertEquals(realResponse.getServiceException().getText(), "No valid X-ONAP-PartnerName header is specified");
2691     }
2692
2693     @Test
2694     public void deleteInstanceGroupNoRquestorIdHeader() throws IOException {
2695         HttpHeaders noRequestorIdHheaders = new HttpHeaders();
2696         noRequestorIdHheaders.set(ONAPLogConstants.Headers.REQUEST_ID, "eca3a1b1-43ab-457e-ab1c-367263d148b4");
2697         noRequestorIdHheaders.set(ONAPLogConstants.Headers.PARTNER_NAME, "eca3a1b1-43ab-457e-ab1c-367263d148b4");
2698         // expect
2699         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2700         RequestReferences requestReferences = new RequestReferences();
2701         requestReferences.setInstanceId("1882939");
2702         expectedResponse.setRequestReferences(requestReferences);
2703         uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c";
2704         ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE, noRequestorIdHheaders);
2705
2706         // then
2707         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
2708         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
2709         assertEquals(realResponse.getServiceException().getText(), "No valid X-RequestorID header is specified");
2710     }
2711
2712     @Test
2713     public void addMembers() throws IOException {
2714         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2715                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2716                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2717         // expect
2718         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2719         RequestReferences requestReferences = new RequestReferences();
2720         requestReferences.setInstanceId("1882939");
2721         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2722         expectedResponse.setRequestReferences(requestReferences);
2723         uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c/addMembers";
2724         ResponseEntity<String> response = sendRequest(inputStream("/AddMembers.json"), uri, HttpMethod.POST, headers);
2725
2726         // then
2727         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2728         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2729         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2730     }
2731
2732     @Test
2733     public void removeMembers() throws IOException {
2734         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2735                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2736                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2737         // expect
2738         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2739         RequestReferences requestReferences = new RequestReferences();
2740         requestReferences.setInstanceId("1882939");
2741         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2742         expectedResponse.setRequestReferences(requestReferences);
2743         uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c/removeMembers";
2744         ResponseEntity<String> response =
2745                 sendRequest(inputStream("/RemoveMembers.json"), uri, HttpMethod.POST, headers);
2746
2747         // then
2748         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2749         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2750         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2751     }
2752
2753     @Test
2754     public void deleteNetworkInstanceNoCustomizationEntry() throws IOException {
2755         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2756                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2757                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2758
2759         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
2760                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2761                         .withStatus(HttpStatus.SC_NOT_FOUND)));
2762
2763         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]"
2764                 + "modelName=VNF-API-DEFAULT&action=deleteInstance"))
2765                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2766                                 .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
2767                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2768
2769         // expected response
2770         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2771         RequestReferences requestReferences = new RequestReferences();
2772         requestReferences.setInstanceId("1882939");
2773         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
2774         expectedResponse.setRequestReferences(requestReferences);
2775         uri = servInstanceuri + "v7"
2776                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
2777         ResponseEntity<String> response =
2778                 sendRequest(inputStream("/NetworkInstance.json"), uri, HttpMethod.DELETE, headers);
2779
2780         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2781         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2782         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
2783     }
2784
2785     @Test
2786     public void updateNetworkInstanceNoCustomizationEntry() throws IOException {
2787         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
2788                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2789                         .withStatus(HttpStatus.SC_NOT_FOUND)));
2790
2791         uri = servInstanceuri + "v7"
2792                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
2793         ResponseEntity<String> response = sendRequest(inputStream("/UpdateNetwork.json"), uri, HttpMethod.PUT, headers);
2794
2795         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
2796         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
2797         assertEquals(realResponse.getServiceException().getText(),
2798                 "No valid modelCustomizationId for networkResourceCustomization lookup is specified");
2799     }
2800
2801     @Test
2802     public void setServiceTypeTestALaCarte() throws JsonProcessingException {
2803         String requestScope = ModelType.service.toString();
2804         Boolean aLaCarteFlag = true;
2805         ServiceInstancesRequest sir = new ServiceInstancesRequest();
2806         RequestDetails requestDetails = new RequestDetails();
2807         RequestInfo requestInfo = new RequestInfo();
2808         requestInfo.setSource("VID");
2809         requestDetails.setRequestInfo(requestInfo);
2810         sir.setRequestDetails(requestDetails);
2811         Service defaultService = new Service();
2812         defaultService.setServiceType("testServiceTypeALaCarte");
2813
2814         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
2815                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2816                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2817
2818         String serviceType = requestHandlerUtils.getServiceType(requestScope, sir, aLaCarteFlag);
2819         assertEquals(serviceType, "testServiceTypeALaCarte");
2820     }
2821
2822     @Test
2823     public void setServiceTypeTest() throws JsonProcessingException {
2824         String requestScope = ModelType.service.toString();
2825         Boolean aLaCarteFlag = false;
2826         ServiceInstancesRequest sir = new ServiceInstancesRequest();
2827         RequestDetails requestDetails = new RequestDetails();
2828         RequestInfo requestInfo = new RequestInfo();
2829         ModelInfo modelInfo = new ModelInfo();
2830         modelInfo.setModelVersionId("0dd91181-49da-446b-b839-cd959a96f04a");
2831         requestInfo.setSource("VID");
2832         requestDetails.setModelInfo(modelInfo);
2833         requestDetails.setRequestInfo(requestInfo);
2834         sir.setRequestDetails(requestDetails);
2835         Service defaultService = new Service();
2836         defaultService.setServiceType("testServiceType");
2837
2838         wireMockServer.stubFor(get(urlMatching(".*/service/0dd91181-49da-446b-b839-cd959a96f04a"))
2839                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2840                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2841
2842         String serviceType = requestHandlerUtils.getServiceType(requestScope, sir, aLaCarteFlag);
2843         assertEquals(serviceType, "testServiceType");
2844     }
2845
2846     @Test
2847     public void setServiceTypeTestDefault() throws JsonProcessingException {
2848         String requestScope = ModelType.service.toString();
2849         Boolean aLaCarteFlag = false;
2850         ServiceInstancesRequest sir = new ServiceInstancesRequest();
2851         RequestDetails requestDetails = new RequestDetails();
2852         RequestInfo requestInfo = new RequestInfo();
2853         ModelInfo modelInfo = new ModelInfo();
2854         modelInfo.setModelVersionId("0dd91181-49da-446b-b839-cd959a96f04a");
2855         requestInfo.setSource("VID");
2856         requestDetails.setModelInfo(modelInfo);
2857         requestDetails.setRequestInfo(requestInfo);
2858         sir.setRequestDetails(requestDetails);
2859         Service defaultService = new Service();
2860         defaultService.setServiceType("testServiceType");
2861
2862         wireMockServer.stubFor(get(urlMatching(".*/service/0dd91181-49da-446b-b839-cd959a96f04a"))
2863                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2864                         .withStatus(HttpStatus.SC_NOT_FOUND)));
2865         wireMockServer.stubFor(get(urlMatching(".*/service/search/.*"))
2866                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2867                         .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
2868
2869         String serviceType = requestHandlerUtils.getServiceType(requestScope, sir, aLaCarteFlag);
2870         assertEquals(serviceType, "testServiceType");
2871     }
2872
2873     @Test
2874     public void setServiceTypeTestNetwork() throws JsonProcessingException {
2875         String requestScope = ModelType.network.toString();
2876         Boolean aLaCarteFlag = null;
2877         ServiceInstancesRequest sir = new ServiceInstancesRequest();
2878         RequestDetails requestDetails = new RequestDetails();
2879         RequestInfo requestInfo = new RequestInfo();
2880         ModelInfo modelInfo = new ModelInfo();
2881         modelInfo.setModelName("networkModelName");
2882         requestInfo.setSource("VID");
2883         requestDetails.setModelInfo(modelInfo);
2884         requestDetails.setRequestInfo(requestInfo);
2885         sir.setRequestDetails(requestDetails);
2886
2887         String serviceType = requestHandlerUtils.getServiceType(requestScope, sir, aLaCarteFlag);
2888         assertEquals(serviceType, "networkModelName");
2889     }
2890
2891     @Test
2892     public void setServiceInstanceIdInstanceGroupTest() throws JsonParseException, JsonMappingException, IOException {
2893         String requestScope = "instanceGroup";
2894         ServiceInstancesRequest sir =
2895                 mapper.readValue(inputStream("/CreateInstanceGroup.json"), ServiceInstancesRequest.class);
2896         assertEquals("ddcbbf3d-f2c1-4ca0-8852-76a807285efc",
2897                 requestHandlerUtils.setServiceInstanceId(requestScope, sir));
2898     }
2899
2900     @Test
2901     public void setServiceInstanceIdTest() {
2902         String requestScope = "vnf";
2903         ServiceInstancesRequest sir = new ServiceInstancesRequest();
2904         sir.setServiceInstanceId("f0a35706-efc4-4e27-80ea-a995d7a2a40f");
2905         assertEquals("f0a35706-efc4-4e27-80ea-a995d7a2a40f",
2906                 requestHandlerUtils.setServiceInstanceId(requestScope, sir));
2907     }
2908
2909     @Test
2910     public void setServiceInstanceIdReturnNullTest() {
2911         String requestScope = "vnf";
2912         ServiceInstancesRequest sir = new ServiceInstancesRequest();
2913         assertNull(requestHandlerUtils.setServiceInstanceId(requestScope, sir));
2914     }
2915
2916     @Test
2917     public void camundaHistoryCheckTest() throws ContactCamundaException, RequestDbFailureException {
2918         wireMockServer.stubFor(get(
2919                 ("/sobpmnengine/history/process-instance?processInstanceBusinessKey=f0a35706-efc4-4e27-80ea-a995d7a2a40f&active=true&maxResults=1"))
2920                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2921                                 .withBodyFile("Camunda/HistoryCheckResponse.json")
2922                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
2923
2924         InfraActiveRequests duplicateRecord = new InfraActiveRequests();
2925         duplicateRecord.setRequestId("f0a35706-efc4-4e27-80ea-a995d7a2a40f");
2926         boolean inProgress = false;
2927         inProgress = requestHandlerUtils.camundaHistoryCheck(duplicateRecord, null);
2928         assertTrue(inProgress);
2929     }
2930
2931     @Test
2932     public void camundaHistoryCheckNoneFoundTest() throws ContactCamundaException, RequestDbFailureException {
2933         wireMockServer.stubFor(get(
2934                 ("/sobpmnengine/history/process-instance?processInstanceBusinessKey=f0a35706-efc4-4e27-80ea-a995d7a2a40f&active=true&maxResults=1"))
2935                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2936                                 .withBody("[]").withStatus(org.apache.http.HttpStatus.SC_OK)));
2937
2938         InfraActiveRequests duplicateRecord = new InfraActiveRequests();
2939         duplicateRecord.setRequestId("f0a35706-efc4-4e27-80ea-a995d7a2a40f");
2940         boolean inProgress = false;
2941         inProgress = requestHandlerUtils.camundaHistoryCheck(duplicateRecord, null);
2942         assertFalse(inProgress);
2943     }
2944
2945     @Test
2946     public void handleReplaceInstance_Test() throws JsonParseException, JsonMappingException, IOException {
2947         String replaceVfModule = inputStream("/ReplaceVfModule.json");
2948         ObjectMapper mapper = new ObjectMapper();
2949         ServiceInstancesRequest sir = mapper.readValue(replaceVfModule, ServiceInstancesRequest.class);
2950         Actions action = servInstances.handleReplaceInstance(Action.replaceInstance, sir);
2951         assertEquals(Action.replaceInstance, action);
2952     }
2953
2954     @Test
2955     public void handleReplaceInstance_retainAssignments_Test()
2956             throws JsonParseException, JsonMappingException, IOException {
2957         String replaceVfModule = inputStream("/ReplaceVfModuleRetainAssignments.json");
2958         ObjectMapper mapper = new ObjectMapper();
2959         ServiceInstancesRequest sir = mapper.readValue(replaceVfModule, ServiceInstancesRequest.class);
2960         Actions action = servInstances.handleReplaceInstance(Action.replaceInstance, sir);
2961         assertEquals(Action.replaceInstanceRetainAssignments, action);
2962     }
2963
2964     @Test
2965     public void getCloudConfigurationAAIEntityNotFoundTest() throws IOException {
2966         RequestError expectedResponse =
2967                 mapper.readValue(inputStream("/AAIEntityNotFoundResponse.json"), RequestError.class);
2968         uri = servInstanceuri + "v7"
2969                 + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
2970         ResponseEntity<String> response =
2971                 sendRequest(inputStream("/ReplaceVfModuleNoCloudConfig.json"), uri, HttpMethod.POST, headers);
2972
2973         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2974         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
2975         assertThat(expectedResponse, sameBeanAs(realResponse));
2976     }
2977
2978 }
2979