Search in sources :

Example 36 with ScriptValue

use of com.enonic.xp.script.ScriptValue in project xp by enonic.

the class ScriptValueTest method testObject.

@Test
public void testObject() throws Exception {
    final ScriptValue obj = evalValue("testObject");
    assertEquals(false, obj.isArray());
    assertEquals(false, obj.isFunction());
    assertEquals(true, obj.isObject());
    assertEquals(false, obj.isValue());
    assertEquals(null, obj.getValue());
    assertEquals(2, obj.getKeys().size());
    assertEquals(true, obj.hasMember("a"));
    assertEquals(1, obj.getMember("a").getValue());
    assertEquals(0, obj.getArray().size());
    assertEquals(null, obj.call("a"));
    assertEquals(null, obj.getValue(String.class));
    assertEquals(0, obj.getArray(String.class).size());
    assertEquals("a=1,b=2", obj.getMap().entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining(",")));
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) Test(org.junit.jupiter.api.Test)

Example 37 with ScriptValue

use of com.enonic.xp.script.ScriptValue in project xp by enonic.

the class ScriptValueTest method testValue.

@Test
public void testValue() throws Exception {
    final ScriptValue obj = evalValue("testValue");
    assertEquals(false, obj.isArray());
    assertEquals(false, obj.isFunction());
    assertEquals(false, obj.isObject());
    assertEquals(true, obj.isValue());
    assertEquals(1, obj.getValue());
    assertEquals(0, obj.getKeys().size());
    assertEquals(false, obj.hasMember("a"));
    assertEquals(null, obj.getMember("a"));
    assertEquals(0, obj.getArray().size());
    assertEquals(null, obj.call("a"));
    assertEquals("1", obj.getValue(String.class));
    assertEquals(0, obj.getArray(String.class).size());
    assertEquals(0, obj.getMap().size());
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) Test(org.junit.jupiter.api.Test)

Example 38 with ScriptValue

use of com.enonic.xp.script.ScriptValue in project xp by enonic.

the class ModifyProfileHandler method newProfileEditor.

private void newProfileEditor(final EditableUser edit) {
    final PropertyTree profile = edit.source.getProfile();
    final PropertyTreeMapper mapper = createPropertyTreeMapper(profile, true);
    final ScriptValue scriptValue = this.editor.call(mapper);
    updateUser(edit, scriptValue);
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) PropertyTree(com.enonic.xp.data.PropertyTree) PropertyTreeMapper(com.enonic.xp.lib.common.PropertyTreeMapper)

Example 39 with ScriptValue

use of com.enonic.xp.script.ScriptValue in project xp by enonic.

the class ModifyNodeHandler method execute.

@Override
public Object execute() {
    final Node node = getExistingNode();
    final ScriptValue updatedNodeScriptValue = applyEditor(node);
    final BinaryAttachments binaryAttachments = getBinaryAttachments(updatedNodeScriptValue);
    final UpdateNodeParams updateNodeParams = UpdateNodeParams.create().id(node.id()).editor(createEditor(updatedNodeScriptValue)).setBinaryAttachments(binaryAttachments).build();
    final Node updatedNode = this.nodeService.update(updateNodeParams);
    return new NodeMapper(updatedNode, false);
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) BinaryAttachments(com.enonic.xp.node.BinaryAttachments) Node(com.enonic.xp.node.Node) EditableNode(com.enonic.xp.node.EditableNode) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) NodeMapper(com.enonic.xp.lib.node.mapper.NodeMapper)

Example 40 with ScriptValue

use of com.enonic.xp.script.ScriptValue in project xp by enonic.

the class UrlServiceScriptTest method execute.

private boolean execute(final String method) {
    final ScriptExports exports = runScript("/test/url-test.js");
    final ScriptValue value = exports.executeMethod(method);
    return value != null ? value.getValue(Boolean.class) : false;
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) ScriptExports(com.enonic.xp.script.ScriptExports)

Aggregations

ScriptValue (com.enonic.xp.script.ScriptValue)40 Test (org.junit.jupiter.api.Test)20 PortalRequest (com.enonic.xp.portal.PortalRequest)7 PortalResponseSerializer (com.enonic.xp.portal.impl.controller.PortalResponseSerializer)5 PortalRequestMapper (com.enonic.xp.portal.impl.mapper.PortalRequestMapper)5 JSObject (jdk.nashorn.api.scripting.JSObject)4 PortalResponseMapper (com.enonic.xp.portal.impl.mapper.PortalResponseMapper)3 ScriptExports (com.enonic.xp.script.ScriptExports)3 PropertyTree (com.enonic.xp.data.PropertyTree)2 ResourceProblemException (com.enonic.xp.resource.ResourceProblemException)2 WebException (com.enonic.xp.web.WebException)2 ByteSource (com.google.common.io.ByteSource)2 Map (java.util.Map)2 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 Content (com.enonic.xp.content.Content)1 ContentId (com.enonic.xp.content.ContentId)1 ContentQuery (com.enonic.xp.content.ContentQuery)1 Contents (com.enonic.xp.content.Contents)1 FindContentIdsByQueryResult (com.enonic.xp.content.FindContentIdsByQueryResult)1 GetContentByIdsParams (com.enonic.xp.content.GetContentByIdsParams)1