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 createTemporaryFile(json, ".json"); }
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 createTemporaryFile(json, ".json"); }
@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); createConfigForTest(createTemporaryFile(json, ".json").getAbsolutePath()); }
@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); createConfigForTest(createTemporaryFile(json, ".json").getAbsolutePath()); }
@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); createConfigForTest(createTemporaryFile(json, ".json").getAbsolutePath()); }
@Test public void resourceLoaderFileTest() throws Exception { // Create a temporary file that we can load from String dynamicValue = "dynamic value"; File temporaryFile = createTemporaryFile(dynamicValue, ".txt"); // 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(DYNAMICALLY_LOADED_VALUE_KEY, ResourceLoader.FILE_PREFIX + temporaryFile.getAbsolutePath()); createConfigForTest(createTemporaryFile(json, ".json").getAbsolutePath()); assertEquals(dynamicValue, config.getString(DEFAULT_CONTAINER, DYNAMICALLY_LOADED_VALUE_KEY).trim()); }
@Test public void resourceLoaderFileTest() throws Exception { // Create a temporary file that we can load from String dynamicValue = "dynamic value"; File temporaryFile = createTemporaryFile(dynamicValue, ".txt"); // 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(DYNAMICALLY_LOADED_VALUE_KEY, ResourceLoader.FILE_PREFIX + temporaryFile.getAbsolutePath()); createConfigForTest(createTemporaryFile(json, ".json").getAbsolutePath()); assertEquals(dynamicValue, config.getString(DEFAULT_CONTAINER, DYNAMICALLY_LOADED_VALUE_KEY).trim()); }
@Test public void expressionEvaluation() 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("expression", "Hello, ${world}!"); json.put("world", "Earth"); createConfigForTest(createTemporaryFile(json, ".json").getAbsolutePath()); assertEquals("Hello, Earth!", config.getString(DEFAULT_CONTAINER, "expression")); }
@Test public void expressionEvaluation() 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("expression", "Hello, ${world}!"); json.put("world", "Earth"); createConfigForTest(createTemporaryFile(json, ".json").getAbsolutePath()); assertEquals("Hello, Earth!", config.getString(DEFAULT_CONTAINER, "expression")); }
@Test public void shindigPortTest() 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("expression", "port=${SERVER_PORT}"); createConfigForTest(createTemporaryFile(json, ".json").getAbsolutePath()); assertEquals("port=8080", config.getString(DEFAULT_CONTAINER, "expression")); }
@Test public void shindigPortTest() 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("expression", "port=${SERVER_PORT}"); createConfigForTest(createTemporaryFile(json, ".json").getAbsolutePath()); assertEquals("port=8080", config.getString(DEFAULT_CONTAINER, "expression")); }
@Test public void resourceLoaderClasspathFailureTest() throws Exception { // Pointer to an invalid resource reference String invalidResource = ResourceLoader.RESOURCE_PREFIX + "does-not-exist"; // 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(DYNAMICALLY_LOADED_VALUE_KEY, invalidResource); createConfigForTest(createTemporaryFile(json, ".json").getAbsolutePath()); // If we fail to load a resource a warning is logged and we just end up with the raw value back assertEquals(invalidResource, config.getString(DEFAULT_CONTAINER, DYNAMICALLY_LOADED_VALUE_KEY)); }
@Test public void resourceLoaderClasspathFailureTest() throws Exception { // Pointer to an invalid resource reference String invalidResource = ResourceLoader.RESOURCE_PREFIX + "does-not-exist"; // 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(DYNAMICALLY_LOADED_VALUE_KEY, invalidResource); createConfigForTest(createTemporaryFile(json, ".json").getAbsolutePath()); // If we fail to load a resource a warning is logged and we just end up with the raw value back assertEquals(invalidResource, config.getString(DEFAULT_CONTAINER, DYNAMICALLY_LOADED_VALUE_KEY)); }
@Test public void shindigPortTest() 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("expression", "port=${SERVER_PORT}"); createConfigForTest(createTemporaryFile(json, ".json").getAbsolutePath()); assertEquals("port=8080", config.getString(DEFAULT_CONTAINER, "expression")); }
@Test public void resourceLoaderClasspathFailureTest() throws Exception { // Pointer to an invalid resource reference String invalidResource = ResourceLoader.RESOURCE_PREFIX + "does-not-exist"; // 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(DYNAMICALLY_LOADED_VALUE_KEY, invalidResource); createConfigForTest(createTemporaryFile(json, ".json").getAbsolutePath()); // If we fail to load a resource a warning is logged and we just end up with the raw value back assertEquals(invalidResource, config.getString(DEFAULT_CONTAINER, DYNAMICALLY_LOADED_VALUE_KEY)); }
@Test public void nullEntryEvaluation() throws Exception { // We use a JSON Object here to guarantee that we're well formed up front. JSONObject json = new JSONObject("{ 'gadgets.container' : ['default'], features : { osapi : null }}"); createConfigForTest(createTemporaryFile(json, ".json").getAbsolutePath()); assertNull(config.getMap("default", "features").get("osapi")); }
@Test public void nullEntryEvaluation() throws Exception { // We use a JSON Object here to guarantee that we're well formed up front. JSONObject json = new JSONObject("{ 'gadgets.container' : ['default'], features : { osapi : null }}"); createConfigForTest(createTemporaryFile(json, ".json").getAbsolutePath()); assertNull(config.getMap("default", "features").get("osapi")); }
@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)); }