use of org.wso2.carbon.apimgt.api.APIConsumer in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testRateAPI.
@Test
public void testRateAPI() throws APIManagementException {
String uuid = UUID.randomUUID().toString();
APIRating apiRating = APIRating.RATING_FOUR;
String user = "Tom";
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(apiMgtDAO);
Mockito.doNothing().when(apiMgtDAO).addRating(uuid, apiRating.getRating(), user);
apiConsumer.rateAPI(uuid, apiRating, user);
Mockito.verify(apiMgtDAO, Mockito.times(1)).addRating(uuid, apiRating.getRating(), user);
}
use of org.wso2.carbon.apimgt.api.APIConsumer in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetSubscriptionCount.
@Test
public void testGetSubscriptionCount() throws APIManagementException {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper();
Subscriber subscriber = new Subscriber("Subscriber");
apiConsumer.apiMgtDAO = apiMgtDAO;
when(apiMgtDAO.getSubscriptionCount((Subscriber) Mockito.anyObject(), Mockito.anyString(), Mockito.anyString())).thenReturn(10);
apiConsumer.apiMgtDAO = apiMgtDAO;
assertEquals((Integer) 10, apiConsumer.getSubscriptionCount(subscriber, "testApplication", "testId"));
}
use of org.wso2.carbon.apimgt.api.APIConsumer in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testRenewConsumerSecret.
@Test
public void testRenewConsumerSecret() throws APIManagementException {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper();
String clientId = UUID.randomUUID().toString();
apiConsumer.apiMgtDAO = apiMgtDAO;
KeyManagerConfigurationDTO keyManagerConfiguration = new KeyManagerConfigurationDTO();
keyManagerConfiguration.setEnabled(true);
Mockito.when(apiMgtDAO.getKeyManagerConfigurationByName(Mockito.anyString(), Mockito.anyString())).thenReturn(keyManagerConfiguration);
Mockito.when(keyManager.getNewApplicationConsumerSecret(Mockito.anyObject())).thenReturn("updatedClientSecret");
assertNotNull(apiConsumer.renewConsumerSecret(clientId, APIConstants.KeyManager.DEFAULT_KEY_MANAGER));
}
use of org.wso2.carbon.apimgt.api.APIConsumer in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetDeniedTiers.
@Test
public void testGetDeniedTiers() throws APIManagementException, org.wso2.carbon.user.core.UserStoreException {
UserRegistry userRegistry = Mockito.mock(UserRegistry.class);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
Mockito.when(apiManagerConfiguration.getFirstProperty(Mockito.anyString())).thenReturn("true", "false");
APIConsumerImpl apiConsumer = new UserAwareAPIConsumerWrapper(userRegistry, apiMgtDAO);
Mockito.when(userRegistry.getUserRealm()).thenReturn(userRealm);
Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
String[] currentUserRoles = { "role1", "role2" };
PowerMockito.when(APIUtil.getListOfRoles(Mockito.anyString())).thenReturn(currentUserRoles);
Assert.assertEquals(apiConsumer.getDeniedTiers().size(), 0);
TierPermissionDTO tierPermissionDTO = new TierPermissionDTO();
TierPermissionDTO tierPermissionDTO1 = new TierPermissionDTO();
tierPermissionDTO.setRoles(new String[] { "role1" });
Set<TierPermissionDTO> tierPermissionDTOs = new HashSet<TierPermissionDTO>();
tierPermissionDTOs.add(tierPermissionDTO);
Mockito.when(apiMgtDAO.getThrottleTierPermissions(Mockito.anyInt())).thenReturn(tierPermissionDTOs);
Assert.assertEquals(apiConsumer.getDeniedTiers().size(), 1);
tierPermissionDTO.setRoles(new String[] { "role3" });
Assert.assertEquals(apiConsumer.getDeniedTiers().size(), 0);
Mockito.when(apiMgtDAO.getTierPermissions(Mockito.anyInt())).thenReturn(tierPermissionDTOs);
Assert.assertEquals(apiConsumer.getDeniedTiers().size(), 0);
tierPermissionDTO.setPermissionType(APIConstants.TIER_PERMISSION_ALLOW);
Mockito.when(userStoreManager.getRoleListOfUser(Mockito.anyString())).thenReturn(new String[0]);
tierPermissionDTOs.add(tierPermissionDTO1);
tierPermissionDTO1.setRoles(new String[] { "role4" });
Assert.assertEquals(apiConsumer.getDeniedTiers().size(), 1);
Mockito.when(userStoreManager.getRoleListOfUser(Mockito.anyString())).thenReturn(new String[] { "role1", "role2" });
tierPermissionDTO1.setRoles(new String[] { "role2" });
tierPermissionDTO1.setTierName("Silver");
Assert.assertEquals(apiConsumer.getDeniedTiers().size(), 2);
}
use of org.wso2.carbon.apimgt.api.APIConsumer in project carbon-apimgt by wso2.
the class APIManagerFactory method getAPIConsumerFromCache.
public APIConsumer getAPIConsumerFromCache(String key, ConsumerCreator consumerCreator) throws APIManagementException {
APIConsumer consumer = consumers.get(key);
if (consumer == null) {
synchronized (key.intern()) {
consumer = consumers.get(key);
if (consumer != null) {
return consumer;
}
consumer = consumerCreator.create();
consumers.put(key, consumer);
}
}
return consumer;
}
Aggregations