@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 = createContainer(json); File parentFile = createDefaultContainer(); ContainerConfig config = new JsonContainerConfig(childFile.getAbsolutePath() + JsonContainerConfigLoader.FILE_SEPARATOR + parentFile.getAbsolutePath(), Expressions.forTesting()); assertEquals(TOP_LEVEL_VALUE, config.getString(CHILD_CONTAINER, "parentExpression")); }
private File createDefaultContainer() 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[]{DEFAULT_CONTAINER}); json.put(TOP_LEVEL_NAME, TOP_LEVEL_VALUE); json.put(ARRAY_NAME, ARRAY_VALUE); // small nested data. JSONObject nested = new JSONObject(); nested.put(NESTED_NAME, NESTED_VALUE); json.put(NESTED_KEY, nested); return createContainer(json); }
@Test public void pathQuery() throws Exception { ContainerConfig config = new JsonContainerConfig(createDefaultContainer().getAbsolutePath(), Expressions.forTesting()); String path = "${" + NESTED_KEY + "['" + NESTED_NAME + "']}"; String data = config.getString(DEFAULT_CONTAINER, path); assertEquals(NESTED_VALUE, data); }
private File createDefaultContainer() 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[]{DEFAULT_CONTAINER}); json.put(TOP_LEVEL_NAME, TOP_LEVEL_VALUE); json.put(ARRAY_NAME, ARRAY_VALUE); // small nested data. JSONObject nested = new JSONObject(); nested.put(NESTED_NAME, NESTED_VALUE); json.put(NESTED_KEY, nested); return createContainer(json); }
@Test public void pathQuery() throws Exception { ContainerConfig config = new JsonContainerConfig(createDefaultContainer().getAbsolutePath(), Expressions.forTesting()); String path = "${" + NESTED_KEY + "['" + NESTED_NAME + "']}"; String data = config.getString(DEFAULT_CONTAINER, path); assertEquals(NESTED_VALUE, data); }
@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 = createContainer(json); File parentFile = createDefaultContainer(); ContainerConfig config = new JsonContainerConfig(childFile.getAbsolutePath() + JsonContainerConfigLoader.FILE_SEPARATOR + parentFile.getAbsolutePath(), Expressions.forTesting()); assertEquals(TOP_LEVEL_VALUE, config.getString(CHILD_CONTAINER, "parentExpression")); }
private File createDefaultContainer() 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[]{DEFAULT_CONTAINER}); json.put(TOP_LEVEL_NAME, TOP_LEVEL_VALUE); json.put(ARRAY_NAME, ARRAY_VALUE); // small nested data. JSONObject nested = new JSONObject(); nested.put(NESTED_NAME, NESTED_VALUE); json.put(NESTED_KEY, nested); return createContainer(json); }
@Test public void invalidContainerReturnsNull() throws Exception { ContainerConfig config = new JsonContainerConfig(createDefaultContainer().getAbsolutePath(), Expressions.forTesting()); assertNull("Did not return null for invalid container.", config.getString("fake", PARENT_KEY)); }
@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 = createContainer(json); File parentFile = createDefaultContainer(); ContainerConfig config = new JsonContainerConfig(childFile.getAbsolutePath() + JsonContainerConfigLoader.FILE_SEPARATOR + parentFile.getAbsolutePath(), Expressions.forTesting()); assertEquals(TOP_LEVEL_VALUE, config.getString(CHILD_CONTAINER, "parentExpression")); }
private File createDefaultContainer() 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[]{DEFAULT_CONTAINER}); json.put(TOP_LEVEL_NAME, TOP_LEVEL_VALUE); json.put(ARRAY_NAME, ARRAY_VALUE); // small nested data. JSONObject nested = new JSONObject(); nested.put(NESTED_NAME, NESTED_VALUE); json.put(NESTED_KEY, nested); return createContainer(json); }
@Test public void invalidContainerReturnsNull() throws Exception { ContainerConfig config = new JsonContainerConfig(createDefaultContainer().getAbsolutePath(), Expressions.forTesting()); assertNull("Did not return null for invalid container.", config.getString("fake", PARENT_KEY)); }
@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 = createContainer(json); File parentFile = createDefaultContainer(); ContainerConfig config = new JsonContainerConfig(childFile.getAbsolutePath() + JsonContainerConfig.FILE_SEPARATOR + parentFile.getAbsolutePath(), Expressions.forTesting()); assertEquals(TOP_LEVEL_VALUE, config.getString(CHILD_CONTAINER, "parentExpression")); }
private File createDefaultContainer() 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[]{DEFAULT_CONTAINER}); json.put(TOP_LEVEL_NAME, TOP_LEVEL_VALUE); json.put(ARRAY_NAME, ARRAY_VALUE); // small nested data. JSONObject nested = new JSONObject(); nested.put(NESTED_NAME, NESTED_VALUE); json.put(NESTED_KEY, nested); return createContainer(json); }
@Test public void pathQuery() throws Exception { ContainerConfig config = new JsonContainerConfig(createDefaultContainer().getAbsolutePath(), Expressions.forTesting()); String path = "${" + NESTED_KEY + "['" + NESTED_NAME + "']}"; String data = config.getString(DEFAULT_CONTAINER, path); assertEquals(NESTED_VALUE, data); }
@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 = createContainer(json); File parentFile = createDefaultContainer(); ContainerConfig config = new JsonContainerConfig(childFile.getAbsolutePath() + JsonContainerConfig.FILE_SEPARATOR + parentFile.getAbsolutePath(), Expressions.forTesting()); assertEquals(TOP_LEVEL_VALUE, config.getString(CHILD_CONTAINER, "parentExpression")); }
@Test(expected = ContainerConfigException.class) public void badConfigThrows() throws Exception { JSONObject json = new JSONObject(); json.put(CONTAINER_KEY, new String[]{CHILD_CONTAINER}); json.put(PARENT_KEY, "bad bad bad parent!"); json.put(ARRAY_NAME, ARRAY_ALT_VALUE); new JsonContainerConfig(createContainer(json).getAbsolutePath(), Expressions.forTesting()); }
@Test public void pathQuery() throws Exception { ContainerConfig config = new JsonContainerConfig(createDefaultContainer().getAbsolutePath(), Expressions.forTesting()); String path = "${" + NESTED_KEY + "['" + NESTED_NAME + "']}"; String data = config.getString(DEFAULT_CONTAINER, path); assertEquals(NESTED_VALUE, data); }
@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 = createContainer(json); ContainerConfig config = new JsonContainerConfig(childFile.getAbsolutePath() + JsonContainerConfig.FILE_SEPARATOR + parentFile.getAbsolutePath(), Expressions.forTesting()); assertEquals(NESTED_VALUE, config.getString(CONTAINER_A, NESTED_KEY)); assertEquals(NESTED_VALUE, config.getString(CONTAINER_B, NESTED_KEY)); }
@Test(expected = ContainerConfigException.class) public void badConfigThrows() throws Exception { JSONObject json = new JSONObject(); json.put(CONTAINER_KEY, new String[]{CHILD_CONTAINER}); json.put(PARENT_KEY, "bad bad bad parent!"); json.put(ARRAY_NAME, ARRAY_ALT_VALUE); new JsonContainerConfig(createContainer(json).getAbsolutePath(), Expressions.forTesting()); }
@Test public void invalidContainerReturnsNull() throws Exception { ContainerConfig config = new JsonContainerConfig(createDefaultContainer().getAbsolutePath(), Expressions.forTesting()); assertNull("Did not return null for invalid container.", config.getString("fake", PARENT_KEY)); }