ef318513fc15c1f158cccf1ee4016be6fbaa3af8
[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.post;
26 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
27 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
28 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
29 import static org.hamcrest.CoreMatchers.containsString;
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertNotNull;
32 import static org.junit.Assert.assertNull;
33 import static org.junit.Assert.assertThat;
34 import static org.junit.Assert.assertTrue;
35
36 import java.io.IOException;
37 import java.nio.file.Files;
38 import java.nio.file.Paths;
39 import java.util.List;
40 import java.util.Map;
41
42 import javax.ws.rs.core.HttpHeaders;
43 import javax.ws.rs.core.MediaType;
44 import javax.ws.rs.core.Response;
45
46 import org.apache.log4j.MDC;
47 import org.junit.Ignore;
48 import org.junit.Test;
49 import org.onap.so.db.request.beans.InfraActiveRequests;
50 import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository;
51 import org.onap.so.logger.MsoLogger;
52 import org.onap.so.serviceinstancebeans.CloudConfiguration;
53 import org.onap.so.serviceinstancebeans.ModelInfo;
54 import org.onap.so.serviceinstancebeans.RequestError;
55 import org.onap.so.serviceinstancebeans.RequestParameters;
56 import org.onap.so.serviceinstancebeans.RequestReferences;
57 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
58 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
59 import org.springframework.beans.factory.annotation.Autowired;
60 import org.springframework.http.HttpEntity;
61 import org.springframework.http.HttpMethod;
62 import org.springframework.http.ResponseEntity;
63 import org.springframework.web.util.UriComponentsBuilder;
64
65 import com.fasterxml.jackson.annotation.JsonInclude.Include;
66 import com.fasterxml.jackson.core.JsonParseException;
67 import com.fasterxml.jackson.databind.DeserializationFeature;
68 import com.fasterxml.jackson.databind.JsonMappingException;
69 import com.fasterxml.jackson.databind.ObjectMapper;
70 import com.github.tomakehurst.wiremock.http.Fault;
71
72 import ch.qos.logback.classic.spi.ILoggingEvent;
73
74
75 public class ServiceInstancesTest extends BaseTest{
76
77     @Autowired
78     private InfraActiveRequestsRepository iar;
79
80     @Autowired
81     private ServiceInstances servInstances;
82
83     private final String servInstanceuri = "/onap/so/infra/serviceInstantiation/";
84     private final String servInstanceUriPrev7 = "/onap/so/infra/serviceInstances/";
85     private String uri;
86
87     public String inputStream(String JsonInput)throws IOException{
88         JsonInput = "src/test/resources/ServiceInstanceTest" + JsonInput;
89         String input = new String(Files.readAllBytes(Paths.get(JsonInput)));
90         return input;
91     }
92
93     public ResponseEntity<String> sendRequest(String requestJson, String uriPath, HttpMethod reqMethod){                 
94         headers.set("Accept", MediaType.APPLICATION_JSON);
95         headers.set("Content-Type",MediaType.APPLICATION_JSON);
96
97         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(uriPath));
98
99         HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);  
100         ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(),
101                 reqMethod, request, String.class);
102
103         return response;
104     }
105
106     @Test
107     public void test_mapJSONtoMSOStyle() throws IOException{
108         ObjectMapper mapper = new ObjectMapper();
109         mapper.setSerializationInclusion(Include.NON_NULL);
110         String testRequest= inputStream("/ServiceInstanceDefault.json");
111         String resultString = servInstances.mapJSONtoMSOStyle(testRequest, null, false, null);
112         ServiceInstancesRequest sir = mapper.readValue(resultString, ServiceInstancesRequest.class);
113         ModelInfo modelInfo = sir.getRequestDetails().getModelInfo();
114         assertEquals("f7ce78bb-423b-11e7-93f8-0050569a796",modelInfo.getModelCustomizationUuid());
115         assertEquals("modelInstanceName",modelInfo.getModelInstanceName());
116         assertEquals("f7ce78bb-423b-11e7-93f8-0050569a7965",modelInfo.getModelInvariantUuid());
117         assertEquals("10",modelInfo.getModelUuid());
118
119     }
120     @Test
121     public void createServiceInstanceVIDDefault() throws JsonParseException, JsonMappingException, IOException{
122         TestAppender.events.clear();
123         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
124                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
125                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
126
127         headers.set(MsoLogger.ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
128         headers.set(MsoLogger.CLIENT_ID, "VID");
129         //expect
130         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
131         RequestReferences requestReferences = new RequestReferences();
132         requestReferences.setInstanceId("1882939");
133         expectedResponse.setRequestReferences(requestReferences);
134         uri = servInstanceuri + "v5/serviceInstances";
135         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST);
136
137         ObjectMapper mapper = new ObjectMapper();
138         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
139
140         //then          
141         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
142         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
143         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
144         
145         
146         
147         for(ILoggingEvent logEvent : TestAppender.events)
148             if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.jersey.JaxRsFilterLogging") &&
149                     logEvent.getMarker().getName().equals("ENTRY")
150                     ){
151                 Map<String,String> mdc = logEvent.getMDCPropertyMap();
152                 assertNotNull(mdc.get(MsoLogger.BEGINTIME));
153                 assertNotNull(mdc.get(MsoLogger.REQUEST_ID));
154                 assertNotNull(mdc.get(MsoLogger.INVOCATION_ID));               
155                 assertEquals("UNKNOWN",mdc.get(MsoLogger.PARTNERNAME));
156                 assertEquals("onap/so/infra/serviceInstantiation/v5/serviceInstances",mdc.get(MsoLogger.SERVICE_NAME));
157                 assertEquals("INPROGRESS",mdc.get(MsoLogger.STATUSCODE));
158             }else if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.jersey.JaxRsFilterLogging") &&
159                     logEvent.getMarker().getName().equals("EXIT")){
160                 Map<String,String> mdc = logEvent.getMDCPropertyMap();
161                 assertNotNull(mdc.get(MsoLogger.BEGINTIME));
162                 assertNotNull(mdc.get(MsoLogger.ENDTIME));
163                 assertNotNull(mdc.get(MsoLogger.REQUEST_ID));
164                 assertNotNull(mdc.get(MsoLogger.INVOCATION_ID));
165                 assertEquals("202",mdc.get(MsoLogger.RESPONSECODE));
166                 assertEquals("UNKNOWN",mdc.get(MsoLogger.PARTNERNAME));
167                 assertEquals("onap/so/infra/serviceInstantiation/v5/serviceInstances",mdc.get(MsoLogger.SERVICE_NAME));
168                 assertEquals("COMPLETE",mdc.get(MsoLogger.STATUSCODE));
169                 assertNotNull(mdc.get(MsoLogger.RESPONSEDESC));
170                 assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
171                 assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
172                 assertEquals("5.0.0", response.getHeaders().get("X-LatestVersion").get(0));
173             }
174         
175         //ExpectedRecord
176         InfraActiveRequests expectedRecord = new InfraActiveRequests();
177         expectedRecord.setRequestStatus("IN_PROGRESS");
178         expectedRecord.setRequestBody(inputStream("/ServiceInstanceDefault.json"));
179         expectedRecord.setAction("createInstance");
180         expectedRecord.setSource("VID");
181         expectedRecord.setVnfId("1882938");
182         expectedRecord.setLastModifiedBy("APIH");
183         expectedRecord.setServiceInstanceId("1882939");
184         expectedRecord.setServiceInstanceName("testService9");
185         expectedRecord.setRequestScope("service");
186         expectedRecord.setRequestorId("xxxxxx");
187         expectedRecord.setRequestAction("createInstance");
188         expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
189
190         //ActualRecord
191         InfraActiveRequests requestRecord = iar.findOneByRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
192         assertEquals(sameBeanAs(expectedRecord).toString(), sameBeanAs(requestRecord).ignoring("startTime").ignoring("modifyTime").toString());
193
194     }
195     @Test
196     public void createServiceInstanceServiceInstancesUri() throws JsonParseException, JsonMappingException, IOException{
197         stubFor(post(urlPathEqualTo("/mso/async/services/CreateGenericALaCarteServiceInstance"))
198                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
199                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
200
201         //expect
202         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
203         RequestReferences requestReferences = new RequestReferences();
204         requestReferences.setInstanceId("1882939");
205         expectedResponse.setRequestReferences(requestReferences);
206         uri = servInstanceUriPrev7 + "v5";
207         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstancePrev7.json"), uri, HttpMethod.POST);
208
209         ObjectMapper mapper = new ObjectMapper();
210         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
211
212         //then          
213         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
214         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
215         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
216     }
217     @Test
218     public void createServiceInstanceBpelStatusError() throws JsonParseException, JsonMappingException, IOException{
219         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
220                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
221                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_BAD_GATEWAY)));
222
223         uri = servInstanceuri + "v5/serviceInstances";
224         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceStatusError.json"), uri, HttpMethod.POST);
225
226         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
227     }
228     @Test
229     public void createServiceInstanceBadGateway() throws JsonParseException, JsonMappingException, IOException{
230         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
231                 .willReturn(aResponse().withStatus(org.apache.http.HttpStatus.SC_BAD_GATEWAY).withBody("{}")));
232
233         uri = servInstanceuri + "v5/serviceInstances";
234         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceBadGateway.json"), uri, HttpMethod.POST);
235
236         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
237     }
238     @Test
239     public void createServiceInstanceBadData() throws JsonParseException, JsonMappingException, IOException{
240         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
241                 .willReturn(aResponse().withStatus(org.apache.http.HttpStatus.SC_BAD_GATEWAY).withBody("{I AM REALLY BAD}")));
242
243         uri = servInstanceuri + "v5/serviceInstances";
244         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceBadGateway.json"), uri, HttpMethod.POST);
245
246         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
247     }
248     @Test
249     public void createServiceInstanceEmptyResponse() throws JsonParseException, JsonMappingException, IOException{
250         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
251                 .willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE)));
252
253         uri = servInstanceuri + "v5/serviceInstances";
254         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceEmpty.json"), uri, HttpMethod.POST);
255
256         assertEquals(Response.Status.BAD_GATEWAY.getStatusCode(), response.getStatusCode().value());
257     }
258     @Test
259     public void activateServiceInstanceNoRecipeALaCarte() throws JsonParseException, JsonMappingException, IOException{
260         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/activate";
261         headers.set("X-ECOMP-RequestID", "32807a28-1a14-4b88-b7b3-2950918aa76d");
262         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceALaCarteTrueNoRecipe.json"), uri, HttpMethod.POST);
263
264         //ExpectedRecord
265         InfraActiveRequests expectedRecord = new InfraActiveRequests();
266         expectedRecord.setRequestStatus("FAILED");
267         expectedRecord.setAction("activateInstance");
268         expectedRecord.setStatusMessage("Recipe could not be retrieved from catalog DB.");
269         expectedRecord.setProgress(new Long(100));
270         expectedRecord.setSource("VID");
271         expectedRecord.setVnfId("1882938");
272         expectedRecord.setRequestBody(inputStream("/ServiceInstanceALaCarteTrueNoRecipe.json"));
273         expectedRecord.setLastModifiedBy("APIH");
274         expectedRecord.setServiceInstanceId("f7ce78bb-423b-11e7-93f8-0050569a7968");
275         expectedRecord.setServiceInstanceName("testService7");
276         expectedRecord.setRequestScope("service");
277         expectedRecord.setRequestAction("activateInstance");
278         expectedRecord.setRequestorId("xxxxxx");
279         expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
280
281         //ActualRecord
282         InfraActiveRequests requestRecord = iar.findOneByRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
283         assertEquals(sameBeanAs(expectedRecord).toString(), sameBeanAs(requestRecord).ignoring("startTime").ignoring("endTime").ignoring("modifyTime").toString());
284         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
285     }
286     @Test
287     public void activateServiceInstanceNoRecipe() throws JsonParseException, JsonMappingException, IOException{
288         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/activate";
289         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceNoRecipe.json"), uri, HttpMethod.POST);
290
291         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
292     }
293     @Test
294     public void activateServiceInstance() throws JsonParseException, JsonMappingException, IOException{
295         stubFor(post(urlPathEqualTo("/mso/async/services/ActivateInstance"))
296                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
297                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
298
299         headers.set("X-TransactionID", "32807a28-1a14-4b88-b7b3-2950918aa76d");
300         //expected response
301         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
302         RequestReferences requestReferences = new RequestReferences();
303         requestReferences.setInstanceId("1882939");
304         expectedResponse.setRequestReferences(requestReferences);
305         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/activate";
306         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceActivate.json"), uri, HttpMethod.POST);
307
308         ObjectMapper mapper = new ObjectMapper();
309         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
310
311         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
312         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
313         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
314     }
315     @Test
316     public void deactivateServiceInstance() throws JsonParseException, JsonMappingException, IOException{
317         stubFor(post(urlPathEqualTo("/mso/async/services/DeactivateInstance"))
318                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
319                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
320         //expected response
321         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
322         RequestReferences requestReferences = new RequestReferences();
323         requestReferences.setInstanceId("1882939");
324         expectedResponse.setRequestReferences(requestReferences);
325         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/deactivate";
326         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDeactivate.json"), uri, HttpMethod.POST);
327
328         ObjectMapper mapper = new ObjectMapper();
329         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
330
331         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
332         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
333         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
334     }
335     @Test
336     public void deleteServiceInstance() throws JsonParseException, JsonMappingException, IOException {
337         stubFor(post(urlPathEqualTo("/mso/async/services/DeleteInstance"))
338                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
339                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
340         //expected response
341         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
342         RequestReferences requestReferences = new RequestReferences();
343         requestReferences.setInstanceId("1882939");
344         expectedResponse.setRequestReferences(requestReferences);
345         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a8868/";
346         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDelete.json"), uri, HttpMethod.DELETE);
347
348         ObjectMapper mapper = new ObjectMapper();
349         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
350
351         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
352         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
353         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
354     }
355     @Test
356     public void assignServiceInstance() throws JsonParseException, JsonMappingException, IOException {
357         stubFor(post(urlPathEqualTo("/mso/async/services/AssignServiceInstance"))
358                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
359                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
360         //expected response
361         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
362         RequestReferences requestReferences = new RequestReferences();
363         requestReferences.setInstanceId("1882939");
364         expectedResponse.setRequestReferences(requestReferences);
365         uri = servInstanceuri + "v7" + "/serviceInstances/assign";
366         ResponseEntity<String> response = sendRequest(inputStream("/ServiceAssign.json"), uri, HttpMethod.POST);
367
368         ObjectMapper mapper = new ObjectMapper();
369         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
370
371         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
372         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
373         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
374     }
375
376     @Test
377     public void unassignServiceInstance() throws JsonParseException, JsonMappingException, IOException {
378         stubFor(post(urlPathEqualTo("/mso/async/services/UnassignServiceInstance"))
379                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
380                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
381         //expected response
382         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
383         RequestReferences requestReferences = new RequestReferences();
384         requestReferences.setInstanceId("1882939");
385         expectedResponse.setRequestReferences(requestReferences);
386         uri = servInstanceuri + "v7" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/unassign";
387         ResponseEntity<String> response = sendRequest(inputStream("/ServiceUnassign.json"), uri, HttpMethod.POST);
388
389         ObjectMapper mapper = new ObjectMapper();
390         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
391
392         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
393         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
394         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
395     }
396     @Test
397     public void createPortConfiguration() throws JsonParseException, JsonMappingException, IOException {
398         stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
399                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
400                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
401         headers.set("X-TransactionID", "32807a28-1a14-4b88-b7b3-2950918aa76d");
402         //expected response
403         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
404         RequestReferences requestReferences = new RequestReferences();
405         requestReferences.setInstanceId("1882939");
406         expectedResponse.setRequestReferences(requestReferences);
407         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations";
408         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstancePortConfiguration.json"), uri, HttpMethod.POST);
409
410         ObjectMapper mapper = new ObjectMapper();
411         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
412
413         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
414         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
415         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));         
416         assertTrue(response.getBody().contains("1882939"));
417     }
418     @Test
419     public void createPortConfigurationEmptyProductFamilyId() throws JsonParseException, JsonMappingException, IOException {
420         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations";
421         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceParseFail.json"), uri, HttpMethod.POST);
422
423         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());    
424     }
425     @Test
426     public void deletePortConfiguration() throws JsonParseException, JsonMappingException, IOException {
427         stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
428                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
429                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
430
431         headers.set("X-ECOMP-RequestID", "32807a28-1a14-4b88-b7b3-2950918aa76d");
432         //expected response
433         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
434         RequestReferences requestReferences = new RequestReferences();
435         requestReferences.setInstanceId("1882939");
436         expectedResponse.setRequestReferences(requestReferences);
437         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970";
438         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstance.json"), uri, HttpMethod.DELETE);
439
440         ObjectMapper mapper = new ObjectMapper();
441         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
442
443         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
444         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
445         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));         
446     }
447     @Test
448     public void enablePort() throws JsonParseException, JsonMappingException, IOException {
449         stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
450                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
451                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
452         //expected response
453         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
454         RequestReferences requestReferences = new RequestReferences();
455         requestReferences.setInstanceId("1882939");
456         expectedResponse.setRequestReferences(requestReferences);
457         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/enablePort";
458         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceEnablePort.json"), uri, HttpMethod.POST);
459
460         ObjectMapper mapper = new ObjectMapper();
461         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
462
463         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
464         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
465         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
466     }
467     @Test
468     public void disablePort() throws JsonParseException, JsonMappingException, IOException {
469         stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
470                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
471                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
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/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/disablePort";
478         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDisablePort.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 activatePort() throws JsonParseException, JsonMappingException, IOException {
489         stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
490                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
491                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
492         //expected response
493         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
494         RequestReferences requestReferences = new RequestReferences();
495         requestReferences.setInstanceId("1882939");
496         expectedResponse.setRequestReferences(requestReferences);
497         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/activate";
498         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceActivatePort.json"), uri, HttpMethod.POST);
499
500         ObjectMapper mapper = new ObjectMapper();
501         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
502
503         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
504         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
505         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
506     }
507     @Test
508     public void deactivatePort() throws JsonParseException, JsonMappingException, IOException {
509         stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
510                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
511                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
512         //expected response
513         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
514         RequestReferences requestReferences = new RequestReferences();
515         requestReferences.setInstanceId("1882939");
516         expectedResponse.setRequestReferences(requestReferences);
517         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/deactivate";
518         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDeactivatePort.json"), uri, HttpMethod.POST);
519
520         ObjectMapper mapper = new ObjectMapper();
521         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
522
523         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
524         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
525         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
526     }
527     @Test
528     public void addRelationships() throws JsonParseException, JsonMappingException, IOException {
529         stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
530                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
531                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
532
533         //expected response
534         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
535         RequestReferences requestReferences = new RequestReferences();
536         requestReferences.setInstanceId("1882939");
537         expectedResponse.setRequestReferences(requestReferences);
538         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/addRelationships";
539         ResponseEntity<String> response = sendRequest(inputStream("/AddRelationships.json"), uri, HttpMethod.POST);
540
541         ObjectMapper mapper = new ObjectMapper();
542         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
543
544         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
545         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
546         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
547     }
548     @Test
549     public void removeRelationships() throws JsonParseException, JsonMappingException, IOException {
550         stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator"))
551                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
552                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
553
554         //expected response
555         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
556         RequestReferences requestReferences = new RequestReferences();
557         requestReferences.setInstanceId("1882939");
558         expectedResponse.setRequestReferences(requestReferences);
559         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/removeRelationships";
560         ResponseEntity<String> response = sendRequest(inputStream("/RemoveRelationships.json"), uri, HttpMethod.POST);
561
562         ObjectMapper mapper = new ObjectMapper();
563         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
564
565         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
566         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
567         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
568     }
569     @Test
570     public void createVnfInstanceNoALaCarte() throws JsonParseException, JsonMappingException, IOException {
571         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
572                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
573                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
574
575         //expected response
576         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
577         RequestReferences requestReferences = new RequestReferences();
578         requestReferences.setInstanceId("1882939");
579         expectedResponse.setRequestReferences(requestReferences);
580         uri = servInstanceuri + "v7" + "/serviceInstances/49585b36-2b5a-443a-8b10-c75d34bb5e46/vnfs";
581         ResponseEntity<String> response = sendRequest(inputStream("/VnfCreateDefault.json"), uri, HttpMethod.POST);
582
583         ObjectMapper mapper = new ObjectMapper();
584         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
585
586         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
587         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
588         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
589     }
590     @Test
591     public void createVnfInstance() throws JsonParseException, JsonMappingException, IOException {
592         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
593                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
594                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
595
596         String requestId = "b7a6b76f-2ee2-416c-971b-548472a8c5c3";
597         headers.set(MsoLogger.ONAP_REQUEST_ID, requestId);
598         //expected response
599         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
600         RequestReferences requestReferences = new RequestReferences();
601         requestReferences.setInstanceId("1882939");
602         expectedResponse.setRequestReferences(requestReferences);
603         uri = servInstanceuri + "v7" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs";
604         ResponseEntity<String> response = sendRequest(inputStream("/VnfWithServiceRelatedInstance.json"), uri, HttpMethod.POST);
605
606         ObjectMapper mapper = new ObjectMapper();
607         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
608
609         InfraActiveRequests record = iar.findOneByRequestId(requestId);
610         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
611         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
612         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
613         assertTrue(response.getBody().contains("1882939"));
614         assertEquals(record.getVnfType(), "vSAMP12/test");
615     }
616     @Test
617     public void createVnfWithServiceRelatedInstanceFail() throws JsonParseException, JsonMappingException, IOException {
618         uri = servInstanceUriPrev7 + "v6" + "/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs";
619         ResponseEntity<String> response = sendRequest(inputStream("/VnfWithServiceRelatedInstanceFail.json"), uri, HttpMethod.POST);
620
621         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
622     }
623     @Test
624     public void createVnfInstanceInvalidVnfResource() throws JsonParseException, JsonMappingException, IOException {            
625         uri = servInstanceuri + "v7" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs";
626         ResponseEntity<String> response = sendRequest(inputStream("/NoVnfResource.json"), uri, HttpMethod.POST);
627
628         ObjectMapper mapper = new ObjectMapper();
629         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
630         mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
631
632         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
633         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
634         assertTrue(realResponse.getServiceException().getText().equals("No valid vnfResource is specified"));
635     }
636     @Test
637     public void replaceVnfInstance() throws JsonParseException, JsonMappingException, IOException {
638         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
639                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
640                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
641
642         //expected response
643         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
644         RequestReferences requestReferences = new RequestReferences();
645         requestReferences.setInstanceId("1882939");
646         expectedResponse.setRequestReferences(requestReferences);
647         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
648         ResponseEntity<String> response = sendRequest(inputStream("/ReplaceVnf.json"), uri, HttpMethod.POST);
649
650         ObjectMapper mapper = new ObjectMapper();
651         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
652
653         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
654         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
655         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
656     }
657     @Test
658     public void replaceVnfRecreateInstance() throws JsonParseException, JsonMappingException, IOException {
659         stubFor(post(urlPathEqualTo("/mso/async/services/RecreateInfraVce"))
660                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
661                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
662
663         //expected response
664         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
665         RequestReferences requestReferences = new RequestReferences();
666         requestReferences.setInstanceId("1882939");
667         expectedResponse.setRequestReferences(requestReferences);
668         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
669         ResponseEntity<String> response = sendRequest(inputStream("/ReplaceVnfRecreate.json"), uri, HttpMethod.POST);
670         logger.debug(response.getBody());
671         ObjectMapper mapper = new ObjectMapper();
672         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
673
674         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
675         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
676         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
677     }
678     @Test
679     public void updateVnfInstance() throws JsonParseException, JsonMappingException, IOException {      
680         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
681                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
682                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
683
684         //expected response
685         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
686         RequestReferences requestReferences = new RequestReferences();
687         requestReferences.setInstanceId("1882939");
688         expectedResponse.setRequestReferences(requestReferences);
689         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
690         ResponseEntity<String> response = sendRequest(inputStream("/UpdateVnf.json"), uri, HttpMethod.PUT);
691
692         ObjectMapper mapper = new ObjectMapper();
693         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
694
695         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
696         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
697         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
698     }
699     @Test
700     public void applyUpdatedConfig() throws JsonParseException, JsonMappingException, IOException {                     
701         stubFor(post(urlPathEqualTo("/mso/async/services/VnfConfigUpdate"))
702                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
703                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
704
705         String requestId = "b7a6b76f-2ee2-416c-971b-548472a8c5c5";
706         headers.set(MsoLogger.ONAP_REQUEST_ID, requestId);
707         //expected response
708         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
709         RequestReferences requestReferences = new RequestReferences();
710         requestReferences.setInstanceId("1882939");
711         expectedResponse.setRequestReferences(requestReferences);
712         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/applyUpdatedConfig";
713         ResponseEntity<String> response = sendRequest(inputStream("/ApplyUpdatedConfig.json"), uri, HttpMethod.POST);
714
715         ObjectMapper mapper = new ObjectMapper();
716         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
717
718         InfraActiveRequests record = iar.findOneByRequestId(requestId);
719         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
720         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
721         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
722         assertNull(record.getVnfType());
723     }
724     @Test
725     public void deleteVnfInstanceV5() throws JsonParseException, JsonMappingException, IOException {
726         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
727                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
728                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
729
730         //expected response
731         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
732         RequestReferences requestReferences = new RequestReferences();
733         requestReferences.setInstanceId("1882939");
734         expectedResponse.setRequestReferences(requestReferences);
735         uri = servInstanceuri + "v5" + "/serviceInstances/e446b97d-9c35-437a-95a2-6b4c542c4507/vnfs/49befbfe-fccb-421d-bb4c-0734a43f5ea0";
736         ResponseEntity<String> response = sendRequest(inputStream("/DeleteVnfV5.json"), uri, HttpMethod.DELETE);
737
738         ObjectMapper mapper = new ObjectMapper();
739         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
740
741         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
742         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
743         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
744     }
745     @Test
746     public void createVfModuleInstance() throws JsonParseException, JsonMappingException, IOException {
747         stubFor(post(urlPathEqualTo("/mso/async/services/CreateVfModuleInfra"))
748                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
749                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
750
751         //expected response
752         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
753         RequestReferences requestReferences = new RequestReferences();
754         requestReferences.setInstanceId("1882939");
755         expectedResponse.setRequestReferences(requestReferences);
756         uri = servInstanceuri + "v7" + "/serviceInstances/7a88cbeb-0ec8-4765-a271-4f9e90c3da7b/vnfs/cbba721b-4803-4df7-9347-307c9a955426/vfModules";
757         ResponseEntity<String> response = sendRequest(inputStream("/VfModuleWithRelatedInstances.json"), uri, HttpMethod.POST);
758
759         ObjectMapper mapper = new ObjectMapper();
760         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
761
762         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
763         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
764         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
765         assertTrue(response.getBody().contains("1882939"));
766     }
767     @Test
768     public void createVfModuleInstanceNoModelCustomization() throws JsonParseException, JsonMappingException, IOException {
769         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
770                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
771                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
772
773         //expected response
774         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
775         RequestReferences requestReferences = new RequestReferences();
776         requestReferences.setInstanceId("1882939");
777         expectedResponse.setRequestReferences(requestReferences);
778         uri = servInstanceuri + "v6" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules";
779         ResponseEntity<String> response = sendRequest(inputStream("/VfModuleNoModelCustomization.json"), uri, HttpMethod.POST);
780         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
781         ObjectMapper mapper = new ObjectMapper();
782         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
783         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
784     }
785     @Test
786     public void deleteVfModuleInstanceNoMatchingModelUUD() throws JsonParseException, JsonMappingException, IOException {
787         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
788                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
789                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
790
791         //expected response
792         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
793         RequestReferences requestReferences = new RequestReferences();
794         requestReferences.setInstanceId("1882939");
795         expectedResponse.setRequestReferences(requestReferences);
796         uri = servInstanceuri + "v6" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
797         ResponseEntity<String> response = sendRequest(inputStream("/VfModuleNoMatchingModelUUID.json"), uri, HttpMethod.DELETE);
798
799         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
800         ObjectMapper mapper = new ObjectMapper();
801         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
802         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
803     }
804     @Test
805     public void createVfModuleInstanceNoRecipe() throws JsonParseException, JsonMappingException, IOException {
806         uri = servInstanceuri + "v6" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules";
807         ResponseEntity<String> response = sendRequest(inputStream("/VfModuleInvalid.json"), uri, HttpMethod.POST);
808
809         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
810         ObjectMapper mapper = new ObjectMapper();
811         mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE,  true);
812         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
813         assertTrue(realResponse.getServiceException().getText().equals("No valid vfModuleCustomization is specified"));
814     }
815     @Test
816     public void replaceVfModuleInstance() throws JsonParseException, JsonMappingException, IOException {
817         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
818                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
819                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
820
821         //expected response
822         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
823         RequestReferences requestReferences = new RequestReferences();
824         requestReferences.setInstanceId("1882939");
825         expectedResponse.setRequestReferences(requestReferences);
826         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace";
827         ResponseEntity<String> response = sendRequest(inputStream("/ReplaceVfModule.json"), uri, HttpMethod.POST);
828
829         ObjectMapper mapper = new ObjectMapper();
830         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
831
832         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
833         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
834         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
835     }
836     @Test
837     public void updateVfModuleInstance() throws JsonParseException, JsonMappingException, IOException {
838         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
839                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
840                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
841
842         //expected response
843         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
844         RequestReferences requestReferences = new RequestReferences();
845         requestReferences.setInstanceId("1882939");
846         expectedResponse.setRequestReferences(requestReferences);
847         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
848         ResponseEntity<String> response = sendRequest(inputStream("/UpdateVfModule.json"), uri, HttpMethod.PUT);
849         logger.debug(response.getBody());
850
851         ObjectMapper mapper = new ObjectMapper();
852         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
853
854         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
855         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
856         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
857     }
858     @Test
859     public void createVfModuleNoModelType() throws JsonParseException, JsonMappingException, IOException{
860         headers.set(MsoLogger.ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
861         InfraActiveRequests expectedRecord = new InfraActiveRequests();
862         expectedRecord.setRequestStatus("FAILED");
863         expectedRecord.setAction("createInstance");
864         expectedRecord.setStatusMessage("Error parsing request: No valid modelType is specified");
865         expectedRecord.setProgress(new Long(100));
866         expectedRecord.setSource("VID");
867         expectedRecord.setRequestBody(inputStream("/VfModuleNoModelType.json"));
868         expectedRecord.setLastModifiedBy("APIH");
869         expectedRecord.setVfModuleName("testVfModule2");
870         expectedRecord.setVfModuleModelName("serviceModel");
871         expectedRecord.setRequestScope("vfModule");
872         expectedRecord.setRequestAction("createInstance");
873         expectedRecord.setRequestorId("zz9999");
874         expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
875         //VnfType is not sent in this request, should be blank in db
876         expectedRecord.setVnfType("");
877         uri = servInstanceuri + "v5/serviceInstances/32807a28-1a14-4b88-b7b3-2950918aa76d/vnfs/32807a28-1a14-4b88-b7b3-2950918aa76d/vfModules";
878
879         ResponseEntity<String> response = sendRequest(inputStream("/VfModuleNoModelType.json"), uri, HttpMethod.POST);
880         //ActualRecord
881         InfraActiveRequests requestRecord = iar.findOneByRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
882         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
883         assertEquals(sameBeanAs(expectedRecord).toString(), sameBeanAs(requestRecord).ignoring("startTime").ignoring("endTime").ignoring("modifyTime").toString());
884         assertNotNull(requestRecord.getStartTime());
885         assertNotNull(requestRecord.getEndTime());
886     }
887     @Test
888     public void inPlaceSoftwareUpdate() throws JsonParseException, JsonMappingException, IOException {                  
889         stubFor(post(urlPathEqualTo("/mso/async/services/VnfInPlaceUpdate"))
890                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
891                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
892
893         //expected response
894         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
895         RequestReferences requestReferences = new RequestReferences();
896         requestReferences.setInstanceId("1882939");
897         expectedResponse.setRequestReferences(requestReferences);
898         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/inPlaceSoftwareUpdate";
899         ResponseEntity<String> response = sendRequest(inputStream("/InPlaceSoftwareUpdate.json"), uri, HttpMethod.POST);
900
901         ObjectMapper mapper = new ObjectMapper();
902         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
903
904         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
905         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
906         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
907     }
908
909     @Test
910     public void inPlaceSoftwareUpdateDuplicate() throws JsonParseException, JsonMappingException, IOException {                 
911         stubFor(post(urlPathEqualTo("/mso/async/services/VnfInPlaceUpdate"))
912                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
913                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
914
915         InfraActiveRequests req = new InfraActiveRequests();
916         req.setRequestStatus("IN_PROGRESS");
917         req.setAction("inPlaceSoftwareUpdate");
918         req.setProgress(new Long(10));
919         req.setRequestBody(inputStream("/ServiceInstanceALaCarteTrueNoRecipe.json"));
920         req.setServiceInstanceId("f7ce78bb-423b-11e7-93f8-0050569a7908");
921         req.setVnfId("ff305d54-75b4-431b-adb2-eb6b9e5ff033");
922         req.setRequestScope("vnf");
923         req.setVnfName("duplicateCheck123");
924         req.setRequestAction("inPlaceSoftwareUpdate");
925         req.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
926         iar.save(req);
927
928         //expected response
929         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
930         RequestReferences requestReferences = new RequestReferences();
931         requestReferences.setInstanceId("1882939");
932         expectedResponse.setRequestReferences(requestReferences);
933         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7908/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff033/inPlaceSoftwareUpdate";
934         ResponseEntity<String> response = sendRequest(inputStream("/InPlaceSoftwareUpdate2.json"), uri, HttpMethod.POST);
935
936         ObjectMapper mapper = new ObjectMapper();
937         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
938
939         assertEquals(Response.Status.CONFLICT.getStatusCode(), response.getStatusCode().value());
940
941         InfraActiveRequests newRecord = iar.findOneByRequestBody(inputStream("/InPlaceSoftwareUpdate2.json"));
942
943         assertNotNull(newRecord.getServiceInstanceId());
944         assertNotNull(newRecord.getVnfId());
945
946     }
947
948     @Test
949     public void deleteVfModuleInstance() throws JsonParseException, JsonMappingException, IOException {
950         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
951                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
952                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
953
954         //expected response
955         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
956         RequestReferences requestReferences = new RequestReferences();
957         requestReferences.setInstanceId("1882939");
958         expectedResponse.setRequestReferences(requestReferences);
959         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
960         ResponseEntity<String> response = sendRequest(inputStream("/DeleteVfModule.json"), uri, HttpMethod.DELETE);
961
962         ObjectMapper mapper = new ObjectMapper();
963         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
964
965         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
966         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
967         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
968     }
969     @Test
970     public void deactivateAndCloudDeleteVfModuleInstance() throws JsonParseException, JsonMappingException, IOException {
971         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
972                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
973                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
974
975         //expected response
976         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
977         RequestReferences requestReferences = new RequestReferences();
978         requestReferences.setInstanceId("1882939");
979         expectedResponse.setRequestReferences(requestReferences);
980         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000/deactivateAndCloudDelete";
981         ResponseEntity<String> response = sendRequest(inputStream("/DeactivateAndCloudDeleteVfModule.json"), uri, HttpMethod.POST);
982
983         ObjectMapper mapper = new ObjectMapper();
984         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
985
986         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
987         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
988         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
989     }
990     @Test
991     public void createVolumeGroupInstance() throws JsonParseException, JsonMappingException, IOException {
992         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
993                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
994                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
995
996         //expected response
997         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
998         RequestReferences requestReferences = new RequestReferences();
999         requestReferences.setInstanceId("1882939");
1000         expectedResponse.setRequestReferences(requestReferences);
1001         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups";
1002         ResponseEntity<String> response = sendRequest(inputStream("/VolumeGroup.json"), uri, HttpMethod.POST);
1003
1004         ObjectMapper mapper = new ObjectMapper();
1005         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1006
1007         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1008         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1009         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1010         assertTrue(response.getBody().contains("1882939"));
1011     }
1012     @Test
1013     public void updateVolumeGroupInstance() throws JsonParseException, JsonMappingException, IOException {
1014         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1015                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1016                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1017
1018         //expected response
1019         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1020         RequestReferences requestReferences = new RequestReferences();
1021         requestReferences.setInstanceId("1882939");
1022         expectedResponse.setRequestReferences(requestReferences);
1023         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1024         ResponseEntity<String> response = sendRequest(inputStream("/UpdateVolumeGroup.json"), uri, HttpMethod.PUT);
1025
1026         ObjectMapper mapper = new ObjectMapper();
1027         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1028
1029         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1030         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1031         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1032     }
1033     @Test
1034     public void deleteVolumeGroupInstance() throws JsonParseException, JsonMappingException, IOException {
1035         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1036                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1037                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1038
1039         //expected response
1040         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1041         RequestReferences requestReferences = new RequestReferences();
1042         requestReferences.setInstanceId("1882939");
1043         expectedResponse.setRequestReferences(requestReferences);
1044         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups/ff305d54-75b4-431b-adb2-eb6b9e5ff000";
1045         ResponseEntity<String> response = sendRequest(inputStream("/DeleteVolumeGroup.json"), uri, HttpMethod.DELETE);
1046
1047         ObjectMapper mapper = new ObjectMapper();
1048         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1049
1050         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1051         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1052         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1053     }
1054     @Test
1055     public void createNetworkInstance() throws JsonParseException, JsonMappingException, IOException {
1056         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1057                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1058                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1059
1060         String requestId = "b7a6b76f-2ee2-416c-971b-548472a8c5c4";
1061         headers.set(MsoLogger.ONAP_REQUEST_ID, requestId);
1062         //expected response
1063         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1064         RequestReferences requestReferences = new RequestReferences();
1065         requestReferences.setInstanceId("1882939");
1066         expectedResponse.setRequestReferences(requestReferences);
1067         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1068         ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreate.json"), uri, HttpMethod.POST);
1069
1070         ObjectMapper mapper = new ObjectMapper();
1071         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1072
1073         InfraActiveRequests record = iar.findOneByRequestId(requestId);
1074         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1075         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1076         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1077         assertEquals(record.getNetworkType(), "TestNetworkType");
1078     }
1079     @Test
1080     public void updateNetworkInstance() throws JsonParseException, JsonMappingException, IOException {
1081         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1082                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1083                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1084
1085         //expected response
1086         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1087         RequestReferences requestReferences = new RequestReferences();
1088         requestReferences.setInstanceId("1882939");
1089         expectedResponse.setRequestReferences(requestReferences);
1090         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1091         ResponseEntity<String> response = sendRequest(inputStream("/UpdateNetwork.json"), uri, HttpMethod.PUT);
1092
1093         ObjectMapper mapper = new ObjectMapper();
1094         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1095
1096         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1097         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1098         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1099         assertTrue(response.getBody().contains("1882939"));
1100     }
1101     @Test
1102     public void deleteNetworkInstance() throws JsonParseException, JsonMappingException, IOException {
1103         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1104                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1105                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1106
1107         //expected response
1108         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1109         RequestReferences requestReferences = new RequestReferences();
1110         requestReferences.setInstanceId("1882939");
1111         expectedResponse.setRequestReferences(requestReferences);
1112         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1113         ResponseEntity<String> response = sendRequest(inputStream("/NetworkInstance.json"), uri, HttpMethod.DELETE);
1114
1115         ObjectMapper mapper = new ObjectMapper();
1116         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1117
1118         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1119         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1120         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1121     }
1122     @Test
1123     public void deleteNetworkInstanceNoReqParams() throws JsonParseException, JsonMappingException, IOException {
1124         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1125                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1126                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1127
1128         //expected response
1129         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1130         RequestReferences requestReferences = new RequestReferences();
1131         requestReferences.setInstanceId("1882939");
1132         expectedResponse.setRequestReferences(requestReferences);
1133         uri = servInstanceuri + "v6" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1134         ResponseEntity<String> response = sendRequest(inputStream("/NetworkInstanceNoReqParams.json"), uri, HttpMethod.DELETE);
1135
1136         ObjectMapper mapper = new ObjectMapper();
1137         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1138
1139         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1140         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1141         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1142     }
1143     @Test
1144     public void convertJsonToServiceInstanceRequestFail() throws JsonParseException, JsonMappingException, IOException {
1145         headers.set(MsoLogger.ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
1146         //ExpectedRecord
1147         InfraActiveRequests expectedRecord = new InfraActiveRequests();
1148         expectedRecord.setRequestStatus("FAILED");
1149         expectedRecord.setStatusMessage("Error mapping request: ");
1150         expectedRecord.setProgress(new Long(100));
1151         expectedRecord.setRequestBody(inputStream("/ConvertRequestFail.json"));
1152         expectedRecord.setLastModifiedBy("APIH");
1153         expectedRecord.setRequestScope("network");
1154         expectedRecord.setRequestAction("deleteInstance");
1155         expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
1156
1157         uri = servInstanceuri + "v6" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb";
1158         ResponseEntity<String> response = sendRequest(inputStream("/ConvertRequestFail.json"), uri, HttpMethod.DELETE);
1159
1160         //ActualRecord
1161         InfraActiveRequests requestRecord = iar.findOneByRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
1162
1163         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
1164         assertThat(expectedRecord, sameBeanAs(requestRecord).ignoring("startTime").ignoring("endTime").ignoring("modifyTime").ignoring("statusMessage"));
1165         assertThat(requestRecord.getStatusMessage(), containsString("Error mapping request: "));
1166         assertNotNull(requestRecord.getStartTime());
1167         assertNotNull(requestRecord.getEndTime());
1168     }
1169     @Test
1170     public void convertJsonToServiceInstanceRequestConfigurationFail() throws JsonParseException, JsonMappingException, IOException {
1171         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/configurations/test/enablePort";
1172         ResponseEntity<String> response = sendRequest(inputStream("/ConvertRequestFail.json"), uri, HttpMethod.POST);
1173
1174         assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
1175     }
1176
1177     @Test
1178     public void creatServiceInstanceGRTestApiNoCustomRecipeFound() throws IOException {
1179         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1180                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1181                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1182
1183         uri = servInstanceuri + "v7" + "/serviceInstances";
1184         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceMacro.json"), uri, HttpMethod.POST);
1185
1186         //expected response
1187         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1188         RequestReferences requestReferences = new RequestReferences();
1189         requestReferences.setInstanceId("1882939");
1190         expectedResponse.setRequestReferences(requestReferences);
1191
1192         ObjectMapper mapper = new ObjectMapper();
1193         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1194
1195         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1196         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1197         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1198     }
1199
1200     @Test
1201     public void createNetworkInstanceTestApiUndefinedUsePropertiesDefault() throws IOException {
1202         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1203                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1204                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1205
1206         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1207         ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateAlternateInstanceName.json"), uri, HttpMethod.POST);
1208
1209         //expected response
1210         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1211         RequestReferences requestReferences = new RequestReferences();
1212         requestReferences.setInstanceId("1882939");
1213         expectedResponse.setRequestReferences(requestReferences);
1214
1215         ObjectMapper mapper = new ObjectMapper();
1216         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1217
1218         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1219         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1220         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1221     }
1222
1223     @Test
1224     public void createNetworkInstanceTestApiIncorrectUsePropertiesDefault() throws IOException {
1225         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1226                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1227                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1228
1229         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1230         ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateTestApiIncorrect.json"), uri, HttpMethod.POST);
1231
1232         //expected response
1233         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1234         RequestReferences requestReferences = new RequestReferences();
1235         requestReferences.setInstanceId("1882939");
1236         expectedResponse.setRequestReferences(requestReferences);
1237
1238         ObjectMapper mapper = new ObjectMapper();
1239         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1240
1241         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
1242     }
1243
1244     @Test
1245     public void createNetworkInstanceTestApiGrApi() throws IOException {
1246         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1247                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1248                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1249
1250         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1251         ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateTestApiGrApi.json"), uri, HttpMethod.POST);
1252
1253         //expected response
1254         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1255         RequestReferences requestReferences = new RequestReferences();
1256         requestReferences.setInstanceId("1882939");
1257         expectedResponse.setRequestReferences(requestReferences);
1258
1259         ObjectMapper mapper = new ObjectMapper();
1260         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1261
1262         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1263         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1264         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1265     }
1266
1267     @Test
1268     public void createNetworkInstanceTestApiVnfApi() throws IOException {
1269         stubFor(post(urlPathEqualTo("/mso/async/services/CreateNetworkInstance"))
1270                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1271                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1272
1273         uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
1274         ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateTestApiVnfApi.json"), uri, HttpMethod.POST);
1275
1276         //expected response
1277         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1278         RequestReferences requestReferences = new RequestReferences();
1279         requestReferences.setInstanceId("1882939");
1280         expectedResponse.setRequestReferences(requestReferences);
1281
1282         ObjectMapper mapper = new ObjectMapper();
1283         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1284
1285         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1286         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1287         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1288     }
1289
1290     @Test
1291     public void activateServiceInstanceRequestStatus() throws JsonParseException, JsonMappingException, IOException{
1292         stubFor(post(urlPathEqualTo("/mso/async/services/ActivateInstance"))
1293                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1294                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1295         headers.set("X-ECOMP-RequestID", "32807a28-1a14-4b88-b7b3-2950918aa76d");
1296
1297         InfraActiveRequests expectedRecord = new InfraActiveRequests();
1298         expectedRecord.setRequestStatus("FAILED");
1299         expectedRecord.setAction("activateInstance");
1300         expectedRecord.setStatusMessage("Recipe could not be retrieved from catalog DB.");
1301         expectedRecord.setProgress(new Long(100));
1302         expectedRecord.setSource("VID");
1303         expectedRecord.setRequestBody(inputStream("/ServiceInstanceALaCarteTrueNoRecipe.json"));
1304         expectedRecord.setLastModifiedBy("APIH");
1305         expectedRecord.setServiceInstanceId("f7ce78bb-423b-11e7-93f8-0050569a7999");
1306         expectedRecord.setServiceInstanceName("testService1234");
1307         expectedRecord.setRequestScope("service");
1308         expectedRecord.setRequestAction("activateInstance");
1309         expectedRecord.setRequestorId("xxxxxx");
1310         expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
1311
1312         //expect
1313         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1314         RequestReferences requestReferences = new RequestReferences();
1315         requestReferences.setInstanceId("1882939");
1316         expectedResponse.setRequestReferences(requestReferences);
1317         uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7999/activate";
1318         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstancePrev8.json"), uri, HttpMethod.POST);
1319
1320         ObjectMapper mapper = new ObjectMapper();
1321         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1322
1323         InfraActiveRequests requestRecord = iar.findOneByRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d");
1324
1325         //then          
1326         assertEquals(Status.IN_PROGRESS.name(), requestRecord.getRequestStatus());
1327         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1328         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1329         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1330     }
1331
1332     @Test
1333     public void invalidRequestId() throws IOException {
1334         String illegalRequestId = "1234";
1335         headers.set("X-ECOMP-RequestID", illegalRequestId);
1336
1337         uri = servInstanceuri + "v5/serviceInstances";
1338         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST);
1339
1340         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
1341         assertTrue(response.getBody().contains("Request Id " + illegalRequestId + " is not a valid UUID"));
1342     }
1343     @Test
1344     public void invalidBPELResponse() throws IOException{
1345         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1346                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1347                         .withBodyFile("Camunda/TestResponseInvalid2.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1348
1349         uri = servInstanceuri + "v5/serviceInstances";
1350         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST);
1351
1352         ObjectMapper mapper = new ObjectMapper();
1353         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1354         mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
1355
1356         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1357         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
1358         assertEquals("Request Failed due to BPEL error with HTTP Status = 202{\"instanceId\": \"1882939\"}", realResponse.getServiceException().getText());
1359     }
1360
1361     @Test
1362     public void invalidBPELResponse2() throws IOException{
1363         stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
1364                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1365                         .withBodyFile("Camunda/TestResponseInvalid.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1366
1367         uri = servInstanceuri + "v5/serviceInstances";
1368         ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST);
1369
1370         ObjectMapper mapper = new ObjectMapper();
1371         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1372         mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
1373
1374         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1375         RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
1376         assertTrue(realResponse.getServiceException().getText().contains("<aetgt:ErrorMessage>Exception in create execution list 500"));
1377     }
1378
1379     @Test
1380     public void createMacroServiceInstance() throws JsonParseException, JsonMappingException, IOException{
1381         stubFor(post(urlPathEqualTo("/mso/async/services/CreateMacroServiceNetworkVnf"))
1382                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
1383                         .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
1384
1385         //expect
1386         ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
1387         RequestReferences requestReferences = new RequestReferences();
1388         requestReferences.setInstanceId("1882939");
1389         expectedResponse.setRequestReferences(requestReferences);
1390         uri = servInstanceUriPrev7 + "v5";
1391         ResponseEntity<String> response = sendRequest(inputStream("/MacroServiceInstance.json"), uri, HttpMethod.POST);
1392
1393         ObjectMapper mapper = new ObjectMapper();
1394         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1395
1396         //then          
1397         assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
1398         ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
1399         assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); 
1400     }
1401
1402     @Test
1403     public void testUserParams() throws JsonParseException, JsonMappingException, IOException {
1404         ObjectMapper mapper = new ObjectMapper();
1405         ServiceInstancesRequest request = mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class);
1406         RequestParameters requestParameters = request.getRequestDetails().getRequestParameters();
1407         String userParamsTxt = inputStream("/userParams.txt");
1408
1409         List<Map<String, Object>> userParams = servInstances.configureUserParams(requestParameters);
1410         System.out.println(userParams);
1411         assertTrue(userParams.size() > 0);
1412         assertTrue(userParams.get(0).containsKey("name"));
1413         assertTrue(userParams.get(0).containsKey("value"));
1414         assertTrue(userParamsTxt.replaceAll("\\s+","").equals(userParams.toString().replaceAll("\\s+","")));
1415     }
1416
1417     @Test
1418     public void testConfigureCloudConfig() throws IOException {
1419         ObjectMapper mapper = new ObjectMapper();
1420         ServiceInstancesRequest request = mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class);
1421         CloudConfiguration cloudConfig = servInstances.configureCloudConfig(request.getRequestDetails().getRequestParameters());
1422
1423         assertEquals("mdt25b", cloudConfig.getLcpCloudRegionId());
1424         assertEquals("aefb697db6524ddebfe4915591b0a347", cloudConfig.getTenantId());
1425     }
1426
1427     @Test
1428     public void testMapToLegacyRequest() throws IOException {
1429         ObjectMapper mapper = new ObjectMapper();
1430         ServiceInstancesRequest request = mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class);
1431         ServiceInstancesRequest expected = mapper.readValue(inputStream("/LegacyMacroServiceInstance.json"), ServiceInstancesRequest.class);
1432         servInstances.mapToLegacyRequest(request.getRequestDetails());
1433         System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(request));
1434         assertThat(request, sameBeanAs(expected));
1435     }
1436 }