use of org.wso2.carbon.utils.ServerConstants.CARBON_HOME 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.utils.ServerConstants.CARBON_HOME in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetAllPaginatedAPIsByStatus.
@Test
public void testGetAllPaginatedAPIsByStatus() throws Exception {
Registry userRegistry = Mockito.mock(Registry.class);
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(userRegistry, apiMgtDAO);
System.setProperty(CARBON_HOME, "");
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.mockStatic(GovernanceUtils.class);
PowerMockito.mockStatic(GovernanceUtils.class);
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);
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);
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, "testStatus", false));
assertNotNull(apiConsumer.getAllPaginatedAPIsByStatus(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10, "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, "testStatus", true));
// 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.getAllPaginatedAPIsByStatus(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10, "testStatus", true));
}
use of org.wso2.carbon.utils.ServerConstants.CARBON_HOME in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetAllPaginatedPublishedAPIs.
@Test
public void testGetAllPaginatedPublishedAPIs() 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.getAPI(artifact)).thenReturn(api);
assertNotNull(apiConsumer.getAllPaginatedPublishedAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
assertNotNull(apiConsumer.getAllPaginatedPublishedAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
// artifact manager null path
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(null);
assertNotNull(apiConsumer.getAllPaginatedPublishedAPIs(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.getAllPaginatedPublishedAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
}
use of org.wso2.carbon.utils.ServerConstants.CARBON_HOME in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testUpdateAuthClient.
@Test
public void testUpdateAuthClient() throws APIManagementException {
String consumerKey = "aNTf-EFga";
OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
OAuthAppRequest oAuthAppRequest = new OAuthAppRequest();
oAuthAppRequest.setOAuthApplicationInfo(oAuthApplicationInfo);
BDDMockito.when(ApplicationUtils.createOauthAppRequest(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(oAuthAppRequest);
Mockito.when(apiMgtDAO.getConsumerKeyByApplicationIdKeyTypeKeyManager(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString())).thenReturn(consumerKey);
OAuthApplicationInfo updatedAppInfo = new OAuthApplicationInfo();
String clientName = "sample client";
updatedAppInfo.setClientName(clientName);
Mockito.when(keyManager.updateApplication((OAuthAppRequest) Mockito.any())).thenReturn(updatedAppInfo);
KeyManagerConfigurationDTO keyManagerConfiguration = new KeyManagerConfigurationDTO();
keyManagerConfiguration.setEnabled(true);
Mockito.when(apiMgtDAO.getKeyManagerConfigurationByName(Mockito.anyString(), Mockito.anyString())).thenReturn(keyManagerConfiguration);
System.setProperty(CARBON_HOME, "");
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(APIConstants.KEYMANAGER_SERVERURL)).thenReturn("http://localhost");
Application application = Mockito.mock(Application.class);
application.setUUID(UUID.nameUUIDFromBytes("app1".getBytes()).toString());
Subscriber subscriber = Mockito.mock(Subscriber.class);
Mockito.when(ApplicationUtils.retrieveApplication("app1", "1", null)).thenReturn(application);
Mockito.when(application.getSubscriber()).thenReturn(subscriber);
Mockito.when(subscriber.getName()).thenReturn("1");
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(apiMgtDAO);
apiConsumer.tenantDomain = SAMPLE_TENANT_DOMAIN_1;
Assert.assertEquals(apiConsumer.updateAuthClient("1", application, "access", "www.host.com", new String[0], null, null, null, null, "default").getClientName(), clientName);
}
use of org.wso2.carbon.utils.ServerConstants.CARBON_HOME in project carbon-apimgt by wso2.
the class APIUtilTest method testGetTiersWhenTierTypeIsApplication.
@Test
public void testGetTiersWhenTierTypeIsApplication() throws Exception {
System.setProperty(CARBON_HOME, "");
int tierType = APIConstants.TIER_APPLICATION_TYPE;
int tenantID = 1;
Tier tier1 = Mockito.mock(Tier.class);
Map<String, Tier> tierMap = new TreeMap<String, Tier>();
tierMap.put("UNLIMITED", tier1);
PowerMockito.mockStatic(PrivilegedCarbonContext.class);
PowerMockito.doNothing().when(PrivilegedCarbonContext.class, "startTenantFlow");
PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
Mockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
doNothing().when(privilegedCarbonContext).setTenantDomain(tenantDomain, true);
Mockito.when(privilegedCarbonContext.getTenantId()).thenReturn(tenantID);
PowerMockito.spy(APIUtil.class);
PowerMockito.doReturn(tenantID).when(APIUtil.class, "getInternalOrganizationId", tenantDomain);
PowerMockito.doReturn(tierMap).when(APIUtil.class, "getTiersFromPolicies", PolicyConstants.POLICY_LEVEL_APP, tenantID);
Map<String, Tier> appTierMap = APIUtil.getTiers(tierType, tenantDomain);
Assert.assertEquals(tierMap, appTierMap);
}
Aggregations