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