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