1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.neo4j.server.rest.repr.formats;
21
22 import static org.hamcrest.Matchers.hasEntry;
23 import static org.hamcrest.Matchers.hasKey;
24 import static org.hamcrest.Matchers.instanceOf;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertThat;
27 import static org.junit.Assert.assertTrue;
28
29 import java.util.Map;
30
31 import org.junit.Test;
32
33 public class JsonInputTest
34 {
35 private final JsonFormat input = new JsonFormat();
36
37 @Test
38 public void canReadEmptyMap() throws Exception
39 {
40 Map<String, Object> map = input.readMap( "{}" );
41 assertNotNull( map );
42 assertTrue( "map is not empty", map.isEmpty() );
43 }
44
45 @Test
46 public void canReadMapWithTwoValues() throws Exception
47 {
48 Map<String, Object> map = input.readMap( "{\"key1\":\"value1\", \"key2\":\"value11\"}" );
49 assertNotNull( map );
50 assertThat( map, hasEntry( "key1", (Object) "value1" ) );
51 assertThat( map, hasEntry( "key2", (Object) "value11" ) );
52 assertTrue( "map contained extra values", map.size() == 2 );
53 }
54
55 @Test
56 public void canReadMapWithNestedMap() throws Exception
57 {
58 Map<String, Object> map = input.readMap( "{\"nested\": {\"key\": \"valuable\"}}" );
59 assertNotNull( map );
60 assertThat( map, hasKey( "nested" ) );
61 assertTrue( "map contained extra values", map.size() == 1 );
62 Object nested = map.get( "nested" );
63 assertThat( nested, instanceOf( Map.class ) );
64 @SuppressWarnings( "unchecked" ) Map<String, String> nestedMap = (Map<String, String>) nested;
65 assertThat( nestedMap, hasEntry( "key", "valuable" ) );
66 }
67 }