Search in sources :

Example 86 with APIPublisher

use of org.wso2.carbon.apimgt.core.api.APIPublisher 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 87 with APIPublisher

use of org.wso2.carbon.apimgt.core.api.APIPublisher 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 88 with APIPublisher

use of org.wso2.carbon.apimgt.core.api.APIPublisher 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 89 with APIPublisher

use of org.wso2.carbon.apimgt.core.api.APIPublisher 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)

Example 90 with APIPublisher

use of org.wso2.carbon.apimgt.core.api.APIPublisher in project carbon-apimgt by wso2.

the class PoliciesApiServiceImplTestCase method testPoliciesTierLevelTierNameGetException.

@Test
public void testPoliciesTierLevelTierNameGetException() throws Exception {
    printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Mockito.doThrow(new LabelException("Error occurred", ExceptionCodes.POLICY_LEVEL_NOT_SUPPORTED)).when(apiPublisher).getPolicyByName(RestApiUtil.mapRestApiPolicyLevelToPolicyLevelEnum("subscription"), "Gold");
    Response response = policiesApiService.policiesTierLevelTierNameGet("Gold", "subscription", null, null, getRequest());
    assertEquals(response.getStatus(), 400);
    assertTrue(response.getEntity().toString().contains("Throttle Policy level invalid"));
}
Also used : Response(javax.ws.rs.core.Response) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) LabelException(org.wso2.carbon.apimgt.core.exception.LabelException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)199 Test (org.testng.annotations.Test)185 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)168 Response (javax.ws.rs.core.Response)144 Test (org.junit.Test)143 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)143 API (org.wso2.carbon.apimgt.core.models.API)124 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)120 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)99 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)99 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)93 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)75 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)61 HashMap (java.util.HashMap)60 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)53 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)52 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)45 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)44 DocumentInfo (org.wso2.carbon.apimgt.core.models.DocumentInfo)41 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)39