diff options
Diffstat (limited to 'so-monitoring/so-monitoring-service/src')
2 files changed, 47 insertions, 55 deletions
diff --git a/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/SoMonitoringController.java b/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/SoMonitoringController.java index 155b4e65a4..d2fa08fdfd 100644 --- a/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/SoMonitoringController.java +++ b/so-monitoring/so-monitoring-service/src/main/java/org/onap/so/monitoring/rest/api/SoMonitoringController.java @@ -33,8 +33,6 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import org.onap.so.monitoring.db.service.DatabaseServiceProvider; -import org.onap.so.monitoring.exception.InvalidRestRequestException; -import org.onap.so.monitoring.exception.RestProcessingException; import org.onap.so.monitoring.model.ActivityInstanceDetail; import org.onap.so.monitoring.model.ProcessDefinitionDetail; import org.onap.so.monitoring.model.ProcessInstanceDetail; @@ -42,14 +40,15 @@ import org.onap.so.monitoring.model.ProcessInstanceIdDetail; import org.onap.so.monitoring.model.ProcessInstanceVariableDetail; import org.onap.so.monitoring.model.SoInfraRequest; import org.onap.so.monitoring.rest.service.CamundaProcessDataServiceProvider; +import org.onap.so.rest.exceptions.InvalidRestRequestException; +import org.onap.so.rest.exceptions.RestProcessingException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.google.common.base.Optional; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * @author waqas.ikram@ericsson.com */ @@ -134,8 +133,7 @@ public class SoMonitoringController { @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Response getProcessDefinitionXml(final @PathParam("processDefinitionId") String processDefinitionId) { if (processDefinitionId == null || processDefinitionId.isEmpty()) { - return Response.status(Status.BAD_REQUEST).entity("Invalid process definition id: " + - processDefinitionId) + return Response.status(Status.BAD_REQUEST).entity("Invalid process definition id: " + processDefinitionId) .build(); } try { @@ -145,18 +143,15 @@ public class SoMonitoringController { final ProcessDefinitionDetail definitionDetail = response.get(); return Response.status(Status.OK).entity(definitionDetail).build(); } - LOGGER.error("Unable to find process definition xml for processDefinitionId: " + - processDefinitionId); + LOGGER.error("Unable to find process definition xml for processDefinitionId: " + processDefinitionId); return Response.status(Status.NO_CONTENT).build(); } catch (final InvalidRestRequestException extensions) { final String message = - "Unable to find process definition xml for processDefinitionId: {}" + - processDefinitionId; + "Unable to find process definition xml for processDefinitionId: {}" + processDefinitionId; return Response.status(Status.BAD_REQUEST).entity(message).build(); } catch (final RestProcessingException restProcessingException) { - final String message = "Unable to get process definition xml for id: " + - processDefinitionId; + final String message = "Unable to get process definition xml for id: " + processDefinitionId; LOGGER.error(message); return Response.status(Status.INTERNAL_SERVER_ERROR).entity(message).build(); } @@ -175,13 +170,11 @@ public class SoMonitoringController { camundaProcessDataServiceProvider.getActivityInstance(processInstanceId); return Response.status(Status.OK).entity(activityInstanceDetails).build(); } catch (final InvalidRestRequestException extensions) { - final String message = "Unable to find activity instance for processInstanceId: " + - processInstanceId; + final String message = "Unable to find activity instance for processInstanceId: " + processInstanceId; LOGGER.error(message); return Response.status(Status.BAD_REQUEST).entity(message).build(); } catch (final RestProcessingException restProcessingException) { - final String message = "Unable to get activity instance detail for id: " + - processInstanceId; + final String message = "Unable to get activity instance detail for id: " + processInstanceId; LOGGER.error(message); return Response.status(Status.INTERNAL_SERVER_ERROR).entity(message).build(); } @@ -201,13 +194,11 @@ public class SoMonitoringController { return Response.status(Status.OK).entity(processInstanceVariable).build(); } catch (final InvalidRestRequestException extensions) { final String message = - "Unable to find process instance variables for processInstanceId: " + - processInstanceId; + "Unable to find process instance variables for processInstanceId: " + processInstanceId; LOGGER.error(message); return Response.status(Status.BAD_REQUEST).entity(message).build(); } catch (final RestProcessingException restProcessingException) { - final String message = "Unable to get process instance variables for id: " + - processInstanceId; + final String message = "Unable to get process instance variables for id: " + processInstanceId; LOGGER.error(message); return Response.status(Status.INTERNAL_SERVER_ERROR).entity(message).build(); } @@ -230,13 +221,13 @@ public class SoMonitoringController { return Response.status(Status.OK).entity(requests).build(); } catch (final InvalidRestRequestException extensions) { - final String message = "Unable to search request for filters: " + filters + ", from: " + - startTime + ", to: " + endTime + ", maxResult: " + maxResult; + final String message = "Unable to search request for filters: " + filters + ", from: " + startTime + + ", to: " + endTime + ", maxResult: " + maxResult; LOGGER.error(message); return Response.status(Status.BAD_REQUEST).entity(message).build(); } catch (final RestProcessingException restProcessingException) { - final String message = "Unable to search request for filters: " + filters + ", from: " + - startTime + ", to: " + endTime + ", maxResult: " + maxResult; + final String message = "Unable to search request for filters: " + filters + ", from: " + startTime + + ", to: " + endTime + ", maxResult: " + maxResult; LOGGER.error(message); return Response.status(Status.INTERNAL_SERVER_ERROR).entity(message).build(); } diff --git a/so-monitoring/so-monitoring-service/src/test/java/org/onap/so/monitoring/rest/api/SoMonitoringControllerTest.java b/so-monitoring/so-monitoring-service/src/test/java/org/onap/so/monitoring/rest/api/SoMonitoringControllerTest.java index 3ca184ebaa..2c4d036397 100644 --- a/so-monitoring/so-monitoring-service/src/test/java/org/onap/so/monitoring/rest/api/SoMonitoringControllerTest.java +++ b/so-monitoring/so-monitoring-service/src/test/java/org/onap/so/monitoring/rest/api/SoMonitoringControllerTest.java @@ -22,8 +22,8 @@ package org.onap.so.monitoring.rest.api; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.onap.so.monitoring.configuration.rest.RestTemplateConfiguration.CAMUNDA_REST_TEMPLATE; -import static org.onap.so.monitoring.configuration.rest.RestTemplateConfiguration.DATABASE_REST_TEMPLATE; +import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; +import static org.onap.so.configuration.rest.BasicHttpHeadersProvider.AUTHORIZATION_HEADER; import static org.onap.so.monitoring.rest.api.Constants.ACTIVITY_INSTANCE_RESPONSE_JSON_FILE; import static org.onap.so.monitoring.rest.api.Constants.EMPTY_ARRAY_RESPONSE; import static org.onap.so.monitoring.rest.api.Constants.EMPTY_STRING; @@ -37,6 +37,7 @@ import static org.onap.so.monitoring.rest.api.Constants.PROCRESS_DEF_ID; import static org.onap.so.monitoring.rest.api.Constants.SEARCH_RESULT_RESPONSE_JSON_FILE; import static org.onap.so.monitoring.rest.api.Constants.SINGLE_PROCCESS_INSTANCE_RESPONSE_JSON_FILE; import static org.onap.so.monitoring.rest.api.Constants.START_TIME_IN_MS; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.header; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withBadRequest; import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; @@ -81,14 +82,14 @@ import org.springframework.web.client.RestTemplate; @ActiveProfiles("test") @SpringBootTest public class SoMonitoringControllerTest { + private static final String CAMUNDA_BASIC_AUTH = + "Basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ=="; - @Autowired - @Qualifier(CAMUNDA_REST_TEMPLATE) - private RestTemplate restTemplate; + private static final String DATABASE_BASIC_AUTH = "Basic YnBlbDpwYXNzd29yZDEk"; @Autowired - @Qualifier(DATABASE_REST_TEMPLATE) - private RestTemplate dataBaseRestTemplate; + @Qualifier(CONFIGURABLE_REST_TEMPLATE) + private RestTemplate restTemplate; @Autowired private CamundaRestUrlProvider urlProvider; @@ -96,23 +97,22 @@ public class SoMonitoringControllerTest { @Autowired private DatabaseUrlProvider databaseUrlProvider; - private MockRestServiceServer camundaMockServer; + private MockRestServiceServer mockRestServiceServer; - private MockRestServiceServer databaseMockServer; @Autowired private SoMonitoringController objUnderTest; @Before public void setUp() throws Exception { - camundaMockServer = MockRestServiceServer.bindTo(restTemplate).build(); - databaseMockServer = MockRestServiceServer.bindTo(dataBaseRestTemplate).build(); + mockRestServiceServer = MockRestServiceServer.bindTo(restTemplate).build(); } @Test public void test_GetProcessInstance_SuccessResponseWithDataFromCamunda() throws Exception { final String jsonString = getJsonResponse(PROCCESS_INSTANCE_RESPONSE_JSON_FILE); - this.camundaMockServer.expect(requestTo(urlProvider.getHistoryProcessInstanceUrl(ID))) + this.mockRestServiceServer.expect(requestTo(urlProvider.getHistoryProcessInstanceUrl(ID))) + .andExpect(header(AUTHORIZATION_HEADER, CAMUNDA_BASIC_AUTH)) .andRespond(withSuccess(jsonString, MediaType.APPLICATION_JSON)); final Response response = objUnderTest.getProcessInstanceId(ID); @@ -125,7 +125,7 @@ public class SoMonitoringControllerTest { @Test public void test_GetProcessInstance_SuccessResponseWithEmptyDataFromCamunda() throws Exception { final String jsonString = EMPTY_ARRAY_RESPONSE; - this.camundaMockServer.expect(requestTo(urlProvider.getHistoryProcessInstanceUrl(ID))) + this.mockRestServiceServer.expect(requestTo(urlProvider.getHistoryProcessInstanceUrl(ID))) .andRespond(withSuccess(jsonString, MediaType.APPLICATION_JSON)); final Response response = objUnderTest.getProcessInstanceId(ID); @@ -135,7 +135,7 @@ public class SoMonitoringControllerTest { @Test public void test_GetProcessInstance_FailureResponseWithEmptyDataFromCamunda() throws Exception { - this.camundaMockServer.expect(requestTo(urlProvider.getHistoryProcessInstanceUrl(ID))) + this.mockRestServiceServer.expect(requestTo(urlProvider.getHistoryProcessInstanceUrl(ID))) .andRespond(withBadRequest()); final Response response = objUnderTest.getProcessInstanceId(ID); @@ -144,7 +144,7 @@ public class SoMonitoringControllerTest { @Test public void test_GetProcessInstance_UnauthorizedRequestFromCamunda() throws Exception { - this.camundaMockServer.expect(requestTo(urlProvider.getHistoryProcessInstanceUrl(ID))) + this.mockRestServiceServer.expect(requestTo(urlProvider.getHistoryProcessInstanceUrl(ID))) .andRespond(withUnauthorizedRequest()); final Response response = objUnderTest.getProcessInstanceId(ID); @@ -155,7 +155,7 @@ public class SoMonitoringControllerTest { @Test public void test_GetSinlgeProcessInstance_SuccessResponseWithDataFromCamunda() throws Exception { final String jsonString = getJsonResponse(SINGLE_PROCCESS_INSTANCE_RESPONSE_JSON_FILE); - this.camundaMockServer.expect(requestTo(urlProvider.getSingleProcessInstanceUrl(PROCESS_INSTACE_ID))) + this.mockRestServiceServer.expect(requestTo(urlProvider.getSingleProcessInstanceUrl(PROCESS_INSTACE_ID))) .andRespond(withSuccess(jsonString, MediaType.APPLICATION_JSON)); final Response response = objUnderTest.getSingleProcessInstance(PROCESS_INSTACE_ID); @@ -171,7 +171,7 @@ public class SoMonitoringControllerTest { @Test public void test_GetSingleProcessInstance_WithBadRequestResponseFromCamunda() throws Exception { - this.camundaMockServer.expect(requestTo(urlProvider.getSingleProcessInstanceUrl(PROCESS_INSTACE_ID))) + this.mockRestServiceServer.expect(requestTo(urlProvider.getSingleProcessInstanceUrl(PROCESS_INSTACE_ID))) .andRespond(withBadRequest()); final Response response = objUnderTest.getSingleProcessInstance(PROCESS_INSTACE_ID); @@ -181,7 +181,7 @@ public class SoMonitoringControllerTest { @Test public void test_GetSingleProcessInstance_WithUnauthorizedRequestResponseFromCamunda() throws Exception { - this.camundaMockServer.expect(requestTo(urlProvider.getSingleProcessInstanceUrl(PROCESS_INSTACE_ID))) + this.mockRestServiceServer.expect(requestTo(urlProvider.getSingleProcessInstanceUrl(PROCESS_INSTACE_ID))) .andRespond(withUnauthorizedRequest()); final Response response = objUnderTest.getSingleProcessInstance(PROCESS_INSTACE_ID); @@ -216,7 +216,7 @@ public class SoMonitoringControllerTest { @Test public void test_GetProcessDefinitionXml_SuccessResponseWithDataFromCamunda() throws Exception { final String jsonString = getJsonResponse(PROCESS_DEF_RESPONSE_JSON_FILE); - this.camundaMockServer.expect(requestTo(urlProvider.getProcessDefinitionUrl(PROCRESS_DEF_ID))) + this.mockRestServiceServer.expect(requestTo(urlProvider.getProcessDefinitionUrl(PROCRESS_DEF_ID))) .andRespond(withSuccess(jsonString, MediaType.APPLICATION_JSON)); final Response response = objUnderTest.getProcessDefinitionXml(PROCRESS_DEF_ID); @@ -228,7 +228,7 @@ public class SoMonitoringControllerTest { @Test public void test_GetProcessDefinitionXml_BadRequestResponseFromCamunda() throws Exception { - this.camundaMockServer.expect(requestTo(urlProvider.getProcessDefinitionUrl(PROCRESS_DEF_ID))) + this.mockRestServiceServer.expect(requestTo(urlProvider.getProcessDefinitionUrl(PROCRESS_DEF_ID))) .andRespond(withBadRequest()); final Response response = objUnderTest.getProcessDefinitionXml(PROCRESS_DEF_ID); @@ -238,7 +238,7 @@ public class SoMonitoringControllerTest { @Test public void test_GetProcessDefinitionXml_UnauthorizedRequestFromCamunda() throws Exception { - this.camundaMockServer.expect(requestTo(urlProvider.getProcessDefinitionUrl(PROCRESS_DEF_ID))) + this.mockRestServiceServer.expect(requestTo(urlProvider.getProcessDefinitionUrl(PROCRESS_DEF_ID))) .andRespond(withUnauthorizedRequest()); final Response response = objUnderTest.getProcessDefinitionXml(PROCRESS_DEF_ID); @@ -260,7 +260,7 @@ public class SoMonitoringControllerTest { @Test public void test_GetActivityInstanceDetail_SuccessResponseWithDataFromCamunda() throws Exception { final String jsonString = getJsonResponse(ACTIVITY_INSTANCE_RESPONSE_JSON_FILE); - this.camundaMockServer.expect(requestTo(urlProvider.getActivityInstanceUrl(PROCESS_INSTACE_ID))) + this.mockRestServiceServer.expect(requestTo(urlProvider.getActivityInstanceUrl(PROCESS_INSTACE_ID))) .andRespond(withSuccess(jsonString, MediaType.APPLICATION_JSON)); final Response response = objUnderTest.getActivityInstanceDetail(PROCESS_INSTACE_ID); @@ -287,7 +287,7 @@ public class SoMonitoringControllerTest { @Test public void test_GetActivityInstanceDetail_SuccessResponseWithEmptyDataFromCamunda() throws Exception { - this.camundaMockServer.expect(requestTo(urlProvider.getActivityInstanceUrl(PROCESS_INSTACE_ID))) + this.mockRestServiceServer.expect(requestTo(urlProvider.getActivityInstanceUrl(PROCESS_INSTACE_ID))) .andRespond(withSuccess(EMPTY_ARRAY_RESPONSE, MediaType.APPLICATION_JSON)); final Response response = objUnderTest.getActivityInstanceDetail(PROCESS_INSTACE_ID); @@ -297,7 +297,7 @@ public class SoMonitoringControllerTest { @Test public void test_GetActivityInstanceDetail_UnauthorizedRequestFromCamunda() throws Exception { - this.camundaMockServer.expect(requestTo(urlProvider.getActivityInstanceUrl(PROCESS_INSTACE_ID))) + this.mockRestServiceServer.expect(requestTo(urlProvider.getActivityInstanceUrl(PROCESS_INSTACE_ID))) .andRespond(withUnauthorizedRequest()); final Response response = objUnderTest.getActivityInstanceDetail(PROCESS_INSTACE_ID); @@ -307,7 +307,7 @@ public class SoMonitoringControllerTest { @Test public void test_GetActivityInstanceDetail_BadRequestFromCamunda() throws Exception { - this.camundaMockServer.expect(requestTo(urlProvider.getActivityInstanceUrl(PROCESS_INSTACE_ID))) + this.mockRestServiceServer.expect(requestTo(urlProvider.getActivityInstanceUrl(PROCESS_INSTACE_ID))) .andRespond(withBadRequest()); final Response response = objUnderTest.getActivityInstanceDetail(PROCESS_INSTACE_ID); @@ -329,7 +329,7 @@ public class SoMonitoringControllerTest { @Test public void test_GetProcessInstanceVariables_SuccessResponseWithDataFromCamunda() throws Exception { final String jsonString = getJsonResponse(PROCESS_INSTANCE_VARIABLES_RESPONSE_JSON_FILE); - this.camundaMockServer.expect(requestTo(urlProvider.getProcessInstanceVariablesUrl(PROCESS_INSTACE_ID))) + this.mockRestServiceServer.expect(requestTo(urlProvider.getProcessInstanceVariablesUrl(PROCESS_INSTACE_ID))) .andRespond(withSuccess(jsonString, MediaType.APPLICATION_JSON)); final Response response = objUnderTest.getProcessInstanceVariables(PROCESS_INSTACE_ID); @@ -347,7 +347,7 @@ public class SoMonitoringControllerTest { @Test public void test_GetProcessInstanceVariables_SuccessResponseWithEmptyDataFromCamunda() throws Exception { - this.camundaMockServer.expect(requestTo(urlProvider.getProcessInstanceVariablesUrl(PROCESS_INSTACE_ID))) + this.mockRestServiceServer.expect(requestTo(urlProvider.getProcessInstanceVariablesUrl(PROCESS_INSTACE_ID))) .andRespond(withSuccess(EMPTY_ARRAY_RESPONSE, MediaType.APPLICATION_JSON)); final Response response = objUnderTest.getProcessInstanceVariables(PROCESS_INSTACE_ID); @@ -358,7 +358,7 @@ public class SoMonitoringControllerTest { @Test public void test_GetProcessInstanceVariables_BadRequestFromCamunda() throws Exception { - this.camundaMockServer.expect(requestTo(urlProvider.getProcessInstanceVariablesUrl(PROCESS_INSTACE_ID))) + this.mockRestServiceServer.expect(requestTo(urlProvider.getProcessInstanceVariablesUrl(PROCESS_INSTACE_ID))) .andRespond(withBadRequest()); final Response response = objUnderTest.getProcessInstanceVariables(PROCESS_INSTACE_ID); @@ -369,7 +369,7 @@ public class SoMonitoringControllerTest { @Test public void test_GetProcessInstanceVariables_UnauthorizedRequestFromCamunda() throws Exception { - this.camundaMockServer.expect(requestTo(urlProvider.getProcessInstanceVariablesUrl(PROCESS_INSTACE_ID))) + this.mockRestServiceServer.expect(requestTo(urlProvider.getProcessInstanceVariablesUrl(PROCESS_INSTACE_ID))) .andRespond(withUnauthorizedRequest()); final Response response = objUnderTest.getProcessInstanceVariables(PROCESS_INSTACE_ID); @@ -396,8 +396,9 @@ public class SoMonitoringControllerTest { @Test public void test_GetInfraActiveRequests_SuccessResponseWithSoInfraRequestList() throws Exception { final String jsonString = getJsonResponse(SEARCH_RESULT_RESPONSE_JSON_FILE); - this.databaseMockServer + this.mockRestServiceServer .expect(requestTo(databaseUrlProvider.getSearchUrl(START_TIME_IN_MS, END_TIME_IN_MS, null))) + .andExpect(header(AUTHORIZATION_HEADER, DATABASE_BASIC_AUTH)) .andRespond(withSuccess(jsonString, MediaType.APPLICATION_JSON)); final Response response = |