use of org.wso2.carbon.apimgt.api.APIConsumer in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetAllPaginatedPublishedLightWeightAPIs.
@Test
public void testGetAllPaginatedPublishedLightWeightAPIs() throws Exception {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper();
PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt());
PowerMockito.when(APIUtil.isAllowDisplayMultipleVersions()).thenReturn(false, true);
System.setProperty(CARBON_HOME, "");
GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
PowerMockito.when(APIUtil.getArtifactManager(apiConsumer.registry, APIConstants.API_KEY)).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.getLightWeightAPI(artifact)).thenReturn(api);
assertNotNull(apiConsumer.getAllPaginatedPublishedLightWeightAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
assertNotNull(apiConsumer.getAllPaginatedPublishedLightWeightAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
// artifact manager null path
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(null);
assertNotNull(apiConsumer.getAllPaginatedPublishedLightWeightAPIs(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.getAllPaginatedPublishedLightWeightAPIs(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 testGetPublishedAPIsByProvider.
@Test
public void testGetPublishedAPIsByProvider() throws APIManagementException, RegistryException {
Registry userRegistry = Mockito.mock(Registry.class);
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(userRegistry, apiMgtDAO);
PowerMockito.when(APIUtil.isAllowDisplayMultipleVersions()).thenReturn(true, false);
PowerMockito.when(APIUtil.isAllowDisplayAPIsWithMultipleStatus()).thenReturn(true, false);
GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(artifactManager);
Association association = Mockito.mock(Association.class);
Association[] associations = new Association[] { association };
Mockito.when(userRegistry.getAssociations(Mockito.anyString(), Mockito.anyString())).thenReturn(associations);
Mockito.when(association.getDestinationPath()).thenReturn("testPath");
Resource resource = Mockito.mock(Resource.class);
Mockito.when(userRegistry.get("testPath")).thenReturn(resource);
Mockito.when(resource.getUUID()).thenReturn("testID");
GenericArtifact genericArtifact = Mockito.mock(GenericArtifact.class);
Mockito.when(artifactManager.getGenericArtifact(Mockito.anyString())).thenReturn(genericArtifact);
Mockito.when(genericArtifact.getAttribute("overview_status")).thenReturn("PUBLISHED");
APIIdentifier apiId1 = new APIIdentifier("admin", "API1", "1.0.0");
API api = new API(apiId1);
Mockito.when(APIUtil.getAPI(genericArtifact)).thenReturn(api);
assertNotNull(apiConsumer.getPublishedAPIsByProvider("testID", 10));
assertNotNull(apiConsumer.getPublishedAPIsByProvider("testID", 10));
}
use of org.wso2.carbon.apimgt.api.APIConsumer in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetAllPaginatedAPIsByStatusSet.
@Test
public void testGetAllPaginatedAPIsByStatusSet() throws Exception {
Registry userRegistry = Mockito.mock(Registry.class);
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(userRegistry, apiMgtDAO);
PowerMockito.mockStatic(GovernanceUtils.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("10", "20");
PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt());
GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
PowerMockito.when(APIUtil.isAllowDisplayMultipleVersions()).thenReturn(false, true);
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).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);
String artifactPath = "artifact/path";
PowerMockito.when(GovernanceUtils.getArtifactPath(userRegistry, artifact.getId())).thenReturn(artifactPath);
Tag tag = new Tag();
Tag[] tags = new Tag[] { tag };
Mockito.when(userRegistry.getTags(artifactPath)).thenReturn(tags);
assertNotNull(apiConsumer.getAllPaginatedAPIsByStatus(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10, new String[] { "testStatus" }, false));
assertNotNull(apiConsumer.getAllPaginatedAPIsByStatus(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10, new String[] { "testStatus" }, true));
// artifact manager null path
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(null);
assertNotNull(apiConsumer.getAllPaginatedAPIsByStatus(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10, new String[] { "testStatus" }, true));
// generic artifact null path
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(artifactManager);
Mockito.when(GovernanceUtils.findGovernanceArtifacts(Mockito.anyString(), (UserRegistry) Mockito.anyObject(), Mockito.anyString())).thenReturn(null);
assertNotNull(apiConsumer.getAllPaginatedAPIsByStatus(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10, new String[] { "testStatus" }, true));
}
use of org.wso2.carbon.apimgt.api.APIConsumer in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetRecentlyAddedAPIs.
@Test
public void testGetRecentlyAddedAPIs() throws Exception {
Registry userRegistry = Mockito.mock(Registry.class);
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(userRegistry, apiMgtDAO);
UserRegistry userRegistry1 = 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");
API api = Mockito.mock(API.class);
Set<API> recentlyAddedAPI = new HashSet<API>();
recentlyAddedAPI.add(api);
PowerMockito.mockStatic(Caching.class);
CacheManager cacheManager = Mockito.mock(CacheManager.class);
Cache<Object, Object> cache = Mockito.mock(Cache.class);
Mockito.when(Caching.getCacheManager(Mockito.anyString())).thenReturn(cacheManager);
Mockito.when(cacheManager.getCache(Mockito.anyString())).thenReturn(cache);
Mockito.when(cache.get(Mockito.anyObject())).thenReturn(recentlyAddedAPI);
Resource resource = new ResourceImpl();
resource.setProperty("overview_status", "overview_status");
resource.setProperty("store_view_roles", "store_view_roles");
String path = "testPath";
Mockito.when(APIUtil.getAPIPath((APIIdentifier) Mockito.anyObject())).thenReturn(path);
Mockito.when(userRegistry1.get(Mockito.anyString())).thenReturn(resource);
PowerMockito.mockStatic(GovernanceUtils.class);
PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt());
PowerMockito.when(APIUtil.isAllowDisplayMultipleVersions()).thenReturn(true, false);
System.setProperty(CARBON_HOME, "");
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.findGovernanceArtifacts(Mockito.anyString())).thenReturn(genericArtifacts);
APIIdentifier apiId1 = new APIIdentifier("admin", "API1", "1.0.0");
API api1 = new API(apiId1);
Mockito.when(APIUtil.getAPI(artifact)).thenReturn(api1);
// set isAllowDisplayMultipleVersions true
assertNotNull(apiConsumer.getRecentlyAddedAPIs(10, "testDomain"));
// set isAllowDisplayMultipleVersions false
assertNotNull(apiConsumer.getRecentlyAddedAPIs(10, "testDomain"));
}
use of org.wso2.carbon.apimgt.api.APIConsumer in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetPaginatedAPIsWithTag.
@Test
public void testGetPaginatedAPIsWithTag() throws Exception {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper();
PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt());
PowerMockito.mockStatic(GovernanceUtils.class);
GovernanceArtifact governanceArtifact = new GenericArtifactImpl(UUID.randomUUID().toString(), new QName(UUID.randomUUID().toString(), "UUID.randomUUID().toString()"), "api");
List<GovernanceArtifact> governanceArtifactList = new ArrayList();
governanceArtifactList.add(governanceArtifact);
Mockito.when(GovernanceUtils.findGovernanceArtifacts(Mockito.anyString(), (Registry) Mockito.anyObject(), Mockito.anyString())).thenReturn(governanceArtifactList);
assertNotNull(apiConsumer.getPaginatedAPIsWithTag("testTag", 0, 10, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
}
Aggregations