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