@Test public void expressionEvaluationUsingParent() throws Exception { // We use a JSON Object here to guarantee that we're well formed up front. JSONObject json = new JSONObject(); json.put(CONTAINER_KEY, new String[]{CHILD_CONTAINER}); json.put(PARENT_KEY, DEFAULT_CONTAINER); json.put("parentExpression", "${parent['" + TOP_LEVEL_NAME + "']}"); File childFile = createTemporaryFile(json, ".json"); File parentFile = createDefaultContainer(); createConfigForTest(childFile.getAbsolutePath() + JsonContainerConfigLoader.FILE_SEPARATOR + parentFile.getAbsolutePath()); assertEquals(TOP_LEVEL_VALUE, config.getString(CHILD_CONTAINER, "parentExpression")); }
@Test public void expressionEvaluationUsingParent() throws Exception { // We use a JSON Object here to guarantee that we're well formed up front. JSONObject json = new JSONObject(); json.put(CONTAINER_KEY, new String[]{CHILD_CONTAINER}); json.put(PARENT_KEY, DEFAULT_CONTAINER); json.put("parentExpression", "${parent['" + TOP_LEVEL_NAME + "']}"); File childFile = createTemporaryFile(json, ".json"); File parentFile = createDefaultContainer(); createConfigForTest(childFile.getAbsolutePath() + JsonContainerConfigLoader.FILE_SEPARATOR + parentFile.getAbsolutePath()); assertEquals(TOP_LEVEL_VALUE, config.getString(CHILD_CONTAINER, "parentExpression")); }
@Test public void expressionEvaluationUsingParent() throws Exception { // We use a JSON Object here to guarantee that we're well formed up front. JSONObject json = new JSONObject(); json.put(CONTAINER_KEY, new String[]{CHILD_CONTAINER}); json.put(PARENT_KEY, DEFAULT_CONTAINER); json.put("parentExpression", "${parent['" + TOP_LEVEL_NAME + "']}"); File childFile = createTemporaryFile(json, ".json"); File parentFile = createDefaultContainer(); createConfigForTest(childFile.getAbsolutePath() + JsonContainerConfigLoader.FILE_SEPARATOR + parentFile.getAbsolutePath()); assertEquals(TOP_LEVEL_VALUE, config.getString(CHILD_CONTAINER, "parentExpression")); }
@Test public void aliasesArePopulated() throws Exception { JSONObject json = new JSONObject() .put(CONTAINER_KEY, new String[]{CONTAINER_A, CONTAINER_B}) .put(NESTED_KEY, NESTED_VALUE); File parentFile = createDefaultContainer(); File childFile = createTemporaryFile(json, ".json"); createConfigForTest(childFile.getAbsolutePath() + JsonContainerConfigLoader.FILE_SEPARATOR + parentFile.getAbsolutePath()); assertEquals(NESTED_VALUE, config.getString(CONTAINER_A, NESTED_KEY)); assertEquals(NESTED_VALUE, config.getString(CONTAINER_B, NESTED_KEY)); }
@Test public void aliasesArePopulated() throws Exception { JSONObject json = new JSONObject() .put(CONTAINER_KEY, new String[]{CONTAINER_A, CONTAINER_B}) .put(NESTED_KEY, NESTED_VALUE); File parentFile = createDefaultContainer(); File childFile = createTemporaryFile(json, ".json"); createConfigForTest(childFile.getAbsolutePath() + JsonContainerConfigLoader.FILE_SEPARATOR + parentFile.getAbsolutePath()); assertEquals(NESTED_VALUE, config.getString(CONTAINER_A, NESTED_KEY)); assertEquals(NESTED_VALUE, config.getString(CONTAINER_B, NESTED_KEY)); }
@Test public void aliasesArePopulated() throws Exception { JSONObject json = new JSONObject() .put(CONTAINER_KEY, new String[]{CONTAINER_A, CONTAINER_B}) .put(NESTED_KEY, NESTED_VALUE); File parentFile = createDefaultContainer(); File childFile = createTemporaryFile(json, ".json"); createConfigForTest(childFile.getAbsolutePath() + JsonContainerConfigLoader.FILE_SEPARATOR + parentFile.getAbsolutePath()); assertEquals(NESTED_VALUE, config.getString(CONTAINER_A, NESTED_KEY)); assertEquals(NESTED_VALUE, config.getString(CONTAINER_B, NESTED_KEY)); }
@Test public void pathQuery() throws Exception { createConfigForTest(createDefaultContainer().getAbsolutePath()); String path = "${" + NESTED_KEY + "['" + NESTED_NAME + "']}"; String data = config.getString(DEFAULT_CONTAINER, path); assertEquals(NESTED_VALUE, data); }
@Test public void pathQuery() throws Exception { createConfigForTest(createDefaultContainer().getAbsolutePath()); String path = "${" + NESTED_KEY + "['" + NESTED_NAME + "']}"; String data = config.getString(DEFAULT_CONTAINER, path); assertEquals(NESTED_VALUE, data); }
@Test public void invalidContainerReturnsNull() throws Exception { createConfigForTest(createDefaultContainer().getAbsolutePath()); assertNull("Did not return null for invalid container.", config.getString("fake", PARENT_KEY)); }
@Test public void pathQuery() throws Exception { createConfigForTest(createDefaultContainer().getAbsolutePath()); String path = "${" + NESTED_KEY + "['" + NESTED_NAME + "']}"; String data = config.getString(DEFAULT_CONTAINER, path); assertEquals(NESTED_VALUE, data); }
@Test public void invalidContainerReturnsNull() throws Exception { createConfigForTest(createDefaultContainer().getAbsolutePath()); assertNull("Did not return null for invalid container.", config.getString("fake", PARENT_KEY)); }
@Test public void invalidContainerReturnsNull() throws Exception { createConfigForTest(createDefaultContainer().getAbsolutePath()); assertNull("Did not return null for invalid container.", config.getString("fake", PARENT_KEY)); }
@Test public void parseWithDefaultInheritance() throws Exception { JSONObject json = new JSONObject(); json.put(CONTAINER_KEY, new String[]{CHILD_CONTAINER}); json.put(PARENT_KEY, DEFAULT_CONTAINER); json.put(ARRAY_NAME, ARRAY_ALT_VALUE); // small nested data. JSONObject nested = new JSONObject(); nested.put(NESTED_NAME, NESTED_ALT_VALUE); json.put(NESTED_KEY, nested); File childFile = createTemporaryFile(json, ".json"); File parentFile = createDefaultContainer(); createConfigForTest(childFile.getAbsolutePath() + JsonContainerConfigLoader.FILE_SEPARATOR + parentFile.getAbsolutePath()); String value = config.getString(CHILD_CONTAINER, TOP_LEVEL_NAME); assertEquals(TOP_LEVEL_VALUE, value); Map<String, Object> nestedObj = config.getMap(CHILD_CONTAINER, NESTED_KEY); String nestedValue = nestedObj.get(NESTED_NAME).toString(); assertEquals(NESTED_ALT_VALUE, nestedValue); String arrayValue = config.getString(CHILD_CONTAINER, ARRAY_NAME); assertEquals(ARRAY_ALT_VALUE, arrayValue); // Verify that the parent value wasn't overwritten as well. List<String> actual = new ArrayList<String>(); for (Object val : config.getList(DEFAULT_CONTAINER, ARRAY_NAME)) { actual.add(val.toString()); } List<String> expected = Arrays.asList(ARRAY_VALUE); assertEquals(expected, actual); }
@Test public void parseWithDefaultInheritance() throws Exception { JSONObject json = new JSONObject(); json.put(CONTAINER_KEY, new String[]{CHILD_CONTAINER}); json.put(PARENT_KEY, DEFAULT_CONTAINER); json.put(ARRAY_NAME, ARRAY_ALT_VALUE); // small nested data. JSONObject nested = new JSONObject(); nested.put(NESTED_NAME, NESTED_ALT_VALUE); json.put(NESTED_KEY, nested); File childFile = createTemporaryFile(json, ".json"); File parentFile = createDefaultContainer(); createConfigForTest(childFile.getAbsolutePath() + JsonContainerConfigLoader.FILE_SEPARATOR + parentFile.getAbsolutePath()); String value = config.getString(CHILD_CONTAINER, TOP_LEVEL_NAME); assertEquals(TOP_LEVEL_VALUE, value); Map<String, Object> nestedObj = config.getMap(CHILD_CONTAINER, NESTED_KEY); String nestedValue = nestedObj.get(NESTED_NAME).toString(); assertEquals(NESTED_ALT_VALUE, nestedValue); String arrayValue = config.getString(CHILD_CONTAINER, ARRAY_NAME); assertEquals(ARRAY_ALT_VALUE, arrayValue); // Verify that the parent value wasn't overwritten as well. List<String> actual = new ArrayList<String>(); for (Object val : config.getList(DEFAULT_CONTAINER, ARRAY_NAME)) { actual.add(val.toString()); } List<String> expected = Arrays.asList(ARRAY_VALUE); assertEquals(expected, actual); }
@Test public void parseWithDefaultInheritance() throws Exception { JSONObject json = new JSONObject(); json.put(CONTAINER_KEY, new String[]{CHILD_CONTAINER}); json.put(PARENT_KEY, DEFAULT_CONTAINER); json.put(ARRAY_NAME, ARRAY_ALT_VALUE); // small nested data. JSONObject nested = new JSONObject(); nested.put(NESTED_NAME, NESTED_ALT_VALUE); json.put(NESTED_KEY, nested); File childFile = createTemporaryFile(json, ".json"); File parentFile = createDefaultContainer(); createConfigForTest(childFile.getAbsolutePath() + JsonContainerConfigLoader.FILE_SEPARATOR + parentFile.getAbsolutePath()); String value = config.getString(CHILD_CONTAINER, TOP_LEVEL_NAME); assertEquals(TOP_LEVEL_VALUE, value); Map<String, Object> nestedObj = config.getMap(CHILD_CONTAINER, NESTED_KEY); String nestedValue = nestedObj.get(NESTED_NAME).toString(); assertEquals(NESTED_ALT_VALUE, nestedValue); String arrayValue = config.getString(CHILD_CONTAINER, ARRAY_NAME); assertEquals(ARRAY_ALT_VALUE, arrayValue); // Verify that the parent value wasn't overwritten as well. List<String> actual = new ArrayList<String>(); for (Object val : config.getList(DEFAULT_CONTAINER, ARRAY_NAME)) { actual.add(val.toString()); } List<String> expected = Arrays.asList(ARRAY_VALUE); assertEquals(expected, actual); }
@Test public void parseBasicConfig() throws Exception { createConfigForTest(createDefaultContainer().getAbsolutePath()); assertEquals(1, config.getContainers().size()); for (String container : config.getContainers()) { assertEquals(DEFAULT_CONTAINER, container); } String value = config.getString(DEFAULT_CONTAINER, TOP_LEVEL_NAME); assertEquals(TOP_LEVEL_VALUE, value); Map<String, Object> nested = config.getMap(DEFAULT_CONTAINER, NESTED_KEY); String nestedValue = nested.get(NESTED_NAME).toString(); assertEquals(NESTED_VALUE, nestedValue); }
@Test public void parseBasicConfig() throws Exception { createConfigForTest(createDefaultContainer().getAbsolutePath()); assertEquals(1, config.getContainers().size()); for (String container : config.getContainers()) { assertEquals(DEFAULT_CONTAINER, container); } String value = config.getString(DEFAULT_CONTAINER, TOP_LEVEL_NAME); assertEquals(TOP_LEVEL_VALUE, value); Map<String, Object> nested = config.getMap(DEFAULT_CONTAINER, NESTED_KEY); String nestedValue = nested.get(NESTED_NAME).toString(); assertEquals(NESTED_VALUE, nestedValue); }
@Test public void parseBasicConfig() throws Exception { createConfigForTest(createDefaultContainer().getAbsolutePath()); assertEquals(1, config.getContainers().size()); for (String container : config.getContainers()) { assertEquals(DEFAULT_CONTAINER, container); } String value = config.getString(DEFAULT_CONTAINER, TOP_LEVEL_NAME); assertEquals(TOP_LEVEL_VALUE, value); Map<String, Object> nested = config.getMap(DEFAULT_CONTAINER, NESTED_KEY); String nestedValue = nested.get(NESTED_NAME).toString(); assertEquals(NESTED_VALUE, nestedValue); }