diff options
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/test/java')
29 files changed, 1280 insertions, 1389 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ApiExceptionTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ApiExceptionTest.java index 4e3a930955..7bb1bdf71a 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ApiExceptionTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ApiExceptionTest.java @@ -26,10 +26,10 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.onap.so.apihandler.common.ErrorNumbers; import org.onap.so.apihandlerinfra.exceptions.*; -import org.onap.so.apihandlerinfra.logging.AlarmLoggerInfo; + import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo; import org.onap.so.logger.MessageEnum; -import org.onap.so.logger.MsoAlarmLogger; + import org.onap.so.logger.MsoLogger; import java.io.IOException; @@ -102,14 +102,13 @@ public class ApiExceptionTest extends BaseTest { @Test public void testValidateException() throws ApiException { - AlarmLoggerInfo testLog = new AlarmLoggerInfo.Builder("MsoConfigurationError", MsoAlarmLogger.CRITICAL, - Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_SDNC_ADAPTER)).build(); + thrown.expect(ValidateException.class); thrown.expectMessage("Test Message"); thrown.expect(hasProperty("httpResponseCode", is(HttpStatus.SC_NOT_FOUND))); thrown.expect(hasProperty("messageID", is(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR))); - thrown.expect(hasProperty("alarmLoggerInfo", sameBeanAs(testLog))); - ValidateException testException = new ValidateException.Builder("Test Message", HttpStatus.SC_NOT_FOUND,ErrorNumbers.SVC_BAD_PARAMETER).messageID(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).alarmInfo(testLog).build(); + + ValidateException testException = new ValidateException.Builder("Test Message", HttpStatus.SC_NOT_FOUND,ErrorNumbers.SVC_BAD_PARAMETER).messageID(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).build(); throw testException; } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/BaseTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/BaseTest.java index 4072613d09..4d4f23c083 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/BaseTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/BaseTest.java @@ -31,7 +31,7 @@ import org.junit.runner.RunWith; import org.onap.so.logger.MsoLogger; import org.onap.so.logger.MsoLogger.Catalog; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; @@ -53,7 +53,6 @@ import java.nio.file.Paths; @ActiveProfiles("test") @ContextConfiguration @Transactional -//@Sql(executionPhase=ExecutionPhase.AFTER_TEST_METHOD,scripts="classpath:InfraActiveRequestsReset.sql") @AutoConfigureWireMock(port = 0) public abstract class BaseTest { protected MsoLogger logger = MsoLogger.getMsoLogger(Catalog.GENERAL, BaseTest.class); @@ -69,6 +68,10 @@ public abstract class BaseTest { return "http://localhost:" + port + uri; } + protected String createURLWithPort(String uri, int iPort) { + return "http://localhost:" + iPort + uri; + } + @After public void tearDown(){ WireMock.reset(); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java index a3d388a5c6..8d5539cf8a 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java @@ -271,4 +271,4 @@ private final ObjectMapper mapper = new ObjectMapper(); RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); assertTrue(realResponse.getServiceException().getText().contains("Request Failed due to BPEL error with HTTP Status")); } -} +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/EmbeddedCatalogDbConfig.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/EmbeddedCatalogDbConfig.java index f504d88008..1e4b99d4ff 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/EmbeddedCatalogDbConfig.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/EmbeddedCatalogDbConfig.java @@ -25,7 +25,7 @@ import ch.vorburger.mariadb4j.springframework.MariaDB4jSpringService; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; +import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/EmbeddedRequestDbConfig.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/EmbeddedRequestDbConfig.java index d150fd773a..00efb6b410 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/EmbeddedRequestDbConfig.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/EmbeddedRequestDbConfig.java @@ -25,7 +25,7 @@ import ch.vorburger.mariadb4j.springframework.MariaDB4jSpringService; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; +import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; import org.springframework.context.annotation.Bean; diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandlerTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandlerTest.java new file mode 100644 index 0000000000..45fadb540a --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandlerTest.java @@ -0,0 +1,236 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.apihandlerinfra; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; + +import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.ArgumentMatchers.anyString; +import java.net.URI; +import java.util.Collections; +import java.util.List; + +import org.springframework.test.util.ReflectionTestUtils; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; + +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.json.JSONException; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.ArgumentMatchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + + +public class GlobalHealthcheckHandlerTest { + @Mock + RestTemplate restTemplate; + + @Mock + ContainerRequestContext requestContext; + + @InjectMocks + @Spy + GlobalHealthcheckHandler globalhealth; + + @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Test + public void testQuerySubsystemHealthNullResult(){ + ReflectionTestUtils.setField(globalhealth, "actuatorContextPath", "/manage"); + ReflectionTestUtils.setField(globalhealth, "endpointBpmn", "http://localhost:8080"); + + Mockito.when(restTemplate.exchange(ArgumentMatchers.any(URI.class), + ArgumentMatchers.any(HttpMethod.class), + ArgumentMatchers.<HttpEntity<?>> any(), + ArgumentMatchers.<Class<Object>> any())).thenReturn(null); + + String result = globalhealth.querySubsystemHealth(MsoSubsystems.BPMN); + System.out.println(result); + assertEquals(HealthcheckStatus.DOWN.toString(),result); + } + + @Test + public void testQuerySubsystemHealthNotNullResult(){ + ReflectionTestUtils.setField(globalhealth, "actuatorContextPath", "/manage"); + ReflectionTestUtils.setField(globalhealth, "endpointAsdc", "http://localhost:8080"); + + SubsystemHealthcheckResponse subSystemResponse = new SubsystemHealthcheckResponse(); + subSystemResponse.setStatus("UP"); + ResponseEntity<Object> r = new ResponseEntity<>(subSystemResponse,HttpStatus.OK); + + Mockito.when(restTemplate.exchange(ArgumentMatchers.any(URI.class), + ArgumentMatchers.any(HttpMethod.class), + ArgumentMatchers.<HttpEntity<?>> any(), + ArgumentMatchers.<Class<Object>> any())).thenReturn(r); + + String result = globalhealth.querySubsystemHealth(MsoSubsystems.ASDC); + System.out.println(result); + assertEquals(HealthcheckStatus.UP.toString(),result); + } + + private Response globalHealthcheck (String status){ + ReflectionTestUtils.setField(globalhealth, "actuatorContextPath", "/manage"); + ReflectionTestUtils.setField(globalhealth, "endpointAsdc", "http://localhost:8080"); + ReflectionTestUtils.setField(globalhealth, "endpointSdnc", "http://localhost:8081"); + ReflectionTestUtils.setField(globalhealth, "endpointBpmn", "http://localhost:8082"); + ReflectionTestUtils.setField(globalhealth, "endpointCatalogdb", "http://localhost:8083"); + ReflectionTestUtils.setField(globalhealth, "endpointOpenstack", "http://localhost:8084"); + ReflectionTestUtils.setField(globalhealth, "endpointRequestdb", "http://localhost:8085"); + ReflectionTestUtils.setField(globalhealth, "endpointRequestdbAttsvc", "http://localhost:8086"); + + SubsystemHealthcheckResponse subSystemResponse = new SubsystemHealthcheckResponse(); + + subSystemResponse.setStatus(status); + ResponseEntity<Object> r = new ResponseEntity<>(subSystemResponse,HttpStatus.OK); + Mockito.when(restTemplate.exchange(ArgumentMatchers.any(URI.class), + ArgumentMatchers.any(HttpMethod.class), + ArgumentMatchers.<HttpEntity<?>> any(), + ArgumentMatchers.<Class<Object>> any())).thenReturn(r); + + Mockito.when(requestContext.getProperty(anyString())).thenReturn("1234567890"); + Response response = globalhealth.globalHealthcheck(true, requestContext); + + return response; + } + + @Test + public void globalHealthcheckAllUPTest() throws JSONException { + Response response = globalHealthcheck("UP"); + assertEquals(Response.Status.OK.getStatusCode(),response.getStatus()); + HealthcheckResponse root; + root = (HealthcheckResponse) response.getEntity(); + String apistatus = root.getApih(); + assertTrue(apistatus.equalsIgnoreCase(HealthcheckStatus.UP.toString())); + + String bpmnstatus = root.getBpmn(); + assertTrue(bpmnstatus.equalsIgnoreCase(HealthcheckStatus.UP.toString())); + + String sdncstatus = root.getSdncAdapter(); + assertTrue(sdncstatus.equalsIgnoreCase(HealthcheckStatus.UP.toString())); + + String asdcstatus = root.getAsdcController(); + assertTrue(asdcstatus.equalsIgnoreCase(HealthcheckStatus.UP.toString())); + + String catastatus = root.getCatalogdbAdapter(); + assertTrue(catastatus.equalsIgnoreCase(HealthcheckStatus.UP.toString())); + + String reqdbstatus = root.getRequestdbAdapter(); + assertTrue(reqdbstatus.equalsIgnoreCase(HealthcheckStatus.UP.toString())); + + String openstatus = root.getOpenstackAdapter(); + assertTrue(openstatus.equalsIgnoreCase(HealthcheckStatus.UP.toString())); + + String reqdbattstatus = root.getRequestdbAdapterAttsvc(); + assertTrue(reqdbattstatus.equalsIgnoreCase(HealthcheckStatus.UP.toString())); + } + + @Test + public void globalHealthcheckAllDOWNTest() throws JSONException { + Response response = globalHealthcheck("DOWN"); + assertEquals(Response.Status.OK.getStatusCode(),response.getStatus()); + HealthcheckResponse root; + root = (HealthcheckResponse) response.getEntity(); + String apistatus = root.getApih(); + assertTrue(apistatus.equalsIgnoreCase(HealthcheckStatus.UP.toString())); + + String bpmnstatus = root.getBpmn(); + assertTrue(bpmnstatus.equalsIgnoreCase(HealthcheckStatus.DOWN.toString())); + + String sdncstatus = root.getSdncAdapter(); + assertTrue(sdncstatus.equalsIgnoreCase(HealthcheckStatus.DOWN.toString())); + + String asdcstatus = root.getAsdcController(); + assertTrue(asdcstatus.equalsIgnoreCase(HealthcheckStatus.DOWN.toString())); + + String catastatus = root.getCatalogdbAdapter(); + assertTrue(catastatus.equalsIgnoreCase(HealthcheckStatus.DOWN.toString())); + + String reqdbstatus = root.getRequestdbAdapter(); + assertTrue(reqdbstatus.equalsIgnoreCase(HealthcheckStatus.DOWN.toString())); + + String openstatus = root.getOpenstackAdapter(); + assertTrue(openstatus.equalsIgnoreCase(HealthcheckStatus.DOWN.toString())); + + String reqdbattstatus = root.getRequestdbAdapterAttsvc(); + assertTrue(reqdbattstatus.equalsIgnoreCase(HealthcheckStatus.DOWN.toString())); + } + + @Test + public void buildHttpEntityForRequestTest(){ + HttpEntity<String> he = globalhealth.buildHttpEntityForRequest(); + assertEquals (MediaType.APPLICATION_JSON,he.getHeaders().getAccept().get(0)); + assertEquals (MediaType.APPLICATION_JSON,he.getHeaders().getContentType()); + } + + @Test + public void getEndpointUrlForSubsystemEnumTest(){ + ReflectionTestUtils.setField(globalhealth, "actuatorContextPath", "/manage"); + ReflectionTestUtils.setField(globalhealth, "endpointAsdc", "http://localhost:8080"); + ReflectionTestUtils.setField(globalhealth, "endpointSdnc", "http://localhost:8081"); + ReflectionTestUtils.setField(globalhealth, "endpointBpmn", "http://localhost:8082"); + ReflectionTestUtils.setField(globalhealth, "endpointCatalogdb", "http://localhost:8083"); + ReflectionTestUtils.setField(globalhealth, "endpointOpenstack", "http://localhost:8084"); + ReflectionTestUtils.setField(globalhealth, "endpointRequestdb", "http://localhost:8085"); + ReflectionTestUtils.setField(globalhealth, "endpointRequestdbAttsvc", "http://localhost:8086"); + + String result = globalhealth.getEndpointUrlForSubsystemEnum(MsoSubsystems.ASDC); + assertEquals("http://localhost:8080", result); + result = globalhealth.getEndpointUrlForSubsystemEnum(MsoSubsystems.SDNC); + assertEquals("http://localhost:8081", result); + result = globalhealth.getEndpointUrlForSubsystemEnum(MsoSubsystems.BPMN); + assertEquals("http://localhost:8082", result); + result = globalhealth.getEndpointUrlForSubsystemEnum(MsoSubsystems.CATALOGDB); + assertEquals("http://localhost:8083", result); + result = globalhealth.getEndpointUrlForSubsystemEnum(MsoSubsystems.OPENSTACK); + assertEquals("http://localhost:8084", result); + result = globalhealth.getEndpointUrlForSubsystemEnum(MsoSubsystems.REQUESTDB); + assertEquals("http://localhost:8085", result); + result = globalhealth.getEndpointUrlForSubsystemEnum(MsoSubsystems.REQUESTDBATT); + assertEquals("http://localhost:8086", result); + } + + @Test + public void processResponseFromSubsystemTest(){ + SubsystemHealthcheckResponse subSystemResponse = new SubsystemHealthcheckResponse(); + subSystemResponse.setStatus("UP"); + ResponseEntity<SubsystemHealthcheckResponse> r = new ResponseEntity<>(subSystemResponse,HttpStatus.OK); + String result = globalhealth.processResponseFromSubsystem(r,MsoSubsystems.BPMN); + assertEquals("UP",result); + } + +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/HealthCheckHandlerTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/HealthCheckHandlerTest.java deleted file mode 100644 index 8b4d353a56..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/HealthCheckHandlerTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.apihandlerinfra; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - -import javax.ws.rs.core.Response; - -import org.json.JSONException; -import org.junit.Test; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; - - -public class HealthCheckHandlerTest extends BaseTest{ - - @Test - public void testHealthcheckGet() throws JSONException { - HttpHeaders headers = new HttpHeaders(); - HttpEntity<String> entity = new HttpEntity<String>(null, headers); - - ResponseEntity<String> response = restTemplate.exchange( - createURLWithPort("/manage/health"), - HttpMethod.GET, entity, String.class); - - assertEquals(Response.Status.OK.getStatusCode(),response.getStatusCode().value()); - assertThat(response.getBody(), containsString("UP")); - - } - - -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ManualTasksTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ManualTasksTest.java index f4fede15e1..bb78c822f7 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ManualTasksTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ManualTasksTest.java @@ -27,7 +27,8 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; + +import static com.shazam.shazamcrest.MatcherAssert.assertThat; import java.io.IOException; import java.util.Map; @@ -44,6 +45,8 @@ import org.onap.so.apihandlerinfra.tasksbeans.TaskRequestReference; import org.onap.so.apihandlerinfra.tasksbeans.TasksRequest; import org.onap.so.apihandlerinfra.tasksbeans.ValidResponses; import org.onap.so.logger.MsoLogger; +import org.onap.so.serviceinstancebeans.RequestError; +import org.onap.so.serviceinstancebeans.ServiceException; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -52,6 +55,7 @@ import org.springframework.web.util.UriComponentsBuilder; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.tomakehurst.wiremock.http.Fault; import ch.qos.logback.classic.spi.ILoggingEvent; @@ -134,4 +138,111 @@ public class ManualTasksTest extends BaseTest{ assertEquals("1.0.0", response.getHeaders().get("X-LatestVersion").get(0)); } } + @Test + public void completeTaskMappingError() throws IOException { + String invalidRequest = "test"; + RequestError expectedResponse = new RequestError(); + ServiceException se = new ServiceException(); + se.setMessageId("SVC0002"); + se.setText("Mapping of request to JSON object failed: Unrecognized token \'test\': " + + "was expecting \'null\', \'true\', \'false\' or NaN\n at [Source: (String)\"test\"; line: 1, column: 9]"); + expectedResponse.setServiceException(se); + + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON); + headers.set("Content-Type", MediaType.APPLICATION_JSON); + headers.set(MsoLogger.ECOMP_REQUEST_ID, "987654321"); + headers.set(MsoLogger.CLIENT_ID, "VID"); + HttpEntity<String> entity = new HttpEntity<String>(invalidRequest, headers); + + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(basePath) + "55" + "/complete"); + ResponseEntity<String> response = restTemplate.exchange( + builder.toUriString(), + HttpMethod.POST, entity, String.class); + + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); + assertThat(realResponse, sameBeanAs(expectedResponse)); + } + @Test + public void completeTaskValidationError() throws IOException { + String taskId = "55"; + TasksRequest taskReq = new TasksRequest(); + RequestDetails reqDetail = new RequestDetails(); + RequestInfo reqInfo = new RequestInfo(); + reqInfo.setSource("testSource"); + reqInfo.setResponseValue(ValidResponses.skip); + reqDetail.setRequestInfo(reqInfo); + taskReq.setRequestDetails(reqDetail); + + RequestError expectedResponse = new RequestError(); + ServiceException se = new ServiceException(); + se.setMessageId("SVC0002"); + se.setText("Mapping of request to JSON Object failed. No valid requestorId is specified"); + expectedResponse.setServiceException(se); + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON); + headers.set("Content-Type", MediaType.APPLICATION_JSON); + headers.set(MsoLogger.ECOMP_REQUEST_ID, "987654321"); + headers.set(MsoLogger.CLIENT_ID, "VID"); + HttpEntity<TasksRequest> entity = new HttpEntity<TasksRequest>(taskReq, headers); + + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(basePath) + taskId + "/complete"); + ResponseEntity<String> response = restTemplate.exchange( + builder.toUriString(), + HttpMethod.POST, entity, String.class); + + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); + assertThat(realResponse, sameBeanAs(expectedResponse)); + } + @Test + public void completeTaskBpelResponseError() throws IOException { + stubFor(post(urlPathEqualTo("/sobpmnengine/task/55/complete")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withFault(Fault.EMPTY_RESPONSE))); + + String taskId = "55"; + TasksRequest taskReq = new TasksRequest(); + RequestDetails reqDetail = new RequestDetails(); + RequestInfo reqInfo = new RequestInfo(); + reqInfo.setRequestorId("testId"); + reqInfo.setSource("testSource"); + reqInfo.setResponseValue(ValidResponses.skip); + reqDetail.setRequestInfo(reqInfo); + taskReq.setRequestDetails(reqDetail); + + RequestError expectedResponse = new RequestError(); + ServiceException se = new ServiceException(); + se.setMessageId("SVC1000"); + se.setText("Request Failed due to BPEL error with HTTP Status = 502"); + expectedResponse.setServiceException(se); + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON); + headers.set("Content-Type", MediaType.APPLICATION_JSON); + headers.set(MsoLogger.ECOMP_REQUEST_ID, "987654321"); + headers.set(MsoLogger.CLIENT_ID, "VID"); + HttpEntity<TasksRequest> entity = new HttpEntity<TasksRequest>(taskReq, headers); + + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(basePath) + taskId + "/complete"); + ResponseEntity<String> response = restTemplate.exchange( + builder.toUriString(), + HttpMethod.POST, entity, String.class); + + + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); + assertEquals(Response.Status.BAD_GATEWAY.getStatusCode(), response.getStatusCode().value()); + assertThat(realResponse, sameBeanAs(expectedResponse)); + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/MsoRequestTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/MsoRequestTest.java index fa3ce07d70..145213fc6c 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/MsoRequestTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/MsoRequestTest.java @@ -25,11 +25,13 @@ import static org.junit.Assert.assertNotNull; import java.io.IOException; import java.io.StringReader; +import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; +import java.util.Optional; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.Response; @@ -177,6 +179,7 @@ public class MsoRequestTest extends BaseTest { this.version = "v" + reqVersion; this.instanceIdMapTest.put("serviceInstanceId", "ff305d54-75b4-431b-adb2-eb6b9e5ff000"); this.instanceIdMapTest.put("vnfInstanceId", "ff305d54-75b4-431b-adb2-eb6b9e5ff000"); + this.instanceIdMapTest.put("instanceGroupId", "ff305d54-75b4-431b-adb2-eb6b9e5ff000"); thrown.expect(ValidationException.class); thrown.expectMessage(expectedException); this.msoRequest = new MsoRequest(); @@ -241,6 +244,7 @@ public class MsoRequestTest extends BaseTest { {"No valid modelVersionId is specified", mapper.readValue(inputStream("/ModelInfo/v5ActivateModelVersionId.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.activateInstance, 5}, {"No valid modelVersionId is specified", mapper.readValue(inputStream("/ModelInfo/ScaleOutNoModelVersionId.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.scaleOut, 7}, {"No valid modelVersionId is specified", mapper.readValue(inputStream("/ModelInfo/VnfRecreateModelVersionId.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.recreateInstance, 7}, + {"No valid modelVersionId is specified", mapper.readValue(inputStream("/ModelInfo/CreateInstanceGroupNoModelVersionId.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.createInstance, 7}, //ValidationException for Platform and LineOfBusiness {"No valid lineOfBusinessName is specified", mapper.readValue(inputStream("/PlatformAndLineOfBusiness/EmptyLineOfBusiness.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.createInstance, 5}, {"No valid platform is specified", mapper.readValue(inputStream("/PlatformAndLineOfBusiness/Platform.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.createInstance, 6}, @@ -284,6 +288,9 @@ public class MsoRequestTest extends BaseTest { {"No valid source vnf relatedInstance for Port Configuration is specified", mapper.readValue(inputStream("/RelatedInstances/v5CreateNoSourceRelatedInstance.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.createInstance, 5}, {"No valid vnfInstanceId matching the vnfInstanceId in request URI is specified", mapper.readValue(inputStream("/RelatedInstances/RelatedInstancesVnfInstanceId.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.activateInstance, 5}, {"No valid instanceName format is specified", mapper.readValue(inputStream("/RelatedInstances/InvalidInstanceName.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.createInstance, 2}, + {"No valid relatedInstanceList is specified", mapper.readValue(inputStream("/RelatedInstances/CreateInstanceGroupNoRelatedInstances.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.createInstance, 7}, + {"No valid related service instance for instanceGroup request is specified", mapper.readValue(inputStream("/RelatedInstances/CreateInstanceGroupService.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.createInstance, 7}, + {"No valid modelVersionId in relatedInstance is specified", mapper.readValue(inputStream("/RelatedInstances/CreateInstanceGroupRelatedInstanceModelVersionId.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.createInstance, 7}, //ValidationException for RequestInfo {"No valid requestInfo is specified", mapper.readValue(inputStream("/RequestInfo/RequestInfoNull.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.createInstance, 5}, {"No valid requestInfo is specified", mapper.readValue(inputStream("/RequestInfo/RequestInfo.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.applyUpdatedConfig, 6}, @@ -310,9 +317,9 @@ public class MsoRequestTest extends BaseTest { //Validation for UserParams {"No valid cloudConfiguration in userParams vnf resources is specified", mapper.readValue(inputStream("/RequestParameters/AssignCloudConfigVnf.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, {"No valid cloudConfiguration in userParams network resources is specified", mapper.readValue(inputStream("/RequestParameters/NetworkCloudConfig.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, - {"No valid model-info in userParams is specified", mapper.readValue(inputStream("/RequestParameters/UserParamsModelInfo.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, - {"No valid model-info in userParams vnf resources is specified", mapper.readValue(inputStream("/RequestParameters/UserParamsVnfModelInfo.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, - {"No valid modelVersionId in userParams is specified", mapper.readValue(inputStream("/RequestParameters/UserParamsModelVersionId.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, + {"No valid modelInfo in userParams is specified", mapper.readValue(inputStream("/RequestParameters/UserParamsModelInfo.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, + {"No valid modelInfo in userParams vnf resources is specified", mapper.readValue(inputStream("/RequestParameters/UserParamsVnfModelInfo.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, + {"No valid modelVersionId in userParams service modelInfo is specified", mapper.readValue(inputStream("/RequestParameters/UserParamsModelVersionId.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, {"No valid modelVersionId in userParams vnf resources is specified", mapper.readValue(inputStream("/RequestParameters/VnfModelVersionId.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, {"No valid modelVersionId in userParams vfModule resources is specified", mapper.readValue(inputStream("/RequestParameters/VfModuleModelVersionId.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, {"No valid modelVersionId in userParams network resources is specified", mapper.readValue(inputStream("/RequestParameters/NetworkModelVersionId.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, @@ -320,13 +327,21 @@ public class MsoRequestTest extends BaseTest { {"No valid platformName in userParams vnf resources is specified", mapper.readValue(inputStream("/RequestParameters/UserParamsPlatformName.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, {"No valid productFamilyId in userParams vnf resources is specified", mapper.readValue(inputStream("/RequestParameters/ProductFamilyId.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, {"No valid vfModules in userParams vnf resources is specified", mapper.readValue(inputStream("/RequestParameters/VfModules.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, - {"No valid model-info in userParams vfModules resources is specified", mapper.readValue(inputStream("/RequestParameters/VfModulesModelInfo.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, - {"No valid model-info in userParams network resources is specified", mapper.readValue(inputStream("/RequestParameters/Network.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, + {"No valid modelInfo in userParams vfModules resources is specified", mapper.readValue(inputStream("/RequestParameters/VfModulesModelInfo.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, + {"No valid modelInfo in userParams network resources is specified", mapper.readValue(inputStream("/RequestParameters/Network.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, {"No valid modelCustomizationId in userParams vfModule resources is specified", mapper.readValue(inputStream("/RequestParameters/VfModuleModelCustomizationId.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, {"No valid modelCustomizationId in userParams vnf resources is specified", mapper.readValue(inputStream("/RequestParameters/VnfModelCustomizationId.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, {"No valid modelCustomizationId in userParams network resources is specified", mapper.readValue(inputStream("/RequestParameters/NetworkModelCustomizationId.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.assignInstance, 7}, //Validation for ConfigurationParameters - {"No valid configuration parameters is specified", mapper.readValue(inputStream("/ConfigurationParameters/NoConfigurationParameters.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.scaleOut, 7} + {"No valid configuration parameters is specified", mapper.readValue(inputStream("/ConfigurationParameters/NoConfigurationParameters.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.scaleOut, 7}, + //Validation for Add and Remove Members + {"No valid vnf relatedInstance is specified", mapper.readValue(inputStream("/MembersValidation/RelatedInstancesVnf.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.addMembers, 7}, + {"No valid related instances is specified", mapper.readValue(inputStream("/MembersValidation/RelatedInstances.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.addMembers, 7}, + {"No valid requestInfo is specified", mapper.readValue(inputStream("/MembersValidation/MembersRequestInfo.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.addMembers, 7}, + {"No valid requestorId is specified", mapper.readValue(inputStream("/MembersValidation/MembersRequestorId.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.addMembers, 7}, + {"No valid source is specified", mapper.readValue(inputStream("/MembersValidation/AddMembersSource.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.addMembers, 7}, + {"No valid instanceId in relatedInstances is specified", mapper.readValue(inputStream("/MembersValidation/AddMembersInstanceId.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.addMembers, 7}, + {"No valid modelType in relatedInstance is specified", mapper.readValue(inputStream("/MembersValidation/DeleteMembersModelType.json"), ServiceInstancesRequest.class), instanceIdMapTest, Action.removeMembers, 7} }); } @Test @@ -413,6 +428,18 @@ public class MsoRequestTest extends BaseTest { this.msoRequest.parse(sir, instanceIdMapTest, action, version, originalRequestJSON, reqVersion, false); } @Test + public void instanceGroupIdHashMapFailureTest() throws JsonParseException, JsonMappingException, IOException, ValidationException{ + this.sir = mapper.readValue(inputStream("/SuccessfulValidation/InstanceIdHashMap.json"), ServiceInstancesRequest.class); + this.instanceIdMapTest.put("instanceGroupId", "test"); + this.action = Action.createInstance; + thrown.expect(ValidationException.class); + this.reqVersion = 7; + this.version = "v" + reqVersion; + thrown.expectMessage("No valid instanceGroupId is specified"); + this.msoRequest = new MsoRequest(); + this.msoRequest.parse(sir, instanceIdMapTest, action, version, originalRequestJSON, reqVersion, false); + } + @Test public void testVfModuleV4UsePreLoad() throws JsonParseException, JsonMappingException, IOException, ValidationException { this.requestJSON = inputStream("/SuccessfulValidation/v4CreateVfModule.json"); this.instanceIdMapTest.put("serviceInstanceId", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc"); @@ -480,4 +507,20 @@ public class MsoRequestTest extends BaseTest { String result = MsoRequest.domToStr(document); assertNotNull(result); } + + @Test + public void buildSelfLinkUrlTest() throws Exception { + // v - version + String incomingUrl = "http://localhost:8080/onap/infra/so/serviceInstantiation/v7/serviceInstances"; + String expectedSelfLink = "http://localhost:8080/orchestrationRequests/v7/efce3167-5e45-4666-9d4d-22e23648e5d1"; + String requestId = "efce3167-5e45-4666-9d4d-22e23648e5d1"; + this.msoRequest = new MsoRequest(); + Optional<URL> actualSelfLinkUrl = msoRequest.buildSelfLinkUrl(incomingUrl, requestId); + assertEquals(expectedSelfLink, actualSelfLinkUrl.get().toString()); + // V - Version + String incomingUrlV = "http://localhost:8080/onap/infra/so/serviceInstantiation/V7/serviceInstances"; + String expectedSelfLinkV = "http://localhost:8080/orchestrationRequests/V7/efce3167-5e45-4666-9d4d-22e23648e5d1"; + Optional<URL> actualSelfLinkUrlV = msoRequest.buildSelfLinkUrl(incomingUrlV, requestId); + assertEquals(expectedSelfLinkV, actualSelfLinkUrlV.get().toString()); + } }
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java index ea2261a94a..28797d247b 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java @@ -31,6 +31,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import java.io.File; import java.io.IOException; @@ -118,12 +119,40 @@ public class OrchestrationRequestsTest extends BaseTest { assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); assertThat(response.getBody(), - sameBeanAs(testResponse).ignoring("request.startTime").ignoring("request.requestStatus.finishTime")); + sameBeanAs(testResponse).ignoring("request.startTime").ignoring("request.finishTime") + .ignoring("request.requestStatus.timeStamp")); assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0)); assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0)); assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0)); assertEquals("7.0.0", response.getHeaders().get("X-LatestVersion").get(0)); assertEquals("00032ab7-na18-42e5-965d-8ea592502018", response.getHeaders().get("X-TransactionID").get(0)); + assertNotNull(response.getBody().getRequest().getFinishTime()); + } + + @Test + public void testGetOrchestrationRequestInstanceGroup() throws Exception { + setupTestGetOrchestrationRequestInstanceGroup(); + // TEST VALID REQUEST + GetOrchestrationResponse testResponse = new GetOrchestrationResponse(); + + Request request = ORCHESTRATION_LIST.getRequestList().get(8).getRequest(); + testResponse.setRequest(request); + String testRequestId = request.getRequestId(); + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON); + headers.set("Content-Type", MediaType.APPLICATION_JSON); + HttpEntity<Request> entity = new HttpEntity<Request>(null, headers); + + UriComponentsBuilder builder = UriComponentsBuilder + .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId)); + + ResponseEntity<GetOrchestrationResponse> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, + entity, GetOrchestrationResponse.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), + sameBeanAs(testResponse).ignoring("request.startTime").ignoring("request.finishTime") + .ignoring("request.requestStatus.timeStamp")); } @Test @@ -149,7 +178,8 @@ public class OrchestrationRequestsTest extends BaseTest { assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); assertThat(response.getBody(), - sameBeanAs(testResponse).ignoring("request.startTime").ignoring("request.requestStatus.finishTime")); + sameBeanAs(testResponse).ignoring("request.startTime").ignoring("request.finishTime") + .ignoring("request.requestStatus.timeStamp")); assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0)); assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0)); assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0)); @@ -197,7 +227,8 @@ public class OrchestrationRequestsTest extends BaseTest { ResponseEntity<GetOrchestrationListResponse> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationListResponse.class); assertThat(response.getBody(), - sameBeanAs(testResponse).ignoring("requestList.request.startTime").ignoring("requestList.request.requestStatus.finishTime")); + sameBeanAs(testResponse).ignoring("requestList.request.startTime").ignoring("requestList.request.finishTime") + .ignoring("requestList.request.requestStatus.timeStamp")); assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); assertEquals(requests.size(), response.getBody().getRequestList().size()); @@ -401,6 +432,17 @@ public class OrchestrationRequestsTest extends BaseTest { .withBody(new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/getRequestProcessingData.json")))) .withStatus(HttpStatus.SC_OK))); } + public void setupTestGetOrchestrationRequestInstanceGroup() throws Exception{ + //For testGetOrchestrationRequest + stubFor(any(urlPathEqualTo("/infraActiveRequests/00032ab7-na18-42e5-965d-8ea592502018")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/getOrchestrationRequestInstanceGroup.json")))) + .withStatus(HttpStatus.SC_OK))); + stubFor(get(urlPathEqualTo("/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc/")) + .withQueryParam("SO_REQUEST_ID", equalTo("00032ab7-na18-42e5-965d-8ea592502018")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/getRequestProcessingData.json")))) + .withStatus(HttpStatus.SC_OK))); + } private void setupTestGetOrchestrationRequestRequestDetails(String requestId, String status) throws Exception{ stubFor(get(urlPathEqualTo(getTestUrl(requestId))).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java index 0ce31a23e3..5603ee8380 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java @@ -29,12 +29,17 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; @@ -45,15 +50,21 @@ import javax.ws.rs.core.Response; import org.apache.http.HttpStatus; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.onap.so.apihandlerinfra.exceptions.ContactCamundaException; +import org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException; import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.ServiceRecipe; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.logger.LogConstants; import org.onap.so.logger.MsoLogger; import org.onap.so.serviceinstancebeans.CloudConfiguration; import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.RequestDetails; import org.onap.so.serviceinstancebeans.RequestError; +import org.onap.so.serviceinstancebeans.RequestInfo; import org.onap.so.serviceinstancebeans.RequestParameters; import org.onap.so.serviceinstancebeans.RequestReferences; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; @@ -68,6 +79,7 @@ import org.springframework.util.ResourceUtils; import org.springframework.web.util.UriComponentsBuilder; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.tomakehurst.wiremock.http.Fault; @@ -78,6 +90,7 @@ import ch.qos.logback.classic.spi.ILoggingEvent; public class ServiceInstancesTest extends BaseTest{ private final ObjectMapper mapper = new ObjectMapper(); + private ObjectMapper errorMapper = new ObjectMapper(); @Autowired private ServiceInstances servInstances; @@ -88,9 +101,27 @@ public class ServiceInstancesTest extends BaseTest{ private final String servInstanceuri = "/onap/so/infra/serviceInstantiation/"; private final String servInstanceUriPrev7 = "/onap/so/infra/serviceInstances/"; private String uri; + private URL selfLink; + private URL initialUrl; + private int initialPort; + private HttpHeaders headers; @Before public void beforeClass() { + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + errorMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + errorMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); + // set headers + headers = new HttpHeaders(); + headers.set(ONAPLogConstants.Headers.PARTNER_NAME, "test_name"); + headers.set(ONAPLogConstants.Headers.REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); + headers.set(MsoLogger.REQUESTOR_ID, "xxxxxx"); + try { // generate one-time port number to avoid RANDOM port number later. + initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH)); + initialPort = initialUrl.getPort(); + } catch (MalformedURLException e) { + e.printStackTrace(); + } stubFor(post(urlMatching(".*/infraActiveRequests.*")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withStatus(HttpStatus.SC_OK))); @@ -101,6 +132,16 @@ public class ServiceInstancesTest extends BaseTest{ return new String(Files.readAllBytes(Paths.get(JsonInput))); } + private URL createExpectedSelfLink(String version, String requestId) { + System.out.println("createdUrl: " + initialUrl.toString()); + try { + selfLink = new URL(initialUrl.toString().concat("/").concat(version).concat("/").concat(requestId)); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + return selfLink; + } + private String getWiremockResponseForCatalogdb(String file) { try { File resource= ResourceUtils.getFile("classpath:__files/catalogdb/"+file); @@ -121,7 +162,7 @@ public class ServiceInstancesTest extends BaseTest{ headers.set(HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_JSON); } - UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(uriPath)); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(uriPath, initialPort)); HttpEntity<String> request = new HttpEntity<>(requestJson, headers); @@ -174,20 +215,16 @@ public class ServiceInstancesTest extends BaseTest{ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(mapper.writeValueAsString(serviceRecipe)) .withStatus(HttpStatus.SC_OK))); - HttpHeaders headers = new HttpHeaders(); - headers.set(MsoLogger.TRANSACTION_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); - headers.set(MsoLogger.CLIENT_ID, "VID"); + //expect ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v5","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v5/serviceInstances"; ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - //then assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -248,17 +285,14 @@ public class ServiceInstancesTest extends BaseTest{ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(mapper.writeValueAsString(serviceRecipe)) .withStatus(HttpStatus.SC_OK))); - //expect ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v5","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceUriPrev7 + "v5"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstancePrev7.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstancePrev7.json"), uri, HttpMethod.POST, headers); //then assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); @@ -358,9 +392,9 @@ public class ServiceInstancesTest extends BaseTest{ @Test public void activateServiceInstanceNoRecipeALaCarte() throws IOException{ uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/activate"; - HttpHeaders headers = new HttpHeaders(); - headers.set("X-ECOMP-RequestID", "32807a28-1a14-4b88-b7b3-2950918aa76d"); - ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceALaCarteTrueNoRecipe.json"), uri, HttpMethod.POST, headers); + HttpHeaders requestIDheaders = new HttpHeaders(); + requestIDheaders.set("X-ECOMP-RequestID", "32807a28-1a14-4b88-b7b3-2950918aa76d"); + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceALaCarteTrueNoRecipe.json"), uri, HttpMethod.POST, requestIDheaders); Service defaultService = new Service(); defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); @@ -419,19 +453,15 @@ public class ServiceInstancesTest extends BaseTest{ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(mapper.writeValueAsString(serviceRecipe)) .withStatus(HttpStatus.SC_OK))); - HttpHeaders headers = new HttpHeaders(); - headers.set("X-TransactionID", "32807a28-1a14-4b88-b7b3-2950918aa76d"); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/activate"; ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceActivate.json"), uri, HttpMethod.POST, headers); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); @@ -467,16 +497,14 @@ public class ServiceInstancesTest extends BaseTest{ .withBody(mapper.writeValueAsString(serviceRecipe)) .withStatus(HttpStatus.SC_OK))); - //expected response + //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/deactivate"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDeactivate.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDeactivate.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -515,12 +543,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a8868/"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDelete.json"), uri, HttpMethod.DELETE); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDelete.json"), uri, HttpMethod.DELETE, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -555,16 +581,14 @@ public class ServiceInstancesTest extends BaseTest{ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(mapper.writeValueAsString(serviceRecipe)) .withStatus(HttpStatus.SC_OK))); - //expected response + //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/assign"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceAssign.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/ServiceAssign.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -604,12 +628,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/unassign"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceUnassign.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/ServiceUnassign.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -620,19 +642,15 @@ public class ServiceInstancesTest extends BaseTest{ stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); - HttpHeaders headers = new HttpHeaders(); - headers.set("X-TransactionID", "32807a28-1a14-4b88-b7b3-2950918aa76d"); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v5","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations"; ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstancePortConfiguration.json"), uri, HttpMethod.POST, headers); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); @@ -651,19 +669,15 @@ public class ServiceInstancesTest extends BaseTest{ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); - HttpHeaders headers = new HttpHeaders(); - headers.set("X-ECOMP-RequestID", "32807a28-1a14-4b88-b7b3-2950918aa76d"); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970"; ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstance.json"), uri, HttpMethod.DELETE, headers); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); @@ -677,12 +691,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/enablePort"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceEnablePort.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceEnablePort.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -697,12 +709,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/disablePort"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDisablePort.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDisablePort.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -717,12 +727,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/activate"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceActivatePort.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceActivatePort.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -737,12 +745,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations/f7ce78bb-423b-11e7-93f8-0050569a7970/deactivate"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDeactivatePort.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDeactivatePort.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -753,17 +759,14 @@ public class ServiceInstancesTest extends BaseTest{ stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); - //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/addRelationships"; - ResponseEntity<String> response = sendRequest(inputStream("/AddRelationships.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/AddRelationships.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -774,17 +777,14 @@ public class ServiceInstancesTest extends BaseTest{ stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); - //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/removeRelationships"; - ResponseEntity<String> response = sendRequest(inputStream("/RemoveRelationships.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/RemoveRelationships.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -816,12 +816,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/49585b36-2b5a-443a-8b10-c75d34bb5e46/vnfs"; - ResponseEntity<String> response = sendRequest(inputStream("/VnfCreateDefault.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/VnfCreateDefault.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -853,20 +851,15 @@ public class ServiceInstancesTest extends BaseTest{ .withBody(getWiremockResponseForCatalogdb("vnfRecipeCreateInstance_Response.json")) .withStatus(org.apache.http.HttpStatus.SC_OK))); - String requestId = "b7a6b76f-2ee2-416c-971b-548472a8c5c3"; - HttpHeaders headers = new HttpHeaders(); - headers.set(MsoLogger.ONAP_REQUEST_ID, requestId); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs"; ResponseEntity<String> response = sendRequest(inputStream("/VnfWithServiceRelatedInstance.json"), uri, HttpMethod.POST, headers); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); @@ -883,13 +876,9 @@ public class ServiceInstancesTest extends BaseTest{ public void createVnfInstanceInvalidVnfResource() throws IOException { uri = servInstanceuri + "v7" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs"; ResponseEntity<String> response = sendRequest(inputStream("/NoVnfResource.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); - + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); - RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); + RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class); assertEquals("No valid vnfResource is specified", realResponse.getServiceException().getText()); } @Test @@ -916,12 +905,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace"; - ResponseEntity<String> response = sendRequest(inputStream("/ReplaceVnf.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/ReplaceVnf.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -952,12 +939,11 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace"; - ResponseEntity<String> response = sendRequest(inputStream("/ReplaceVnfRecreate.json"), uri, HttpMethod.POST); + ResponseEntity<String> response = sendRequest(inputStream("/ReplaceVnfRecreate.json"), uri, HttpMethod.POST, headers); logger.debug(response.getBody()); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -988,12 +974,11 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/recreate"; - ResponseEntity<String> response = sendRequest(inputStream("/VnfRecreate.json"), uri, HttpMethod.POST); + ResponseEntity<String> response = sendRequest(inputStream("/VnfRecreate.json"), uri, HttpMethod.POST, headers); logger.debug(response.getBody()); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -1025,12 +1010,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000"; - ResponseEntity<String> response = sendRequest(inputStream("/UpdateVnf.json"), uri, HttpMethod.PUT); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/UpdateVnf.json"), uri, HttpMethod.PUT, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -1049,20 +1032,15 @@ public class ServiceInstancesTest extends BaseTest{ .withBody(getWiremockResponseForCatalogdb("vnfRecipeApplyUpdatedConfig_Response.json")) .withStatus(org.apache.http.HttpStatus.SC_OK))); - String requestId = "b7a6b76f-2ee2-416c-971b-548472a8c5c5"; - HttpHeaders headers = new HttpHeaders(); - headers.set(MsoLogger.ONAP_REQUEST_ID, requestId); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/applyUpdatedConfig"; ResponseEntity<String> response = sendRequest(inputStream("/ApplyUpdatedConfig.json"), uri, HttpMethod.POST, headers); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); @@ -1082,20 +1060,17 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v5","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v5" + "/serviceInstances/e446b97d-9c35-437a-95a2-6b4c542c4507/vnfs/49befbfe-fccb-421d-bb4c-0734a43f5ea0"; - ResponseEntity<String> response = sendRequest(inputStream("/DeleteVnfV5.json"), uri, HttpMethod.DELETE); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - + ResponseEntity<String> response = sendRequest(inputStream("/DeleteVnfV5.json"), uri, HttpMethod.DELETE, headers); + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test public void createVfModuleInstance() throws IOException { - stubFor(get(urlMatching(".*/vfModuleCustomization/cb82ffd8-252a-11e7-93ae-92361f002671")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(getWiremockResponseForCatalogdb("vfModuleCustomization_Response.json")) @@ -1124,12 +1099,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/7a88cbeb-0ec8-4765-a271-4f9e90c3da7b/vnfs/cbba721b-4803-4df7-9347-307c9a955426/vfModules"; - ResponseEntity<String> response = sendRequest(inputStream("/VfModuleWithRelatedInstances.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/VfModuleWithRelatedInstances.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -1185,9 +1158,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v6","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v6" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules"; - ResponseEntity<String> response = sendRequest(inputStream("/VfModuleNoModelCustomization.json"), uri, HttpMethod.POST); + ResponseEntity<String> response = sendRequest(inputStream("/VfModuleNoModelCustomization.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ObjectMapper mapper = new ObjectMapper(); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -1239,9 +1213,11 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v6","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v6" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000"; - ResponseEntity<String> response = sendRequest(inputStream("/VfModuleNoMatchingModelUUID.json"), uri, HttpMethod.DELETE); + ResponseEntity<String> response = sendRequest(inputStream("/VfModuleNoMatchingModelUUID.json"), uri, HttpMethod.DELETE, headers); + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ObjectMapper mapper = new ObjectMapper(); @@ -1274,12 +1250,10 @@ public class ServiceInstancesTest extends BaseTest{ .withStatus(org.apache.http.HttpStatus.SC_OK))); uri = servInstanceuri + "v6" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules"; - ResponseEntity<String> response = sendRequest(inputStream("/VfModuleInvalid.json"), uri, HttpMethod.POST); - + ResponseEntity<String> response = sendRequest(inputStream("/VfModuleInvalid.json"), uri, HttpMethod.POST, headers); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); - RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); + RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class); assertEquals("No valid vfModuleCustomization is specified", realResponse.getServiceException().getText()); } @Test @@ -1303,12 +1277,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000/replace"; - ResponseEntity<String> response = sendRequest(inputStream("/ReplaceVfModule.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/ReplaceVfModule.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -1345,22 +1317,18 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000"; - ResponseEntity<String> response = sendRequest(inputStream("/UpdateVfModule.json"), uri, HttpMethod.PUT); + ResponseEntity<String> response = sendRequest(inputStream("/UpdateVfModule.json"), uri, HttpMethod.PUT, headers); logger.debug(response.getBody()); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test public void createVfModuleNoModelType() throws IOException{ - HttpHeaders headers = new HttpHeaders(); - headers.set(MsoLogger.ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); InfraActiveRequests expectedRecord = new InfraActiveRequests(); expectedRecord.setRequestStatus("FAILED"); expectedRecord.setAction("createInstance"); @@ -1399,12 +1367,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/inPlaceSoftwareUpdate"; - ResponseEntity<String> response = sendRequest(inputStream("/InPlaceSoftwareUpdate.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/InPlaceSoftwareUpdate.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -1433,12 +1399,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000"; - ResponseEntity<String> response = sendRequest(inputStream("/DeleteVfModule.json"), uri, HttpMethod.DELETE); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/DeleteVfModule.json"), uri, HttpMethod.DELETE, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -1460,12 +1424,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/196b4a84-0858-4317-a1f6-497e2e52ae43/vnfs/36e4f902-ec32-451e-8d53-e3edc19e40a4/vfModules/09f3a38d-933f-450a-8784-9e6c4dec3f72"; - ResponseEntity<String> response = sendRequest(inputStream("/DeleteVfModuleNoModelInvariantId.json"), uri, HttpMethod.DELETE); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/DeleteVfModuleNoModelInvariantId.json"), uri, HttpMethod.DELETE, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -1493,13 +1455,11 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules/ff305d54-75b4-431b-adb2-eb6b9e5ff000/deactivateAndCloudDelete"; - ResponseEntity<String> response = sendRequest(inputStream("/DeactivateAndCloudDeleteVfModule.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - + ResponseEntity<String> response = sendRequest(inputStream("/DeactivateAndCloudDeleteVfModule.json"), uri, HttpMethod.POST, headers); + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); @@ -1530,12 +1490,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups"; - ResponseEntity<String> response = sendRequest(inputStream("/VolumeGroup.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/VolumeGroup.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -1568,12 +1526,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups/ff305d54-75b4-431b-adb2-eb6b9e5ff000"; - ResponseEntity<String> response = sendRequest(inputStream("/UpdateVolumeGroup.json"), uri, HttpMethod.PUT); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/UpdateVolumeGroup.json"), uri, HttpMethod.PUT, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -1609,13 +1565,11 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/volumeGroups/ff305d54-75b4-431b-adb2-eb6b9e5ff000"; - ResponseEntity<String> response = sendRequest(inputStream("/DeleteVolumeGroup.json"), uri, HttpMethod.DELETE); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - + ResponseEntity<String> response = sendRequest(inputStream("/DeleteVolumeGroup.json"), uri, HttpMethod.DELETE, headers); + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); @@ -1642,20 +1596,15 @@ public class ServiceInstancesTest extends BaseTest{ .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json")) .withStatus(org.apache.http.HttpStatus.SC_OK))); - String requestId = "b7a6b76f-2ee2-416c-971b-548472a8c5c4"; - HttpHeaders headers = new HttpHeaders(); - headers.set(MsoLogger.ONAP_REQUEST_ID, requestId); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks"; ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreate.json"), uri, HttpMethod.POST, headers); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); @@ -1685,12 +1634,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb"; - ResponseEntity<String> response = sendRequest(inputStream("/UpdateNetwork.json"), uri, HttpMethod.PUT); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/UpdateNetwork.json"), uri, HttpMethod.PUT, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -1723,12 +1670,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb"; - ResponseEntity<String> response = sendRequest(inputStream("/NetworkInstance.json"), uri, HttpMethod.DELETE); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/NetworkInstance.json"), uri, HttpMethod.DELETE, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -1751,12 +1696,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v6","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v6" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb"; - ResponseEntity<String> response = sendRequest(inputStream("/NetworkInstanceNoReqParams.json"), uri, HttpMethod.DELETE); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/NetworkInstanceNoReqParams.json"), uri, HttpMethod.DELETE, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -1764,8 +1707,6 @@ public class ServiceInstancesTest extends BaseTest{ } @Test public void convertJsonToServiceInstanceRequestFail() throws IOException { - HttpHeaders headers = new HttpHeaders(); - headers.set(MsoLogger.ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); //ExpectedRecord InfraActiveRequests expectedRecord = new InfraActiveRequests(); expectedRecord.setRequestStatus("FAILED"); @@ -1818,17 +1759,15 @@ public class ServiceInstancesTest extends BaseTest{ .withStatus(HttpStatus.SC_OK))); uri = servInstanceuri + "v7" + "/serviceInstances"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceMacro.json"), uri, HttpMethod.POST); + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceMacro.json"), uri, HttpMethod.POST, headers); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); @@ -1857,17 +1796,15 @@ public class ServiceInstancesTest extends BaseTest{ .withStatus(org.apache.http.HttpStatus.SC_OK))); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks"; - ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateAlternateInstanceName.json"), uri, HttpMethod.POST); + ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateAlternateInstanceName.json"), uri, HttpMethod.POST, headers); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); @@ -1888,9 +1825,6 @@ public class ServiceInstancesTest extends BaseTest{ requestReferences.setInstanceId("1882939"); expectedResponse.setRequestReferences(requestReferences); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); } @@ -1917,17 +1851,15 @@ public class ServiceInstancesTest extends BaseTest{ .withStatus(org.apache.http.HttpStatus.SC_OK))); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks"; - ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateTestApiGrApi.json"), uri, HttpMethod.POST); + ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateTestApiGrApi.json"), uri, HttpMethod.POST, headers); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); @@ -1956,17 +1888,15 @@ public class ServiceInstancesTest extends BaseTest{ .withStatus(org.apache.http.HttpStatus.SC_OK))); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks"; - ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateTestApiVnfApi.json"), uri, HttpMethod.POST); + ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateTestApiVnfApi.json"), uri, HttpMethod.POST, headers); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); @@ -1986,8 +1916,6 @@ public class ServiceInstancesTest extends BaseTest{ stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); - HttpHeaders headers = new HttpHeaders(); - headers.set("X-ECOMP-RequestID", "32807a28-1a14-4b88-b7b3-2950918aa76d"); stubFor(get(urlMatching(".*/service/.*")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) @@ -2003,13 +1931,11 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v5","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7999/activate"; ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstancePrev8.json"), uri, HttpMethod.POST, headers); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); @@ -2018,11 +1944,10 @@ public class ServiceInstancesTest extends BaseTest{ @Test public void invalidRequestId() throws IOException { String illegalRequestId = "1234"; - HttpHeaders headers = new HttpHeaders(); - headers.set(ONAPLogConstants.Headers.REQUEST_ID, illegalRequestId); - + HttpHeaders ivalidRequestIdHeaders = new HttpHeaders(); + ivalidRequestIdHeaders.set(ONAPLogConstants.Headers.REQUEST_ID, illegalRequestId); uri = servInstanceuri + "v5/serviceInstances"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers); + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, ivalidRequestIdHeaders); assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); assertTrue(response.getBody().contains("Request Id " + illegalRequestId + " is not a valid UUID")); @@ -2054,14 +1979,10 @@ public class ServiceInstancesTest extends BaseTest{ .withStatus(HttpStatus.SC_OK))); uri = servInstanceuri + "v5/serviceInstances"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); - + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers); + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); - RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); + RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class); assertEquals("Request Failed due to BPEL error with HTTP Status = 202{\"instanceId\": \"1882939\"}", realResponse.getServiceException().getText()); } @Test @@ -2091,14 +2012,10 @@ public class ServiceInstancesTest extends BaseTest{ .withStatus(HttpStatus.SC_OK))); uri = servInstanceuri + "v5/serviceInstances"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); + RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class); assertEquals("Exception caught mapping Camunda JSON response to object", realResponse.getServiceException().getText()); } @@ -2128,14 +2045,10 @@ public class ServiceInstancesTest extends BaseTest{ .withBody(mapper.writeValueAsString(serviceRecipe)) .withStatus(HttpStatus.SC_OK))); uri = servInstanceuri + "v5/serviceInstances"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); - + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers); + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); - RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); + RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class); assertTrue(realResponse.getServiceException().getText().contains("<aetgt:ErrorMessage>Exception in create execution list 500")); } @@ -2172,12 +2085,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v5","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceUriPrev7 + "v5"; - ResponseEntity<String> response = sendRequest(inputStream("/MacroServiceInstance.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/MacroServiceInstance.json"), uri, HttpMethod.POST, headers); //then assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); @@ -2254,12 +2165,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/7a88cbeb-0ec8-4765-a271-4f9e90c3da7b/vnfs/cbba721b-4803-4df7-9347-307c9a955426/vfModules/scaleOut"; - ResponseEntity<String> response = sendRequest(inputStream("/ScaleOutRequest.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/ScaleOutRequest.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -2292,14 +2201,10 @@ public class ServiceInstancesTest extends BaseTest{ .withStatus(HttpStatus.SC_OK))); uri = servInstanceuri + "v5/serviceInstances"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); - + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers); + assertEquals(Response.Status.NOT_ACCEPTABLE.getStatusCode(), response.getStatusCode().value()); - RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); + RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class); assertEquals("Exception caught mapping Camunda JSON response to object", realResponse.getServiceException().getText()); } @Test @@ -2309,16 +2214,60 @@ public class ServiceInstancesTest extends BaseTest{ .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); uri = servInstanceuri + "v5/serviceInstances"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers); + + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class); + assertEquals("Unable to check for duplicate instance due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException: 500 Server Error", realResponse.getServiceException().getText()); + } + @Test + public void createServiceInstanceDuplicateHistoryCheck() throws IOException{ + stubFor(post(urlMatching(".*/infraActiveRequests/checkInstanceNameDuplicate")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("InfraActiveRequests/createInfraActiveRequests.json") + .withStatus(HttpStatus.SC_ACCEPTED))); + stubFor(get(("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("Camunda/HistoryCheckResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + uri = servInstanceuri + "v5/serviceInstances"; + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers); + + assertEquals(Response.Status.CONFLICT.getStatusCode(), response.getStatusCode().value()); + RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class); + assertEquals("Error: Locked instance - This service (testService9) already has a request being worked with a status of UNLOCKED (RequestId - f0a35706-efc4-4e27-80ea-a995d7a2a40f). The existing request must finish or be cleaned up before proceeding.", realResponse.getServiceException().getText()); + } + @Test + public void createServiceInstanceDuplicateHistoryCheckException() throws IOException{ + stubFor(post(urlMatching(".*/infraActiveRequests/checkInstanceNameDuplicate")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("InfraActiveRequests/createInfraActiveRequests.json") + .withStatus(HttpStatus.SC_ACCEPTED))); + stubFor(get(("/sobpmnengine/history/process-instance?variables=mso-request-id_eq_f0a35706-efc4-4e27-80ea-a995d7a2a40f")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withStatus(org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR))); + + uri = servInstanceuri + "v5/serviceInstances"; + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers); + + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class); + assertEquals("Unable to get process-instance history from Camunda for requestId: f0a35706-efc4-4e27-80ea-a995d7a2a40f due to error: org.springframework.web.client.HttpServerErrorException: 500 Server Error", realResponse.getServiceException().getText()); + } + @Test + public void createServiceInstanceDuplicate() throws IOException{ + stubFor(post(urlMatching(".*/infraActiveRequests/checkInstanceNameDuplicate")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); + + uri = servInstanceuri + "v5/serviceInstances"; + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); + RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class); assertEquals("Unable to check for duplicate instance due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException: 500 Server Error", realResponse.getServiceException().getText()); } + @Test public void createServiceInstanceSaveError() throws IOException{ ServiceRecipe serviceRecipe = new ServiceRecipe(); @@ -2343,14 +2292,10 @@ public class ServiceInstancesTest extends BaseTest{ .withStatus(HttpStatus.SC_OK))); uri = servInstanceuri + "v5/serviceInstances"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST, headers); assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); + RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class); assertEquals("Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException: 500 Server Error", realResponse.getServiceException().getText()); } @Test @@ -2362,17 +2307,11 @@ public class ServiceInstancesTest extends BaseTest{ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); - HttpHeaders headers = new HttpHeaders(); - uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations"; ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstancePortConfiguration.json"), uri, HttpMethod.POST, headers); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); - + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); + RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class); assertEquals("Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException: 500 Server Error", realResponse.getServiceException().getText()); } @Test @@ -2382,18 +2321,15 @@ public class ServiceInstancesTest extends BaseTest{ .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceParseFail.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); - + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceParseFail.json"), uri, HttpMethod.POST, headers); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); + RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class); assertEquals("Unable to save instance to db due to error contacting requestDb: org.springframework.web.client.HttpServerErrorException: 500 Server Error", realResponse.getServiceException().getText()); } @Test public void vnfUpdateWithNetworkInstanceGroup() throws IOException{ + TestAppender.events.clear(); stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); @@ -2413,18 +2349,139 @@ public class ServiceInstancesTest extends BaseTest{ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(getWiremockResponseForCatalogdb("UpdateVnfRecipe_Response.json")) .withStatus(org.apache.http.HttpStatus.SC_OK))); - HttpHeaders headers = new HttpHeaders(); - headers.set(MsoLogger.CLIENT_ID, "VID"); + headers.set(ONAPLogConstants.Headers.PARTNER_NAME, "VID"); //expect ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7/serviceInstances/e05864f0-ab35-47d0-8be4-56fd9619ba3c/vnfs/f501ce76-a9bc-4601-9837-74fd9f4d5eca"; ResponseEntity<String> response = sendRequest(inputStream("/VnfwithNeteworkInstanceGroup.json"), uri, HttpMethod.PUT, headers); + //then + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); + ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); + assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); + assertEquals(response.getHeaders().get(MsoLogger.TRANSACTION_ID).get(0), "32807a28-1a14-4b88-b7b3-2950918aa76d"); + + for(ILoggingEvent logEvent : TestAppender.events){ + if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.JaxRsFilterLogging") && + logEvent.getMarker() != null && logEvent.getMarker().getName().equals("ENTRY")){ + Map<String,String> mdc = logEvent.getMDCPropertyMap(); + assertEquals("32807a28-1a14-4b88-b7b3-2950918aa76d", mdc.get(ONAPLogConstants.MDCs.REQUEST_ID)); + } + } + } + @Test + public void createInstanceGroup() throws IOException{ + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + //expect + ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); + RequestReferences requestReferences = new RequestReferences(); + requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); + expectedResponse.setRequestReferences(requestReferences); + uri = servInstanceuri + "/v7/instanceGroups"; + ResponseEntity<String> response = sendRequest(inputStream("/CreateInstanceGroup.json"), uri, HttpMethod.POST, headers); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + //then + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); + ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); + assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); + } + @Test + public void deleteInstanceGroup() throws IOException{ + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + //expect + ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); + RequestReferences requestReferences = new RequestReferences(); + requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); + expectedResponse.setRequestReferences(requestReferences); + uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c"; + ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE, headers); + + //then + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); + ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); + assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); + } + @Test + public void deleteInstanceGroupNoRequestIdHeader() throws IOException{ + uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c"; + ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE); + //then + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); + RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class); + assertEquals(realResponse.getServiceException().getText(), "No valid X-ONAP-RequestID header is specified"); + } + @Test + public void deleteInstanceGroupNoPartnerNameHeader() throws IOException{ + HttpHeaders noPartnerHeaders = new HttpHeaders(); + noPartnerHeaders.set(ONAPLogConstants.Headers.REQUEST_ID, "eca3a1b1-43ab-457e-ab1c-367263d148b4"); + uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c"; + ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE, noPartnerHeaders); + //then + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); + RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class); + assertEquals(realResponse.getServiceException().getText(), "No valid X-ONAP-PartnerName header is specified"); + } + @Test + public void deleteInstanceGroupNoRquestorIdHeader() throws IOException{ + HttpHeaders noRequestorIdHheaders = new HttpHeaders(); + noRequestorIdHheaders.set(ONAPLogConstants.Headers.REQUEST_ID, "eca3a1b1-43ab-457e-ab1c-367263d148b4"); + noRequestorIdHheaders.set(ONAPLogConstants.Headers.PARTNER_NAME, "eca3a1b1-43ab-457e-ab1c-367263d148b4"); + //expect + ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); + RequestReferences requestReferences = new RequestReferences(); + requestReferences.setInstanceId("1882939"); + expectedResponse.setRequestReferences(requestReferences); + uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c"; + ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE, noRequestorIdHheaders); + + //then + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); + RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class); + assertEquals(realResponse.getServiceException().getText(), "No valid X-RequestorID header is specified"); + } + @Test + public void addMembers() throws IOException{ + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + //expect + ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); + RequestReferences requestReferences = new RequestReferences(); + requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); + expectedResponse.setRequestReferences(requestReferences); + uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c/addMembers"; + ResponseEntity<String> response = sendRequest(inputStream("/AddMembers.json"), uri, HttpMethod.POST, headers); + + //then + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); + ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); + assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); + } + @Test + public void removeMembers() throws IOException{ + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + //expect + ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); + RequestReferences requestReferences = new RequestReferences(); + requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); + expectedResponse.setRequestReferences(requestReferences); + uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c/removeMembers"; + ResponseEntity<String> response = sendRequest(inputStream("/RemoveMembers.json"), uri, HttpMethod.POST, headers); //then assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); @@ -2451,12 +2508,10 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v7","32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb"; - ResponseEntity<String> response = sendRequest(inputStream("/NetworkInstance.json"), uri, HttpMethod.DELETE); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ResponseEntity<String> response = sendRequest(inputStream("/NetworkInstance.json"), uri, HttpMethod.DELETE, headers); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); @@ -2469,14 +2524,100 @@ public class ServiceInstancesTest extends BaseTest{ .withStatus(HttpStatus.SC_NOT_FOUND))); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks/1710966e-097c-4d63-afda-e0d3bb7015fb"; - ResponseEntity<String> response = sendRequest(inputStream("/UpdateNetwork.json"), uri, HttpMethod.PUT); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); - + ResponseEntity<String> response = sendRequest(inputStream("/UpdateNetwork.json"), uri, HttpMethod.PUT, headers); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); - RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); + RequestError realResponse = errorMapper.readValue(response.getBody(), RequestError.class); assertEquals(realResponse.getServiceException().getText(), "No valid modelCustomizationId for networkResourceCustomization lookup is specified"); } + + @Test + public void setServiceTypeTestALaCarte() throws JsonProcessingException{ + String requestScope = ModelType.service.toString(); + Boolean aLaCarteFlag = true; + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + RequestDetails requestDetails = new RequestDetails(); + RequestInfo requestInfo = new RequestInfo(); + requestInfo.setSource("VID"); + requestDetails.setRequestInfo(requestInfo); + sir.setRequestDetails(requestDetails); + Service defaultService = new Service(); + defaultService.setServiceType("testServiceTypeALaCarte"); + + stubFor(get(urlMatching(".*/service/search/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + String serviceType = servInstances.getServiceType(requestScope, sir, aLaCarteFlag); + assertEquals(serviceType, "testServiceTypeALaCarte"); + } + @Test + public void setServiceTypeTest() throws JsonProcessingException{ + String requestScope = ModelType.service.toString(); + Boolean aLaCarteFlag = false; + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + RequestDetails requestDetails = new RequestDetails(); + RequestInfo requestInfo = new RequestInfo(); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelVersionId("0dd91181-49da-446b-b839-cd959a96f04a"); + requestInfo.setSource("VID"); + requestDetails.setModelInfo(modelInfo); + requestDetails.setRequestInfo(requestInfo); + sir.setRequestDetails(requestDetails); + Service defaultService = new Service(); + defaultService.setServiceType("testServiceType"); + + stubFor(get(urlMatching(".*/service/0dd91181-49da-446b-b839-cd959a96f04a")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + String serviceType = servInstances.getServiceType(requestScope, sir, aLaCarteFlag); + assertEquals(serviceType, "testServiceType"); + } + @Test + public void setServiceTypeTestDefault() throws JsonProcessingException{ + String requestScope = ModelType.service.toString(); + Boolean aLaCarteFlag = false; + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + RequestDetails requestDetails = new RequestDetails(); + RequestInfo requestInfo = new RequestInfo(); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelVersionId("0dd91181-49da-446b-b839-cd959a96f04a"); + requestInfo.setSource("VID"); + requestDetails.setModelInfo(modelInfo); + requestDetails.setRequestInfo(requestInfo); + sir.setRequestDetails(requestDetails); + Service defaultService = new Service(); + defaultService.setServiceType("testServiceType"); + + stubFor(get(urlMatching(".*/service/0dd91181-49da-446b-b839-cd959a96f04a")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withStatus(HttpStatus.SC_NOT_FOUND))); + stubFor(get(urlMatching(".*/service/search/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + String serviceType = servInstances.getServiceType(requestScope, sir, aLaCarteFlag); + assertEquals(serviceType, "testServiceType"); + } + @Test + public void setServiceTypeTestNetwork() throws JsonProcessingException{ + String requestScope = ModelType.network.toString(); + Boolean aLaCarteFlag = null; + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + RequestDetails requestDetails = new RequestDetails(); + RequestInfo requestInfo = new RequestInfo(); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelName("networkModelName"); + requestInfo.setSource("VID"); + requestDetails.setModelInfo(modelInfo); + requestDetails.setRequestInfo(requestInfo); + sir.setRequestDetails(requestDetails); + + String serviceType = servInstances.getServiceType(requestScope, sir, aLaCarteFlag); + assertEquals(serviceType, "networkModelName"); + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/TasksHandlerTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/TasksHandlerTest.java index fa323a12c2..c7b4cc0574 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/TasksHandlerTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/TasksHandlerTest.java @@ -120,4 +120,4 @@ public class TasksHandlerTest extends BaseTest{ assertEquals("1.0.0", response.getHeaders().get("X-LatestVersion").get(0)); } -} +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/RequestDetailsTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/RequestDetailsTest.java deleted file mode 100644 index 80cd0fac2f..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/RequestDetailsTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.apihandlerinfra.tasksbeans; - -import org.junit.After; -import static org.junit.Assert.assertTrue; -import org.junit.Before; -import org.junit.Test; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - - -public class RequestDetailsTest { - - RequestDetails _requestDetails; - RequestInfo _requestInfo; - - public RequestDetailsTest() { - } - - @Before - public void setUp() { - _requestDetails = mock(RequestDetails.class); - _requestInfo = new RequestInfo(); - when(_requestDetails.getRequestInfo()).thenReturn(_requestInfo); - } - - @After - public void tearDown() { - _requestDetails = null; - _requestInfo = null; - } - - /** - * Test of getRequestInfo method - */ - @Test - public void testGetRequestInfo() { - _requestDetails.setRequestInfo(_requestInfo); - assertTrue(_requestDetails.getRequestInfo().equals(_requestInfo)); - - } - - /** - * Test setRequestInfo - */ - @Test - public void testSetRequestInfo() { - _requestDetails.setRequestInfo(_requestInfo); - verify(_requestDetails).setRequestInfo(_requestInfo); - } -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/RequestInfoTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/RequestInfoTest.java deleted file mode 100644 index 852376eb7a..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/RequestInfoTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.apihandlerinfra.tasksbeans; - -import org.junit.After; - -import static org.junit.Assert.assertEquals; -import org.junit.Before; -import org.junit.Test; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class RequestInfoTest { - - RequestInfo _requestInfo; - String _source; - ValidResponses _responseValue; - String _requestorId; - - public RequestInfoTest() { - } - - @Before - public void setUp() { - _requestInfo = mock(RequestInfo.class); - _responseValue = ValidResponses.abort; - _requestorId = "xxxxxx"; - _source = "VID"; - when(_requestInfo.getRequestorId()).thenReturn(_requestorId); - when(_requestInfo.getSource()).thenReturn(_source); - when(_requestInfo.getResponseValue()).thenReturn(_responseValue); - - } - - @After - public void tearDown() { - _requestInfo = null; - _responseValue = null; - } - - /** - * Test of getSource method - */ - @Test - public void testGetSource() { - String result = _requestInfo.getSource(); - assertEquals(_source, result); - - } - - /** - * Test setSource - */ - @Test - public void testSetSource() { - _requestInfo.setSource("VID"); - verify(_requestInfo).setSource(_source); - } - - /** - * Test of getRequestorId method - */ - @Test - public void testGetRequestorId() { - String result = _requestInfo.getRequestorId(); - assertEquals(_requestorId, result); - - } - - /** - * Test setRequestInfo - */ - @Test - public void testSetRequestorId() { - _requestInfo.setRequestorId(_requestorId); - verify(_requestInfo).setRequestorId(_requestorId); - } - - - /** - * Test of getResponseValue method - */ - @Test - public void testGetResponseValue() { - ValidResponses result = _requestInfo.getResponseValue(); - assertEquals(_responseValue, result); - - } - - /** - * Test setResponseValues method - */ - @Test - public void testSetResponseValue() { - _requestInfo.setResponseValue(ValidResponses.abort); - verify(_requestInfo).setResponseValue(_responseValue); - } -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TaskListTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TaskListTest.java deleted file mode 100644 index 62bfee989b..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TaskListTest.java +++ /dev/null @@ -1,247 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.apihandlerinfra.tasksbeans; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.List; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class TaskListTest { - - TaskList _taskList; - protected String _taskId; - protected String _type; - protected String _nfRole; - protected String _subscriptionServiceType; - protected String _originalRequestId; - protected String _originalRequestorId; - protected String _errorSource; - protected String _errorCode; - protected String _errorMessage; - protected String _buildingBlockName; - protected String _buildingBlockStep; - protected List<String> _validResponses; - - public TaskListTest() { - } - - @Before - public void setUp() { - _taskList = mock(TaskList.class); - _taskId = "_taskid"; - _type = "type"; - _nfRole = "nfrole"; - _subscriptionServiceType = "subscriptionservicetype"; - _originalRequestId = "originalrequestid"; - _originalRequestorId = "originalrequestorid"; - _errorSource = "errorsource"; - _errorCode = "errorcode"; - _errorMessage = "errormessage"; - _buildingBlockName = "buildingblockname"; - _buildingBlockStep = "buildingblockstep"; - _validResponses = mock(List.class); - - when(_taskList.getTaskId()).thenReturn(_taskId); - when(_taskList.getType()).thenReturn(_type); - when(_taskList.getNfRole()).thenReturn(_nfRole); - when(_taskList.getSubscriptionServiceType()).thenReturn(_subscriptionServiceType); - when(_taskList.getOriginalRequestId()).thenReturn(_originalRequestId); - when(_taskList.getOriginalRequestorId()).thenReturn(_originalRequestorId); - when(_taskList.getErrorSource()).thenReturn(_errorSource); - when(_taskList.getErrorCode()).thenReturn(_errorCode); - when(_taskList.getErrorMessage()).thenReturn(_errorMessage); - when(_taskList.getBuildingBlockName()).thenReturn(_buildingBlockName); - when(_taskList.getBuildingBlockStep()).thenReturn(_buildingBlockStep); - when(_taskList.getValidResponses()).thenReturn(_validResponses); - } - - @After - public void tearDown() { - _taskList = null; - _validResponses = null; - } - - @Test - public void testGetTaskId() { - String result = _taskList.getTaskId(); - assertEquals(_taskId, result); - - } - - @Test - public void testSetTaskId() { - _taskList.setTaskId("_taskid"); - verify(_taskList).setTaskId(_taskId); - } - - @Test - public void testGetType() { - String result = _taskList.getType(); - assertEquals(_type, result); - - } - - @Test - public void testSetType() { - _taskList.setType(_type); - verify(_taskList).setType(_type); - } - - @Test - public void testGetNfRole() { - String result = _taskList.getNfRole(); - assertEquals(_nfRole, result); - - } - - @Test - public void testSetNfRole() { - _taskList.setType(_nfRole); - verify(_taskList).setType(_nfRole); - } - - @Test - public void testGetSubscriptionServiceType() { - String result = _taskList.getSubscriptionServiceType(); - assertEquals(_subscriptionServiceType, result); - - } - - @Test - public void testSetSubscriptionServiceType() { - _taskList.setSubscriptionServiceType(_subscriptionServiceType); - verify(_taskList).setSubscriptionServiceType(_subscriptionServiceType); - } - - @Test - public void testGetOriginalRequestId() { - String result = _taskList.getOriginalRequestId(); - assertEquals(_originalRequestId, result); - - } - - @Test - public void testSetOriginalRequestId() { - _taskList.setOriginalRequestId(_originalRequestId); - verify(_taskList).setOriginalRequestId(_originalRequestId); - } - - @Test - public void testGetOriginalRequestorId() { - String result = _taskList.getOriginalRequestorId(); - assertEquals(_originalRequestorId, result); - - } - - @Test - public void testSetOriginalRequestorId() { - _taskList.setOriginalRequestorId(_originalRequestorId); - verify(_taskList).setOriginalRequestorId(_originalRequestorId); - } - - @Test - public void testGetErrorSource() { - String result = _taskList.getErrorSource(); - assertEquals(_errorSource, result); - - } - - @Test - public void testSetErrorSource() { - _taskList.setErrorSource(_errorSource); - verify(_taskList).setErrorSource(_errorSource); - } - - @Test - public void testGetErrorCode() { - String result = _taskList.getErrorCode(); - assertEquals(_errorCode, result); - - } - - @Test - public void testSetErrorCode() { - _taskList.setErrorCode(_errorCode); - verify(_taskList).setErrorCode(_errorCode); - } - - @Test - public void testGetErrorMessage() { - String result = _taskList.getErrorMessage(); - assertEquals(_errorMessage, result); - - } - - @Test - public void testSetErrorMessage() { - _taskList.setErrorMessage(_errorMessage); - verify(_taskList).setErrorMessage(_errorMessage); - } - - @Test - public void testGetBuildingBlockName() { - String result = _taskList.getBuildingBlockName(); - assertEquals(_buildingBlockName, result); - - } - - @Test - public void testSetBuildingBlockName() { - _taskList.setBuildingBlockName(_buildingBlockName); - verify(_taskList).setBuildingBlockName(_buildingBlockName); - } - - @Test - public void testGetBuildingBlockStep() { - String result = _taskList.getBuildingBlockStep(); - assertEquals(_buildingBlockStep, result); - - } - - @Test - public void testSetBuildingBlockStep() { - _taskList.setBuildingBlockStep(_buildingBlockStep); - verify(_taskList).setBuildingBlockStep(_buildingBlockStep); - } - - @Test - public void testGetValidResponses() { - - List<String> result = _taskList.getValidResponses(); - assertEquals(_validResponses, result); - - } - - @Test - public void testSetValidResponses() { - _taskList.setValidResponses(_validResponses); - verify(_taskList).setValidResponses(_validResponses); - } - - -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TaskRequestReferenceTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TaskRequestReferenceTest.java deleted file mode 100644 index 043f4ea93d..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TaskRequestReferenceTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.apihandlerinfra.tasksbeans; - -import org.junit.After; - -import static org.junit.Assert.assertEquals; -import org.junit.Before; -import org.junit.Test; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class TaskRequestReferenceTest { - - TaskRequestReference _taskRequestReference; - - protected String _taskId; - public TaskRequestReferenceTest() { - } - - @Before - public void setUp() { - _taskRequestReference = mock(TaskRequestReference.class); - _taskId = "taskid"; - - when(_taskRequestReference.getTaskId()).thenReturn(_taskId); - } - - @After - public void tearDown() { - _taskRequestReference = null; - } - - /** - * Test getTaskRequestReference - */ - @Test - public void taskGetRequestReference() { - String result = _taskRequestReference.getTaskId(); - assertEquals(_taskId, result); - } - - /** - * Test setTaskRequestReference - */ - @Test - public void testSetRequestInfo() { - _taskRequestReference.setTaskId(_taskId); - verify(_taskRequestReference).setTaskId(_taskId); - } -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TaskVariableValueTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TaskVariableValueTest.java deleted file mode 100644 index bc6a5ab890..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TaskVariableValueTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.apihandlerinfra.tasksbeans; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static org.junit.Assert.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class TaskVariableValueTest { - TaskVariableValue _taskVariableValue; - protected String _name; - protected String _value; - protected String _operator; - - public TaskVariableValueTest() { - } - - @Before - public void setUp() { - _taskVariableValue = mock(TaskVariableValue.class); - _name = "name"; - _value = "value"; - _operator = "operator"; - when(_taskVariableValue.getName()).thenReturn(_name); - when(_taskVariableValue.getValue()).thenReturn(_value); - when(_taskVariableValue.getOperator()).thenReturn(_operator); - } - - @After - public void tearDown() { - _taskVariableValue = null; - } - - /** - * Test of getName method - */ - @Test - public void testGetName() { - _taskVariableValue.setName(_name); - assertEquals(_taskVariableValue.getName(),_name); - - } - - /** - * Test setName - */ - @Test - public void testSetName() { - _taskVariableValue.setName(_name); - verify(_taskVariableValue).setName(_name); - } - - /** - * Test of getName method - */ - @Test - public void testGetValue() { - _taskVariableValue.setValue(_value); - assertEquals(_taskVariableValue.getValue(),_value); - - } - - /** - * Test setName - */ - @Test - public void testSetValue() { - _taskVariableValue.setValue(_value); - verify(_taskVariableValue).setValue(_value); - } - - /** - * Test of getName method - */ - @Test - public void testGetOperator() { - _taskVariableValue.setOperator(_operator); - assertEquals(_taskVariableValue.getOperator(),_operator); - - } - - /** - * Test setName - */ - @Test - public void testSetRequestDetails() { - _taskVariableValue.setOperator(_operator); - verify(_taskVariableValue).setOperator(_operator); - } - -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TaskVariablesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TaskVariablesTest.java deleted file mode 100644 index 8e2c3ae7da..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TaskVariablesTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.apihandlerinfra.tasksbeans; - -import org.junit.After; - -import static org.junit.Assert.assertEquals; -import org.junit.Before; -import org.junit.Test; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.List; - -public class TaskVariablesTest { - - TaskVariables _taskVariables; - private List<TaskVariableValue> _taskVariableValueList; - - public TaskVariablesTest() { - } - - @SuppressWarnings("unchecked") - @Before - public void setUp() { - _taskVariables = mock(TaskVariables.class); - _taskVariableValueList = mock(List.class); - when(_taskVariables.getTaskVariables()).thenReturn(_taskVariableValueList); - } - - @After - public void tearDown() { - _taskVariables = null; - } - - @Test - public void testGetTaskVariables() { - List<TaskVariableValue> result = _taskVariables.getTaskVariables(); - assertEquals(_taskVariableValueList, result); - - } - - @Test - public void testSetTaskVariables() { - _taskVariables.setTaskVariables(_taskVariableValueList); - verify(_taskVariables).setTaskVariables(_taskVariableValueList); - - } -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/ValueTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TasksBeansTest.java index dc5cf8ed39..cbdfe6b831 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/ValueTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TasksBeansTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,49 +20,22 @@ package org.onap.so.apihandlerinfra.tasksbeans; -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import org.onap.so.apihandlerinfra.BaseTest; -public class ValueTest { - Value _valueInstance; - protected String _value; +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; - public ValueTest() { - } - - @Before - public void setUp() { - _valueInstance = mock(Value.class); - _value = "_value"; - when(_valueInstance.getValue()).thenReturn(_value); - } - - @After - public void tearDown() { - _valueInstance = null; - } - - /** - * Test of getValue method - */ - @Test - public void testGetValue() { - _valueInstance.setValue(_value); - assertEquals(_valueInstance.getValue(),_value); - - } - - /** - * Test setValue - */ +public class TasksBeansTest extends BaseTest{ @Test - public void testSetValue() { - _valueInstance.setValue(_value); - verify(_valueInstance).setValue(_value); + public void validateGettersAndSetters() { + Validator validator = ValidatorBuilder.create().with(new SetterMustExistRule(), new GetterMustExistRule()) + .with(new SetterTester(), new GetterTester()).build(); + validator.validate("org.onap.so.apihandlerinfra.tasksbeans", new FilterPackageInfo()); } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TasksGetResponseTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TasksGetResponseTest.java deleted file mode 100644 index f4ec27e852..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TasksGetResponseTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.apihandlerinfra.tasksbeans; - -import org.junit.After; - -import static org.junit.Assert.assertEquals; -import org.junit.Before; -import org.junit.Test; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.List; - -public class TasksGetResponseTest { - - TasksGetResponse _tasksGetResponse; - private List<TaskList> _taskList; - - public TasksGetResponseTest() { - } - - @SuppressWarnings("unchecked") - @Before - public void setUp() { - _tasksGetResponse = mock(TasksGetResponse.class); - _taskList = mock(List.class); - when(_tasksGetResponse.getTaskList()).thenReturn(_taskList); - } - - @After - public void tearDown() { - _tasksGetResponse = null; - } - - @Test - public void testGetTaskList() { - List<TaskList> result = _tasksGetResponse.getTaskList(); - assertEquals(_taskList, result); - - } - - @Test - public void testSetTaskList() { - _tasksGetResponse.setTaskList(_taskList); - verify(_tasksGetResponse).setTaskList(_taskList); - - } -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TasksRequestTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TasksRequestTest.java deleted file mode 100644 index 09af2b0a52..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/TasksRequestTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.apihandlerinfra.tasksbeans; - -import org.junit.After; -import static org.junit.Assert.assertTrue; -import org.junit.Before; -import org.junit.Test; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - - -public class TasksRequestTest { - TasksRequest _tasksRequest; - private RequestDetails _requestDetails; - - public TasksRequestTest() { - } - - @Before - public void setUp() { - _tasksRequest = mock(TasksRequest.class); - _requestDetails = new RequestDetails(); - when(_tasksRequest.getRequestDetails()).thenReturn(_requestDetails); - } - - @After - public void tearDown() { - _tasksRequest = null; - } - - /** - * Test of getRequestDetails method - */ - @Test - public void testGetRequestDetails() { - _tasksRequest.setRequestDetails(_requestDetails); - assertTrue(_tasksRequest.getRequestDetails().equals(_requestDetails)); - - } - - /** - * Test setRequestDetails - */ - @Test - public void testSetRequestDetails() { - _tasksRequest.setRequestDetails(_requestDetails); - verify(_tasksRequest).setRequestDetails(_requestDetails); - } - -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/VariablesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/VariablesTest.java deleted file mode 100644 index d79e5f6294..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tasksbeans/VariablesTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.apihandlerinfra.tasksbeans; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static org.junit.Assert.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class VariablesTest { - - Variables _variables; - protected Value _source; - protected Value _responseValue; - protected Value _requestorId; - - @Before - public void setUp() { - _variables = mock(Variables.class); - _source = mock(Value.class); - _responseValue = mock(Value.class); - _requestorId = mock(Value.class); - - when(_variables.getSource()).thenReturn(_source); - when(_variables.getRequestorId()).thenReturn(_requestorId); - when(_variables.getResponseValue()).thenReturn(_responseValue); - - } - - @After - public void tearDown() { - _variables = null; - _source = null; - _responseValue = null; - _requestorId = null; - } - - @Test - public void testGetSource() { - _variables.setSource(_source); - assertTrue(_variables.getSource().equals(_source)); - } - - @Test - public void testSetSource(){ - _variables.setSource(_source); - verify(_variables).setSource(_source); - } - - @Test - public void testGetResponseValue() { - _variables.setResponseValue(_responseValue); - assertTrue(_variables.getResponseValue().equals(_responseValue)); - } - - @Test - public void testSetResponseValue(){ - _variables.setResponseValue(_responseValue); - verify(_variables).setResponseValue(_responseValue); - } - - @Test - public void testGetRequestorId() { - _variables.setRequestorId(_requestorId); - assertTrue(_variables.getRequestorId().equals(_requestorId)); - } - - @Test - public void testSetRequestorId(){ - _variables.setRequestorId(_requestorId); - verify(_variables).setRequestorId(_requestorId); - } - -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequestTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequestTest.java index 37ec14a0b5..9a8f4880f7 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequestTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequestTest.java @@ -25,9 +25,9 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.contains; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.contains; import static org.mockito.Mockito.doNothing; import javax.inject.Provider; @@ -43,7 +43,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.apihandler.common.ErrorNumbers; import org.onap.so.apihandlerinfra.ApiHandlerApplication; import org.onap.so.apihandlerinfra.BaseTest; diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/AAIClientHelperTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/AAIClientHelperTest.java index 9aa961c665..0a57b4f245 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/AAIClientHelperTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/AAIClientHelperTest.java @@ -28,8 +28,8 @@ import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelperTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelperTest.java index 7fd92d2d7e..76bf0b0dbc 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelperTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelperTest.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -41,9 +41,9 @@ public class SDCClientHelperTest extends BaseTest{ String operationalEnvironmentId = "TEST_operationalEnvironmentId"; String workloadContext = "TEST_workloadContext"; - @Autowired - private SDCClientHelper sdcClientUtils; - + @Autowired + private SDCClientHelper sdcClientUtils; + @Test public void postActivateOperationalEnvironment_Test() throws ApiException { @@ -51,77 +51,77 @@ public class SDCClientHelperTest extends BaseTest{ jsonObject.put("statusCode", "202"); jsonObject.put("message", "Success"); jsonObject.put("distributionId", "TEST_distributionId"); - + stubFor(post(urlPathMatching("/sdc/v1/catalog/services/TEST_uuid1/distr.*")) .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(jsonObject.toString()).withStatus(HttpStatus.SC_ACCEPTED))); - + JSONObject jsonResponse = sdcClientUtils.postActivateOperationalEnvironment(serviceModelVersionId, operationalEnvironmentId, workloadContext); - + assertEquals("202", jsonResponse.get("statusCode")); assertEquals("Success", jsonResponse.get("message")); - } - + } + @Test public void postActivateOperationalEnvironment_InvalidJson_Test() throws ApiException { - + // ERROR in asdc response, invalid json object JSONObject jsonErrorResponse = new JSONObject(); - jsonErrorResponse.put("requestError", ""); - + jsonErrorResponse.put("requestError", ""); + stubFor(post(urlPathMatching("/sdc/v1/catalog/services/TEST_uuid1/distr.*")) .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(jsonErrorResponse.toString()).withStatus(HttpStatus.SC_BAD_REQUEST))); - + JSONObject jsonResponse = sdcClientUtils.postActivateOperationalEnvironment(serviceModelVersionId, operationalEnvironmentId, workloadContext); - + assertEquals("500", jsonResponse.get("statusCode")); assertEquals("", jsonResponse.get("messageId")); assertEquals(" Encountered Error while calling SDC POST Activate. JSONObject[\"requestError\"] is not a JSONObject.", jsonResponse.get("message")); - } - + } + @Test public void buildUriBuilderTest() { - - try { + + try { String url = sdcClientUtils.buildUriBuilder(serviceModelVersionId, operationalEnvironmentId); assertEquals("http://localhost:" + env.getProperty("wiremock.server.port") + "/sdc/v1/catalog/services/TEST_uuid1/distribution/TEST_operationalEnvironmentId/activate", url); - + } catch (Exception e) { fail("Exception caught: " + e.getMessage()); - } - } + } + } + - @Test public void buildJsonWorkloadContextTest() throws JSONException { - + String jsonPayload = sdcClientUtils.buildJsonWorkloadContext(workloadContext); assertEquals("{\"workloadContext\":\"TEST_workloadContext\"}", jsonPayload); - - } - + + } + @Test public void enhanceJsonResponseTest_Success() throws JSONException { - + // build success response data JSONObject sdcResponseJsonObj = new JSONObject(); sdcResponseJsonObj.put("distributionId", "TEST_distributionId"); int statusCode = 202; sdcResponseJsonObj = sdcClientUtils.enhanceJsonResponse(sdcResponseJsonObj, statusCode); - + assertEquals("202", sdcResponseJsonObj.getString("statusCode")); assertEquals("", sdcResponseJsonObj.getString("messageId")); assertEquals("Success", sdcResponseJsonObj.getString("message")); assertEquals("TEST_distributionId", sdcResponseJsonObj.getString("distributionId")); - - } - + + } + @Test public void enhanceJsonResponseTest_Error() throws JSONException { - + // build error response data JSONObject jsonMessages = new JSONObject(); jsonMessages.put("messageId", "SVC4675"); @@ -132,20 +132,20 @@ public class SDCClientHelperTest extends BaseTest{ jsonErrorRequest.put("requestError", jsonServException); String responseData = jsonErrorRequest.toString(); - + JSONObject sdcResponseJsonObj = new JSONObject(responseData); int statusCode = 409; sdcResponseJsonObj = sdcClientUtils.enhanceJsonResponse(sdcResponseJsonObj, statusCode); - + assertEquals("409", sdcResponseJsonObj.getString("statusCode")); assertEquals("SVC4675", sdcResponseJsonObj.getString("messageId")); assertEquals("Error: Service state is invalid for this action.", sdcResponseJsonObj.getString("message")); - - } + + } @Test public void enhanceJsonResponseTest_Error_policyException() throws JSONException { - + // build error response data JSONObject jsonMessages = new JSONObject(); jsonMessages.put("messageId", "POL5003"); @@ -156,20 +156,20 @@ public class SDCClientHelperTest extends BaseTest{ jsonErrorRequest.put("requestError", jsonServException); String responseData = jsonErrorRequest.toString(); - + JSONObject sdcResponseJsonObj = new JSONObject(responseData); int statusCode = 403; sdcResponseJsonObj = sdcClientUtils.enhanceJsonResponse(sdcResponseJsonObj, statusCode); - + assertEquals("403", sdcResponseJsonObj.getString("statusCode")); assertEquals("POL5003", sdcResponseJsonObj.getString("messageId")); assertEquals("Error: Not authorized to use the API.", sdcResponseJsonObj.getString("message")); - - } - + + } + @Test public void enhanceJsonResponseTest_Error_UnexpectedFormat() throws JSONException { - + // build error response data JSONObject jsonMessages = new JSONObject(); jsonMessages.put("messageId", "POL5003"); @@ -180,15 +180,15 @@ public class SDCClientHelperTest extends BaseTest{ jsonErrorRequest.put("unexpectedResponseTag", jsonServException); String responseData = jsonErrorRequest.toString(); - + JSONObject sdcResponseJsonObj = new JSONObject(responseData); int statusCode = 403; sdcResponseJsonObj = sdcClientUtils.enhanceJsonResponse(sdcResponseJsonObj, statusCode); - + assertEquals("500", sdcResponseJsonObj.getString("statusCode")); assertEquals("Undefined Error Message!", sdcResponseJsonObj.getString("messageId")); assertEquals("Unexpected response format from SDC.", sdcResponseJsonObj.getString("message")); - - } - + + } + } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironmentTest.java index 585eff23c4..ce1dde835d 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironmentTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironmentTest.java @@ -89,7 +89,7 @@ public class CreateEcompOperationalEnvironmentTest extends BaseTest{ .withBody(mapper.writeValueAsString(iar)) .withStatus(HttpStatus.SC_OK))); stubFor(post(urlPathEqualTo("/infraActiveRequests/")) - .withRequestBody(containing("{\"requestId\":\"123\",\"clientRequestId\":null,\"action\":null,\"requestStatus\":\"COMPLETE\",\"statusMessage\":\"SUCCESSFUL, operationalEnvironmentId - operationalEnvId; Success Message: SUCCESSFULLY Created ECOMP OperationalEnvironment.\",\"progress\":100")) + .withRequestBody(containing("{\"requestId\":\"123\",\"clientRequestId\":null,\"action\":null,\"requestStatus\":\"COMPLETE\",\"statusMessage\":\"SUCCESSFUL, operationalEnvironmentId - operationalEnvId; Success Message: SUCCESSFULLY Created ECOMP OperationalEnvironment.\",\"rollbackStatusMessage\":null,\"flowStatus\":null,\"retryStatusMessage\":null,\"progress\":100")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withStatus(HttpStatus.SC_OK))); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironmentTest.java index 809e39c772..100bc82f7a 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironmentTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironmentTest.java @@ -52,6 +52,7 @@ public class CreateVnfOperationalEnvironmentTest extends BaseTest{ private CloudOrchestrationRequest request; private ServiceEndPointList serviceEndpoints; + private ServiceEndPointList serviceEndpoints2; @Autowired private CreateVnfOperationalEnvironment createVnfOpEnv; @@ -63,6 +64,8 @@ public class CreateVnfOperationalEnvironmentTest extends BaseTest{ request = mapper.readValue(jsonRequest, CloudOrchestrationRequest.class); String jsonServiceEndpoints = getFileContentsAsString("__files/vnfoperenv/endpoints.json"); serviceEndpoints = mapper.readValue(jsonServiceEndpoints, ServiceEndPointList.class); + String jsonServiceEndpoints2 = getFileContentsAsString("__files/vnfoperenv/endpoints2.json"); + serviceEndpoints2 = mapper.readValue(jsonServiceEndpoints2, ServiceEndPointList.class); } @Test public void testGetEcompManagingEnvironmentId() throws Exception { @@ -83,6 +86,13 @@ public class CreateVnfOperationalEnvironmentTest extends BaseTest{ assertEquals("DEV", createVnfOpEnv.getEnvironmentName(props)); } + @Test + public void testGetEnvironmentNameEndpointListBeginWithUpperCase() { + createVnfOpEnv.setRequest(request); + List<Property> props = serviceEndpoints2.getServiceEndPointList().get(0).getProperties(); + assertEquals("DEV", createVnfOpEnv.getEnvironmentName(props)); + } + @Test public void testBuildServiceNameForVnf() throws Exception { createVnfOpEnv.setRequest(request); @@ -141,4 +151,34 @@ public class CreateVnfOperationalEnvironmentTest extends BaseTest{ .withStatus(HttpStatus.SC_OK))); createVnfOpEnv.execute(requestId, request); } + + @Test + public void testExecuteEndpointsListBeginWithUppercase() throws ApiException, JsonProcessingException { + stubFor(get(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("vnfoperenv/ecompOperationalEnvironment.json").withStatus(HttpStatus.SC_ACCEPTED))); + stubFor(post(urlPathMatching("/GRMLWPService/v1/serviceEndPoint/findRunning")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("vnfoperenv/endpoints2.json").withStatus(HttpStatus.SC_ACCEPTED))); + stubFor(post(urlPathMatching("/GRMLWPService/v1/serviceEndPoint/add")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_ACCEPTED))); + stubFor(put(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("vnfoperenv/ecompOperationalEnvironment.json").withStatus(HttpStatus.SC_ACCEPTED))); + String requestId = UUID.randomUUID().toString(); + InfraActiveRequests iar = new InfraActiveRequests(); + iar.setRequestId(requestId); + iar.setOperationalEnvName("myOpEnv"); + iar.setRequestScope("create"); + iar.setRequestStatus("PENDING"); + iar.setRequestAction("UNKNOWN"); + ObjectMapper mapper = new ObjectMapper(); + stubFor(post(urlPathEqualTo("/infraActiveRequests/")) + .withRequestBody(containing("{\"requestId\":\""+ requestId+"\",\"clientRequestId\":null,\"action\":null,\"requestStatus\":\"COMPLETE\",\"statusMessage\":\"SUCCESSFUL")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlPathEqualTo("/infraActiveRequests/"+requestId)) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(iar)) + .withStatus(HttpStatus.SC_OK))); + createVnfOpEnv.execute(requestId, request); + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/validation/UserParamsValidationTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/validation/UserParamsValidationTest.java new file mode 100644 index 0000000000..c1c4915672 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/validation/UserParamsValidationTest.java @@ -0,0 +1,109 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.apihandlerinfra.validation; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Map; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.so.apihandlerinfra.Action; +import org.onap.so.exceptions.ValidationException; +import org.onap.so.serviceinstancebeans.Service; +import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class UserParamsValidationTest{ + + UserParamsValidation validation = new UserParamsValidation(); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + public ValidationInformation setupValidationInformation(String path) throws IOException{ + String jsonInput = new String(Files.readAllBytes(Paths.get(path))); + ObjectMapper mapper = new ObjectMapper(); + ServiceInstancesRequest sir = mapper.readValue(jsonInput, ServiceInstancesRequest.class); + ValidationInformation info = new ValidationInformation(sir, null, Action.createInstance, 7, false, sir.getRequestDetails().getRequestParameters()); + for(Map<String, Object> params : sir.getRequestDetails().getRequestParameters().getUserParams()){ + ObjectMapper obj = new ObjectMapper(); + String input = obj.writeValueAsString(params.get("service")); + Service validate = obj.readValue(input, Service.class); + info.setUserParams(validate); + break; + } + info.setRequestInfo(sir.getRequestDetails().getRequestInfo()); + return info; + } + + @Test + public void validateModelTypeExceptionTest() throws IOException, ValidationException{ + thrown.expect(ValidationException.class); + thrown.expectMessage("No valid modelType in userParams service modelInfo is specified"); + validation.validate(setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelInfoNoModelType.json")); + } + @Test + public void validateInstanceNameExceptionTest() throws IOException, ValidationException{ + thrown.expect(ValidationException.class); + thrown.expectMessage("instanceName in requestInfo does not match instanceName in userParams service"); + validation.validate(setupValidationInformation("src/test/resources/Validation/UserParamsValidation/MacroRequest.json")); + } + @Test + public void validateModelTypeTest() throws ValidationException, IOException{ + thrown.expect(ValidationException.class); + thrown.expectMessage("modelType in modelInfo does not match modelType in userParams service"); + validation.validate(setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelType.json")); + } + @Test + public void validateModelInvariantIdTest() throws ValidationException, IOException{ + thrown.expect(ValidationException.class); + thrown.expectMessage("modelInvariantId in modelInfo does not match modelInvariantId in userParams service"); + validation.validate(setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelInvariantId.json")); + } + @Test + public void validateModelVersionIdTest() throws ValidationException, IOException{ + thrown.expect(ValidationException.class); + thrown.expectMessage("modelVersionId in modelInfo does not match modelVersionId in userParams service"); + validation.validate(setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelVersionId.json")); + } + @Test + public void validateModelNameTest() throws ValidationException, IOException{ + thrown.expect(ValidationException.class); + thrown.expectMessage("modelName in modelInfo does not match modelName in userParams service"); + validation.validate(setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelName.json")); + } + @Test + public void validateModelVersionTest() throws ValidationException, IOException{ + thrown.expect(ValidationException.class); + thrown.expectMessage("modelVersion in modelInfo does not match modelVersion in userParams service"); + validation.validate(setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelVersion.json")); + } + @Test + public void validateModelCustomizationIdTest() throws ValidationException, IOException{ + thrown.expect(ValidationException.class); + thrown.expectMessage("modelCustomizationId in modelInfo does not match modelCustomizationId in userParams service"); + validation.validate(setupValidationInformation("src/test/resources/Validation/UserParamsValidation/ModelCustomizationId.json")); + } +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/client/grm/GRMClientTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/client/grm/GRMClientTest.java new file mode 100644 index 0000000000..6555a9a66e --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/client/grm/GRMClientTest.java @@ -0,0 +1,172 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.grm; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; +import static com.github.tomakehurst.wiremock.client.WireMock.matching; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.client.WireMock.verify; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import java.io.File; +import java.nio.file.Files; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.MediaType; + +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.onap.so.apihandlerinfra.BaseTest; +import org.onap.so.apihandlerinfra.TestAppender; +import org.onap.so.client.grm.GRMClient; +import org.onap.so.client.grm.beans.ServiceEndPoint; +import org.onap.so.client.grm.beans.ServiceEndPointList; +import org.onap.so.client.grm.beans.ServiceEndPointLookupRequest; +import org.onap.so.client.grm.beans.ServiceEndPointRequest; +import org.onap.so.client.grm.exceptions.GRMClientCallFailed; +import org.slf4j.MDC; + +import ch.qos.logback.classic.spi.ILoggingEvent; + + +public class GRMClientTest extends BaseTest{ + + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private static final String uuidRegex = "(?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-5][0-9a-f]{3}-?[089ab][0-9a-f]{3}-?[0-9a-f]{12}$"; + + @BeforeClass + public static void setUp() throws Exception { + System.setProperty("mso.config.path", "src/test/resources"); + } + + @Test + public void testFind() throws Exception { + TestAppender.events.clear(); + String endpoints = getFileContentsAsString("__files/grm/endpoints.json"); + stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", MediaType.APPLICATION_JSON) + .withBody(endpoints))); + + MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, "/test"); + GRMClient client = new GRMClient(); + ServiceEndPointList sel = client.findRunningServices("TEST.ECOMP_PSL.*", 1, "TEST"); + List<ServiceEndPoint> list = sel.getServiceEndPointList(); + assertEquals(3, list.size()); + + boolean foundInvoke = false; + boolean foundInvokeReturn = false; + for(ILoggingEvent logEvent : TestAppender.events) + if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.JaxRsClientLogging") && + logEvent.getMarker() != null && logEvent.getMarker().getName().equals("INVOKE") + ){ + Map<String,String> mdc = logEvent.getMDCPropertyMap(); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID)); + assertEquals("GRM",mdc.get("TargetEntity")); + assertEquals("INPROGRESS",mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); + foundInvoke=true; + }else if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.JaxRsClientLogging") && + logEvent.getMarker()!= null && logEvent.getMarker().getName().equals("INVOKE_RETURN")){ + Map<String,String> mdc = logEvent.getMDCPropertyMap(); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID)); + assertEquals("200",mdc.get(ONAPLogConstants.MDCs.RESPONSE_CODE)); + assertEquals("COMPLETED",mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); + foundInvokeReturn=true; + } + + if(!foundInvoke) + fail("INVOKE Marker not found"); + + if(!foundInvokeReturn) + fail("INVOKE RETURN Marker not found"); + + verify(postRequestedFor(urlEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning")) + .withHeader(ONAPLogConstants.Headers.INVOCATION_ID.toString(), matching(uuidRegex)) + .withHeader(ONAPLogConstants.Headers.REQUEST_ID.toString(), matching(uuidRegex)) + .withHeader(ONAPLogConstants.Headers.PARTNER_NAME.toString(), equalTo("SO"))); + TestAppender.events.clear(); + } + + @Test + public void testFindFail() throws Exception { + stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning")) + .willReturn(aResponse() + .withStatus(400) + .withHeader("Content-Type", MediaType.APPLICATION_JSON) + .withBody(""))); + + GRMClient client = new GRMClient(); + thrown.expect(GRMClientCallFailed.class); + client.findRunningServices("TEST.ECOMP_PSL.*", 1, "TEST"); + } + + @Test + public void testAddFail() throws Exception { + stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/add")) + .willReturn(aResponse() + .withStatus(404) + .withHeader("Content-Type", MediaType.APPLICATION_JSON) + .withBody("test"))); + ServiceEndPointRequest request = new ServiceEndPointRequest(); + GRMClient client = new GRMClient(); + thrown.expect(GRMClientCallFailed.class); + client.addServiceEndPoint(request); + } + + @Test + public void testBuildServiceEndPointLookupRequest() { + GRMClient client = new GRMClient(); + ServiceEndPointLookupRequest request = client.buildServiceEndPointlookupRequest("TEST.ECOMP_PSL.Inventory", 1, "DEV"); + assertEquals("TEST.ECOMP_PSL.Inventory", request.getServiceEndPoint().getName()); + assertEquals(Integer.valueOf(1), Integer.valueOf(request.getServiceEndPoint().getVersion().getMajor())); + assertEquals("DEV", request.getEnv()); + + } + + protected String getFileContentsAsString(String fileName) { + String content = ""; + try { + ClassLoader classLoader = this.getClass().getClassLoader(); + File file = new File(classLoader.getResource(fileName).getFile()); + content = new String(Files.readAllBytes(file.toPath())); + } + catch(Exception e) { + e.printStackTrace(); + System.out.println("Exception encountered reading " + fileName + ". Error: " + e.getMessage()); + } + return content; + } +} |