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