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