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