use of org.wso2.carbon.apimgt.rest.api.store.v1.SubscriptionsApiService in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method subscriptionsGetTest.
@Test
public void subscriptionsGetTest() throws Exception {
APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
Mockito.when(instance.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
Mockito.when(apiMgtAdminService.getAPISubscriptionsOfApi(API_CONTEXT, API_VERSION)).thenReturn(createSubscriptionValidationDataList());
Response response = subscriptionsApiService.subscriptionsGet(API_CONTEXT, API_VERSION, LIMIT, null, getRequest());
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
Assert.assertEquals(((SubscriptionListDTO) response.getEntity()).getList().size(), 2);
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.SubscriptionsApiService in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method testSubscriptionsSubscriptionIdGet.
@Test
public void testSubscriptionsSubscriptionIdGet() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String subsID1 = UUID.randomUUID().toString();
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = TestUtil.getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
Subscription subscription = SampleTestObjectCreator.createSubscription(subsID1);
Mockito.when(apiStore.getSubscriptionByUUID(subsID1)).thenReturn(subscription);
Response response = subscriptionsApiService.subscriptionsSubscriptionIdGet(subsID1, null, null, request);
Assert.assertEquals(200, response.getStatus());
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.SubscriptionsApiService in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method testSubscriptionsSubscriptionIdGet.
@Test
public void testSubscriptionsSubscriptionIdGet() throws Exception {
printTestMethodName();
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
String sub1 = UUID.randomUUID().toString();
Subscription subscription = SampleTestObjectCreator.createSubscription(sub1);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Mockito.doReturn(subscription).doThrow(new IllegalArgumentException()).when(apiPublisher).getSubscriptionByUUID(sub1);
Response response = subscriptionsApiService.subscriptionsSubscriptionIdGet(sub1, null, null, getRequest());
assertEquals(response.getStatus(), 200);
assertTrue(response.getEntity().toString().contains(sub1));
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.SubscriptionsApiService in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method testSubscriptionsUnblockSubscriptionPost.
@Test
public void testSubscriptionsUnblockSubscriptionPost() 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.BLOCKED);
Subscription newSubscription = SampleTestObjectCreator.createSubscription(subscriptionId);
newSubscription.setStatus(APIMgtConstants.SubscriptionStatus.ACTIVE);
Mockito.doReturn(subscription).doReturn(newSubscription).doThrow(new IllegalArgumentException()).when(apiPublisher).getSubscriptionByUUID(subscriptionId);
Mockito.doNothing().doThrow(new IllegalArgumentException()).when(apiPublisher).updateSubscriptionStatus(subscriptionId, APIMgtConstants.SubscriptionStatus.BLOCKED);
Response response = subscriptionsApiService.subscriptionsUnblockSubscriptionPost(subscriptionId, null, null, getRequest());
assertEquals(response.getStatus(), 200);
assertTrue(response.getEntity().toString().contains("ACTIVE"));
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.SubscriptionsApiService in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method testSubscriptionsGetNotExist.
@Test(expected = BadRequestException.class)
public void testSubscriptionsGetNotExist() 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.doReturn(subscriptions).doThrow(new IllegalArgumentException()).when(apiPublisher).getSubscriptionsByAPI(apiId);
Response response = subscriptionsApiService.subscriptionsGet(null, 10, 0, null, getRequest());
}
Aggregations