Search in sources :

Example 31 with OpenSecurityProvider

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());
}
Also used : Node(javax.jcr.Node) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) Tree(org.apache.jackrabbit.oak.api.Tree) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) Session(javax.jcr.Session) Test(org.junit.Test)

Example 32 with OpenSecurityProvider

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);
}
Also used : InputStream(java.io.InputStream) Calendar(java.util.Calendar) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Node(javax.jcr.Node) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) Tree(org.apache.jackrabbit.oak.api.Tree) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) Session(javax.jcr.Session) Test(org.junit.Test)

Example 33 with OpenSecurityProvider

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();
        }
    }
}
Also used : Closeable(java.io.Closeable) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) Test(org.junit.Test)

Example 34 with OpenSecurityProvider

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();
            }
        }
    }
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) Test(org.junit.Test)

Example 35 with OpenSecurityProvider

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();
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) Closeable(java.io.Closeable) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) WhiteboardIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.WhiteboardIndexEditorProvider) ReferenceEditorProvider(org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider) Registration(org.apache.jackrabbit.oak.spi.whiteboard.Registration) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Tree(org.apache.jackrabbit.oak.api.Tree) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) Test(org.junit.Test)

Aggregations

OpenSecurityProvider (org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)51 Oak (org.apache.jackrabbit.oak.Oak)38 InitialContent (org.apache.jackrabbit.oak.InitialContent)25 Test (org.junit.Test)19 Root (org.apache.jackrabbit.oak.api.Root)16 Tree (org.apache.jackrabbit.oak.api.Tree)14 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)14 ContentRepository (org.apache.jackrabbit.oak.api.ContentRepository)12 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)11 Before (org.junit.Before)11 IOException (java.io.IOException)8 NodeTypeIndexProvider (org.apache.jackrabbit.oak.plugins.index.nodetype.NodeTypeIndexProvider)8 QueryIndexProvider (org.apache.jackrabbit.oak.spi.query.QueryIndexProvider)8 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)7 Nonnull (javax.annotation.Nonnull)6 Closeable (java.io.Closeable)5 LuceneIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider)5 LuceneIndexProvider (org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProvider)5 Observer (org.apache.jackrabbit.oak.spi.commit.Observer)5 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)4