use of com.enonic.xp.node.Node in project xp by enonic.
the class VersionTableVacuumTaskTest method delete_node_deletes_versions.
@Test
void delete_node_deletes_versions() {
final int updates = 10_000;
// to make sure nodes fetched in batches
final int versionsBatchSize = updates / 2;
final int expectedVersionCount = updates + 1;
final Node node1 = createNode(NodePath.ROOT, "node1");
updateNode(node1.id(), updates);
doDeleteNode(node1.id());
assertVersions(node1.id(), expectedVersionCount);
final VacuumTaskResult result = NodeHelper.runAsAdmin(() -> this.task.execute(VacuumTaskParams.create().ageThreshold(NEGATIVE_AGE_THRESHOLD_MILLIS).versionsBatchSize(versionsBatchSize).build()));
refresh();
assertEquals(updates + 12, result.getProcessed());
// Old version of CMS repository entry is also delete. Remove +1 when config to specify repository is implemented
assertEquals(expectedVersionCount + 1, result.getDeleted());
assertVersions(node1.id(), 0);
}
use of com.enonic.xp.node.Node in project xp by enonic.
the class CreateNodeHandlerTest method example_3.
@Test
public void example_3() {
final PropertyTree data = new PropertyTree();
data.setString("displayName", "Child node inheriting permissions");
final Node node = Node.create().name("myName").parentPath(NodePath.create("/parent").build()).id(NodeId.from("b186d24f-ac38-42ca-a6db-1c1bda6c6c26")).data(data).inheritPermissions(true).permissions(AccessControlList.create().add(AccessControlEntry.create().allowAll().principal(RoleKeys.ADMIN).build()).add(AccessControlEntry.create().allow(Permission.READ).principal(RoleKeys.EVERYONE).build()).add(AccessControlEntry.create().allow(Permission.READ, Permission.MODIFY, Permission.CREATE, Permission.DELETE).principal(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).build()).build()).build();
mockCreateNode(node);
Mockito.when(this.repositoryService.get(RepositoryId.from("com.enonic.cms.default"))).thenReturn(Repository.create().id(RepositoryId.from("com.enonic.cms.default")).branches(Branches.from(ContentConstants.BRANCH_DRAFT, ContentConstants.BRANCH_MASTER)).build());
runScript("/lib/xp/examples/node/create-3.js");
}
use of com.enonic.xp.node.Node in project xp by enonic.
the class CreateNodeHandlerTest method example_1.
@Test
public void example_1() {
final PropertyTree data = new PropertyTree();
data.addString("likes", "plywood");
data.addDouble("numberOfUselessGadgets", 123.0);
final Node node = Node.create().id(NodeId.from("a-random-node-id")).data(data).permissions(AccessControlList.create().add(AccessControlEntry.create().allowAll().principal(RoleKeys.ADMIN).build()).build()).build();
mockCreateNode(node);
Mockito.when(this.repositoryService.get(RepositoryId.from("com.enonic.cms.default"))).thenReturn(Repository.create().id(RepositoryId.from("com.enonic.cms.default")).branches(Branches.from(ContentConstants.BRANCH_DRAFT, ContentConstants.BRANCH_MASTER)).build());
runScript("/lib/xp/examples/node/create-1.js");
}
use of com.enonic.xp.node.Node in project xp by enonic.
the class ModifyNodeExecutorTest method update_child_order.
@Test
public void update_child_order() throws Exception {
final Node originalNode = Node.create().name("myNode").childOrder(ChildOrder.manualOrder()).parentPath(NodePath.ROOT).build();
final EditableNode editableNode = new EditableNode(originalNode);
final PropertyTree updateScript = new PropertyTree();
updateScript.setString("_childOrder", ChildOrder.reverseManualOrder().toString());
ModifyNodeExecutor.create().editableNode(editableNode).propertyTree(updateScript).build().execute();
assertEquals(ChildOrder.reverseManualOrder(), editableNode.childOrder);
}
use of com.enonic.xp.node.Node in project xp by enonic.
the class ModifyNodeHandlerTest method testExample.
@Test
public void testExample() {
final PropertyTree data = new PropertyTree();
data.setString("notChanged", "originalValue");
data.setString("myString", "originalValue");
data.setString("toBeRemoved", "removeThis");
final PropertySet mySet = data.addSet("mySet");
mySet.setGeoPoint("myGeoPoint", new GeoPoint(30, -30));
final Node node = Node.create().id(NodeId.from("abc")).parentPath(NodePath.ROOT).data(data).name("myNode").build();
mockGetNode(node);
mockUpdateNode(node);
runScript("/lib/xp/examples/node/modify.js");
Mockito.verify(this.nodeService).update(updateCaptor.capture());
assertEquals(updateCaptor.getValue().getId(), NodeId.from("abc"));
final EditableNode editedNode = getEditedNode(node);
assertEquals("modified", editedNode.data.getString("myString"));
assertEquals("originalValue", editedNode.data.getString("notChanged"));
assertEquals(new GeoPoint(0, 0), editedNode.data.getGeoPoint("mySet.myGeoPoint"));
final Iterable<String> myArray = editedNode.data.getStrings("myArray");
assertNotNull(myArray);
final ArrayList<String> myArrayValues = Lists.newArrayList(myArray);
assertEquals(3, myArrayValues.size());
assertTrue(myArrayValues.containsAll(List.of("modified1", "modified2", "modified3")));
final AccessControlList permissions = editedNode.permissions;
assertTrue(permissions.getEntry(PrincipalKey.from("role:newRole")).isAllowed(Permission.MODIFY));
assertTrue(permissions.getEntry(PrincipalKey.from("user:system:newUser")).isAllowed(Permission.CREATE));
final IndexConfigDocument indexConfigDocument = editedNode.indexConfigDocument;
assertFalse(indexConfigDocument.getConfigForPath(PropertyPath.from("displayName")).isEnabled());
assertTrue(indexConfigDocument.getConfigForPath(PropertyPath.from("whatever")).isFulltext());
}
Aggregations