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