Search in sources :

Example 66 with APIPublisher

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

the class SubscriptionsApiServiceImplTestCase method testSubscriptionsUnblockSubscriptionPostException.

@Test
public void testSubscriptionsUnblockSubscriptionPostException() throws Exception {
    printTestMethodName();
    SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    List<Subscription> subscriptions = new ArrayList<>();
    String sub1 = UUID.randomUUID().toString();
    String sub2 = UUID.randomUUID().toString();
    subscriptions.add(SampleTestObjectCreator.createSubscription(sub1));
    subscriptions.add(SampleTestObjectCreator.createSubscription(sub2));
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String apiId = UUID.randomUUID().toString();
    Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.SUBSCRIPTION_STATE_INVALID)).when(apiPublisher).getSubscriptionsByAPI(apiId);
    Response response = subscriptionsApiService.subscriptionsGet(apiId, 10, 0, null, getRequest());
    assertEquals(response.getStatus(), 400);
    assertTrue(response.getEntity().toString().contains("Invalid state change for subscription"));
}
Also used : Response(javax.ws.rs.core.Response) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ArrayList(java.util.ArrayList) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 67 with APIPublisher

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

the class SubscriptionsApiServiceImplTestCase method testSubscriptionsBlockSubscriptionPostNotExist.

@Test
public void testSubscriptionsBlockSubscriptionPostNotExist() throws Exception {
    printTestMethodName();
    SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String subscriptionId = UUID.randomUUID().toString();
    Mockito.doReturn(null).doThrow(new IllegalArgumentException()).when(apiPublisher).getSubscriptionByUUID(subscriptionId);
    Response response = subscriptionsApiService.subscriptionsBlockSubscriptionPost(subscriptionId, null, null, null, getRequest());
    assertEquals(response.getStatus(), 404);
    assertTrue(response.getEntity().toString().contains("Subscription not found"));
}
Also used : Response(javax.ws.rs.core.Response) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 68 with APIPublisher

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

the class SubscriptionsApiServiceImplTestCase method testSubscriptionsBlockSubscriptionPostException.

@Test
public void testSubscriptionsBlockSubscriptionPostException() throws Exception {
    printTestMethodName();
    SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String subscriptionId = UUID.randomUUID().toString();
    Subscription subscription = SampleTestObjectCreator.createSubscription(subscriptionId);
    subscription.setStatus(APIMgtConstants.SubscriptionStatus.REJECTED);
    Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.SUBSCRIPTION_STATE_INVALID)).when(apiPublisher).getSubscriptionByUUID(subscriptionId);
    Response response = subscriptionsApiService.subscriptionsBlockSubscriptionPost(subscriptionId, APIMgtConstants.SubscriptionStatus.BLOCKED.name(), null, null, getRequest());
    assertEquals(response.getStatus(), 400);
    assertTrue(response.getEntity().toString().contains("Invalid state change for subscription"));
}
Also used : Response(javax.ws.rs.core.Response) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 69 with APIPublisher

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

the class ExportApiServiceImplTestCase method testExportApisGetNotFound.

@Test
public void testExportApisGetNotFound() throws Exception {
    printTestMethodName();
    ExportApiServiceImpl exportApiService = new ExportApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Response response = exportApiService.exportApisGet("", null, null, getRequest());
    assertEquals(response.getStatus(), 404);
}
Also used : 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 70 with APIPublisher

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

the class ExternalResourcesApiServiceImplTestCase method testExternalResourcesServicesGet.

@Test
public void testExternalResourcesServicesGet() throws Exception {
    printTestMethodName();
    ExternalResourcesApiServiceImpl externalResourcesApiService = new ExternalResourcesApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Endpoint endpoint1 = SampleTestObjectCreator.createMockEndpoint();
    Endpoint endpoint2 = SampleTestObjectCreator.createMockEndpoint();
    List<Endpoint> endpointList = new ArrayList<>();
    endpointList.add(endpoint1);
    endpointList.add(endpoint2);
    Mockito.doReturn(endpointList).doThrow(new IllegalArgumentException()).when(apiPublisher).discoverServiceEndpoints();
    Response response = externalResourcesApiService.externalResourcesServicesGet(null, null, getRequest());
    Assert.assertEquals(response.getStatus(), 200);
    Assert.assertTrue(response.getEntity().toString().contains(endpoint1.getId()));
    Assert.assertTrue(response.getEntity().toString().contains(endpoint2.getId()));
}
Also used : Response(javax.ws.rs.core.Response) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ArrayList(java.util.ArrayList) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) 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