use of org.wso2.carbon.apimgt.api.model.Subscriber 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.Subscriber in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testAddApplicationInvalidTier.
@Test
public void testAddApplicationInvalidTier() throws APIManagementException {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(apiMgtDAO);
Application application = Mockito.mock(Application.class);
Mockito.when(application.getName()).thenReturn("app");
Mockito.when(application.getTier()).thenReturn("tier1");
PowerMockito.when(application.getSubscriber()).thenReturn(new Subscriber("User1"));
PowerMockito.when(MultitenantUtils.getTenantDomain("userID")).thenReturn("carbon.super");
PowerMockito.when(APIUtil.isApplicationExist("userID", "app", "1", "testorg")).thenReturn(false);
Map<String, Tier> tierMap = new HashMap<>();
tierMap.put("tier2", new Tier("tier2"));
PowerMockito.when(APIUtil.getTiers(APIConstants.TIER_APPLICATION_TYPE, "testorg")).thenReturn(tierMap);
PowerMockito.when(APIUtil.findTier(tierMap.values(), "tier1")).thenReturn(null);
Mockito.when(apiMgtDAO.addApplication(application, "userID", "testorg")).thenReturn(1);
try {
apiConsumer.addApplication(application, "userID", "testorg");
Assert.fail();
} catch (APIManagementException e) {
Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.TIER_NAME_INVALID);
}
}
use of org.wso2.carbon.apimgt.api.model.Subscriber 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.Subscriber 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.Subscriber in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetSubscriber.
@Test
public void testGetSubscriber() throws APIManagementException {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper();
when(apiMgtDAO.getSubscriber(Mockito.anyString())).thenReturn(new Subscriber(UUID.randomUUID().toString()));
apiConsumer.apiMgtDAO = apiMgtDAO;
assertNotNull(apiConsumer.getSubscriber(UUID.randomUUID().toString()));
when(apiMgtDAO.getSubscriber(Mockito.anyString())).thenThrow(APIManagementException.class);
try {
apiConsumer.getSubscriber(UUID.randomUUID().toString());
assertTrue(false);
} catch (APIManagementException e) {
assertEquals("Failed to get Subscriber", e.getMessage());
}
}
Aggregations