Search in sources :

Example 86 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class RestApiUtil method handleBadRequest.

/**
 * Logs the error, builds a BadRequestException with specified details and throws it
 *
 * @param msg error message
 * @param log Log instance
 * @throws BadRequestException If 400 bad request comes.
 */
public static void handleBadRequest(String msg, Logger log) throws BadRequestException {
    BadRequestException badRequestException = buildBadRequestException(msg);
    log.error(msg);
    throw badRequestException;
}
Also used : BadRequestException(org.wso2.carbon.apimgt.rest.api.common.exception.BadRequestException)

Example 87 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method apisApiIdGatewayConfigGetWhenGatewayConfigNullTestCase.

@Test
public void apisApiIdGatewayConfigGetWhenGatewayConfigNullTestCase() throws Exception {
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    String apiID = UUID.randomUUID().toString();
    String gatewayConfig = null;
    Mockito.when(adminService.getAPIGatewayServiceConfig(apiID)).thenReturn(gatewayConfig);
    APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
    PowerMockito.mockStatic(APIManagerFactory.class);
    PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
    Mockito.when(instance.getAPIMgtAdminService()).thenReturn(adminService);
    Response response = apisApiService.apisApiIdGatewayConfigGet(apiID, null, getRequest());
    Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 88 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class ApplicationsApiServiceImplTestCase method applicationsGetExceptionTestCase.

@Test
public void applicationsGetExceptionTestCase() throws Exception {
    ApplicationsApiServiceImpl applicationsApiService = new ApplicationsApiServiceImpl();
    String message = "Error while retrieving applications.";
    APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
    PowerMockito.mockStatic(APIManagerFactory.class);
    PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
    APIManagementException apiManagementException = new APIManagementException(message, ExceptionCodes.APPLICATION_NOT_FOUND);
    Mockito.when(instance.getAPIMgtAdminService()).thenThrow(apiManagementException);
    Response response = applicationsApiService.applicationsGet(null, getRequest());
    Assert.assertEquals(response.getStatus(), 404);
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 89 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class BlacklistApiServiceImplTestCase method applicationsGetExceptionTestCase.

@Test
public void applicationsGetExceptionTestCase() throws Exception {
    BlacklistApiServiceImpl blacklistApiService = new BlacklistApiServiceImpl();
    String message = "Error while retrieving applications.";
    APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
    PowerMockito.mockStatic(APIManagerFactory.class);
    PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
    APIManagementException apiManagementException = new APIManagementException(message, ExceptionCodes.APPLICATION_INACTIVE);
    Mockito.when(instance.getAPIMgtAdminService()).thenThrow(apiManagementException);
    Response response = blacklistApiService.blacklistGet(null, getRequest());
    Assert.assertEquals(response.getStatus(), 400);
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 90 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class EndpointsApiServiceImplTestCase method endpointsEndpointIdGatewayConfigGetExceptionTest.

@Test
public void endpointsEndpointIdGatewayConfigGetExceptionTest() throws Exception {
    EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
    String message = "Error while retrieving gateway configuration.";
    APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
    PowerMockito.mockStatic(APIManagerFactory.class);
    PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
    APIManagementException apiManagementException = new APIManagementException(message, ExceptionCodes.ENDPOINT_CONFIG_NOT_FOUND);
    Mockito.when(instance.getAPIMgtAdminService()).thenThrow(apiManagementException);
    String endpointId = UUID.randomUUID().toString();
    Response response = endpointsApiService.endpointsEndpointIdGatewayConfigGet(endpointId, null, getRequest());
    Assert.assertEquals(response.getStatus(), 404);
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ArrayList (java.util.ArrayList)28 Test (org.junit.Test)23 Response (javax.ws.rs.core.Response)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)21 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)20 HashMap (java.util.HashMap)15 Path (javax.ws.rs.Path)15 RuntimeService (org.activiti.engine.RuntimeService)15 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)15 InstanceManagementException (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException)14 Produces (javax.ws.rs.Produces)13 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)13 IOException (java.io.IOException)12 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)12 GET (javax.ws.rs.GET)11 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)11 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)10 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8