use of org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class ServiceReferenceHolderTestCase method testServiceReferenceHolder.
@Test
public void testServiceReferenceHolder() {
ServiceReferenceHolder serviceReferenceHolder = ServiceReferenceHolder.getInstance();
Assert.assertTrue(serviceReferenceHolder instanceof ServiceReferenceHolder);
serviceReferenceHolder.getThrottleDataHolder();
ThrottleDataHolder throttleDataHolder = Mockito.mock(ThrottleDataHolder.class);
serviceReferenceHolder.setThrottleDataHolder(throttleDataHolder);
ConfigurationContextService cfgCtxService = Mockito.mock(ConfigurationContextService.class);
serviceReferenceHolder.setConfigurationContextService(cfgCtxService);
cfgCtxService = serviceReferenceHolder.getConfigurationContextService();
Assert.assertNotNull(cfgCtxService);
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
serviceReferenceHolder.setAPIManagerConfigurationService(apiManagerConfigurationService);
apiManagerConfigurationService = serviceReferenceHolder.getApiManagerConfigurationService();
Assert.assertNotNull(apiManagerConfigurationService);
Assert.assertNull(serviceReferenceHolder.getAPIManagerConfiguration());
Assert.assertNull(serviceReferenceHolder.getServerConfigurationContext());
ThrottleProperties throttleProperties = Mockito.mock(ThrottleProperties.class);
serviceReferenceHolder.setThrottleProperties(throttleProperties);
Assert.assertNotNull(serviceReferenceHolder.getThrottleProperties());
}
use of org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class APIRealmUtilTest method testLoggedInUserClaims.
@Test
public void testLoggedInUserClaims() throws APIManagementException, UserStoreException, XMLStreamException {
String configuredClaims = "http://wso2.org/claim1,http://wso2.org/claim2,http://wso2.org/claim3";
PowerMockito.mockStatic(MultitenantUtils.class);
PowerMockito.mockStatic(APIUtil.class);
Mockito.when(MultitenantUtils.getTenantDomain("admin")).thenReturn("carbon.super");
ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
PowerMockito.when(tenantManager.getTenantId(Matchers.anyString())).thenReturn(-1234);
SortedMap<String, String> claimValues = new TreeMap<String, String>();
claimValues.put("claim1", "http://wso2.org/claim1");
claimValues.put("claim2", "http://wso2.org/claim2");
claimValues.put("claim3", "http://wso2.org/claim3");
PowerMockito.when(APIUtil.getTenantId("carbon.super")).thenReturn(-1234);
PowerMockito.when(APIUtil.getClaims("admin", -1234, DEFAULT_DIALECT_URI)).thenReturn(claimValues);
Map loggedInUserClaims = APIRealmUtils.getUserClaims("admin");
assertNotNull(loggedInUserClaims);
assertEquals(configuredClaims.split(",").length, loggedInUserClaims.size());
}
use of org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class APIUtilTest method testIsRoleNameNotExist.
@Test
public void testIsRoleNameNotExist() throws Exception {
String userName = "John";
String roleName = "developer";
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
UserRealm userRealm = Mockito.mock(UserRealm.class);
UserStoreManager userStoreManager = Mockito.mock(UserStoreManager.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
Mockito.when(realmService.getTenantUserRealm(Mockito.anyInt())).thenReturn(userRealm);
Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
Mockito.when(userStoreManager.isExistingRole(roleName)).thenReturn(false);
Assert.assertFalse(APIUtil.isRoleNameExist(userName, roleName));
}
use of org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class APIUtilTest method testGetAppAttributeKeysFromRegistry.
@Test
public void testGetAppAttributeKeysFromRegistry() throws Exception {
System.setProperty("carbon.home", APIUtilTest.class.getResource("/").getFile());
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
final int tenantId = -1234;
final String property = APIConstants.ApplicationAttributes.APPLICATION_CONFIGURATIONS;
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
RegistryService registryService = Mockito.mock(RegistryService.class);
Resource resource = Mockito.mock(Resource.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
File siteConfFile = new File(Thread.currentThread().getContextClassLoader().getResource("tenant-conf.json").getFile());
String tenantConfValue = FileUtils.readFileToString(siteConfFile);
APIMConfigService apimConfigService = Mockito.mock(APIMConfigService.class);
Mockito.when(serviceReferenceHolder.getApimConfigService()).thenReturn(apimConfigService);
Mockito.when(apimConfigService.getTenantConfig(tenantDomain)).thenReturn(tenantConfValue);
JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(tenantConfValue);
JSONObject applicationAttributes = (JSONObject) json.get(property);
JSONObject appAttributes = APIUtil.getAppAttributeKeysFromRegistry(tenantDomain);
Assert.assertEquals(applicationAttributes, appAttributes);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class APIUtilTest method testIsPerAPISequenceResourceMissing.
@Test
public void testIsPerAPISequenceResourceMissing() throws Exception {
APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
RegistryService registryService = Mockito.mock(RegistryService.class);
UserRegistry registry = Mockito.mock(UserRegistry.class);
String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion();
String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "in" + RegistryConstants.PATH_SEPARATOR;
PowerMockito.mockStatic(ServiceReferenceHolder.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry);
Mockito.when(registry.resourceExists(eq(path))).thenReturn(false);
boolean isPerAPiSequence = APIUtil.isPerAPISequence("sample", 1, apiIdentifier, "in");
Assert.assertFalse(isPerAPiSequence);
}
Aggregations