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();
}
}
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");
}
}
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");
}
}
Aggregations