Search in sources :

Example 56 with Subscription

use of org.wso2.carbon.apimgt.api.model.subscription.Subscription in project carbon-apimgt by wso2.

the class AbstractAPIManagerTestCase method testGetSubscriptionByUUID.

@Test(description = "Get subscription by UUID")
public void testGetSubscriptionByUUID() throws APIManagementException {
    APISubscriptionDAO apiSubscriptionDAO = mock(APISubscriptionDAO.class);
    AbstractAPIManager apiStore = getAPIStoreImpl(apiSubscriptionDAO);
    when(apiSubscriptionDAO.getAPISubscription(UUID)).thenReturn(new Subscription(UUID, null, null, null));
    apiStore.getSubscriptionByUUID(UUID);
    verify(apiSubscriptionDAO, times(1)).getAPISubscription(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 57 with Subscription

use of org.wso2.carbon.apimgt.api.model.subscription.Subscription in project carbon-apimgt by wso2.

the class SubscriptionThrottlePolicyMappingUtilTest method fromSubscriptionPolicyArrayToListDTOTest.

@Test(description = "Convert Subscription Throttle Policy List to List DTO")
public void fromSubscriptionPolicyArrayToListDTOTest() throws Exception {
    List<SubscriptionPolicy> subscriptionPolicies = new ArrayList<>();
    SubscriptionPolicy policy1 = SampleTestObjectCreator.createSubscriptionPolicyWithRequestLimit("Gold1");
    SubscriptionPolicy policy2 = SampleTestObjectCreator.createSubscriptionPolicyWithRequestLimit("Gold2");
    subscriptionPolicies.add(policy1);
    subscriptionPolicies.add(policy2);
    SubscriptionThrottlePolicyListDTO listDTO = SubscriptionThrottlePolicyMappingUtil.fromSubscriptionPolicyArrayToListDTO(subscriptionPolicies);
    assertEquals(listDTO.getCount(), (Integer) subscriptionPolicies.size());
    assertEquals(listDTO.getList().get(0).getPolicyName(), policy1.getPolicyName());
    assertEquals(listDTO.getList().get(0).getDescription(), policy1.getDescription());
    assertEquals(listDTO.getList().get(0).getDefaultLimit().getUnitTime(), (Integer) policy1.getDefaultQuotaPolicy().getLimit().getUnitTime());
    assertEquals(listDTO.getList().get(0).getDefaultLimit().getRequestCountLimit().getRequestCount(), (Integer) ((RequestCountLimit) policy1.getDefaultQuotaPolicy().getLimit()).getRequestCount());
    assertEquals(listDTO.getList().get(1).getPolicyName(), policy2.getPolicyName());
    assertEquals(listDTO.getList().get(1).getDescription(), policy2.getDescription());
    assertEquals(listDTO.getList().get(1).getDefaultLimit().getUnitTime(), (Integer) policy2.getDefaultQuotaPolicy().getLimit().getUnitTime());
    assertEquals(listDTO.getList().get(1).getDefaultLimit().getRequestCountLimit().getRequestCount(), (Integer) ((RequestCountLimit) policy2.getDefaultQuotaPolicy().getLimit()).getRequestCount());
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) ArrayList(java.util.ArrayList) SubscriptionThrottlePolicyListDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.SubscriptionThrottlePolicyListDTO) Test(org.testng.annotations.Test)

Example 58 with Subscription

use of org.wso2.carbon.apimgt.api.model.subscription.Subscription in project carbon-apimgt by wso2.

the class SubscriptionMappingUtilTestCase method testFromSubscriptionListToDTO.

@Test
public void testFromSubscriptionListToDTO() {
    String subUuid1 = UUID.randomUUID().toString();
    String subUuid2 = UUID.randomUUID().toString();
    Subscription subscription1 = SampleTestObjectCreator.createSubscription(subUuid1);
    Subscription subscription2 = SampleTestObjectCreator.createSubscription(subUuid2);
    List<Subscription> subscriptionList = new ArrayList<>();
    subscriptionList.add(subscription1);
    subscriptionList.add(subscription2);
    SubscriptionListDTO subscriptionListDTO = SubscriptionMappingUtil.fromSubscriptionListToDTO(subscriptionList, 10, 0);
    assertEquals(subscriptionListDTO.getCount(), (Integer) subscriptionList.size());
    assertEquals(subscription1.getId(), subscriptionListDTO.getList().get(0).getSubscriptionId());
    assertEquals(subscription1.getApi().getName(), subscriptionListDTO.getList().get(0).getApiName());
    assertEquals(subscription1.getApi().getId(), subscriptionListDTO.getList().get(0).getApiIdentifier());
    assertEquals(subscription1.getApi().getVersion(), subscriptionListDTO.getList().get(0).getApiVersion());
    assertEquals(SubscriptionDTO.LifeCycleStatusEnum.valueOf(subscription1.getStatus().toString()).name(), subscriptionListDTO.getList().get(0).getLifeCycleStatus().name());
    assertEquals(subscriptionListDTO.getCount(), (Integer) subscriptionList.size());
    assertEquals(subscription2.getId(), subscriptionListDTO.getList().get(1).getSubscriptionId());
    assertEquals(subscription2.getApi().getName(), subscriptionListDTO.getList().get(1).getApiName());
    assertEquals(subscription2.getApi().getId(), subscriptionListDTO.getList().get(1).getApiIdentifier());
    assertEquals(subscription2.getApi().getVersion(), subscriptionListDTO.getList().get(1).getApiVersion());
    assertEquals(SubscriptionDTO.LifeCycleStatusEnum.valueOf(subscription2.getStatus().toString()).name(), subscriptionListDTO.getList().get(1).getLifeCycleStatus().name());
}
Also used : ArrayList(java.util.ArrayList) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) SubscriptionListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionListDTO) Test(org.testng.annotations.Test)

Example 59 with Subscription

use of org.wso2.carbon.apimgt.api.model.subscription.Subscription in project carbon-apimgt by wso2.

the class TierMappingUtilTestCase method testFromTierListToDTO.

@Test
public void testFromTierListToDTO() {
    Policy policy1 = SampleTestObjectCreator.createSubscriptionPolicyWithRequestLimit("Gold");
    Policy policy2 = SampleTestObjectCreator.createSubscriptionPolicyWithBndwidthLimit("Silver");
    List<Policy> policyList = new ArrayList<>();
    policyList.add(policy1);
    policyList.add(policy2);
    TierListDTO tierListDTO = TierMappingUtil.fromTierListToDTO(policyList, "subscription", 10, 0);
    assertEquals(tierListDTO.getCount(), (Integer) policyList.size());
    assertEquals(tierListDTO.getList().get(0).getName(), policy1.getPolicyName());
    assertEquals(tierListDTO.getList().get(0).getDescription(), policy1.getDescription());
    assertEquals(tierListDTO.getList().get(0).getTierLevel().name(), "SUBSCRIPTION");
    assertEquals(tierListDTO.getList().get(0).getUnitTime().longValue(), policy1.getDefaultQuotaPolicy().getLimit().getUnitTime());
    assertEquals(tierListDTO.getList().get(0).getRequestCount().longValue(), ((RequestCountLimit) policy1.getDefaultQuotaPolicy().getLimit()).getRequestCount());
    assertEquals(tierListDTO.getList().get(1).getName(), policy2.getPolicyName());
    assertEquals(tierListDTO.getList().get(1).getDescription(), policy2.getDescription());
    assertEquals(tierListDTO.getList().get(1).getTierLevel().name(), "SUBSCRIPTION");
    assertEquals(tierListDTO.getList().get(1).getUnitTime().longValue(), policy2.getDefaultQuotaPolicy().getLimit().getUnitTime());
    assertEquals(tierListDTO.getList().get(1).getRequestCount().longValue(), ((BandwidthLimit) policy2.getDefaultQuotaPolicy().getLimit()).getDataAmount());
}
Also used : Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) ArrayList(java.util.ArrayList) TierListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.TierListDTO) Test(org.testng.annotations.Test)

Example 60 with Subscription

use of org.wso2.carbon.apimgt.api.model.subscription.Subscription in project carbon-apimgt by wso2.

the class SubscriptionsApiServiceImplTestCase method testSubscriptionsGetfromAPI.

@Test
public void testSubscriptionsGetfromAPI() throws APIManagementException, NotFoundException {
    TestUtil.printTestMethodName();
    String apiId = UUID.randomUUID().toString();
    String subsID1 = UUID.randomUUID().toString();
    String subsID2 = 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);
    List<Subscription> subscriptionList = new ArrayList<>();
    subscriptionList.add(SampleTestObjectCreator.createSubscription(subsID1));
    subscriptionList.add(SampleTestObjectCreator.createSubscription(subsID2));
    Mockito.when(apiStore.getSubscriptionsByAPI(apiId)).thenReturn(subscriptionList);
    Response response = subscriptionsApiService.subscriptionsGet(apiId, null, null, 0, 10, null, request);
    Assert.assertEquals(200, response.getStatus());
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) Request(org.wso2.msf4j.Request) ArrayList(java.util.ArrayList) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.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