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