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