52021c35872e2caff730e38f49090fcb41269542
[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/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/68dc9a92-214c-11e7-93ae-92361f002671/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/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/68dc9a92-214c-11e7-93ae-92361f002671/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/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/68dc9a92-214c-11e7-93ae-92361f002674/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/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/68dc9a92-214c-11e7-93ae-92361f002674/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/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/68dc9a92-214c-11e7-93ae-92361f002674/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/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(".*/vfModuleCustomization/cb82ffd8-252a-11e7-93ae-92361f002671/vfModule"))
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(".*/vfModule/20c4431c-246d-11e7-93ae-92361f002671"))
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(post(urlPathEqualTo("/mso/async/services/CreateVfModuleInfra"))
1083                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1084                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1085
1086         wireMockServer.stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" +
1087                 "[?]vfModuleModelUUID=20c4431c-246d-11e7-93ae-92361f002671&vnfComponentType=vfModule&action=createInstance"))
1088                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1089                         .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipe_Response.json"))
1090                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1091         //expected response
1092         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1093         RequestReferences requestReferences = new RequestReferences();
1094         requestReferences.setInstanceId("1882939");
1095         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1096         expectedResponse.setRequestReferences(requestReferences);
1097         uri = servInstanceuri + "v7" + "/serviceInstances/7a88cbeb-0ec8-4765-a271-4f9e90c3da7b/vnfs/cbba721b-4803-4df7-9347-307c9a955426/vfModules";
1098         ResponseEntity<String> response = sendRequest(inputStream("/VfModuleWithRelatedInstances.json"), uri, HttpMethod.POST, headers);
1099
1100         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1101         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1102         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1103         assertTrue(response.getBody().contains("1882939"));
1104     }
1105     @Test
1106     public void createVfModuleInstanceNoModelCustomization() throws IOException {
1107         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/CreateVfModuleInfra"))
1108                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1109                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1110
1111         wireMockServer.stubFor(get(urlMatching(".*/vnfResource/fe6478e4-ea33-3346-ac12-ab121484a3fe"))
1112                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1113                         .withBody(getWiremockResponseForCatalogdb("vnfResourceForVfModule_Response.json"))
1114                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1115
1116         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/search/findByModelInstanceNameAndVnfResources" +
1117                 "[?]modelInstanceName=test&vnfResourceModelUUID=fe6478e4-ea33-3346-ac12-ab121484a3fe"))
1118                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1119                         .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomizationForVfModule_Response.json"))
1120                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1121
1122         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002673/vfModuleCustomizations"))
1123                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1124                         .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationsPCM_Response.json"))
1125                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1126
1127         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/search/findByModelCustomizationUUIDAndVfModuleModelUUID[?]" +
1128                 "modelCustomizationUUID=b4ea86b4-253f-11e7-93ae-92361f002672&vfModuleModelUUID=066de97e-253e-11e7-93ae-92361f002672"))
1129                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1130                         .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationPCM_Response.json"))
1131                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1132
1133         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/b4ea86b4-253f-11e7-93ae-92361f002672/vfModule"))
1134                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1135                         .withBody(getWiremockResponseForCatalogdb("vfModulePCM_Response.json"))
1136                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1137
1138         wireMockServer.stubFor(get(urlMatching(".*/vfModule/066de97e-253e-11e7-93ae-92361f002672"))
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
1144         wireMockServer.stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVnfComponentTypeAndAction" +
1145                 "[?]vnfComponentType=vfModule&action=createInstance"))
1146                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1147                         .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeVNF_API_Response.json"))
1148                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1149         
1150         //expected response
1151         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1152         RequestReferences requestReferences = new RequestReferences();
1153         requestReferences.setInstanceId("1882939");
1154         requestReferences.setRequestSelfLink(createExpectedSelfLink("v6","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1155         expectedResponse.setRequestReferences(requestReferences);
1156         uri = servInstanceuri + "v6" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules";
1157         ResponseEntity<String> response = sendRequest(inputStream("/VfModuleNoModelCustomization.json"), uri, HttpMethod.POST, headers);
1158         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1159         ObjectMapper mapper = new ObjectMapper();
1160         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1161         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1162     }
1163     @Test
1164     public void deleteVfModuleInstanceNoMatchingModelUUD() throws IOException {
1165         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1166                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1167                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1168
1169         wireMockServer.stubFor(get(urlMatching(".*/vnfResource/.*"))
1170                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1171                         .withBody(getWiremockResponseForCatalogdb("vnfResourceForVfModule_Response.json"))
1172                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1173
1174         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/search/findByModelInstanceNameAndVnfResources.*"))
1175                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1176                         .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomizationForVfModule_Response.json"))
1177                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1178
1179         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002673/vfModuleCustomizations"))
1180                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1181                         .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationsPCM_Response.json"))
1182                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1183
1184         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/b4ea86b4-253f-11e7-93ae-92361f002672"))
1185                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1186                         .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationPCM_Response.json"))
1187                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1188
1189         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/b4ea86b4-253f-11e7-93ae-92361f002672/vfModule"))
1190                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1191                         .withBody(getWiremockResponseForCatalogdb("vfModulePCM_Response.json"))
1192                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1193
1194         wireMockServer.stubFor(get(urlMatching(".*/vfModule/066de97e-253e-11e7-93ae-92361f002672"))
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(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" +
1200                 "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=deleteInstance"))
1201                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1202                         .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeDeleteVfModule_Response.json"))
1203                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1204         
1205         //expected response
1206         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1207         RequestReferences requestReferences = new RequestReferences();
1208         requestReferences.setInstanceId("1882939");
1209         requestReferences.setRequestSelfLink(createExpectedSelfLink("v6","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1210         expectedResponse.setRequestReferences(requestReferences);
1211         uri = servInstanceuri + "v6" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1212         ResponseEntity<String> response = sendRequest(inputStream("/VfModuleNoMatchingModelUUID.json"), uri, HttpMethod.DELETE, headers);
1213         
1214
1215         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1216         ObjectMapper mapper = new ObjectMapper();
1217         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1218         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1219     }
1220     @Test
1221     public void createVfModuleInstanceNoRecipe() throws IOException {
1222
1223         wireMockServer.stubFor(get(urlMatching(".*/vnfResource/fe6478e4-ea33-3346-ac12-ab121484a3fe"))
1224                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1225                         .withBody(getWiremockResponseForCatalogdb("vnfResourceForVfModule_Response.json"))
1226                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1227
1228         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/search/findByModelInstanceNameAndVnfResources" +
1229                 "[?]modelInstanceName=test&vnfResourceModelUUID=fe6478e4-ea33-3346-ac12-ab121484a3fe"))
1230                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1231                         .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomizationForVfModule_Response.json"))
1232                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1233
1234         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002673/vfModuleCustomizations"))
1235                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1236                         .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationsPCM_Response.json"))
1237                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1238
1239         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/search/findByModelCustomizationUUIDAndVfModuleModelUUID[?]" +
1240                 "modelCustomizationUUID=b4ea86b4-253f-11e7-93ae-92361f002672&vfModuleModelUUID=066de97e-253e-11e7-93ae-92361f002672"))
1241                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1242                         .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationPCM_Response.json"))
1243                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1244             
1245             uri = servInstanceuri + "v6" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules";
1246         ResponseEntity<String> response = sendRequest(inputStream("/VfModuleInvalid.json"), uri, HttpMethod.POST, headers);
1247         
1248         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
1249         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
1250         assertEquals("No valid vfModuleCustomization is specified", realResponse.getServiceException().getText());
1251     }
1252     @Test
1253     public void replaceVfModuleInstance() throws IOException {
1254         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1255                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1256                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1257         
1258         wireMockServer.stubFor(get(urlMatching(".*/vfModule/search/findFirstVfModuleByModelInvariantUUIDAndModelVersion[?]" +
1259                 "modelInvariantUUID=78ca26d0-246d-11e7-93ae-92361f002671&modelVersion=2"))
1260                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1261                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1262                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1263
1264         wireMockServer.stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" +
1265                 "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=replaceInstance"))
1266                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1267                         .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeDeleteVfModule_Response.json"))
1268                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1269         //expected response
1270         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1271         RequestReferences requestReferences = new RequestReferences();
1272         requestReferences.setInstanceId("1882939");
1273         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1274         expectedResponse.setRequestReferences(requestReferences);
1275         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
1276         ResponseEntity<String> response = sendRequest(inputStream("/ReplaceVfModule.json"), uri, HttpMethod.POST, headers);
1277
1278         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1279         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1280         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1281     }
1282     @Test
1283     public void updateVfModuleInstance() throws IOException {
1284         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1285                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1286                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1287
1288         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/cb82ffd8-252a-11e7-93ae-92361f002671"))
1289                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1290                         .withBody(getWiremockResponseForCatalogdb("vfModuleCustomization_Response.json"))
1291                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1292
1293         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/cb82ffd8-252a-11e7-93ae-92361f002671/vfModule"))
1294                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1295                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1296                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1297
1298         wireMockServer.stubFor(get(urlMatching(".*/vfModule/20c4431c-246d-11e7-93ae-92361f002671"))
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(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" +
1304                 "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=updateInstance"))
1305                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1306                         .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipe_GRAPI_Response.json"))
1307                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1308
1309         //expected response
1310         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1311         RequestReferences requestReferences = new RequestReferences();
1312         requestReferences.setInstanceId("1882939");
1313         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1314         expectedResponse.setRequestReferences(requestReferences);
1315         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1316         ResponseEntity<String> response = sendRequest(inputStream("/UpdateVfModule.json"), uri, HttpMethod.PUT, headers);
1317         logger.debug(response.getBody());
1318
1319         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1320         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1321         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1322     }
1323     @Test
1324     public void createVfModuleNoModelType() throws IOException{
1325         InfraActiveRequests expectedRecord = new InfraActiveRequests();
1326         expectedRecord.setRequestStatus("FAILED");
1327         expectedRecord.setAction("createInstance");
1328         expectedRecord.setStatusMessage("Error parsing request: No valid modelType is specified");
1329         expectedRecord.setProgress(100L);
1330         expectedRecord.setSource("VID");
1331         expectedRecord.setRequestBody(inputStream("/VfModuleNoModelType.json"));
1332         expectedRecord.setLastModifiedBy("APIH");
1333         expectedRecord.setVfModuleName("testVfModule2");
1334         expectedRecord.setVfModuleModelName("serviceModel");
1335         expectedRecord.setRequestScope("vfModule");
1336         expectedRecord.setRequestAction("createInstance");
1337         expectedRecord.setRequestorId("zz9999");
1338         expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
1339         //VnfType is not sent in this request, should be blank in db
1340         expectedRecord.setVnfType("");
1341         uri = servInstanceuri + "v5/serviceInstances/32807a28-1a14-4b88-b7b3-2950918aa76d/vnfs/32807a28-1a14-4b88-b7b3-2950918aa76d/vfModules";
1342
1343         ResponseEntity<String> response = sendRequest(inputStream("/VfModuleNoModelType.json"), uri, HttpMethod.POST, headers);
1344         //ActualRecord
1345         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
1346     }
1347     @Test
1348     public void inPlaceSoftwareUpdate() throws IOException {
1349         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/VnfInPlaceUpdate"))
1350                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1351                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1352         
1353         wireMockServer.stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]" +
1354                 "nfRole=GR-API-DEFAULT&action=inPlaceSoftwareUpdate"))
1355                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1356                         .withBody(getWiremockResponseForCatalogdb("vnfRecipeInPlaceUpdate_Response.json"))
1357                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1358
1359         //expected response
1360         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1361         RequestReferences requestReferences = new RequestReferences();
1362         requestReferences.setInstanceId("1882939");
1363         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1364         expectedResponse.setRequestReferences(requestReferences);
1365         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/inPlaceSoftwareUpdate";
1366         ResponseEntity<String> response = sendRequest(inputStream("/InPlaceSoftwareUpdate.json"), uri, HttpMethod.POST, headers);
1367
1368         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1369         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1370         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1371     }
1372     
1373     @Test
1374     public void deleteVfModuleInstance() throws IOException {
1375         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1376                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1377                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1378
1379         wireMockServer.stubFor(get(urlMatching(".*/vfModule/search/findFirstVfModuleByModelInvariantUUIDAndModelVersion[?]" +
1380                 "modelInvariantUUID=78ca26d0-246d-11e7-93ae-92361f002671&modelVersion=2"))
1381                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1382                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1383                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1384         
1385         wireMockServer.stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" +
1386                 "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=deleteInstance"))
1387                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1388                         .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeDeleteVfModule_Response.json"))
1389                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1390
1391         //expected response
1392         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1393         RequestReferences requestReferences = new RequestReferences();
1394         requestReferences.setInstanceId("1882939");
1395         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1396         expectedResponse.setRequestReferences(requestReferences);
1397         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1398         ResponseEntity<String> response = sendRequest(inputStream("/DeleteVfModule.json"), uri, HttpMethod.DELETE, headers);
1399
1400         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1401         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1402         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1403     }
1404     @Test
1405     public void deleteVfModuleNoModelInvariantId() throws IOException {
1406         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1407                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1408                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1409         
1410         wireMockServer.stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" +
1411                 "[?]vfModuleModelUUID=VNF-API-DEFAULT&vnfComponentType=vfModule&action=deleteInstance"))
1412                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1413                         .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeDeleteVfModule_Response.json"))
1414                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1415
1416         //expected response
1417         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1418         RequestReferences requestReferences = new RequestReferences();
1419         requestReferences.setInstanceId("1882939");
1420         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1421         expectedResponse.setRequestReferences(requestReferences);
1422         uri = servInstanceuri + "v7" + "/serviceInstances/196b4a84-0858-4317-a1f6-497e2e52ae43/vnfs/36e4f902-ec32-451e-8d53-e3edc19e40a4/vfModules/09f3a38d-933f-450a-8784-9e6c4dec3f72";
1423         ResponseEntity<String> response = sendRequest(inputStream("/DeleteVfModuleNoModelInvariantId.json"), uri, HttpMethod.DELETE, headers);
1424
1425         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1426         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1427         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1428     }
1429     @Test
1430     public void deactivateAndCloudDeleteVfModuleInstance() throws IOException {
1431         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1432                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1433                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1434
1435         wireMockServer.stubFor(get(urlMatching(".*/vfModule/search/findFirstVfModuleByModelInvariantUUIDAndModelVersion[?]" +
1436                 "modelInvariantUUID=78ca26d0-246d-11e7-93ae-92361f002671&modelVersion=2"))
1437                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1438                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
1439                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1440
1441         wireMockServer.stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" +
1442                 "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=deactivateAndCloudDelete"))
1443                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1444                         .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeDeactivate_Response.json"))
1445                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1446
1447         //expected response
1448         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1449         RequestReferences requestReferences = new RequestReferences();
1450         requestReferences.setInstanceId("1882939");
1451         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1452         expectedResponse.setRequestReferences(requestReferences);
1453         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000/deactivateAndCloudDelete";
1454         ResponseEntity<String> response = sendRequest(inputStream("/DeactivateAndCloudDeleteVfModule.json"), uri, HttpMethod.POST, headers);
1455         
1456         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1457         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1458         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1459     }
1460     @Test
1461     public void createVolumeGroupInstance() throws IOException {
1462         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1463                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1464                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1465
1466         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/b4ea86b4-253f-11e7-93ae-92361f002671"))
1467                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1468                         .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationVolGrp_Response.json"))
1469                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1470
1471         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/b4ea86b4-253f-11e7-93ae-92361f002671/vfModule"))
1472                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1473                         .withBody(getWiremockResponseForCatalogdb("vfModuleVolGroup_Response.json"))
1474                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1475
1476         wireMockServer.stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" +
1477                 "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=volumeGroup&action=createInstance"))
1478                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1479                         .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeVolGrp_GRAPI_Response.json"))
1480                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1481
1482         //expected response
1483         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1484         RequestReferences requestReferences = new RequestReferences();
1485         requestReferences.setInstanceId("1882939");
1486         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1487         expectedResponse.setRequestReferences(requestReferences);
1488         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups";
1489         ResponseEntity<String> response = sendRequest(inputStream("/VolumeGroup.json"), uri, HttpMethod.POST, headers);
1490
1491         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1492         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1493         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1494         assertTrue(response.getBody().contains("1882939"));
1495     }
1496     @Test
1497     public void updateVolumeGroupInstance() throws IOException {
1498         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1499                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1500                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1501
1502         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/b4ea86b4-253f-11e7-93ae-92361f002671"))
1503                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1504                         .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationVolGrp_Response.json"))
1505                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1506
1507         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/b4ea86b4-253f-11e7-93ae-92361f002671/vfModule"))
1508                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1509                         .withBody(getWiremockResponseForCatalogdb("vfModuleVolGroup_Response.json"))
1510                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1511
1512         wireMockServer.stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" +
1513                 "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=volumeGroup&action=updateInstance"))
1514                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1515                         .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeVolGrp_GRAPI_Response.json"))
1516                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1517
1518         //expected response
1519         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1520         RequestReferences requestReferences = new RequestReferences();
1521         requestReferences.setInstanceId("1882939");
1522         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1523         expectedResponse.setRequestReferences(requestReferences);
1524         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1525         ResponseEntity<String> response = sendRequest(inputStream("/UpdateVolumeGroup.json"), uri, HttpMethod.PUT, headers);
1526
1527         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1528         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1529         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1530     }
1531     @Test
1532     public void deleteVolumeGroupInstance() throws IOException {
1533         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1534                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1535                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1536
1537         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1538                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1539                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1540
1541         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/b4ea86b4-253f-11e7-93ae-92361f002671"))
1542                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1543                         .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationVolGrp_Response.json"))
1544                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1545
1546         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/b4ea86b4-253f-11e7-93ae-92361f002671/vfModule"))
1547                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1548                         .withBody(getWiremockResponseForCatalogdb("vfModuleVolGroup_Response.json"))
1549                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1550
1551         wireMockServer.stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" +
1552                 "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=volumeGroup&action=deleteInstance"))
1553                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1554                         .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeVolGrp_GRAPI_Response.json"))
1555                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1556         
1557         //expected response
1558         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1559         RequestReferences requestReferences = new RequestReferences();
1560         requestReferences.setInstanceId("1882939");
1561         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1562         expectedResponse.setRequestReferences(requestReferences);
1563         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1564         ResponseEntity<String> response = sendRequest(inputStream("/DeleteVolumeGroup.json"), uri, HttpMethod.DELETE, headers);
1565         
1566         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1567         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1568         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1569     }
1570     @Test
1571     public void createNetworkInstance() throws IOException {
1572         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1573                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1574                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1575
1576         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
1577                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1578                         .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json"))
1579                         .withStatus(HttpStatus.SC_OK)));
1580
1581         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource"))
1582                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1583                         .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json"))
1584                         .withStatus(HttpStatus.SC_OK)));
1585
1586         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]" +
1587                 "modelName=GR-API-DEFAULT&action=createInstance"))
1588                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1589                         .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
1590                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1591         
1592         //expected response
1593         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1594         RequestReferences requestReferences = new RequestReferences();
1595         requestReferences.setInstanceId("1882939");
1596         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1597         expectedResponse.setRequestReferences(requestReferences);
1598         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1599         ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreate.json"), uri, HttpMethod.POST, headers);
1600
1601         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1602         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1603         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1604     }
1605     @Test
1606     public void updateNetworkInstance() throws IOException {
1607         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1608                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1609                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1610
1611         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
1612                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1613                         .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json"))
1614                         .withStatus(HttpStatus.SC_OK)));
1615
1616         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource"))
1617                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1618                         .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json"))
1619                         .withStatus(HttpStatus.SC_OK)));
1620
1621         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]" +
1622                 "modelName=GR-API-DEFAULT&action=updateInstance"))
1623                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1624                         .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
1625                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1626         //expected response
1627         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1628         RequestReferences requestReferences = new RequestReferences();
1629         requestReferences.setInstanceId("1882939");
1630         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1631         expectedResponse.setRequestReferences(requestReferences);
1632         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1633         ResponseEntity<String> response = sendRequest(inputStream("/UpdateNetwork.json"), uri, HttpMethod.PUT, headers);
1634
1635         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1636         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1637         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1638         assertTrue(response.getBody().contains("1882939"));
1639     }
1640     @Test
1641     public void deleteNetworkInstance() throws IOException {
1642         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1643                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1644                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1645
1646         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
1647                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1648                         .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json"))
1649                         .withStatus(HttpStatus.SC_OK)));
1650
1651         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource"))
1652                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1653                                 .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json"))
1654                         .withStatus(HttpStatus.SC_OK)));
1655
1656         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]" +
1657                 "modelName=VNF-API-DEFAULT&action=deleteInstance"))
1658                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1659                         .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
1660                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1661         
1662         //expected response
1663         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1664         RequestReferences requestReferences = new RequestReferences();
1665         requestReferences.setInstanceId("1882939");
1666         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1667         expectedResponse.setRequestReferences(requestReferences);
1668         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1669         ResponseEntity<String> response = sendRequest(inputStream("/NetworkInstance.json"), uri, HttpMethod.DELETE, headers);
1670
1671         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1672         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1673         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1674     }
1675     @Test
1676     public void deleteNetworkInstanceNoReqParams() throws IOException {
1677         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1678                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1679                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1680
1681         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]" +
1682                 "modelName=GR-API-DEFAULT&action=deleteInstance"))
1683                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1684                         .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
1685                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1686
1687
1688         //expected response
1689         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1690         RequestReferences requestReferences = new RequestReferences();
1691         requestReferences.setInstanceId("1882939");
1692         requestReferences.setRequestSelfLink(createExpectedSelfLink("v6","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1693         expectedResponse.setRequestReferences(requestReferences);
1694         uri = servInstanceuri + "v6" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1695         ResponseEntity<String> response = sendRequest(inputStream("/NetworkInstanceNoReqParams.json"), uri, HttpMethod.DELETE, headers);
1696
1697         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1698         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1699         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1700     }
1701     @Test
1702     public void convertJsonToServiceInstanceRequestFail() throws IOException {
1703         //ExpectedRecord
1704         InfraActiveRequests expectedRecord = new InfraActiveRequests();
1705         expectedRecord.setRequestStatus("FAILED");
1706         expectedRecord.setStatusMessage("Error mapping request: ");
1707         expectedRecord.setProgress(100L);
1708         expectedRecord.setRequestBody(inputStream("/ConvertRequestFail.json"));
1709         expectedRecord.setLastModifiedBy("APIH");
1710         expectedRecord.setRequestScope("network");
1711         expectedRecord.setRequestAction("deleteInstance");
1712         expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
1713
1714         uri = servInstanceuri + "v6" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1715         ResponseEntity<String> response = sendRequest(inputStream("/ConvertRequestFail.json"), uri, HttpMethod.DELETE, headers);
1716
1717         //ActualRecord
1718
1719         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
1720     }
1721     @Test
1722     public void convertJsonToServiceInstanceRequestConfigurationFail() throws IOException {
1723         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/configurations/test/enablePort";
1724         ResponseEntity<String> response = sendRequest(inputStream("/ConvertRequestFail.json"), uri, HttpMethod.POST);
1725
1726         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
1727     }
1728
1729     @Test
1730     public void creatServiceInstanceGRTestApiNoCustomRecipeFound() throws IOException {
1731         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1732                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1733                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1734
1735         ServiceRecipe serviceRecipe = new ServiceRecipe();
1736         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
1737         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
1738         serviceRecipe.setAction(Action.createInstance.toString());
1739         serviceRecipe.setId(1);
1740         serviceRecipe.setRecipeTimeout(180);
1741         Service defaultService = new Service();
1742         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
1743         
1744         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
1745                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1746                         .withBody(mapper.writeValueAsString(defaultService))
1747                         .withStatus(HttpStatus.SC_OK)));
1748
1749         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
1750                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1751                         .withBody(mapper.writeValueAsString(serviceRecipe))
1752                         .withStatus(HttpStatus.SC_OK)));
1753         
1754         uri = servInstanceuri + "v7" + "/serviceInstances";
1755         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceMacro.json"), uri, HttpMethod.POST, headers);
1756
1757         //expected response
1758         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1759         RequestReferences requestReferences = new RequestReferences();
1760         requestReferences.setInstanceId("1882939");
1761         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1762         expectedResponse.setRequestReferences(requestReferences);
1763
1764         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1765         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1766         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1767     }
1768
1769     @Test
1770     public void createNetworkInstanceTestApiUndefinedUsePropertiesDefault() throws IOException {
1771         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1772                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1773                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1774
1775         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
1776                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1777                         .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json"))
1778                         .withStatus(HttpStatus.SC_OK)));
1779
1780         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource"))
1781                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1782                         .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json"))
1783                         .withStatus(HttpStatus.SC_OK)));
1784
1785         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]" +
1786                 "modelName=GR-API-DEFAULT&action=createInstance"))
1787                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1788                         .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
1789                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1790         
1791         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1792         ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateAlternateInstanceName.json"), uri, HttpMethod.POST, headers);
1793
1794         //expected response
1795         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1796         RequestReferences requestReferences = new RequestReferences();
1797         requestReferences.setInstanceId("1882939");
1798         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1799         expectedResponse.setRequestReferences(requestReferences);
1800
1801         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1802         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1803         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1804     }
1805
1806     @Test
1807     public void createNetworkInstanceTestApiIncorrectUsePropertiesDefault() throws IOException {
1808         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1809                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1810                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1811
1812         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1813         ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateTestApiIncorrect.json"), uri, HttpMethod.POST);
1814
1815         //expected response
1816         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1817         RequestReferences requestReferences = new RequestReferences();
1818         requestReferences.setInstanceId("1882939");
1819         expectedResponse.setRequestReferences(requestReferences);
1820
1821         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
1822     }
1823
1824     @Test
1825     public void createNetworkInstanceTestApiGrApi() throws IOException {
1826         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1827                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1828                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1829
1830         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
1831                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1832                         .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json"))
1833                         .withStatus(HttpStatus.SC_OK)));
1834
1835         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource"))
1836                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1837                         .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json"))
1838                         .withStatus(HttpStatus.SC_OK)));
1839         
1840         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]" +
1841                 "modelName=GR-API-DEFAULT&action=createInstance"))
1842                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1843                         .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
1844                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1845         
1846         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1847         ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateTestApiGrApi.json"), uri, HttpMethod.POST, headers);
1848
1849         //expected response
1850         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1851         RequestReferences requestReferences = new RequestReferences();
1852         requestReferences.setInstanceId("1882939");
1853         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1854         expectedResponse.setRequestReferences(requestReferences);
1855
1856         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1857         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1858         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1859     }
1860
1861     @Test
1862     public void createNetworkInstanceTestApiVnfApi() throws IOException {
1863         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/CreateNetworkInstance"))
1864                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1865                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1866
1867         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
1868                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1869                         .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json"))
1870                         .withStatus(HttpStatus.SC_OK)));
1871
1872         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource"))
1873                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1874                         .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json"))
1875                         .withStatus(HttpStatus.SC_OK)));
1876         
1877         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]" +
1878                 "modelName=VNF-API-DEFAULT&action=createInstance"))
1879                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1880                         .withBody(getWiremockResponseForCatalogdb("networkRecipeVNF_API_Response.json"))
1881                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
1882         
1883         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1884         ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateTestApiVnfApi.json"), uri, HttpMethod.POST, headers);
1885
1886         //expected response
1887         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1888         RequestReferences requestReferences = new RequestReferences();
1889         requestReferences.setInstanceId("1882939");
1890         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));
1891         expectedResponse.setRequestReferences(requestReferences);
1892
1893         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1894         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1895         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1896     }
1897
1898     @Test
1899     public void activateServiceInstanceRequestStatus() throws IOException{
1900         ServiceRecipe serviceRecipe = new ServiceRecipe();
1901         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
1902         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
1903         serviceRecipe.setAction(Action.createInstance.toString());
1904         serviceRecipe.setId(1);
1905         serviceRecipe.setRecipeTimeout(180);
1906         Service defaultService = new Service();
1907         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
1908             
1909             wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1910                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1911                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1912
1913         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
1914                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1915                         .withBody(mapper.writeValueAsString(defaultService))
1916                         .withStatus(HttpStatus.SC_OK)));
1917
1918         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
1919                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1920                         .withBody(mapper.writeValueAsString(serviceRecipe))
1921                         .withStatus(HttpStatus.SC_OK)));
1922         
1923         //expect
1924         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1925         RequestReferences requestReferences = new RequestReferences();
1926         requestReferences.setInstanceId("1882939");
1927         requestReferences.setRequestSelfLink(createExpectedSelfLink("v5","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
1928         expectedResponse.setRequestReferences(requestReferences);
1929         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7999/activate";
1930         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstancePrev8.json"), uri, HttpMethod.POST, headers);
1931
1932         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1933         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1934         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1935     }
1936
1937     @Test
1938     public void invalidRequestId() throws IOException {
1939         String illegalRequestId = "1234";
1940         HttpHeaders ivalidRequestIdHeaders = new HttpHeaders();
1941         ivalidRequestIdHeaders.set(ONAPLogConstants.Headers.REQUEST_ID, illegalRequestId);
1942         uri = servInstanceuri + "v5/serviceInstances";
1943         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, ivalidRequestIdHeaders);
1944
1945         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
1946         assertTrue(response.getBody().contains("Request Id " + illegalRequestId + " is not a valid UUID"));
1947     }
1948     @Test
1949     public void invalidBPELResponse() throws IOException{
1950
1951         ServiceRecipe serviceRecipe = new ServiceRecipe();
1952         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
1953         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
1954         serviceRecipe.setAction(Action.createInstance.toString());
1955         serviceRecipe.setId(1);
1956         serviceRecipe.setRecipeTimeout(180);
1957         Service defaultService = new Service();
1958         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
1959             
1960             wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1961                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1962                         .withBodyFile("Camunda/TestResponseInvalid2.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1963
1964         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
1965                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1966                         .withBody(mapper.writeValueAsString(defaultService))
1967                         .withStatus(HttpStatus.SC_OK)));
1968
1969         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
1970                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1971                         .withBody(mapper.writeValueAsString(serviceRecipe))
1972                         .withStatus(HttpStatus.SC_OK)));
1973         
1974         uri = servInstanceuri + "v5/serviceInstances";
1975         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
1976         
1977         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1978         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
1979         assertEquals("Request Failed due to BPEL error with HTTP Status = 202{\"instanceId\": \"1882939\"}", realResponse.getServiceException().getText());
1980     }
1981     @Test
1982     public void unauthorizedBPELResponse() throws IOException{
1983
1984         ServiceRecipe serviceRecipe = new ServiceRecipe();
1985         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
1986         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
1987         serviceRecipe.setAction(Action.createInstance.toString());
1988         serviceRecipe.setId(1);
1989         serviceRecipe.setRecipeTimeout(180);
1990         Service defaultService = new Service();
1991         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
1992             
1993             wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1994                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1995                         .withBodyFile("Camunda/UnauthorizedResponse.json").withStatus(org.apache.http.HttpStatus.SC_UNAUTHORIZED)));
1996
1997         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
1998                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
1999                         .withBody(mapper.writeValueAsString(defaultService))
2000                         .withStatus(HttpStatus.SC_OK)));
2001
2002         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2003                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2004                         .withBody(mapper.writeValueAsString(serviceRecipe))
2005                         .withStatus(HttpStatus.SC_OK)));
2006         
2007         uri = servInstanceuri + "v5/serviceInstances";
2008         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2009
2010         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2011         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2012         assertEquals("Exception caught mapping Camunda JSON response to object", realResponse.getServiceException().getText());
2013     }
2014
2015     @Test
2016     public void invalidBPELResponse2() throws IOException{
2017
2018         ServiceRecipe serviceRecipe = new ServiceRecipe();
2019         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
2020         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2021         serviceRecipe.setAction(Action.createInstance.toString());
2022         serviceRecipe.setId(1);
2023         serviceRecipe.setRecipeTimeout(180);
2024         Service defaultService = new Service();
2025         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2026             
2027             wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2028                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2029                         .withBodyFile("Camunda/TestResponseInvalid.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2030
2031         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
2032                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2033                         .withBody(mapper.writeValueAsString(defaultService))
2034                         .withStatus(HttpStatus.SC_OK)));
2035
2036         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2037                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2038                         .withBody(mapper.writeValueAsString(serviceRecipe))
2039                         .withStatus(HttpStatus.SC_OK)));
2040         uri = servInstanceuri + "v5/serviceInstances";
2041         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2042     
2043         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2044         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2045         assertTrue(realResponse.getServiceException().getText().contains("<aetgt:ErrorMessage>Exception in create execution list 500"));
2046     }
2047
2048     @Test
2049     public void createMacroServiceInstance() throws IOException{
2050         ServiceRecipe serviceRecipe = new ServiceRecipe();
2051         serviceRecipe.setOrchestrationUri("/mso/async/services/CreateMacroServiceNetworkVnf");
2052         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2053         serviceRecipe.setAction(Action.createInstance.toString());
2054         serviceRecipe.setId(1);
2055         serviceRecipe.setRecipeTimeout(180);
2056         Service defaultService = new Service();
2057         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2058             
2059             wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/CreateMacroServiceNetworkVnf"))
2060                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2061                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2062
2063         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2064                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2065                         .withBodyFile("Camunda/TestResponseInvalid.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2066
2067         wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
2068                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2069                         .withBody(mapper.writeValueAsString(defaultService))
2070                         .withStatus(HttpStatus.SC_OK)));
2071
2072         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2073                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2074                         .withBody(mapper.writeValueAsString(serviceRecipe))
2075                         .withStatus(HttpStatus.SC_OK)));
2076
2077         //expect
2078         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2079         RequestReferences requestReferences = new RequestReferences();
2080         requestReferences.setInstanceId("1882939");
2081         requestReferences.setRequestSelfLink(createExpectedSelfLink("v5","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
2082         expectedResponse.setRequestReferences(requestReferences);
2083         uri = servInstanceUriPrev7 + "v5";
2084         ResponseEntity<String> response = sendRequest(inputStream("/MacroServiceInstance.json"), uri, HttpMethod.POST, headers);
2085
2086         //then          
2087         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2088         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2089         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
2090     }
2091
2092     @Test
2093     public void testUserParams() throws IOException {
2094         ObjectMapper mapper = new ObjectMapper();
2095         ServiceInstancesRequest request = mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class);
2096         RequestParameters requestParameters = request.getRequestDetails().getRequestParameters();
2097         String userParamsTxt = inputStream("/userParams.txt");
2098
2099         List<Map<String, Object>> userParams = servInstances.configureUserParams(requestParameters);
2100         System.out.println(userParams);
2101         assertTrue(userParams.size() > 0);
2102         assertTrue(userParams.get(0).containsKey("name"));
2103         assertTrue(userParams.get(0).containsKey("value"));
2104         assertEquals(userParamsTxt.replaceAll("\\s+", ""), userParams.toString().replaceAll("\\s+", ""));
2105     }
2106
2107     @Test
2108     public void testConfigureCloudConfig() throws IOException {
2109         ObjectMapper mapper = new ObjectMapper();
2110         ServiceInstancesRequest request = mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class);
2111         CloudConfiguration cloudConfig = servInstances.configureCloudConfig(request.getRequestDetails().getRequestParameters());
2112
2113         assertEquals("mdt25b", cloudConfig.getLcpCloudRegionId());
2114         assertEquals("aefb697db6524ddebfe4915591b0a347", cloudConfig.getTenantId());
2115     }
2116
2117     @Test
2118     public void testMapToLegacyRequest() throws IOException {
2119         ObjectMapper mapper = new ObjectMapper();
2120         ServiceInstancesRequest request = mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class);
2121         ServiceInstancesRequest expected = mapper.readValue(inputStream("/LegacyMacroServiceInstance.json"), ServiceInstancesRequest.class);
2122         servInstances.mapToLegacyRequest(request.getRequestDetails());
2123         System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(request));
2124         assertThat(request, sameBeanAs(expected));
2125     }
2126     @Test
2127     public void scaleOutVfModule() throws IOException {
2128         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2129                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2130                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2131
2132         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/cb82ffd8-252a-11e7-93ae-92361f002671"))
2133                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2134                         .withBody(getWiremockResponseForCatalogdb("vfModuleCustomization_Response.json"))
2135                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
2136
2137         wireMockServer.stubFor(get(urlMatching(".*/vfModuleCustomization/cb82ffd8-252a-11e7-93ae-92361f002671/vfModule"))
2138                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2139                         .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json"))
2140                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
2141
2142         wireMockServer.stubFor(get(urlMatching(".*/vfModule/20c4431c-246d-11e7-93ae-92361f002671"))
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
2148         wireMockServer.stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" +
2149                 "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=scaleOut"))
2150                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2151                         .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeVfModuleScaleOut_Response.json")).withStatus(org.apache.http.HttpStatus.SC_OK)));
2152         
2153         wireMockServer.stubFor(get(urlMatching(".*/vfModule/search/findByModelInvariantUUIDOrderByModelVersionDesc[?]modelInvariantUUID=78ca26d0-246d-11e7-93ae-92361f002671"))
2154                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2155                         .withBody(getWiremockResponseForCatalogdb("vfModulesListByInvariantId_Response.json")).withStatus(org.apache.http.HttpStatus.SC_OK)));
2156         
2157         //expected response
2158         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2159         RequestReferences requestReferences = new RequestReferences();
2160         requestReferences.setInstanceId("1882939");
2161         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));
2162         expectedResponse.setRequestReferences(requestReferences);
2163         uri = servInstanceuri + "v7" + "/serviceInstances/7a88cbeb-0ec8-4765-a271-4f9e90c3da7b/vnfs/cbba721b-4803-4df7-9347-307c9a955426/vfModules/scaleOut";
2164         ResponseEntity<String> response = sendRequest(inputStream("/ScaleOutRequest.json"), uri, HttpMethod.POST, headers);
2165
2166         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2167         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2168         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
2169         assertTrue(response.getBody().contains("1882939"));
2170     }
2171     @Test
2172     public void createServiceInstanceBadResponse() throws IOException{
2173           ServiceRecipe serviceRecipe = new ServiceRecipe();
2174           serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
2175           serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2176           serviceRecipe.setAction(Action.createInstance.toString());
2177           serviceRecipe.setId(1);
2178           serviceRecipe.setRecipeTimeout(180);
2179           Service defaultService = new Service();
2180           defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2181             
2182             wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2183                   .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2184                           .withBodyFile("Camunda/TestBadResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2185
2186           wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
2187                   .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2188                           .withBody(mapper.writeValueAsString(defaultService))
2189                           .withStatus(HttpStatus.SC_OK)));
2190
2191           wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2192                   .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2193                           .withBody(mapper.writeValueAsString(serviceRecipe))
2194                           .withStatus(HttpStatus.SC_OK)));
2195           
2196           uri = servInstanceuri + "v5/serviceInstances";
2197           ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2198           
2199           assertEquals(Response.Status.NOT_ACCEPTABLE.getStatusCode(), response.getStatusCode().value());
2200           RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2201           assertEquals("Exception caught mapping Camunda JSON response to object", realResponse.getServiceException().getText());
2202     }
2203     @Test
2204     public void createServiceInstanceDuplicateError() throws IOException{
2205                 wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/checkInstanceNameDuplicate"))
2206                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2207                                                 .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
2208           
2209         uri = servInstanceuri + "v5/serviceInstances";
2210         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2211        
2212         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2213         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2214         assertEquals("Unable to check for duplicate instance due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException: 500 Server Error", realResponse.getServiceException().getText());
2215     }
2216     @Test
2217     public void createServiceInstanceDuplicateHistoryCheck() throws IOException{
2218                 wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/checkInstanceNameDuplicate"))
2219                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2220                                                 .withBodyFile("InfraActiveRequests/createInfraActiveRequests.json")
2221                                                 .withStatus(HttpStatus.SC_ACCEPTED)));
2222                 wireMockServer.stubFor(get(("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f"))
2223                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2224                         .withBodyFile("Camunda/HistoryCheckResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2225           
2226         uri = servInstanceuri + "v5/serviceInstances";
2227         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2228         
2229         assertEquals(Response.Status.CONFLICT.getStatusCode(), response.getStatusCode().value());
2230         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2231         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());
2232     }
2233     @Test
2234     public void createServiceInstanceDuplicateHistoryCheckException() throws IOException{
2235                 wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/checkInstanceNameDuplicate"))
2236                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2237                                                 .withBodyFile("InfraActiveRequests/createInfraActiveRequests.json")
2238                                                 .withStatus(HttpStatus.SC_ACCEPTED)));
2239                 wireMockServer.stubFor(get(("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f"))
2240                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2241                         .withStatus(org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR)));
2242           
2243         uri = servInstanceuri + "v5/serviceInstances";
2244         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2245   
2246         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2247         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2248         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());
2249     }
2250     @Test
2251     public void createServiceInstanceDuplicate() throws IOException{
2252                 wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/checkInstanceNameDuplicate"))
2253                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2254                                                 .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
2255           
2256         uri = servInstanceuri + "v5/serviceInstances";
2257         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2258
2259         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2260         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2261         assertEquals("Unable to check for duplicate instance due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException: 500 Server Error", realResponse.getServiceException().getText());
2262     }
2263     
2264     @Test
2265     public void createServiceInstanceSaveError() throws IOException{
2266         ServiceRecipe serviceRecipe = new ServiceRecipe();
2267         serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
2268         serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2269         serviceRecipe.setAction(Action.createInstance.toString());
2270         serviceRecipe.setId(1);
2271         serviceRecipe.setRecipeTimeout(180);
2272         Service defaultService = new Service();
2273         defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
2274                 wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/"))
2275                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2276                                                 .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
2277                 wireMockServer.stubFor(get(urlMatching(".*/service/.*"))
2278                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2279                         .withBody(mapper.writeValueAsString(defaultService))
2280                         .withStatus(HttpStatus.SC_OK)));
2281
2282         wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
2283                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2284                         .withBody(mapper.writeValueAsString(serviceRecipe))
2285                         .withStatus(HttpStatus.SC_OK)));
2286           
2287         uri = servInstanceuri + "v5/serviceInstances";
2288         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers);
2289
2290         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2291         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2292         assertEquals("Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException: 500 Server Error", realResponse.getServiceException().getText());
2293     }
2294     @Test
2295     public void createPortConfigurationSaveError() throws IOException {
2296         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/"))
2297                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2298                                                 .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
2299         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
2300                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2301                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2302         
2303         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations";
2304         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstancePortConfiguration.json"), uri, HttpMethod.POST, headers);
2305  
2306         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2307         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2308         assertEquals("Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException: 500 Server Error", realResponse.getServiceException().getText());
2309     }
2310     @Test
2311     public void createPortConfigDbUpdateError() throws IOException {
2312         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/"))
2313                                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2314                                                 .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
2315         
2316         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations";
2317         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceParseFail.json"), uri, HttpMethod.POST, headers);
2318   
2319         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
2320         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2321         assertEquals("Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException: 500 Server Error", realResponse.getServiceException().getText());
2322     }
2323     @Test
2324     public void vnfUpdateWithNetworkInstanceGroup() throws IOException{
2325         TestAppender.events.clear();
2326         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2327                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2328                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2329
2330         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/2ccae1b4-7d9e-46fa-a452-9180ce008d17"))
2331                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2332                         .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomization_Response.json"))
2333                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
2334
2335         wireMockServer.stubFor(get(urlMatching(".*/vnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002674/vnfResources"))
2336                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2337                         .withBody(getWiremockResponseForCatalogdb("vnfResources_Response.json"))
2338                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
2339         
2340         wireMockServer.stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction" +
2341                 "[?]nfRole=GR-API-DEFAULT&action=updateInstance"))
2342                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2343                         .withBody(getWiremockResponseForCatalogdb("UpdateVnfRecipe_Response.json"))
2344                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
2345         headers.set(ONAPLogConstants.Headers.PARTNER_NAME, "VID");
2346         //expect
2347         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2348         RequestReferences requestReferences = new RequestReferences();
2349         requestReferences.setInstanceId("1882939");
2350         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
2351         expectedResponse.setRequestReferences(requestReferences);
2352         uri = servInstanceuri + "v7/serviceInstances/e05864f0-ab35-47d0-8be4-56fd9619ba3c/vnfs/f501ce76-a9bc-4601-9837-74fd9f4d5eca";
2353         ResponseEntity<String> response = sendRequest(inputStream("/VnfwithNeteworkInstanceGroup.json"), uri, HttpMethod.PUT, headers);
2354         //then          
2355         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2356         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2357         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
2358         assertEquals(response.getHeaders().get(TRANSACTION_ID).get(0), "32807a28-1a14-4b88-b7b3-2950918aa76d");
2359         
2360         for(ILoggingEvent logEvent : TestAppender.events){
2361             if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.JaxRsFilterLogging") &&
2362                         logEvent.getMarker() != null && logEvent.getMarker().getName().equals("ENTRY")){
2363                 Map<String,String> mdc = logEvent.getMDCPropertyMap();
2364                 assertEquals("32807a28-1a14-4b88-b7b3-2950918aa76d", mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));             
2365                 assertEquals("VID",mdc.get(PARTNERNAME));
2366             }
2367         }
2368     }
2369     @Test
2370     public void createInstanceGroup() throws IOException{
2371         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2372                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2373                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2374         
2375         //expect
2376         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2377         RequestReferences requestReferences = new RequestReferences();
2378         requestReferences.setInstanceId("1882939");
2379         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
2380         expectedResponse.setRequestReferences(requestReferences);
2381         uri = servInstanceuri + "/v7/instanceGroups";
2382         ResponseEntity<String> response = sendRequest(inputStream("/CreateInstanceGroup.json"), uri, HttpMethod.POST, headers);
2383
2384         //then          
2385         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2386         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2387         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
2388     }
2389     @Test
2390     public void deleteInstanceGroup() throws IOException{
2391         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2392                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2393                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2394         
2395         //expect
2396         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2397         RequestReferences requestReferences = new RequestReferences();
2398         requestReferences.setInstanceId("1882939");
2399         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
2400         expectedResponse.setRequestReferences(requestReferences);
2401         uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c";
2402         ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE, headers);
2403
2404         //then          
2405         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2406         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2407         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
2408     }
2409     @Test
2410     public void deleteInstanceGroupNoRequestIdHeader() throws IOException{
2411         uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c";
2412         ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE);
2413         //then          
2414         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
2415         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2416         assertEquals(realResponse.getServiceException().getText(), "No valid X-ONAP-RequestID header is specified");    
2417     }
2418     @Test
2419     public void deleteInstanceGroupNoPartnerNameHeader() throws IOException{
2420         HttpHeaders noPartnerHeaders = new HttpHeaders();
2421         noPartnerHeaders.set(ONAPLogConstants.Headers.REQUEST_ID, "eca3a1b1-43ab-457e-ab1c-367263d148b4");
2422         noPartnerHeaders.set(REQUESTOR_ID, "xxxxxx");
2423         uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c";
2424         ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE, noPartnerHeaders);
2425         //then          
2426         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
2427         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2428         assertEquals(realResponse.getServiceException().getText(), "No valid X-ONAP-PartnerName header is specified");  
2429     }
2430     @Test
2431     public void deleteInstanceGroupNoRquestorIdHeader() throws IOException{
2432         HttpHeaders noRequestorIdHheaders = new HttpHeaders();
2433         noRequestorIdHheaders.set(ONAPLogConstants.Headers.REQUEST_ID, "eca3a1b1-43ab-457e-ab1c-367263d148b4");
2434         noRequestorIdHheaders.set(ONAPLogConstants.Headers.PARTNER_NAME, "eca3a1b1-43ab-457e-ab1c-367263d148b4");       
2435         //expect
2436         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2437         RequestReferences requestReferences = new RequestReferences();
2438         requestReferences.setInstanceId("1882939");
2439         expectedResponse.setRequestReferences(requestReferences);
2440         uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c";
2441         ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE, noRequestorIdHheaders);
2442         
2443         //then          
2444         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
2445         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2446         assertEquals(realResponse.getServiceException().getText(), "No valid X-RequestorID header is specified");       
2447     }
2448     @Test
2449     public void addMembers() throws IOException{
2450         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2451                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2452                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2453         //expect 
2454         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2455         RequestReferences requestReferences = new RequestReferences();
2456         requestReferences.setInstanceId("1882939");
2457         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
2458         expectedResponse.setRequestReferences(requestReferences);
2459         uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c/addMembers";
2460         ResponseEntity<String> response = sendRequest(inputStream("/AddMembers.json"), uri, HttpMethod.POST, headers);
2461
2462         //then          
2463         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2464         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2465         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
2466     }
2467     @Test
2468     public void removeMembers() throws IOException{
2469         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2470                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2471                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2472         //expect
2473         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2474         RequestReferences requestReferences = new RequestReferences();
2475         requestReferences.setInstanceId("1882939");
2476         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
2477         expectedResponse.setRequestReferences(requestReferences);
2478         uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c/removeMembers";
2479         ResponseEntity<String> response = sendRequest(inputStream("/RemoveMembers.json"), uri, HttpMethod.POST, headers);
2480
2481         //then          
2482         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2483         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2484         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
2485     }
2486     @Test
2487     public void deleteNetworkInstanceNoCustomizationEntry() throws IOException {
2488         wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
2489                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2490                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
2491
2492         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
2493                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2494                         .withStatus(HttpStatus.SC_NOT_FOUND)));
2495
2496         wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]" +
2497                 "modelName=VNF-API-DEFAULT&action=deleteInstance"))
2498                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2499                         .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json"))
2500                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
2501         
2502         //expected response
2503         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
2504         RequestReferences requestReferences = new RequestReferences();
2505         requestReferences.setInstanceId("1882939");
2506         requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d"));        
2507         expectedResponse.setRequestReferences(requestReferences);
2508         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
2509         ResponseEntity<String> response = sendRequest(inputStream("/NetworkInstance.json"), uri, HttpMethod.DELETE, headers);
2510
2511         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
2512         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
2513         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
2514     }
2515     @Test
2516     public void updateNetworkInstanceNoCustomizationEntry() throws IOException {
2517         wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac"))
2518                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
2519                         .withStatus(HttpStatus.SC_NOT_FOUND)));
2520         
2521         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
2522         ResponseEntity<String> response = sendRequest(inputStream("/UpdateNetwork.json"), uri, HttpMethod.PUT, headers);
2523         
2524         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
2525         RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class);
2526         assertEquals(realResponse.getServiceException().getText(), "No valid modelCustomizationId for networkResourceCustomization lookup is specified");
2527     }
2528     
2529    
2530 }