use of org.wso2.carbon.apimgt.core.models.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);
}
use of org.wso2.carbon.apimgt.core.models.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());
}
use of org.wso2.carbon.apimgt.core.models.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());
}
use of org.wso2.carbon.apimgt.core.models.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());
}
use of org.wso2.carbon.apimgt.core.models.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());
}
Aggregations