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