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