Search in sources :

Example 1 with MicroPlatform

use of org.pentaho.test.platform.engine.core.MicroPlatform in project pentaho-kettle by pentaho.

the class UIEERepositoryDirectoryIT method setUp.

@Before
public void setUp() throws Exception {
    this.testContextManager = new TestContextManager(getClass());
    this.testContextManager.prepareTestInstance(this);
    loginAsRepositoryAdmin();
    SimpleJcrTestUtils.deleteItem(testJcrTemplate, ServerRepositoryPaths.getPentahoRootFolderPath());
    mp = new MicroPlatform();
    // used by DefaultPentahoJackrabbitAccessControlHelper
    mp.defineInstance("tenantedUserNameUtils", userNameUtils);
    mp.defineInstance("tenantedRoleNameUtils", roleNameUtils);
    mp.defineInstance(IAuthorizationPolicy.class, authorizationPolicy);
    mp.defineInstance(ITenantManager.class, tenantManager);
    mp.defineInstance("roleAuthorizationPolicyRoleBindingDaoTarget", roleBindingDaoTarget);
    mp.defineInstance("repositoryAdminUsername", repositoryAdminUsername);
    mp.defineInstance("RepositoryFileProxyFactory", new RepositoryFileProxyFactory(testJcrTemplate, repositoryFileDao));
    mp.defineInstance("useMultiByteEncoding", new Boolean(false));
    mp.defineInstance(IAclService.class, new Boolean(false));
    // Start the micro-platform
    mp.start();
    loginAsRepositoryAdmin();
    setAclManagement();
    systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), singleTenantAdminRoleName, tenantAuthenticatedRoleName, "Anonymous");
    userRoleDao.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { singleTenantAdminRoleName });
    logout();
    super.setUp();
    KettleEnvironment.init();
    // programmatically register plugins, annotation based plugins do not get loaded unless
    // they are in kettle's plugins folder.
    JobEntryPluginType.getInstance().registerCustom(JobEntryAttributeTesterJobEntry.class, "test", "JobEntryAttributeTester", "JobEntryAttributeTester", "JobEntryAttributeTester", "");
    StepPluginType.getInstance().registerCustom(TransStepAttributeTesterTransStep.class, "test", "StepAttributeTester", "StepAttributeTester", "StepAttributeTester", "");
    repositoryMeta = new PurRepositoryMeta();
    repositoryMeta.setName("JackRabbit");
    repositoryMeta.setDescription("JackRabbit test repository");
    userInfo = new UserInfo(EXP_LOGIN, "password", EXP_USERNAME, "Apache Tomcat user", true);
    repository = new PurRepository();
    repository.init(repositoryMeta);
    login(sysAdminUserName, systemTenant, new String[] { singleTenantAdminRoleName, tenantAuthenticatedRoleName });
    ITenant tenantAcme = tenantManager.createTenant(systemTenant, EXP_TENANT, singleTenantAdminRoleName, tenantAuthenticatedRoleName, "Anonymous");
    userRoleDao.createUser(tenantAcme, EXP_LOGIN, "password", "", new String[] { singleTenantAdminRoleName });
    logout();
    setUpUser();
    PurRepository purRep = (PurRepository) repository;
    final PurRepositoryConnector purRepositoryConnector = new PurRepositoryConnector(purRep, (PurRepositoryMeta) repositoryMeta, purRep.getRootRef());
    purRep.setPurRepositoryConnector(purRepositoryConnector);
    purRep.setTest(repo);
    repository.connect(EXP_LOGIN, "password");
    login(EXP_LOGIN, tenantAcme, new String[] { singleTenantAdminRoleName, tenantAuthenticatedRoleName });
    System.out.println("PUR NAME!!!: " + repo.getClass().getCanonicalName());
    RepositoryFile repositoryFile = repo.getFile(ClientRepositoryPaths.getPublicFolderPath());
    Serializable repositoryFileId = repositoryFile.getId();
    List<RepositoryFile> files = repo.getChildren(repositoryFileId);
    StringBuilder buf = new StringBuilder();
    for (RepositoryFile file : files) {
        buf.append("\n").append(file);
    }
    assertTrue("files not deleted: " + buf, files.isEmpty());
}
Also used : Serializable(java.io.Serializable) PurRepository(org.pentaho.di.repository.pur.PurRepository) PurRepositoryMeta(org.pentaho.di.repository.pur.PurRepositoryMeta) PurRepositoryConnector(org.pentaho.di.repository.pur.PurRepositoryConnector) UserInfo(org.pentaho.di.repository.UserInfo) TestContextManager(org.springframework.test.context.TestContextManager) ITenant(org.pentaho.platform.api.mt.ITenant) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileProxyFactory(org.pentaho.platform.repository2.unified.jcr.RepositoryFileProxyFactory) Before(org.junit.Before)

Example 2 with MicroPlatform

use of org.pentaho.test.platform.engine.core.MicroPlatform in project pentaho-platform by pentaho.

the class RepositoryCleanerTest method gc.

@Test
public void gc() throws Exception {
    GarbageCollector collector = mock(GarbageCollector.class);
    RepositoryImpl repository = mock(RepositoryImpl.class);
    when(repository.createDataStoreGarbageCollector()).thenReturn(collector);
    MicroPlatform mp = new MicroPlatform(getSolutionPath());
    mp.defineInstance(Repository.class, repository);
    mp.defineInstance("jcrRepository", repository);
    mp.start();
    RepositoryCleaner cleaner = new RepositoryCleaner();
    Session systemSession = mock(Session.class);
    IPentahoSystemSessionFactory sessionFactory = mock(IPentahoSystemSessionFactory.class);
    when(sessionFactory.create(repository)).thenReturn(systemSession);
    cleaner.setSystemSessionFactory(sessionFactory);
    try {
        cleaner.gc();
    } finally {
        mp.stop();
    }
    verify(collector, times(1)).mark();
    verify(collector, times(1)).sweep();
    verify(collector, times(1)).close();
}
Also used : IPentahoSystemSessionFactory(org.apache.jackrabbit.core.IPentahoSystemSessionFactory) RepositoryImpl(org.apache.jackrabbit.core.RepositoryImpl) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) GarbageCollector(org.apache.jackrabbit.core.gc.GarbageCollector) Session(javax.jcr.Session) Test(org.junit.Test)

Example 3 with MicroPlatform

use of org.pentaho.test.platform.engine.core.MicroPlatform in project pentaho-platform by pentaho.

the class RepositoryGCOrphanTest method testOrphanNodePurge.

@Test
public void testOrphanNodePurge() throws Exception {
    GarbageCollector collector = mock(GarbageCollector.class);
    RepositoryImpl repository = mock(RepositoryImpl.class);
    RepositoryContext context = mock(RepositoryContext.class);
    when(repository.getRepositoryContext()).thenReturn(context);
    RepositoryImpl.WorkspaceInfo workspaceInfo = mock(RepositoryImpl.WorkspaceInfo.class);
    when(repository.getWorkspaceInfo("default")).thenReturn(workspaceInfo);
    WorkspaceConfig config = mock(WorkspaceConfig.class);
    when(workspaceInfo.getConfig()).thenReturn(config);
    when(repository.createDataStoreGarbageCollector()).thenReturn(collector);
    RepositoryCleaner cleaner = new RepositoryCleaner();
    Session systemSession = mock(Session.class);
    IPentahoSystemSessionFactory sessionFactory = mock(IPentahoSystemSessionFactory.class);
    when(sessionFactory.create(repository)).thenReturn(systemSession);
    cleaner.setSystemSessionFactory(sessionFactory);
    Node rootNode = mock(Node.class);
    when(systemSession.getNode("/jcr:system/jcr:versionStorage")).thenReturn(rootNode);
    when(rootNode.getName()).thenReturn("jcr:frozenNode");
    Property uuid = mock(Property.class);
    when(rootNode.getProperty("jcr:frozenUuid")).thenReturn(uuid);
    when(rootNode.hasProperty("jcr:frozenUuid")).thenReturn(true);
    Value value = mock(Value.class);
    when(uuid.getValue()).thenReturn(value);
    when(uuid.getString()).thenReturn("Foo");
    when(systemSession.getNodeByIdentifier(anyString())).thenThrow(new RepositoryException("err"));
    Version parent = mock(Version.class);
    VersionHistory grandParent = mock(VersionHistory.class);
    when(rootNode.getParent()).thenReturn(parent);
    when(parent.getParent()).thenReturn(grandParent);
    when(parent.getName()).thenReturn("Bar");
    NodeIterator nodes = mock(NodeIterator.class);
    when(rootNode.getNodes()).thenReturn(nodes);
    when(nodes.hasNext()).thenReturn(false);
    MicroPlatform mp = new MicroPlatform(getSolutionPath());
    mp.defineInstance(Repository.class, repository);
    mp.defineInstance("jcrRepository", repository);
    mp.start();
    try {
        cleaner.gc();
    } finally {
        mp.stop();
    }
    verify(grandParent, times(1)).removeVersion("Bar");
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) RepositoryCleaner(org.pentaho.platform.repository2.unified.jcr.RepositoryCleaner) Version(javax.jcr.version.Version) Value(javax.jcr.Value) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) WorkspaceConfig(org.apache.jackrabbit.core.config.WorkspaceConfig) Property(javax.jcr.Property) GarbageCollector(org.apache.jackrabbit.core.gc.GarbageCollector) Session(javax.jcr.Session) Test(org.junit.Test)

Example 4 with MicroPlatform

use of org.pentaho.test.platform.engine.core.MicroPlatform in project pentaho-platform by pentaho.

the class SpringSecurityPrincipalProvider_Caching_Test method setUp.

@Before
public void setUp() throws Exception {
    userResolver = mock(ITenantedPrincipleNameResolver.class);
    roleResolver = mock(ITenantedPrincipleNameResolver.class);
    cacheManager = spy(new SimpleMapCacheManager());
    doReturn(false).when(cacheManager).cacheEnabled(USER_CACHE_REGION);
    doReturn(false).when(cacheManager).cacheEnabled(ROLE_CACHE_REGION);
    userTenant = new Tenant(USER_PRINCIPLE, true);
    roleTenant = new Tenant(ROLE_PRINCIPLE, true);
    mp = new MicroPlatform(getSolutionPath());
    mp.defineInstance("tenantedUserNameUtils", userResolver);
    mp.defineInstance("tenantedRoleNameUtils", roleResolver);
    mp.defineInstance(ICacheManager.class, cacheManager);
    mp.start();
    provider = new SpringSecurityPrincipalProvider();
    provider.init(new Properties());
    provider = spy(provider);
    User user = new User(USER_PRINCIPLE, "", true, true, true, true, new ArrayList<GrantedAuthority>());
    doReturn(user).when(provider).internalGetUserDetails(USER_PRINCIPLE);
}
Also used : Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) User(org.springframework.security.core.userdetails.User) GrantedAuthority(org.springframework.security.core.GrantedAuthority) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) ITenantedPrincipleNameResolver(org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver) Properties(java.util.Properties) SpringSecurityPrincipalProvider(org.pentaho.platform.repository2.unified.jcr.jackrabbit.security.SpringSecurityPrincipalProvider) SimpleMapCacheManager(org.pentaho.platform.engine.core.system.SimpleMapCacheManager) Before(org.junit.Before)

Example 5 with MicroPlatform

use of org.pentaho.test.platform.engine.core.MicroPlatform in project pentaho-platform by pentaho.

the class SpringSecurityPrincipalProvider_PrincipalCreation_Test method setUp.

@Before
public void setUp() throws Exception {
    userResolver = mock(ITenantedPrincipleNameResolver.class);
    mp = new MicroPlatform(getSolutionPath());
    mp.defineInstance("tenantedUserNameUtils", userResolver);
    mp.start();
    setUpProvider(createBasicProperties());
}
Also used : MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) ITenantedPrincipleNameResolver(org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver) Before(org.junit.Before)

Aggregations

MicroPlatform (org.pentaho.test.platform.engine.core.MicroPlatform)64 Before (org.junit.Before)40 File (java.io.File)15 Test (org.junit.Test)12 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)10 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)10 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)10 RepositoryFileProxyFactory (org.pentaho.platform.repository2.unified.jcr.RepositoryFileProxyFactory)9 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)8 FileSystemBackedUnifiedRepository (org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository)8 BeforeClass (org.junit.BeforeClass)7 IPluginResourceLoader (org.pentaho.platform.api.engine.IPluginResourceLoader)6 ArrayList (java.util.ArrayList)5 IUserRoleListService (org.pentaho.platform.api.engine.IUserRoleListService)5 SystemSettings (org.pentaho.platform.engine.core.system.SystemSettings)5 PluginResourceLoader (org.pentaho.platform.plugin.services.pluginmgr.PluginResourceLoader)5 Serializable (java.io.Serializable)4 HashMap (java.util.HashMap)4 Matchers.anyString (org.mockito.Matchers.anyString)4 ITenant (org.pentaho.platform.api.mt.ITenant)4