private static void setup(Root root) throws Exception { Tree tree = root.getTree("/"); tree.addChild("c").setProperty("p", "base"); root.commit(); }
@Test public void rebaseWithAddNode() throws CommitFailedException { Root root1 = session.getLatestRoot(); Root root2 = session.getLatestRoot(); checkEqual(root1.getTree("/"), root2.getTree("/")); root2.getTree("/").addChild("one").addChild("two").addChild("three") .setProperty("p1", "V1"); root2.commit(); root1.getTree("/").addChild("child"); root1.rebase(); root2.getTree("/").addChild("child"); checkEqual(root1.getTree("/"), (root2.getTree("/"))); }
@Test public void rebaseWithAddProperty() throws CommitFailedException { Root root1 = session.getLatestRoot(); Root root2 = session.getLatestRoot(); checkEqual(root1.getTree("/"), root2.getTree("/")); root2.getTree("/").addChild("one").addChild("two").addChild("three") .setProperty("p1", "V1"); root2.commit(); root1.getTree("/").setProperty("new", 42); root1.rebase(); root2.getTree("/").setProperty("new", 42); checkEqual(root1.getTree("/"), (root2.getTree("/"))); }
@Test public void rebaseWithSetProperty() throws CommitFailedException { Root root1 = session.getLatestRoot(); Root root2 = session.getLatestRoot(); checkEqual(root1.getTree("/"), root2.getTree("/")); root2.getTree("/").addChild("one").addChild("two").addChild("three") .setProperty("p1", "V1"); root2.commit(); root1.getTree("/").setProperty("a", 42); root1.rebase(); root2.getTree("/").setProperty("a", 42); checkEqual(root1.getTree("/"), (root2.getTree("/"))); }
@Test public void testChangeDeletedNode() throws CommitFailedException { theirRoot.getTree("/x").remove(); ourRoot.getTree("/x").setProperty("p", OUR_VALUE); theirRoot.commit(); ourRoot.commit(); Tree n = ourRoot.getTree("/x"); assertFalse(n.exists()); }
@Test public void testDeleteChangedNode() throws CommitFailedException { theirRoot.getTree("/x").setProperty("p", THEIR_VALUE); ourRoot.getTree("/x").remove(); theirRoot.commit(); ourRoot.commit(); Tree n = ourRoot.getTree("/x"); assertFalse(n.exists()); }
@Test public void testNativeLuceneQuery() throws Exception { String nativeQueryString = "select [jcr:path] from [nt:base] where native('lucene', 'title:foo -title:bar')"; Tree test = root.getTree("/").addChild("test"); test.addChild("a").setProperty("title", "foo"); test.addChild("b").setProperty("title", "bar"); root.commit(); Iterator<String> result = executeQuery(nativeQueryString, "JCR-SQL2").iterator(); assertTrue(result.hasNext()); assertEquals("/test/a", result.next()); assertFalse(result.hasNext()); }
@Test public void testMultiNotEqual() throws Exception { Tree c = root.getTree("/").addChild("content"); c.addChild("one").setProperty("prop", "value"); c.addChild("two").setProperty("prop", ImmutableList.of("aaa", "value", "bbb"), Type.STRINGS); c.addChild("three").setProperty("prop", ImmutableList.of("aaa", "bbb", "ccc"), Type.STRINGS); root.commit(); assertQuery("//*[@prop != 'value']", "xpath", ImmutableList.of("/content/two", "/content/three")); }
@Test public void containsPath() throws Exception { Tree test = root.getTree("/").addChild("test"); test.addChild("a").setProperty("name", "/parent/child/node"); root.commit(); StringBuffer stmt = new StringBuffer(); stmt.append("//*[jcr:contains(., '/parent/child')]"); assertQuery(stmt.toString(), "xpath", ImmutableList.of("/test/a")); }
@Test(expected = CommitFailedException.class) public void oakIndexableFailing() throws IOException, CommitFailedException { registerNodeType(root, "oak3725-1.cnd"); Tree test = root.getTree("/").addChild("test"); test.setProperty(JCR_PRIMARYTYPE, NT_FOLDER, NAME); test.addChild("oak:index").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME); root.commit(); }
@Test public void testMultiAndEquals() throws Exception { Tree c = root.getTree("/").addChild("content"); c.addChild("one").setProperty("prop", "aaa"); c.addChild("two").setProperty("prop", ImmutableList.of("aaa", "bbb", "ccc"), Type.STRINGS); c.addChild("three").setProperty("prop", ImmutableList.of("aaa", "bbb"), Type.STRINGS); root.commit(); assertQuery("//*[(@prop = 'aaa' and @prop = 'bbb' and @prop = 'ccc')]", "xpath", ImmutableList.of("/content/two")); }
@Test public void descendantTest2() throws Exception { Tree test = root.getTree("/").addChild("test"); test.addChild("a").setProperty("name", asList("Hello", "World"), STRINGS); test.addChild("b").setProperty("name", "Hello"); root.commit(); Iterator<String> result = executeQuery( "select [jcr:path] from [nt:base] where isdescendantnode('/test') and name='World'", "JCR-SQL2").iterator(); assertTrue(result.hasNext()); assertEquals("/test/a", result.next()); assertFalse(result.hasNext()); }
@Test public void oakIndexableSuccessful() throws IOException, CommitFailedException { registerNodeType(root, "oak3725-2.cnd"); Tree test = root.getTree("/").addChild("test"); test.setProperty(JCR_PRIMARYTYPE, NT_FOLDER, NAME); test.setProperty(JCR_MIXINTYPES, of(MIX_INDEXABLE), Type.NAMES); test.addChild("oak:index").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME); root.commit(); }
@Test public void testMultiAndLike() throws Exception { Tree c = root.getTree("/").addChild("content"); c.addChild("one").setProperty("prop", "aaaBoom"); c.addChild("two").setProperty("prop", ImmutableList.of("aaaBoom", "bbbBoom", "cccBoom"), Type.STRINGS); c.addChild("three").setProperty("prop", ImmutableList.of("aaaBoom", "bbbBoom"), Type.STRINGS); root.commit(); assertQuery("//*[(jcr:like(@prop, 'aaa%') and jcr:like(@prop, 'bbb%') and jcr:like(@prop, 'ccc%'))]", "xpath", ImmutableList.of("/content/two")); }
@Test public void testLowercaseOnArrays() throws Exception { // OAK-1829 Tree content = root.getTree("/").addChild("content"); content.setProperty("array", Arrays.asList("X", "Y"), Type.STRINGS); root.commit(); assertQuery("//*[jcr:like(fn:lower-case(@array), '%x%')]", "xpath", Arrays.asList("/content")); }
@Test public void containsPathNum() throws Exception { Tree test = root.getTree("/").addChild("test"); Tree a = test.addChild("a"); a.setProperty("name", "/segment1/segment2/segment3"); root.commit(); StringBuffer stmt = new StringBuffer(); stmt.append("//*[jcr:contains(., '/segment1/segment2')]"); assertQuery(stmt.toString(), "xpath", ImmutableList.of("/test/a")); }
@Test public void testAddExistingNode() throws CommitFailedException { theirRoot.getTree("/").addChild("n").setProperty("p", THEIR_VALUE); ourRoot.getTree("/").addChild("n").setProperty("p", OUR_VALUE); theirRoot.commit(); ourRoot.commit(); Tree n = ourRoot.getTree("/n"); assertTrue(n.exists()); assertEquals(OUR_VALUE, n.getProperty("p").getValue(STRING)); }