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