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