@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(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(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 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"); ContainerConfig config = new JsonContainerConfig(createContainer(json).getAbsolutePath(), Expressions.forTesting()); 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"); ContainerConfig config = new JsonContainerConfig(createContainer(json).getAbsolutePath(), Expressions.forTesting()); 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"); ContainerConfig config = new JsonContainerConfig(createContainer(json).getAbsolutePath(), Expressions.forTesting()); 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}"); ContainerConfig config = new JsonContainerConfig(createContainer(json).getAbsolutePath(), Expressions.forTesting()); 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}"); ContainerConfig config = new JsonContainerConfig(createContainer(json).getAbsolutePath(), Expressions.forTesting()); 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}"); ContainerConfig config = new JsonContainerConfig(createContainer(json).getAbsolutePath(), Expressions.forTesting()); assertEquals("port=8080", config.getString(DEFAULT_CONTAINER, "expression")); }
@Before public void setUp() throws Exception { JSONObject config = new JSONObject('{' + ContainerConfig.DEFAULT_CONTAINER + ':' + "{'gadgets.features':{views:" + "{aliased: {aliases: ['some-alias', 'alias']}}" + "}}}"); containerConfig = new JsonContainerConfig(config, Expressions.forTesting()); processor = new Processor(gadgetSpecFactory, substituter, containerConfig, blacklist, null); }
@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 }}"); JsonContainerConfig config = new JsonContainerConfig(createContainer(json).getAbsolutePath(), Expressions.forTesting()); 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 = 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 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 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() + JsonContainerConfigLoader.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 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 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 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 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 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); }
@Before public void setUp() throws Exception { JSONObject config = createConfig(); JsonContainerConfig containerConfig = new JsonContainerConfig(config, Expressions.forTesting(new Functions())); mockFetcher = mock(HttpFetcher.class); fetcher = new DefaultServiceFetcher(containerConfig, mockFetcher); }