use of com.enonic.xp.script.ScriptExports in project xp by enonic.
the class ScriptRuntimeTest method testEmpty.
@Test
public void testEmpty() {
final ResourceKey script = ResourceKey.from("myapplication:/empty-test.js");
final ScriptExports exports = runTestScript(script);
assertNotNull(exports);
assertSame(script, exports.getScript());
assertFalse(exports.hasMethod("hello"));
}
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 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;
}
use of com.enonic.xp.script.ScriptExports in project xp by enonic.
the class ScriptMapGeneratorTest method testArray.
@Test
public void testArray() {
final Object obj = (MapSerializable) gen -> {
gen.value("a", 1);
gen.value("b", 2);
};
final List<Object> list = List.of(obj, 2);
final ScriptExports exports = runTestScript("serializer/serializer-test.js");
exports.executeMethod("testArray", list);
}
use of com.enonic.xp.script.ScriptExports in project xp by enonic.
the class ScriptMapGeneratorTest method testListValue.
@Test
public void testListValue() {
final List<Object> level2List = new ArrayList<>();
level2List.add("list2A");
level2List.add("list2B");
final List<Object> level1List = new ArrayList<>();
level1List.add("list1A");
level1List.add("list1B");
level1List.add(level2List);
final Map<String, Object> map = new HashMap<>();
map.put("mapValue", 1);
final HashMultimap<Object, Object> multimap = HashMultimap.create();
multimap.put("multimapValue", 1);
multimap.put("multimapValue", 2);
final List<Object> list = new ArrayList<>();
list.add(1);
list.add(true);
list.add("string");
list.add(level1List);
list.add(map);
list.add(multimap);
final MapSerializable value = gen -> gen.value("root", list);
final ScriptExports exports = runTestScript("serializer/serializer-test.js");
exports.executeMethod("testListValue", value);
}
Aggregations