Search in sources :

Example 1 with TenantIndexingLoader

use of org.wso2.carbon.registry.indexing.service.TenantIndexingLoader in project carbon-apimgt by wso2.

the class APIUtilRolesTest method testCreateDefaultRoles.

@Test
public void testCreateDefaultRoles() throws Exception {
    System.setProperty("carbon.home", APIUtilRolesTest.class.getResource("/").getFile());
    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
        final int tenantId = MultitenantConstants.SUPER_TENANT_ID;
        final String tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
        File siteConfFile = new File(Thread.currentThread().getContextClassLoader().getResource("tenant-conf.json").getFile());
        String tenantConfValue = FileUtils.readFileToString(siteConfFile);
        InputStream signUpConfStream = new FileInputStream(Thread.currentThread().getContextClassLoader().getResource("default-sign-up-config.xml").getFile());
        ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
        RealmService realmService = Mockito.mock(RealmService.class);
        RegistryService registryService = Mockito.mock(RegistryService.class);
        TenantManager tenantManager = Mockito.mock(TenantManager.class);
        TenantIndexingLoader indexingLoader = Mockito.mock(TenantIndexingLoader.class);
        UserRealm userRealm = Mockito.mock(UserRealm.class);
        UserStoreManager userStoreManager = Mockito.mock(UserStoreManager.class);
        RealmConfiguration realmConfiguration = Mockito.mock(RealmConfiguration.class);
        APIMConfigService apimConfigService = Mockito.mock(APIMConfigService.class);
        PowerMockito.mockStatic(PrivilegedCarbonContext.class);
        PowerMockito.mockStatic(ServiceReferenceHolder.class);
        PowerMockito.mockStatic(APIManagerComponent.class);
        Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
        Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
        Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
        Mockito.when(serviceReferenceHolder.getIndexLoaderService()).thenReturn(indexingLoader);
        Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
        Mockito.when(realmService.getBootstrapRealm()).thenReturn(userRealm);
        Mockito.when(realmService.getTenantUserRealm(tenantId)).thenReturn(userRealm);
        Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
        Mockito.when(userRealm.getRealmConfiguration()).thenReturn(realmConfiguration);
        Mockito.when(realmConfiguration.getAdminUserName()).thenReturn("admin");
        Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantId);
        Mockito.when(tenantManager.getDomain(tenantId)).thenReturn(tenantDomain);
        Mockito.when(serviceReferenceHolder.getApimConfigService()).thenReturn(apimConfigService);
        Mockito.when(apimConfigService.getTenantConfig(tenantDomain)).thenReturn(tenantConfValue);
        Mockito.when(apimConfigService.getSelfSighupConfig(tenantDomain)).thenReturn(IOUtils.toString(signUpConfStream));
        APIUtil.createDefaultRoles(tenantId);
        String[] adminName = { "admin" };
        Mockito.verify(userStoreManager, Mockito.atLeastOnce()).addRole(eq("Internal/publisher"), eq(adminName), new Permission[] { Mockito.any(Permission.class) });
        Mockito.verify(userStoreManager, Mockito.atLeastOnce()).addRole(eq("Internal/subscriber"), eq(adminName), new Permission[] { Mockito.any(Permission.class) });
        Mockito.verify(userStoreManager, Mockito.atLeastOnce()).addRole(eq("Internal/creator"), eq(adminName), new Permission[] { Mockito.any(Permission.class) });
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) FileInputStream(java.io.FileInputStream) RealmConfiguration(org.wso2.carbon.user.core.config.RealmConfiguration) TenantIndexingLoader(org.wso2.carbon.registry.indexing.service.TenantIndexingLoader) UserRealm(org.wso2.carbon.user.core.UserRealm) RealmService(org.wso2.carbon.user.core.service.RealmService) Permission(org.wso2.carbon.user.api.Permission) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) File(java.io.File) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) APIMConfigService(org.wso2.carbon.apimgt.impl.config.APIMConfigService) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 APIMConfigService (org.wso2.carbon.apimgt.impl.config.APIMConfigService)1 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)1 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)1 TenantIndexingLoader (org.wso2.carbon.registry.indexing.service.TenantIndexingLoader)1 Permission (org.wso2.carbon.user.api.Permission)1 UserRealm (org.wso2.carbon.user.core.UserRealm)1 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)1 RealmConfiguration (org.wso2.carbon.user.core.config.RealmConfiguration)1 RealmService (org.wso2.carbon.user.core.service.RealmService)1 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)1