use of org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider in project jackrabbit-oak by apache.
the class NodeStateCopyUtilsTest method copyToJcr.
@Test
public void copyToJcr() throws Exception {
repository = new Jcr().with(new OpenSecurityProvider()).createRepository();
Tree srcTree = TreeFactory.createTree(builder);
srcTree.setOrderableChildren(true);
srcTree.setProperty("foo", "x");
srcTree.setProperty("foo", "x");
srcTree.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_OAK_UNSTRUCTURED, Type.NAME);
srcTree.addChild("a").setOrderableChildren(true);
srcTree.addChild("a").setProperty("foo", "y");
srcTree.addChild("a").setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_OAK_UNSTRUCTURED, Type.NAME);
srcTree.addChild("b").setOrderableChildren(true);
srcTree.addChild("b").setProperty("foo", "z");
srcTree.addChild("b").setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_OAK_UNSTRUCTURED, Type.NAME);
Session session = repository.login(null, null);
Node node = session.getRootNode();
Node test = node.addNode("test", NT_OAK_UNSTRUCTURED);
NodeStateCopyUtils.copyToNode(builder.getNodeState(), test);
session.save();
test = session.getNode("/test");
assertEquals("y", test.getProperty("a/foo").getString());
assertEquals("z", test.getProperty("b/foo").getString());
}
use of org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider in project jackrabbit-oak by apache.
the class NodeStateCopyUtilsTest method copyToJcrVariousProps.
@Test
public void copyToJcrVariousProps() throws Exception {
repository = new Jcr().with(new OpenSecurityProvider()).createRepository();
Calendar cal = ISO8601.parse(ISO8601.format(Calendar.getInstance()));
Tree srcTree = TreeFactory.createTree(builder);
srcTree.setOrderableChildren(true);
srcTree.setProperty("fooString", "x");
srcTree.setProperty("fooLong", 1L, Type.LONG);
srcTree.setProperty("fooPath", "/fooNode", Type.PATH);
srcTree.setProperty("fooName", "mix:title", Type.NAME);
srcTree.setProperty("fooDouble", 1.0, Type.DOUBLE);
srcTree.setProperty("fooDate", ISO8601.format(cal), Type.DATE);
srcTree.setProperty("fooBoolean", true, Type.BOOLEAN);
srcTree.setProperty("fooStrings", asList("a", "b"), Type.STRINGS);
srcTree.setProperty("fooBlob", new ArrayBasedBlob("foo".getBytes()), Type.BINARY);
srcTree.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_OAK_UNSTRUCTURED, Type.NAME);
srcTree.setProperty(JcrConstants.JCR_MIXINTYPES, asList("mix:mimeType", "mix:title"), Type.NAMES);
Session session = repository.login(null, null);
Node node = session.getRootNode();
Node test = node.addNode("test", NT_OAK_UNSTRUCTURED);
Node fooNode = node.addNode("fooNode", NT_OAK_UNSTRUCTURED);
NodeStateCopyUtils.copyToNode(builder.getNodeState(), test);
session.save();
test = session.getNode("/test");
assertEquals("x", test.getProperty("fooString").getString());
assertEquals("/fooNode", test.getProperty("fooPath").getNode().getPath());
assertEquals("mix:title", test.getProperty("fooName").getString());
assertEquals(1, test.getProperty("fooLong").getLong());
assertEquals(cal, test.getProperty("fooDate").getDate());
assertEquals("a", test.getProperty("fooStrings").getValues()[0].getString());
assertEquals("b", test.getProperty("fooStrings").getValues()[1].getString());
InputStream is = test.getProperty("fooBlob").getBinary().getStream();
String streamVal = IOUtils.toString(is, "UTF-8");
assertEquals("foo", streamVal);
}
use of org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider in project jackrabbit-oak by apache.
the class OakTest method testContentRepositoryReuse.
@Test
public void testContentRepositoryReuse() throws Exception {
Oak oak = new Oak().with(new OpenSecurityProvider());
ContentRepository r0 = null;
ContentRepository r1 = null;
try {
r0 = oak.createContentRepository();
r1 = oak.createContentRepository();
assertEquals(r0, r1);
} finally {
if (r0 != null) {
((Closeable) r0).close();
}
}
}
use of org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider in project jackrabbit-oak by apache.
the class OakTest method testWithDefaultWorkspaceName.
@Test
public void testWithDefaultWorkspaceName() throws Exception {
ContentRepository repo = new Oak().with("test").with(new OpenSecurityProvider()).createContentRepository();
String[] valid = new String[] { null, "test" };
for (String wspName : valid) {
ContentSession cs = null;
try {
cs = repo.login(null, wspName);
assertEquals("test", cs.getWorkspaceName());
} finally {
if (cs != null) {
cs.close();
}
}
}
String[] invalid = new String[] { "", "another", Oak.DEFAULT_WORKSPACE_NAME };
for (String wspName : invalid) {
ContentSession cs = null;
try {
cs = repo.login(null, wspName);
fail("invalid workspace nam");
} catch (NoSuchWorkspaceException e) {
// success
} finally {
if (cs != null) {
cs.close();
}
}
}
}
use of org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider in project jackrabbit-oak by apache.
the class OakTest method checkMissingStrategySetting.
@Test(expected = CommitFailedException.class)
public void checkMissingStrategySetting() throws Exception {
Whiteboard wb = new DefaultWhiteboard();
WhiteboardIndexEditorProvider wbProvider = new WhiteboardIndexEditorProvider();
wbProvider.start(wb);
Registration r1 = wb.register(IndexEditorProvider.class, new PropertyIndexEditorProvider(), null);
Registration r2 = wb.register(IndexEditorProvider.class, new ReferenceEditorProvider(), null);
Oak oak = new Oak().with(new OpenSecurityProvider()).with(new InitialContent()).with(wb).with(wbProvider).withFailOnMissingIndexProvider();
ContentRepository repo = oak.createContentRepository();
ContentSession cs = repo.login(null, null);
Root root = cs.getLatestRoot();
Tree t = root.getTree("/");
t.setProperty("foo", "u1", Type.REFERENCE);
r1.unregister();
root.commit();
cs.close();
((Closeable) repo).close();
}
Aggregations