Search in sources :

Example 1 with Node

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);
}
Also used : VacuumTaskResult(com.enonic.xp.vacuum.VacuumTaskResult) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 2 with Node

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");
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 3 with Node

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");
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 4 with Node

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);
}
Also used : Node(com.enonic.xp.node.Node) EditableNode(com.enonic.xp.node.EditableNode) PropertyTree(com.enonic.xp.data.PropertyTree) EditableNode(com.enonic.xp.node.EditableNode) Test(org.junit.jupiter.api.Test)

Example 5 with Node

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());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) GeoPoint(com.enonic.xp.util.GeoPoint) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) EditableNode(com.enonic.xp.node.EditableNode) PropertySet(com.enonic.xp.data.PropertySet) IndexConfigDocument(com.enonic.xp.index.IndexConfigDocument) EditableNode(com.enonic.xp.node.EditableNode) Test(org.junit.jupiter.api.Test)

Aggregations

Node (com.enonic.xp.node.Node)521 Test (org.junit.jupiter.api.Test)371 PropertyTree (com.enonic.xp.data.PropertyTree)114 NodeId (com.enonic.xp.node.NodeId)52 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)51 NodePath (com.enonic.xp.node.NodePath)45 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)42 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)34 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)32 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)29 NodeQuery (com.enonic.xp.node.NodeQuery)27 AccessControlList (com.enonic.xp.security.acl.AccessControlList)27 BinaryReference (com.enonic.xp.util.BinaryReference)26 ByteSource (com.google.common.io.ByteSource)24 Content (com.enonic.xp.content.Content)23 PropertySet (com.enonic.xp.data.PropertySet)20 NodeIds (com.enonic.xp.node.NodeIds)18 Context (com.enonic.xp.context.Context)17 InternalContext (com.enonic.xp.repo.impl.InternalContext)17 Application (com.enonic.xp.app.Application)16