Search in sources :

Example 81 with User

use of org.wso2.carbon.identity.application.common.model.xsd.User in project carbon-apimgt by wso2.

the class EndpointsApiServiceImplTestCase method testEndpointsEndpointIdGetException.

@Test
public void testEndpointsEndpointIdGetException() throws Exception {
    printTestMethodName();
    EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Endpoint endpoint = SampleTestObjectCreator.createMockEndpoint();
    String endpointId = endpoint.getId();
    Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.APPLICATION_INACTIVE)).when(apiPublisher).getEndpoint(endpointId);
    Response response = endpointsApiService.endpointsEndpointIdGet(endpointId, null, null, getRequest());
    assertEquals(response.getStatus(), 400);
    assertTrue(response.getEntity().toString().contains("Application is not active"));
}
Also used : Response(javax.ws.rs.core.Response) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 82 with User

use of org.wso2.carbon.identity.application.common.model.xsd.User in project carbon-apimgt by wso2.

the class EndpointsApiServiceImplTestCase method getRequest.

// Sample request to be used by tests
private Request getRequest() throws Exception {
    HTTPCarbonMessage carbonMessage = Mockito.mock(HTTPCarbonMessage.class);
    Mockito.when(carbonMessage.getProperty("LOGGED_IN_USER")).thenReturn(USER);
    Request request = new Request(carbonMessage);
    return request;
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) Request(org.wso2.msf4j.Request)

Example 83 with User

use of org.wso2.carbon.identity.application.common.model.xsd.User in project carbon-apimgt by wso2.

the class EndpointsApiServiceImplTestCase method testEndpointsEndpointIdPutException.

@Test
public void testEndpointsEndpointIdPutException() throws Exception {
    printTestMethodName();
    EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Endpoint endpoint = SampleTestObjectCreator.createMockEndpoint();
    String endpointId = endpoint.getId();
    EndPointDTO endPointDTO = MappingUtil.toEndPointDTO(endpoint);
    Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.ENDPOINT_ALREADY_EXISTS)).when(apiPublisher).getEndpoint(endpointId);
    Response response = endpointsApiService.endpointsEndpointIdPut(endpointId, endPointDTO, null, null, getRequest());
    assertEquals(response.getStatus(), 409);
    assertTrue(response.getEntity().toString().contains("Endpoint already exists"));
}
Also used : Response(javax.ws.rs.core.Response) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) EndPointDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 84 with User

use of org.wso2.carbon.identity.application.common.model.xsd.User in project carbon-apimgt by wso2.

the class EndpointsApiServiceImplTestCase method testEndpointsEndpointIdPutNotExist.

@Test
public void testEndpointsEndpointIdPutNotExist() throws Exception {
    printTestMethodName();
    EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Endpoint endpoint = SampleTestObjectCreator.createMockEndpoint();
    EndPointDTO endPointDTO = MappingUtil.toEndPointDTO(endpoint);
    String endpointId = endpoint.getId();
    Mockito.doReturn(null).doThrow(new IllegalArgumentException()).when(apiPublisher).getEndpoint(endpointId);
    Response response = endpointsApiService.endpointsEndpointIdPut(endpointId, endPointDTO, null, null, getRequest());
    assertEquals(response.getStatus(), 404);
    assertTrue(response.getEntity().toString().contains("Endpoint Not Found"));
}
Also used : Response(javax.ws.rs.core.Response) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) EndPointDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 85 with User

use of org.wso2.carbon.identity.application.common.model.xsd.User in project carbon-apimgt by wso2.

the class PoliciesApiServiceImplTestCase method testPoliciesTierLevelTierNameGet.

@Test
public void testPoliciesTierLevelTierNameGet() throws Exception {
    printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Policy gold = SampleTestObjectCreator.goldSubscriptionPolicy;
    Mockito.doReturn(gold).doThrow(new IllegalArgumentException()).when(apiPublisher).getPolicyByName(RestApiUtil.mapRestApiPolicyLevelToPolicyLevelEnum("subscription"), "Gold");
    Response response = policiesApiService.policiesTierLevelTierNameGet("Gold", "subscription", null, null, getRequest());
    assertEquals(response.getStatus(), 200);
    assertTrue(response.getEntity().toString().contains("Gold"));
}
Also used : Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) Response(javax.ws.rs.core.Response) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Test (org.testng.annotations.Test)423 ArrayList (java.util.ArrayList)323 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)322 HashMap (java.util.HashMap)311 UserStoreException (org.wso2.carbon.user.api.UserStoreException)286 Test (org.junit.Test)272 Response (javax.ws.rs.core.Response)233 SQLException (java.sql.SQLException)166 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)158 PreparedStatement (java.sql.PreparedStatement)151 Connection (java.sql.Connection)148 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)134 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)130 Map (java.util.Map)115 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)114 User (org.wso2.charon3.core.objects.User)114 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)112 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)105 Request (org.wso2.msf4j.Request)105 UserStoreException (org.wso2.carbon.user.core.UserStoreException)103