use of com.enonic.xp.script.ScriptExports in project xp by enonic.
the class ScriptMapGeneratorTest method testMultimapValue.
@Test
public void testMultimapValue() {
final HashMultimap<Object, Object> submap = HashMultimap.create();
submap.put("children", 5);
submap.put("children", 6);
submap.put("children", 7);
final HashMultimap<Object, Object> map = HashMultimap.create();
map.put("value1", 1);
map.put("value1", 2);
map.put("value1", 3);
map.put("value2", true);
map.put("value2", false);
map.put("value3", "string1");
map.put("value4", submap);
final Object obj = (MapSerializable) gen -> gen.value("multimap", map);
final ScriptExports exports = runTestScript("serializer/serializer-test.js");
exports.executeMethod("testMultimapValue", obj);
}
use of com.enonic.xp.script.ScriptExports in project xp by enonic.
the class NamedTaskScriptFactoryImpl method doCreate.
private NamedTaskScript doCreate(final TaskDescriptor descriptor, final PropertyTree data) {
final ResourceKey scriptResourceKey = ResourceKey.from(descriptor.getApplicationKey(), TASKS_PATH_PREFIX + descriptor.getName() + "/" + descriptor.getName() + ".js");
final ScriptExports exports;
try {
exports = this.scriptService.execute(scriptResourceKey);
} catch (ResourceNotFoundException e) {
throw new TaskNotFoundException(descriptor.getKey(), "Missing task script");
}
final boolean exists = exports.hasMethod(NamedTaskScript.SCRIPT_METHOD_NAME);
if (!exists) {
throw new TaskNotFoundException(descriptor.getKey(), "Missing exported function '" + NamedTaskScript.SCRIPT_METHOD_NAME + "' in task script");
}
return new NamedTaskScript(exports, descriptor, data);
}
use of com.enonic.xp.script.ScriptExports in project xp by enonic.
the class ScriptRuntimeTest method testRequire.
@Test
public void testRequire() {
final ResourceKey script = ResourceKey.from("myapplication:/site/require/require-test.js");
final ScriptExports exports = runTestScript(script);
assertNotNull(exports);
}
use of com.enonic.xp.script.ScriptExports in project xp by enonic.
the class ScriptRuntimeTest method testExecuteExported_objectArg.
@Test
public void testExecuteExported_objectArg() {
final ResourceKey script = ResourceKey.from("myapplication:/export-test.js");
final ScriptExports exports = runTestScript(script);
assertNotNull(exports);
assertSame(script, exports.getScript());
assertTrue(exports.hasMethod("helloObject"));
assertEquals("Hello World!", exports.executeMethod("helloObject", (MapSerializable) gen -> gen.value("name", "World")).getValue());
}
use of com.enonic.xp.script.ScriptExports in project xp by enonic.
the class NewBeanScriptTest method testEmpty.
@Test
public void testEmpty() {
final ResourceKey script = ResourceKey.from("myapplication:/bean/simple-test.js");
final ScriptExports exports = runTestScript(script);
assertNotNull(exports);
assertSame(script, exports.getScript());
}
Aggregations