Search in sources :

Example 11 with FileSystem

use of org.apache.jackrabbit.core.fs.FileSystem in project jackrabbit by apache.

the class RetentionRegistryImplTest method testWriteFileWithChanges.

public void testWriteFileWithChanges() throws RepositoryException, NotExecutableException {
    PathResolver resolver = (SessionImpl) superuser;
    FileSystem fs = createFileSystem();
    RetentionRegistryImpl re = new RetentionRegistryImpl((SessionImpl) superuser, fs);
    String childN3Path = childN3.getPath();
    try {
        retentionMgr.removeRetentionPolicy(childNPath);
        retentionMgr.removeHold(childNPath, retentionMgr.getHolds(childNPath)[0]);
        superuser.save();
        retentionMgr.setRetentionPolicy(childN3Path, getApplicableRetentionPolicy("retentionOnChild2"));
        retentionMgr.addHold(childNPath, "holdOnChild", false);
        superuser.save();
        // write the changes to the fs
        re.close();
        // create a new dummy registry again.
        re = new RetentionRegistryImpl((SessionImpl) superuser, fs);
        // test holds
        assertTrue(re.hasEffectiveHold(resolver.getQPath(childNPath), false));
        assertTrue(re.hasEffectiveHold(resolver.getQPath(childNPath), true));
        assertTrue(re.hasEffectiveHold(resolver.getQPath(childN3Path), true));
        assertFalse(re.hasEffectiveHold(resolver.getQPath(childN3Path), false));
        assertFalse(re.hasEffectiveHold(resolver.getQPath(childN3Path + "/child"), false));
        assertFalse(re.hasEffectiveHold(resolver.getQPath(childN3Path + "/child"), true));
        // test policies
        assertTrue(re.hasEffectiveRetention(resolver.getQPath(childN3Path), false));
        assertTrue(re.hasEffectiveRetention(resolver.getQPath(childN3Path + "/child"), true));
        assertFalse(re.hasEffectiveRetention(resolver.getQPath(childN3Path + "/child/more"), true));
        assertFalse(re.hasEffectiveRetention(resolver.getQPath(childNPath), true));
        assertFalse(re.hasEffectiveRetention(resolver.getQPath(childNPath), false));
    } finally {
        re.close();
        // remove the extra policy that is not cleared upon teardown
        if (retentionMgr.getRetentionPolicy(childN3Path) != null) {
            retentionMgr.removeRetentionPolicy(childN3.getPath());
        }
        superuser.save();
    }
}
Also used : FileSystem(org.apache.jackrabbit.core.fs.FileSystem) MemoryFileSystem(org.apache.jackrabbit.core.fs.mem.MemoryFileSystem) PathResolver(org.apache.jackrabbit.spi.commons.conversion.PathResolver) RetentionRegistryImpl(org.apache.jackrabbit.core.retention.RetentionRegistryImpl)

Example 12 with FileSystem

use of org.apache.jackrabbit.core.fs.FileSystem in project jackrabbit by apache.

the class CustomPrivilegeTest method testInvalidCustomDefinitions.

public void testInvalidCustomDefinitions() throws RepositoryException, FileSystemException, IOException {
    // setup the custom privilege file with cyclic references
    FileSystem fs = ((RepositoryImpl) superuser.getRepository()).getConfig().getFileSystem();
    FileSystemResource resource = new FileSystemResource(fs, "/privileges/custom_privileges.xml");
    if (!resource.exists()) {
        resource.makeParentDirs();
    }
    StringBuilder sb = new StringBuilder();
    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><privileges><privilege isAbstract=\"false\" name=\"test\"><contains name=\"test2\"/></privilege></privileges>");
    Writer writer = new OutputStreamWriter(resource.getOutputStream(), "utf-8");
    writer.write(sb.toString());
    writer.flush();
    writer.close();
    try {
        new PrivilegeRegistry(superuser.getWorkspace().getNamespaceRegistry(), fs);
        fail("Invalid names must be detected upon registry startup.");
    } catch (RepositoryException e) {
    // success
    } finally {
        fs.deleteFolder("/privileges");
    }
}
Also used : FileSystem(org.apache.jackrabbit.core.fs.FileSystem) OutputStreamWriter(java.io.OutputStreamWriter) RepositoryException(javax.jcr.RepositoryException) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) PrivilegeDefinitionWriter(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionWriter) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Example 13 with FileSystem

use of org.apache.jackrabbit.core.fs.FileSystem in project jackrabbit by apache.

the class CustomPrivilegeTest method testCustomDefinitionsWithCyclicReferences.

public void testCustomDefinitionsWithCyclicReferences() throws RepositoryException, FileSystemException, IOException {
    // setup the custom privilege file with cyclic references
    FileSystem fs = ((RepositoryImpl) superuser.getRepository()).getConfig().getFileSystem();
    FileSystemResource resource = new FileSystemResource(fs, "/privileges/custom_privileges.xml");
    if (!resource.exists()) {
        resource.makeParentDirs();
    }
    NameFactory nf = NameFactoryImpl.getInstance();
    Name test = nf.create(Name.NS_DEFAULT_URI, "test");
    Name test2 = nf.create(Name.NS_DEFAULT_URI, "test2");
    Name test3 = nf.create(Name.NS_DEFAULT_URI, "test3");
    Name test4 = nf.create(Name.NS_DEFAULT_URI, "test4");
    Name test5 = nf.create(Name.NS_DEFAULT_URI, "test5");
    OutputStream out = resource.getOutputStream();
    try {
        List<PrivilegeDefinition> defs = new ArrayList<PrivilegeDefinition>();
        defs.add(new PrivilegeDefinitionImpl(test, false, Collections.singleton(test2)));
        defs.add(new PrivilegeDefinitionImpl(test4, true, Collections.singleton(test5)));
        defs.add(new PrivilegeDefinitionImpl(test5, false, Collections.singleton(test3)));
        defs.add(new PrivilegeDefinitionImpl(test3, false, Collections.singleton(test)));
        defs.add(new PrivilegeDefinitionImpl(test2, false, Collections.singleton(test4)));
        PrivilegeDefinitionWriter pdw = new PrivilegeDefinitionWriter("text/xml");
        pdw.writeDefinitions(out, defs.toArray(new PrivilegeDefinition[defs.size()]), Collections.<String, String>emptyMap());
        new PrivilegeRegistry(superuser.getWorkspace().getNamespaceRegistry(), fs);
        fail("Cyclic definitions must be detected upon registry startup.");
    } catch (RepositoryException e) {
    // success
    } finally {
        out.close();
        fs.deleteFolder("/privileges");
    }
}
Also used : PrivilegeDefinitionImpl(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl) FileSystem(org.apache.jackrabbit.core.fs.FileSystem) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) PrivilegeDefinition(org.apache.jackrabbit.spi.PrivilegeDefinition) RepositoryException(javax.jcr.RepositoryException) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) PrivilegeDefinitionWriter(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionWriter) NameFactory(org.apache.jackrabbit.spi.NameFactory) Name(org.apache.jackrabbit.spi.Name)

Aggregations

FileSystem (org.apache.jackrabbit.core.fs.FileSystem)13 RepositoryException (javax.jcr.RepositoryException)8 IOException (java.io.IOException)5 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)5 FileSystemResource (org.apache.jackrabbit.core.fs.FileSystemResource)4 File (java.io.File)3 OutputStreamWriter (java.io.OutputStreamWriter)3 MemoryFileSystem (org.apache.jackrabbit.core.fs.mem.MemoryFileSystem)3 PrivilegeDefinitionWriter (org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionWriter)3 OutputStream (java.io.OutputStream)2 Writer (java.io.Writer)2 ArrayList (java.util.ArrayList)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 TransformerException (javax.xml.transform.TransformerException)2 RetentionRegistryImpl (org.apache.jackrabbit.core.retention.RetentionRegistryImpl)2 Name (org.apache.jackrabbit.spi.Name)2 NameFactory (org.apache.jackrabbit.spi.NameFactory)2 PrivilegeDefinition (org.apache.jackrabbit.spi.PrivilegeDefinition)2 PathResolver (org.apache.jackrabbit.spi.commons.conversion.PathResolver)2 PrivilegeDefinitionImpl (org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl)2