+
+ @Test
+ public void testConvertObjectToArraySpliterator() throws Exception
+ {
+ LOG.info("<-- Start Of New Test-Case!");
+
+ try
+ {
+ SimpleMapper.getArraySpliterator(get("/object/1.json"));
+ fail("it must not be possible, to get an array-spliterator for an object");
+ }
+ catch(IllegalArgumentException e)
+ {
+ LOG.trace("expected exception", e);
+ }
+
+ try
+ {
+ SimpleMapper.getArraySpliterator(get("/object/2.json"));
+ fail("it must not be possible, to get an array-spliterator for an object");
+ }
+ catch(IllegalArgumentException e)
+ {
+ LOG.trace("expected exception", e);
+ }
+ }
+
+ @Test
+ public void testConvertObjectToList() throws Exception
+ {
+ LOG.info("<-- Start Of New Test-Case!");
+
+ try
+ {
+ SimpleMapper.convertArray(get("/object/1.json"));
+ fail("it must not be possible, to get a list for an object");
+ }
+ catch(IllegalArgumentException e)
+ {
+ LOG.trace("expected exception", e);
+ }
+
+ try
+ {
+ SimpleMapper.convertArray(get("/object/2.json"));
+ fail("it must not be possible, to get a list for an object");
+ }
+ catch(IllegalArgumentException e)
+ {
+ LOG.trace("expected exception", e);
+ }
+ }
+
+ @Test
+ public void testConvertObjectToObjectSpliterator() throws Exception
+ {
+ LOG.info("<-- Start Of New Test-Case!");
+
+ Spliterator<Entry<String, Object>> spliterator;
+
+ spliterator = SimpleMapper.getObjectSpliterator(get("/object/1.json"));
+ checkObjectSpliterator(spliterator);
+ spliterator = SimpleMapper.getObjectSpliterator(get("/object/2.json"));
+ checkObjectSpliterator(spliterator);
+ }
+
+ void checkObjectSpliterator(Spliterator<Entry<String, Object>> spliterator)
+ throws
+ Exception
+ {
+ assertNotNull(spliterator);
+
+ final LinkedHashMap<String, Object> map = new LinkedHashMap<>();
+ for (int i = 0; i < 4; i++)
+ assertTrue(
+ "The created splitter should have a " + (i+1) + ". entry",
+ spliterator.tryAdvance((Entry<String, Object> e) -> {
+ map.put(e.getKey(), e.getValue());
+ }));
+
+ assertFalse(
+ "The created splitter should have no more entries",
+ spliterator.tryAdvance((Object t) ->
+ {
+ fail("The consumer should not have been called");
+ }));
+
+ checkVariables(map);
+ }
+
+ @Test
+ public void testConvertObjectToMap() throws Exception
+ {
+ LOG.info("<-- Start Of New Test-Case!");
+
+ Map<String, Object> map;
+
+ map = SimpleMapper.convertObject(get("/object/1.json"));
+ assertNotNull(map);
+ assertEquals(4, map.size());
+ checkVariables(map);
+ map = SimpleMapper.convertObject(get("/object/2.json"));
+ assertNotNull(map);
+ assertEquals(4, map.size());
+ checkVariables(map);
+ }
+
+ @Test
+ public void testConvertObject() throws Exception
+ {
+ LOG.info("<-- Start Of New Test-Case!");
+
+ Object object;
+ Map<String, Object> map;
+
+ object = SimpleMapper.convert(get("/object/1.json"));
+ assertNotNull(object);
+ assertTrue("the returned object should be a map", object instanceof Map);
+ map = (Map<String, Object>)object;
+ assertEquals(4, map.size());
+ checkVariables(map);
+ object = SimpleMapper.convert(get("/object/2.json"));
+ assertNotNull(object);
+ assertTrue("the returned object should be a map", object instanceof Map);
+ map = (Map<String, Object>)object;
+ assertEquals(4, map.size());
+ checkVariables(map);
+ }
+
+ void checkVariables(Map<String, Object> map)
+ {
+ Iterator<Entry<String, Object>> iterator = map.entrySet().iterator();
+ Entry<String, Object> entry;
+
+ assertTrue("The map should have a first element", iterator.hasNext());
+ entry = iterator.next();
+ assertEquals("bootstrap", entry.getKey());
+ assertEquals("bootstrap.min.css", entry.getValue());
+
+ assertTrue("The map should have a second element", iterator.hasNext());
+ entry = iterator.next();
+ assertEquals("pages", entry.getKey());
+ assertTrue(
+ "The pages-variable should be of type List",
+ entry.getValue() instanceof List
+ );
+ assertEquals(4, ((List)entry.getValue()).size());
+ checkPartnerPageData(((List)entry.getValue()).get(3));
+
+ assertTrue("The map should have a third element", iterator.hasNext());
+ entry = iterator.next();
+ assertEquals("footer", entry.getKey());
+ assertTrue(
+ "The footer-variable should be of type List",
+ entry.getValue() instanceof List
+ );
+ assertEquals(3, ((List)entry.getValue()).size());
+
+ assertTrue("The map should have a third element", iterator.hasNext());
+ entry = iterator.next();
+ assertEquals("sponsorship", entry.getKey());
+ assertTrue(
+ "The sponsorship-variable should be of type List",
+ entry.getValue() instanceof List
+ );
+ assertEquals(3, ((List)entry.getValue()).size());
+ }
+
+