Search in sources :

Example 76 with Nonnull

use of javax.annotation.Nonnull in project jackrabbit-oak by apache.

the class WhiteboardAuthorizableActionProviderTest method testRegisteredImplementation.

@Test
public void testRegisteredImplementation() {
    actionProvider.start(whiteboard);
    AuthorizableActionProvider registered = new AuthorizableActionProvider() {

        @Nonnull
        @Override
        public List<? extends AuthorizableAction> getAuthorizableActions(@Nonnull SecurityProvider securityProvider) {
            return ImmutableList.of(new TestAction());
        }
    };
    whiteboard.register(AuthorizableActionProvider.class, registered, ImmutableMap.of());
    List<? extends AuthorizableAction> actions = actionProvider.getAuthorizableActions(Mockito.mock(SecurityProvider.class));
    assertNotNull(actions);
    assertEquals(1, actions.size());
    assertTrue(actions.get(0) instanceof TestAction);
}
Also used : Nonnull(javax.annotation.Nonnull) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) AuthorizableActionProvider(org.apache.jackrabbit.oak.spi.security.user.action.AuthorizableActionProvider) Test(org.junit.Test)

Example 77 with Nonnull

use of javax.annotation.Nonnull in project jackrabbit-oak by apache.

the class WhiteboardAuthorizableNodeNameTest method testRegisteredImplementation.

@Test
public void testRegisteredImplementation() {
    authorizableNodeName.start(whiteboard);
    AuthorizableNodeName registered = new AuthorizableNodeName() {

        @Nonnull
        @Override
        public String generateNodeName(@Nonnull String authorizableId) {
            return "generated";
        }
    };
    whiteboard.register(AuthorizableNodeName.class, registered, ImmutableMap.of());
    assertEquals(registered.generateNodeName(TEST_ID), authorizableNodeName.generateNodeName(TEST_ID));
}
Also used : Nonnull(javax.annotation.Nonnull) AuthorizableNodeName(org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName) Test(org.junit.Test)

Example 78 with Nonnull

use of javax.annotation.Nonnull in project jackrabbit-oak by apache.

the class NodeStoreTest method beforeCommitHook.

@Test
public void beforeCommitHook() throws CommitFailedException {
    NodeState root = store.getRoot();
    NodeBuilder rootBuilder = root.builder();
    NodeBuilder testBuilder = rootBuilder.child("test");
    NodeBuilder newNodeBuilder = testBuilder.child("newNode");
    newNodeBuilder.setProperty("n", 42);
    testBuilder.getChildNode("a").remove();
    store.merge(rootBuilder, new CommitHook() {

        @Nonnull
        @Override
        public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) {
            NodeBuilder rootBuilder = after.builder();
            NodeBuilder testBuilder = rootBuilder.child("test");
            testBuilder.child("fromHook");
            return rootBuilder.getNodeState();
        }
    }, CommitInfo.EMPTY);
    NodeState test = store.getRoot().getChildNode("test");
    assertTrue(test.getChildNode("newNode").exists());
    assertTrue(test.getChildNode("fromHook").exists());
    assertFalse(test.getChildNode("a").exists());
    assertEquals(42, (long) test.getChildNode("newNode").getProperty("n").getValue(LONG));
    assertEquals(test, store.getRoot().getChildNode("test"));
}
Also used : Nonnull(javax.annotation.Nonnull) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Example 79 with Nonnull

use of javax.annotation.Nonnull in project jackrabbit-oak by apache.

the class NodeStoreTest method rebaseWithFailedMerge.

// OAK-1320
@Test
public void rebaseWithFailedMerge() throws CommitFailedException {
    NodeBuilder rootBuilder = store.getRoot().builder();
    rootBuilder.child("foo");
    // commit something in between to force rebase
    NodeBuilder b = store.getRoot().builder();
    b.child("bar");
    store.merge(b, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    try {
        store.merge(rootBuilder, new CommitHook() {

            @Nonnull
            @Override
            public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
                throw new CommitFailedException("", 0, "commit rejected");
            }
        }, CommitInfo.EMPTY);
        fail("must throw CommitFailedException");
    } catch (CommitFailedException e) {
    // expected
    }
    // merge again
    NodeState root = store.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    assertTrue(root.hasChildNode("bar"));
}
Also used : Nonnull(javax.annotation.Nonnull) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Example 80 with Nonnull

use of javax.annotation.Nonnull in project jackrabbit-oak by apache.

the class VersionHistoryDelegate method getAllVersions.

@Nonnull
public Iterator<VersionDelegate> getAllVersions() throws RepositoryException {
    List<NodeDelegate> versions = new ArrayList<NodeDelegate>();
    for (Iterator<NodeDelegate> it = getChildren(); it.hasNext(); ) {
        NodeDelegate n = it.next();
        String primaryType = n.getProperty(JcrConstants.JCR_PRIMARYTYPE).getString();
        if (primaryType.equals(VersionConstants.NT_VERSION)) {
            versions.add(n);
        }
    }
    // best-effort sort by created time stamp, see JCR 2.0, 15.1.1.2
    Collections.sort(versions, new Comparator<NodeDelegate>() {

        @Override
        public int compare(NodeDelegate n1, NodeDelegate n2) {
            try {
                PropertyDelegate c1 = n1.getPropertyOrNull(JcrConstants.JCR_CREATED);
                PropertyDelegate c2 = n2.getPropertyOrNull(JcrConstants.JCR_CREATED);
                if (c1 != null && c2 != null) {
                    return c1.getDate().compareTo(c2.getDate());
                } else if (c1 != null) {
                    return 1;
                } else if (c2 != null) {
                    return -1;
                } else {
                    return 0;
                }
            } catch (RepositoryException ex) {
                // best effort
                return 0;
            }
        }
    });
    final Tree thisTree = getTree();
    return Iterators.transform(versions.iterator(), new Function<NodeDelegate, VersionDelegate>() {

        @Override
        public VersionDelegate apply(NodeDelegate nd) {
            return VersionDelegate.create(sessionDelegate, thisTree.getChild(nd.getName()));
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Tree(org.apache.jackrabbit.oak.api.Tree) RepositoryException(javax.jcr.RepositoryException) Nonnull(javax.annotation.Nonnull)

Aggregations

Nonnull (javax.annotation.Nonnull)2624 Nullable (javax.annotation.Nullable)338 ArrayList (java.util.ArrayList)336 ItemStack (net.minecraft.item.ItemStack)327 List (java.util.List)305 Map (java.util.Map)229 Layer (com.simiacryptus.mindseye.lang.Layer)188 Tensor (com.simiacryptus.mindseye.lang.Tensor)185 Arrays (java.util.Arrays)182 Collectors (java.util.stream.Collectors)169 IOException (java.io.IOException)165 JsonObject (com.google.gson.JsonObject)156 HashMap (java.util.HashMap)145 IntStream (java.util.stream.IntStream)145 Test (org.junit.Test)143 LoggerFactory (org.slf4j.LoggerFactory)138 Logger (org.slf4j.Logger)137 Result (com.simiacryptus.mindseye.lang.Result)130 TensorList (com.simiacryptus.mindseye.lang.TensorList)123 DeltaSet (com.simiacryptus.mindseye.lang.DeltaSet)111