use of org.wso2.carbon.identity.common.testng.realm.InMemoryRealmService in project carbon-identity-framework by wso2.
the class CarbonBasedTestListener method createRealmService.
private RealmService createRealmService(WithRealmService withRealmService, boolean reuseIfAvailable) throws UserStoreException {
if (testSessionRealmService != null && reuseIfAvailable) {
return testSessionRealmService;
}
try {
int tenantId = withRealmService.tenantId();
String tenantDomain = withRealmService.tenantDomain();
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
testSessionRealmService = new InMemoryRealmService(tenantId);
UserStoreManager userStoreManager = testSessionRealmService.getTenantUserRealm(tenantId).getUserStoreManager();
((MockUserStoreManager) userStoreManager).addSecondaryUserStoreManager("PRIMARY", (MockUserStoreManager) userStoreManager);
IdentityTenantUtil.setRealmService(testSessionRealmService);
TenantManager tenantManager = new InMemoryTenantManager();
testSessionRealmService.setTenantManager(tenantManager);
RegistryDataHolder.getInstance().setRealmService(testSessionRealmService);
OSGiDataHolder.getInstance().setUserRealmService(testSessionRealmService);
Class[] singletonClasses = withRealmService.injectToSingletons();
for (Class singletonClass : singletonClasses) {
Object instance = getSingletonInstance(singletonClass);
if (instance != null) {
setInstanceValue(testSessionRealmService, RealmService.class, singletonClass, instance);
} else {
setInstanceValue(testSessionRealmService, RealmService.class, singletonClass, null);
}
}
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
return testSessionRealmService;
}
use of org.wso2.carbon.identity.common.testng.realm.InMemoryRealmService in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImplTest method setupConfiguration.
private void setupConfiguration() throws UserStoreException, RegistryException {
String carbonHome = Paths.get(System.getProperty("user.dir"), "target", "test-classes", "repository").toString();
System.setProperty(CarbonBaseConstants.CARBON_HOME, carbonHome);
System.setProperty(CarbonBaseConstants.CARBON_CONFIG_DIR_PATH, Paths.get(carbonHome, "conf").toString());
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(SUPER_TENANT_DOMAIN_NAME);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(SUPER_TENANT_ID);
PrivilegedCarbonContext.getThreadLocalCarbonContext();
// Configure RealmService.
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(SUPER_TENANT_ID);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(SUPER_TENANT_DOMAIN_NAME);
InMemoryRealmService testSessionRealmService = new InMemoryRealmService(SUPER_TENANT_ID);
UserStoreManager userStoreManager = testSessionRealmService.getTenantUserRealm(SUPER_TENANT_ID).getUserStoreManager();
((MockUserStoreManager) userStoreManager).addSecondaryUserStoreManager("PRIMARY", (MockUserStoreManager) userStoreManager);
IdentityTenantUtil.setRealmService(testSessionRealmService);
RegistryDataHolder.getInstance().setRealmService(testSessionRealmService);
OSGiDataHolder.getInstance().setUserRealmService(testSessionRealmService);
IdentityCoreServiceDataHolder.getInstance().setRealmService(testSessionRealmService);
ApplicationManagementServiceComponentHolder holder = ApplicationManagementServiceComponentHolder.getInstance();
setInstanceValue(testSessionRealmService, RealmService.class, ApplicationManagementServiceComponentHolder.class, holder);
// Configure Registry Service.
RegistryService mockRegistryService = mock(RegistryService.class);
UserRegistry mockRegistry = mock(UserRegistry.class);
when(mockRegistryService.getGovernanceUserRegistry(anyString(), anyInt())).thenReturn(mockRegistry);
OSGiDataHolder.getInstance().setRegistryService(mockRegistryService);
CarbonCoreDataHolder.getInstance().setRegistryService(mockRegistryService);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setRegistry(RegistryType.USER_GOVERNANCE, mockRegistryService.getRegistry());
when(mockRegistry.resourceExists(anyString())).thenReturn(FALSE);
Collection mockPermissionNode = mock(Collection.class);
when(mockRegistry.newCollection()).thenReturn(mockPermissionNode);
when(mockRegistry.get(anyString())).thenReturn(mockPermissionNode);
}
Aggregations