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