use of org.wso2.carbon.apimgt.api.APIConsumer in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testIsSubscribed.
@Test
public void testIsSubscribed() throws APIManagementException {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper();
apiConsumer.apiMgtDAO = apiMgtDAO;
APIIdentifier apiIdentifier = new APIIdentifier(API_PROVIDER, SAMPLE_API_NAME, SAMPLE_API_VERSION);
Mockito.when(apiMgtDAO.isSubscribed(apiIdentifier, "testID")).thenReturn(true);
assertEquals(true, apiConsumer.isSubscribed(apiIdentifier, "testID"));
// Error Path
Mockito.when(apiMgtDAO.isSubscribed(apiIdentifier, "testID")).thenThrow(APIManagementException.class);
try {
apiConsumer.isSubscribed(apiIdentifier, "testID");
assertTrue(false);
} catch (APIManagementException e) {
assertTrue(true);
}
}
use of org.wso2.carbon.apimgt.api.APIConsumer in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetAllPaginatedAPIs.
@Test
public void testGetAllPaginatedAPIs() throws Exception {
Registry userRegistry = Mockito.mock(Registry.class);
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(userRegistry, apiMgtDAO);
PowerMockito.mockStatic(GovernanceUtils.class);
PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt());
PowerMockito.when(APIUtil.isAllowDisplayMultipleVersions()).thenReturn(false, true);
UserRegistry userRegistry1 = Mockito.mock(UserRegistry.class);
Mockito.when(registryService.getGovernanceUserRegistry(Mockito.anyString(), Mockito.anyInt())).thenReturn(userRegistry1);
Mockito.when(registryService.getGovernanceSystemRegistry(Mockito.anyInt())).thenReturn(userRegistry1);
GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(artifactManager);
GenericArtifact artifact = Mockito.mock(GenericArtifact.class);
GenericArtifact[] genericArtifacts = new GenericArtifact[] { artifact };
Mockito.when(artifactManager.findGenericArtifacts(Mockito.anyMap())).thenReturn(genericArtifacts);
APIIdentifier apiId1 = new APIIdentifier("admin", "API1", "1.0.0");
API api = new API(apiId1);
Mockito.when(APIUtil.getAPI(artifact)).thenReturn(api);
assertNotNull(apiConsumer.getAllPaginatedAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
assertNotNull(apiConsumer.getAllPaginatedAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
// artifact manager null path
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(null);
assertNotNull(apiConsumer.getAllPaginatedAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
// generic artifact null path
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(artifactManager);
Mockito.when(artifactManager.findGenericArtifacts(Mockito.anyMap())).thenReturn(null);
assertNotNull(apiConsumer.getAllPaginatedAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
}
use of org.wso2.carbon.apimgt.api.APIConsumer 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.APIConsumer in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetAPIsWithTag.
@Test
public void testGetAPIsWithTag() throws Exception {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper();
PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt());
PowerMockito.mockStatic(GovernanceUtils.class);
GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
PowerMockito.when(APIUtil.getArtifactManager(apiConsumer.registry, APIConstants.API_KEY)).thenReturn(artifactManager);
List<GovernanceArtifact> governanceArtifacts = new ArrayList<GovernanceArtifact>();
GenericArtifact artifact = Mockito.mock(GenericArtifact.class);
governanceArtifacts.add(artifact);
Mockito.when(GovernanceUtils.findGovernanceArtifacts(Mockito.anyString(), (UserRegistry) Mockito.anyObject(), Mockito.anyString())).thenReturn(governanceArtifacts);
APIIdentifier apiId1 = new APIIdentifier("admin", "API1", "1.0.0");
API api = new API(apiId1);
Mockito.when(APIUtil.getAPI(artifact)).thenReturn(api);
Mockito.when(artifact.getAttribute("overview_status")).thenReturn("PUBLISHED");
assertNotNull(apiConsumer.getAPIsWithTag("testTag", "testDomain"));
}
use of org.wso2.carbon.apimgt.api.APIConsumer in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testReadMonetizationConfig.
@Test
public void testReadMonetizationConfig() throws Exception {
String json = "{\"EnableMonetization\":\"true\"}";
JSONObject jsonObject = (JSONObject) new JSONParser().parse(json);
PowerMockito.when(APIUtil.class, "getTenantConfig", Mockito.anyString()).thenReturn(jsonObject);
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper();
boolean isEnabled = apiConsumer.isMonetizationEnabled(MultitenantConstants.TENANT_DOMAIN);
assertTrue("Expected true but returned " + isEnabled, isEnabled);
// error path UserStoreException
PowerMockito.when(APIUtil.class, "getTenantConfig", Mockito.anyString()).thenThrow(APIManagementException.class);
try {
apiConsumer.isMonetizationEnabled(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
assertFalse(true);
} catch (APIManagementException e) {
assertTrue(true);
}
}
Aggregations