Search in sources :

Example 11 with ScriptValue

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

the class ScriptValueFactoryImplTest method newValue_scalar.

@Test
public void newValue_scalar() {
    final ScriptValue value = this.factory.newValue("2");
    assertNotNull(value);
    assertEquals(false, value.isArray());
    assertEquals(false, value.isFunction());
    assertEquals(false, value.isObject());
    assertEquals(true, value.isValue());
    assertEquals("2", value.getValue());
    assertEquals(2, value.getValue(Integer.class));
    assertTrue(value.getList().isEmpty());
    assertNonArray(value);
    assertNonObject(value);
    assertNonFunction(value);
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) Test(org.junit.jupiter.api.Test)

Example 12 with ScriptValue

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

the class ScriptValueFactoryImplTest method newValue_null.

@Test
public void newValue_null() {
    final ScriptValue value = this.factory.newValue(null);
    assertNull(value);
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) Test(org.junit.jupiter.api.Test)

Example 13 with ScriptValue

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

the class ScriptValueTest method testUndefined.

@Test
public void testUndefined() throws Exception {
    final ScriptValue obj = evalValue("testUndefined");
    assertEquals(null, obj);
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) Test(org.junit.jupiter.api.Test)

Example 14 with ScriptValue

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

the class ScriptValueTest method testArray.

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

Example 15 with ScriptValue

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

the class ScriptValueTest method testFunction.

@Test
public void testFunction() throws Exception {
    final ScriptValue obj = evalValue("testFunction");
    assertEquals(false, obj.isArray());
    assertEquals(true, obj.isFunction());
    assertEquals(false, obj.isObject());
    assertEquals(false, obj.isValue());
    assertEquals(null, obj.getValue());
    assertEquals(0, obj.getKeys().size());
    assertEquals(false, obj.hasMember("a"));
    assertEquals(null, obj.getMember("a"));
    assertEquals(0, obj.getArray().size());
    assertEquals("a", obj.call("a").getValue());
    assertEquals(null, 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)

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