use of org.wso2.carbon.apimgt.api.model.Tier 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.Tier 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.Tier 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());
}
}
use of org.wso2.carbon.apimgt.api.model.Tier in project carbon-apimgt by wso2.
the class APIProviderImpl method checkResourceThrottlingTiersInURITemplates.
private void checkResourceThrottlingTiersInURITemplates(Set<URITemplate> uriTemplates, String tenantDomain) throws APIManagementException {
Map<String, Tier> tierMap = APIUtil.getTiers(APIConstants.TIER_RESOURCE_TYPE, tenantDomain);
if (tierMap != null) {
for (URITemplate template : uriTemplates) {
if (template.getThrottlingTier() != null && !tierMap.containsKey(template.getThrottlingTier())) {
String message = "Invalid x-throttling tier " + template.getThrottlingTier() + " found in api definition for resource " + template.getHTTPVerb() + " " + template.getUriTemplate();
log.error(message);
throw new APIManagementException(message);
}
}
}
}
use of org.wso2.carbon.apimgt.api.model.Tier in project carbon-apimgt by wso2.
the class APIKeyValidationService method getAllURITemplates.
/**
* Return the URI Templates for an API
*
* @param context Requested context
* @param version API Version
* @return APIKeyValidationInfoDTO with authorization info and tier info if authorized. If it is not
* authorized, tier information will be <pre>null</pre>
*/
public ArrayList<URITemplate> getAllURITemplates(String context, String version) throws APIManagementException {
Timer timer6 = MetricManager.timer(org.wso2.carbon.metrics.manager.Level.INFO, MetricManager.name(APIConstants.METRICS_PREFIX, this.getClass().getSimpleName(), "GET_URI_TEMPLATE"));
Timer.Context timerContext6 = timer6.start();
if (log.isDebugEnabled()) {
log.debug("getAllURITemplates request from gateway to keymanager: requestTime=" + new SimpleDateFormat("[yyyy.MM.dd HH:mm:ss,SSS zzz]").format(new Date()) + " ,for:" + context);
}
ArrayList<URITemplate> templates = getTemplates(context, version);
if (log.isDebugEnabled()) {
log.debug("getAllURITemplates response from keyManager to gateway for:" + context + " at " + new SimpleDateFormat("[yyyy.MM.dd HH:mm:ss,SSS zzz]").format(new Date()));
}
timerContext6.stop();
return templates;
}
Aggregations