Search in sources :

Example 51 with Subscription

use of org.wso2.carbon.apimgt.keymgt.model.entity.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);
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) Application(org.wso2.carbon.apimgt.core.models.Application) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 52 with Subscription

use of org.wso2.carbon.apimgt.keymgt.model.entity.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);
}
Also used : APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) Test(org.testng.annotations.Test)

Example 53 with Subscription

use of org.wso2.carbon.apimgt.keymgt.model.entity.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");
    }
}
Also used : AnalyticsDAO(org.wso2.carbon.apimgt.core.dao.AnalyticsDAO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ArrayList(java.util.ArrayList) SubscriptionInfo(org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer) Test(org.testng.annotations.Test)

Example 54 with Subscription

use of org.wso2.carbon.apimgt.keymgt.model.entity.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");
    }
}
Also used : AnalyticsDAO(org.wso2.carbon.apimgt.core.dao.AnalyticsDAO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ArrayList(java.util.ArrayList) APISubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount) SubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.SubscriptionCount) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer) Test(org.testng.annotations.Test)

Example 55 with Subscription

use of org.wso2.carbon.apimgt.keymgt.model.entity.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);
}
Also used : APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) Test(org.testng.annotations.Test)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)79 ArrayList (java.util.ArrayList)69 Test (org.testng.annotations.Test)58 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)58 Test (org.junit.Test)56 SQLException (java.sql.SQLException)55 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)51 Connection (java.sql.Connection)49 PreparedStatement (java.sql.PreparedStatement)48 ResultSet (java.sql.ResultSet)39 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)37 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)35 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)34 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)34 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)31 Application (org.wso2.carbon.apimgt.core.models.Application)30 API (org.wso2.carbon.apimgt.core.models.API)28 Response (javax.ws.rs.core.Response)24 Application (org.wso2.carbon.apimgt.api.model.Application)22 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)22