Search in sources :

Example 1 with Collections.emptyMap

use of java.util.Collections.emptyMap in project elasticsearch by elastic.

the class BaseXContentTestCase method testMap.

public void testMap() throws Exception {
    Map<String, Map<String, ?>> maps = new HashMap<>();
    maps.put("{'map':null}", (Map) null);
    maps.put("{'map':{}}", Collections.emptyMap());
    maps.put("{'map':{'key':'value'}}", singletonMap("key", "value"));
    Map<String, Object> innerMap = new HashMap<>();
    innerMap.put("string", "value");
    innerMap.put("int", 42);
    innerMap.put("long", 42L);
    innerMap.put("long[]", new long[] { 1L, 3L });
    innerMap.put("path", PathUtils.get("path", "to", "file"));
    innerMap.put("object", singletonMap("key", "value"));
    final String path = Constants.WINDOWS ? "path\\\\to\\\\file" : "path/to/file";
    maps.put("{'map':{'path':'" + path + "','string':'value','long[]':[1,3],'int':42,'long':42,'object':{'key':'value'}}}", innerMap);
    for (Map.Entry<String, Map<String, ?>> m : maps.entrySet()) {
        final String expected = m.getKey();
        assertResult(expected, () -> builder().startObject().field("map", m.getValue()).endObject());
        assertResult(expected, () -> builder().startObject().field("map").value(m.getValue()).endObject());
        assertResult(expected, () -> builder().startObject().field("map").map(m.getValue()).endObject());
    }
}
Also used : HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) HashMap(java.util.HashMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap)

Aggregations

Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1