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