Search in sources :

Example 6 with MapSerializable

use of com.enonic.xp.script.serializer.MapSerializable 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);
}
Also used : Test(org.junit.jupiter.api.Test) AbstractScriptTest(com.enonic.xp.script.impl.AbstractScriptTest) List(java.util.List) HashMultimap(com.google.common.collect.HashMultimap) Map(java.util.Map) HashMap(java.util.HashMap) ScriptExports(com.enonic.xp.script.ScriptExports) MapSerializable(com.enonic.xp.script.serializer.MapSerializable) ArrayList(java.util.ArrayList) MapSerializable(com.enonic.xp.script.serializer.MapSerializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ScriptExports(com.enonic.xp.script.ScriptExports) Test(org.junit.jupiter.api.Test) AbstractScriptTest(com.enonic.xp.script.impl.AbstractScriptTest)

Example 7 with MapSerializable

use of com.enonic.xp.script.serializer.MapSerializable 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)

Aggregations

MapSerializable (com.enonic.xp.script.serializer.MapSerializable)7 Test (org.junit.jupiter.api.Test)7 ScriptExports (com.enonic.xp.script.ScriptExports)6 AbstractScriptTest (com.enonic.xp.script.impl.AbstractScriptTest)5 HashMap (java.util.HashMap)2 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 Event (com.enonic.xp.event.Event)1 ResourceKey (com.enonic.xp.resource.ResourceKey)1 ResourceProblemException (com.enonic.xp.resource.ResourceProblemException)1 JsonMapGenerator (com.enonic.xp.script.serializer.JsonMapGenerator)1 HashMultimap (com.google.common.collect.HashMultimap)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1 Assertions.assertNotSame (org.junit.jupiter.api.Assertions.assertNotSame)1 Assertions.assertSame (org.junit.jupiter.api.Assertions.assertSame)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1