use of org.wso2.carbon.apimgt.core.models.Subscription in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testDeleteSubscription.
@Test(description = "Delete subscription")
public void testDeleteSubscription() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, apiSubscriptionDAO, workflowDAO, apiGateway);
Application application = SampleTestObjectCreator.createDefaultApplication();
APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
API api = builder.build();
Subscription subscription = new Subscription(UUID, application, api, new SubscriptionPolicy("Gold"));
Mockito.when(apiSubscriptionDAO.getAPISubscription(UUID)).thenReturn(subscription);
apiStore.deleteAPISubscription(UUID);
Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).deleteAPISubscription(UUID);
}
use of org.wso2.carbon.apimgt.core.models.Subscription in project carbon-apimgt by wso2.
the class AbstractAPIManagerTestCase method testGetSubscriptionsByAPI.
@Test(description = "Getting subscriptions by API")
public void testGetSubscriptionsByAPI() throws APIManagementException {
APISubscriptionDAO apiSubscriptionDAO = mock(APISubscriptionDAO.class);
AbstractAPIManager apiStore = getAPIStoreImpl(apiSubscriptionDAO);
when(apiSubscriptionDAO.getAPISubscriptionsByAPI(UUID)).thenReturn(new ArrayList<Subscription>());
apiStore.getSubscriptionsByAPI(UUID);
verify(apiSubscriptionDAO, times(1)).getAPISubscriptionsByAPI(UUID);
}
use of org.wso2.carbon.apimgt.core.models.Subscription in project carbon-apimgt by wso2.
the class AnalyzerImplTestCase method testGetSubscrptionInfo.
@Test(description = "Get Subscription Info test")
public void testGetSubscrptionInfo() throws APIManagementException {
AnalyticsDAO analyticsDAO = Mockito.mock(AnalyticsDAO.class);
SubscriptionInfo subscriptionInfo = new SubscriptionInfo();
List<SubscriptionInfo> subscriptionInfos = new ArrayList<>();
subscriptionInfos.add(subscriptionInfo);
Analyzer analyzer = getAnalyzerImpl(analyticsDAO);
when(analyticsDAO.getSubscriptionInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null)).thenReturn(subscriptionInfos);
List<SubscriptionInfo> subscriptionInfoResult = analyzer.getSubscriptionInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
Assert.assertNotNull(subscriptionInfoResult);
verify(analyticsDAO, Mockito.times(1)).getSubscriptionInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
// Error path
Mockito.when(analyticsDAO.getSubscriptionInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null)).thenThrow(APIMgtDAOException.class);
try {
analyzer.getSubscriptionInfo(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error occurred while fetching Subscription information");
}
}
use of org.wso2.carbon.apimgt.core.models.Subscription in project carbon-apimgt by wso2.
the class AnalyzerImplTestCase method testGetSubscriptionCount.
@Test(description = "Get subscription count test")
public void testGetSubscriptionCount() throws APIManagementException {
AnalyticsDAO analyticsDAO = Mockito.mock(AnalyticsDAO.class);
SubscriptionCount subscriptionCount = new SubscriptionCount();
List<SubscriptionCount> subscriptionCountList = new ArrayList<>();
subscriptionCountList.add(subscriptionCount);
Analyzer analyzer = getAnalyzerImpl(analyticsDAO);
when(analyticsDAO.getSubscriptionCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null)).thenReturn(subscriptionCountList);
List<SubscriptionCount> subscriptionCountDB = analyzer.getSubscriptionCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
Assert.assertNotNull(subscriptionCountDB);
verify(analyticsDAO, Mockito.times(1)).getSubscriptionCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
// Error path
Mockito.when(analyticsDAO.getSubscriptionCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null)).thenThrow(APIMgtDAOException.class);
try {
analyzer.getSubscriptionCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error occurred while fetching Subscription count information");
}
}
use of org.wso2.carbon.apimgt.core.models.Subscription in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testGetSubscribersOfProvider.
@Test(description = "Get subscriptions for a provider's APIs")
public void testGetSubscribersOfProvider() throws APIManagementException {
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiSubscriptionDAO);
Mockito.when(apiSubscriptionDAO.getAPISubscriptionsForUser(1, 2, USER)).thenReturn(new ArrayList<Subscription>());
apiPublisher.getSubscribersOfProvider(1, 2, USER);
Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).getAPISubscriptionsForUser(1, 2, USER);
}
Aggregations