Search in sources :

Example 1 with SubscriptionsApiService

use of org.wso2.carbon.apimgt.rest.api.store.v1.SubscriptionsApiService 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 2 with SubscriptionsApiService

use of org.wso2.carbon.apimgt.rest.api.store.v1.SubscriptionsApiService 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 3 with SubscriptionsApiService

use of org.wso2.carbon.apimgt.rest.api.store.v1.SubscriptionsApiService 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 4 with SubscriptionsApiService

use of org.wso2.carbon.apimgt.rest.api.store.v1.SubscriptionsApiService in project carbon-apimgt by wso2.

the class SubscriptionsApiServiceImplTestCase method testSubscriptionsSubscriptionIdGetExist.

@Test
public void testSubscriptionsSubscriptionIdGetExist() throws Exception {
    printTestMethodName();
    SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    String sub1 = UUID.randomUUID().toString();
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Mockito.doReturn(null).doThrow(new IllegalArgumentException()).when(apiPublisher).getSubscriptionByUUID(sub1);
    Response response = subscriptionsApiService.subscriptionsSubscriptionIdGet(sub1, 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 5 with SubscriptionsApiService

use of org.wso2.carbon.apimgt.rest.api.store.v1.SubscriptionsApiService in project carbon-apimgt by wso2.

the class SubscriptionsApiServiceImplTestCase method testSubscriptionsGetException.

@Test
public void testSubscriptionsGetException() 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.subscriptionsUnblockSubscriptionPost(subscriptionId, 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)

Aggregations

Response (javax.ws.rs.core.Response)20 Test (org.junit.Test)20 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)20 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)14 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)13 ArrayList (java.util.ArrayList)5 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)5 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)5 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)5 Request (org.wso2.msf4j.Request)5 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)4 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)2 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)2 Application (org.wso2.carbon.apimgt.core.models.Application)2 API (org.wso2.carbon.apimgt.core.models.API)1 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)1 SubscriptionListDTO (org.wso2.carbon.apimgt.rest.api.core.dto.SubscriptionListDTO)1 SubscriptionDTO (org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionDTO)1