Search in sources :

Example 21 with ScriptExports

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

the class ScriptMapGeneratorTest method testObject.

@Test
public void testObject() {
    final Object obj = (MapSerializable) gen -> {
        gen.value("a", 1);
        gen.value("b", "2");
        gen.value("c", 3L);
        gen.value("d", 4.0f);
    };
    final ScriptExports exports = runTestScript("serializer/serializer-test.js");
    exports.executeMethod("testObject", obj);
}
Also used : MapSerializable(com.enonic.xp.script.serializer.MapSerializable) ScriptExports(com.enonic.xp.script.ScriptExports) Test(org.junit.jupiter.api.Test) AbstractScriptTest(com.enonic.xp.script.impl.AbstractScriptTest)

Example 22 with ScriptExports

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

the class ScriptTestSupport method runFunction.

protected final ScriptValue runFunction(final String path, final String funcName, final Object... funcParams) {
    final ScriptExports exports = runScript(path);
    assertNotNull(exports, "No exports in [" + path + "]");
    assertTrue(exports.hasMethod(funcName), "No functions exported named [" + funcName + "] in [" + path + "]");
    return exports.executeMethod(funcName, funcParams);
}
Also used : ScriptExports(com.enonic.xp.script.ScriptExports)

Aggregations

ScriptExports (com.enonic.xp.script.ScriptExports)22 Test (org.junit.jupiter.api.Test)17 ResourceKey (com.enonic.xp.resource.ResourceKey)14 AbstractScriptTest (com.enonic.xp.script.impl.AbstractScriptTest)6 MapSerializable (com.enonic.xp.script.serializer.MapSerializable)6 PortalRequest (com.enonic.xp.portal.PortalRequest)3 PortalResponse (com.enonic.xp.portal.PortalResponse)3 PortalScriptService (com.enonic.xp.portal.script.PortalScriptService)3 ScriptValue (com.enonic.xp.script.ScriptValue)3 ResponseProcessorDescriptor (com.enonic.xp.site.processor.ResponseProcessorDescriptor)3 ApplicationKey (com.enonic.xp.app.ApplicationKey)2 RenderException (com.enonic.xp.portal.impl.rendering.RenderException)2 ResourceNotFoundException (com.enonic.xp.resource.ResourceNotFoundException)2 ResourceProblemException (com.enonic.xp.resource.ResourceProblemException)2 HashMap (java.util.HashMap)2 PortalRequestMapper (com.enonic.xp.portal.impl.mapper.PortalRequestMapper)1 PortalResponseMapper (com.enonic.xp.portal.impl.mapper.PortalResponseMapper)1 TaskNotFoundException (com.enonic.xp.task.TaskNotFoundException)1 HashMultimap (com.google.common.collect.HashMultimap)1 ByteSource (com.google.common.io.ByteSource)1