Search in sources :

Example 11 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class GetNodeHandlerTest method mockGetNode.

private void mockGetNode() {
    final Node node = createNode();
    Mockito.when(this.nodeService.getById(NodeId.from("nodeId"))).thenReturn(node);
    Mockito.when(this.nodeService.getByPath(NodePath.create("/node2-path").build())).thenReturn(node);
    Mockito.when(this.nodeService.getByIdAndVersionId(NodeId.from("nodeId"), NodeVersionId.from("versionKey"))).thenReturn(createNode());
    Mockito.when(this.nodeService.getByPathAndVersionId(NodePath.create("/my-name").build(), NodeVersionId.from("versionKey"))).thenReturn(node);
}
Also used : Node(com.enonic.xp.node.Node)

Example 12 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class ModifyNodeHandlerTest method keep_original_value_types_when_not_touched.

@Test
public void keep_original_value_types_when_not_touched() {
    final PropertyTree data = new PropertyTree();
    data.setString("myString", "originalValue");
    data.setString("untouchedString", "originalValue");
    data.setBoolean("untouchedBoolean", true);
    data.setDouble("untouchedDouble", 2.0);
    data.setLong("untouchedLong", 2L);
    data.setLink("untouchedLink", Link.from("myLink"));
    data.setInstant("untouchedInstant", Instant.parse("2017-01-02T10:00:00Z"));
    data.setBinaryReference("untouchedBinaryRef", BinaryReference.from("abcd"));
    data.setGeoPoint("untouchedGeoPoint", GeoPoint.from("30,-30"));
    data.setLocalDate("untouchedLocalDate", LocalDate.parse("2017-03-24"));
    data.setReference("untouchedReference", Reference.from("myReference"));
    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-keep-types.js");
    Mockito.verify(this.nodeService).update(updateCaptor.capture());
    assertEquals(updateCaptor.getValue().getId(), NodeId.from("abc"));
    final EditableNode editedNode = getEditedNode(node);
    assertEquals("modifiedValue", editedNode.data.getString("myString"));
    // Validate that properties not changed keeps original type
    assertTrue(editedNode.data.getProperty("untouchedString").getType().equals(ValueTypes.STRING));
    assertTrue(editedNode.data.getProperty("untouchedBoolean").getType().equals(ValueTypes.BOOLEAN));
    assertTrue(editedNode.data.getProperty("untouchedDouble").getType().equals(ValueTypes.DOUBLE));
    assertTrue(editedNode.data.getProperty("untouchedLong").getType().equals(ValueTypes.LONG));
    assertTrue(editedNode.data.getProperty("untouchedLink").getType().equals(ValueTypes.LINK));
    assertTrue(editedNode.data.getProperty("untouchedInstant").getType().equals(ValueTypes.DATE_TIME));
    assertTrue(editedNode.data.getProperty("untouchedGeoPoint").getType().equals(ValueTypes.GEO_POINT));
    assertTrue(editedNode.data.getProperty("untouchedLocalDate").getType().equals(ValueTypes.LOCAL_DATE));
    assertTrue(editedNode.data.getProperty("untouchedReference").getType().equals(ValueTypes.REFERENCE));
    assertTrue(editedNode.data.getProperty("untouchedBinaryRef").getType().equals(ValueTypes.BINARY_REFERENCE));
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) EditableNode(com.enonic.xp.node.EditableNode) EditableNode(com.enonic.xp.node.EditableNode) Test(org.junit.jupiter.api.Test)

Example 13 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class ApplicationServiceImpl method reinstallStoredApplicationIfExists.

private void reinstallStoredApplicationIfExists(final ApplicationKey applicationKey) {
    final Node applicationNode = this.repoService.getApplicationNode(applicationKey);
    if (applicationNode != null) {
        final Application application = doInstallStoredApplication(applicationNode.id());
        if (application == null) {
            return;
        }
        LOG.info("Stored application [{}] installed successfully", applicationKey);
        if (storedApplicationIsStarted(applicationNode)) {
            doStartApplication(applicationKey, false, false);
        }
    }
}
Also used : Node(com.enonic.xp.node.Node) Application(com.enonic.xp.app.Application)

Example 14 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class ApplicationRepoServiceImpl method updateApplicationNode.

@Override
public Node updateApplicationNode(final Application application, final ByteSource source) {
    final String appName = application.getKey().getName();
    final Node existingNode = doGetNodeByName(appName);
    if (existingNode == null) {
        throw new RuntimeException("Expected to find existing node in repository for application with key [" + application.getKey() + "]");
    }
    return this.nodeService.update(ApplicationNodeTransformer.toUpdateNodeParams(application, source, existingNode));
}
Also used : Node(com.enonic.xp.node.Node)

Example 15 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class ApplicationClusterEventListenerTest method installed.

@Test
void installed() {
    final Node node = Node.create().name("myNode").id(NodeId.from("myNodeId")).parentPath(NodePath.ROOT).build();
    final Application application = mock(Application.class);
    when(application.getKey()).thenReturn(ApplicationKey.from("appKey"));
    when(applicationService.installStoredApplication(eq(node.id()), any())).thenReturn(application);
    this.applicationClusterEventListener.onEvent(Event.create(ApplicationClusterEvents.EVENT_TYPE).localOrigin(false).value(ApplicationClusterEvents.NODE_ID_PARAM, node.id()).value(ApplicationClusterEvents.EVENT_TYPE_KEY, ApplicationClusterEvents.INSTALLED).build());
    verify(this.applicationService, times(1)).installStoredApplication(node.id(), ApplicationInstallationParams.create().start(false).triggerEvent(false).build());
}
Also used : Node(com.enonic.xp.node.Node) Application(com.enonic.xp.app.Application) 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