use of com.enonic.xp.script.serializer.MapSerializable in project xp by enonic.
the class ScriptEventListenerImplTest method testEvent.
@Test
public void testEvent() {
final Event event = Event.create("application").localOrigin(true).value("a", 1).build();
this.listener.onEvent(event);
assertNotNull(this.event);
assertTrue(this.event instanceof MapSerializable);
final MapSerializable serializable = (MapSerializable) this.event;
final JsonMapGenerator generator = new JsonMapGenerator();
serializable.serialize(generator);
}
use of com.enonic.xp.script.serializer.MapSerializable in project xp by enonic.
the class ScriptMapGeneratorTest method testMapValue.
@Test
public void testMapValue() {
final Map<String, Object> submap = new HashMap<>();
submap.put("child1", 1);
submap.put("child2", 2);
final Map<String, Object> map = new HashMap<>();
map.put("value1", 1);
map.put("value2", true);
map.put("value3", "string");
map.put("value4", submap);
final Object obj = (MapSerializable) gen -> {
gen.value("map", map);
gen.value("b", 2);
};
final ScriptExports exports = runTestScript("serializer/serializer-test.js");
exports.executeMethod("testMapValue", obj);
}
use of com.enonic.xp.script.serializer.MapSerializable 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.serializer.MapSerializable 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.serializer.MapSerializable 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);
}
Aggregations