@Test public void testReadNumericField() { properties.put("attr", 2.3); List<Object> values = parserUtil.readField(properties, "attr"); assertTrue(values.size() == 1); assertTrue(values.get(0).equals(2.3)); }
@Test public void testReadStringField() { properties.put("attr", "value"); List<Object> values = parserUtil.readField(properties, "attr"); assertTrue(values.size() == 1); assertTrue(values.get(0).equals("value")); }
@Test public void testReadInnerString() { properties.put("parent", new LinkedHashMap<String, Object>()); ((Map) properties.get("parent")).put("attr", "value"); List<Object> values = parserUtil.readField(properties, "parent.attr"); assertTrue(values.size() == 1); assertTrue(values.get(0).equals("value")); }
@Test public void testReadInnerStringArray() { properties.put("parent", new LinkedHashMap<String, Object>()); ((Map) properties.get("parent")).put("attr", Arrays.asList(new String[] {"value1", "value2"})); List<Object> values = parserUtil.readField(properties, "parent.attr"); assertTrue(values.size() == 2); assertTrue(values.get(0).equals("value1")); assertTrue(values.get(1).equals("value2")); }
@Test public void testReadMapField() { final Map<String, Object> map = new LinkedHashMap<String, Object>(); properties.put("attr", map); map.put("attr2", "value2"); map.put("attr3", "value3"); List<Object> values = parserUtil.readField(properties, "attr"); assertTrue(values.size() == 1); assertTrue(values.get(0).equals(map)); }
@Test public void testReadStringFieldWithConfuser() { properties.put("parent1", new LinkedHashMap<String, Object>()); ((Map) properties.get("parent1")).put("attr", "value2"); properties.put("attr", "value"); properties.put("parent2", new LinkedHashMap<String, Object>()); ((Map) properties.get("parent2")).put("attr", "value3"); List<Object> values = parserUtil.readField(properties, "attr"); assertTrue(values.size() == 1); assertTrue(values.get(0).equals("value")); }
@Test public void testReadStringFromObjectArray() { properties.put("parent", new ArrayList<Map<String, Object>>()); ((List) properties.get("parent")).add(new LinkedHashMap<String, Object>()); ((Map) ((List) properties.get("parent")).get(0)).put("attr", "value1"); ((List) properties.get("parent")).add(new LinkedHashMap<String, Object>()); ((Map) ((List) properties.get("parent")).get(1)).put("attr", "value2"); List<Object> values = parserUtil.readField(properties, "parent.attr"); assertTrue(values.size() == 2); assertTrue(values.get(0).equals("value1")); assertTrue(values.get(1).equals("value2")); }