use of org.wso2.carbon.apimgt.api.model.SubscribedAPI in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetSubscribedAPIs.
@Test
public void testGetSubscribedAPIs() throws APIManagementException {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper();
apiConsumer.apiMgtDAO = apiMgtDAO;
Set<SubscribedAPI> originalSubscribedAPIs = new HashSet<SubscribedAPI>();
SubscribedAPI subscribedAPI = Mockito.mock(SubscribedAPI.class);
originalSubscribedAPIs.add(subscribedAPI);
Subscriber subscriber = new Subscriber("Subscriber");
Tier tier = Mockito.mock(Tier.class);
when(apiMgtDAO.getSubscribedAPIs("testorg", subscriber, "testID")).thenReturn(originalSubscribedAPIs);
when(subscribedAPI.getTier()).thenReturn(tier);
when(tier.getName()).thenReturn("tier");
assertNotNull(apiConsumer.getSubscribedAPIs("testorg", subscriber, "testID"));
}
use of org.wso2.carbon.apimgt.api.model.SubscribedAPI in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testAddSubscription.
@Test
public void testAddSubscription() throws APIManagementException {
API api = new API(new APIIdentifier(API_PROVIDER, "published_api", SAMPLE_API_VERSION));
api.setSubscriptionAvailability(APIConstants.SUBSCRIPTION_TO_ALL_TENANTS);
Application application = new Application(1);
api.setStatus(APIConstants.PUBLISHED);
Set<Tier> tiers = new HashSet<>();
tiers.add(new Tier("tier1"));
api.setAvailableTiers(tiers);
ApiTypeWrapper apiTypeWrapper = new ApiTypeWrapper(api);
apiTypeWrapper.setTier("tier1");
Mockito.when(apiMgtDAO.addSubscription(Mockito.eq(apiTypeWrapper), Mockito.eq(application), Mockito.anyString(), Mockito.anyString())).thenReturn(1);
SubscribedAPI subscribedAPI = new SubscribedAPI(UUID.randomUUID().toString());
Mockito.when(apiMgtDAO.getSubscriptionById(1)).thenReturn(subscribedAPI);
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(apiMgtDAO, SAMPLE_TENANT_DOMAIN_1);
Assert.assertEquals(apiConsumer.addSubscription(apiTypeWrapper, "user1", application).getSubscriptionUUID(), subscribedAPI.getUUID());
try {
api.setStatus(APIConstants.CREATED);
apiConsumer.addSubscription(apiTypeWrapper, "sub1", application);
Assert.fail("Resource not found exception not thrown for wrong api state");
} catch (APIManagementException e) {
Assert.assertTrue(e.getMessage().contains("Subscriptions not allowed on APIs/API Products in the state"));
}
}
use of org.wso2.carbon.apimgt.api.model.SubscribedAPI in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetSubscribedAPIsWithApp.
@Test
public void testGetSubscribedAPIsWithApp() throws APIManagementException {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(apiMgtDAO);
Set<SubscribedAPI> originalSubscribedAPIs = new HashSet<SubscribedAPI>();
SubscribedAPI subscribedAPI = Mockito.mock(SubscribedAPI.class);
originalSubscribedAPIs.add(subscribedAPI);
Subscriber subscriber = new Subscriber("Subscriber");
Tier tier = Mockito.mock(Tier.class);
when(apiMgtDAO.getSubscribedAPIs(subscriber, "testApplication", "testID")).thenReturn(originalSubscribedAPIs);
when(subscribedAPI.getTier()).thenReturn(tier);
when(tier.getName()).thenReturn("tier");
assertNotNull(apiConsumer.getSubscribedAPIs(subscriber, "testApplication", "testID"));
}
use of org.wso2.carbon.apimgt.api.model.SubscribedAPI in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetSubscribedIdentifiers.
@Test
public void testGetSubscribedIdentifiers() throws APIManagementException {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(apiMgtDAO);
Set<SubscribedAPI> originalSubscribedAPIs = new HashSet<>();
SubscribedAPI subscribedAPI = Mockito.mock(SubscribedAPI.class);
originalSubscribedAPIs.add(subscribedAPI);
Subscriber subscriber = new Subscriber("Subscriber");
APIIdentifier apiId1 = new APIIdentifier(API_PROVIDER, SAMPLE_API_NAME, SAMPLE_API_VERSION);
Tier tier = Mockito.mock(Tier.class);
when(apiMgtDAO.getSubscribedAPIs("testorg", subscriber, "testID")).thenReturn(originalSubscribedAPIs);
when(subscribedAPI.getTier()).thenReturn(tier);
when(tier.getName()).thenReturn("tier");
when(subscribedAPI.getApiId()).thenReturn(apiId1);
Application app = Mockito.mock(Application.class);
when(app.getId()).thenReturn(1);
when(subscribedAPI.getApplication()).thenReturn(app);
Set<APIKey> apiKeys = new HashSet<>();
APIKey apiKey = new APIKey();
apiKey.setType("Production");
apiKeys.add(apiKey);
Mockito.when(apiMgtDAO.getKeyMappingsFromApplicationId(Mockito.anyInt())).thenReturn(apiKeys);
AccessTokenInfo accessTokenInfo = new AccessTokenInfo();
accessTokenInfo.setAccessToken(UUID.randomUUID().toString());
Mockito.when(keyManager.getAccessTokenByConsumerKey(Mockito.anyString())).thenReturn(accessTokenInfo);
assertNotNull(apiConsumer.getSubscribedIdentifiers(subscriber, apiId1, "testID", "testorg"));
}
use of org.wso2.carbon.apimgt.api.model.SubscribedAPI in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testAddSubscriptionInvalidTier.
@Test
public void testAddSubscriptionInvalidTier() throws APIManagementException {
API api = new API(new APIIdentifier(API_PROVIDER, "published_api", SAMPLE_API_VERSION));
api.setSubscriptionAvailability(APIConstants.SUBSCRIPTION_TO_ALL_TENANTS);
Application application = new Application(1);
api.setStatus(APIConstants.PUBLISHED);
Set<Tier> tiers = new HashSet<>();
tiers.add(new Tier("tier1"));
api.setAvailableTiers(tiers);
ApiTypeWrapper apiTypeWrapper = new ApiTypeWrapper(api);
apiTypeWrapper.setTier("tier2");
Mockito.when(apiMgtDAO.addSubscription(Mockito.eq(apiTypeWrapper), Mockito.eq(application), Mockito.anyString(), Mockito.anyString())).thenReturn(1);
SubscribedAPI subscribedAPI = new SubscribedAPI(UUID.randomUUID().toString());
Mockito.when(apiMgtDAO.getSubscriptionById(1)).thenReturn(subscribedAPI);
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(apiMgtDAO, SAMPLE_TENANT_DOMAIN_1);
try {
apiConsumer.addSubscription(apiTypeWrapper, "sub1", application);
Assert.fail("Invalid Tier error not thrown.");
} catch (APIManagementException e) {
Assert.assertEquals(e.getErrorHandler().getErrorCode(), ExceptionCodes.SUBSCRIPTION_TIER_NOT_ALLOWED.getErrorCode());
}
}
Aggregations