@Test public void testPropertiesParseUtfKey() throws Exception { configFile.setFileContents( " gsa.hostname=not_used\n" + "how\\u2202you= i am happy. how are you?\n"); config.load(configFile); assertEquals("i am happy. how are you?", config.getValue("how\u2202you")); }
@Test public void testPropertiesParseKeyEscapedWhitespace() throws Exception { configFile.setFileContents( " gsa.hostname=not_used\n" + " \\ \\ Tru\\ \\ th\\ \\ : Beauty"); config.load(configFile); assertEquals("Beauty", config.getValue(" Tru th ")); }
@Test public void testGetTransformPipelineSpecValid() throws Exception { final List<Map<String, String>> golden = new ArrayList<Map<String, String>>(); { Map<String, String> map; map = new HashMap<String, String>(); map.put("name", "trans1"); map.put("key1", "value1"); golden.add(map); map = new HashMap<String, String>(); map.put("name", "trans2"); map.put("key2", "value2"); map.put("key3", "value3"); golden.add(map); map = new HashMap<String, String>(); map.put("name", "trans3"); golden.add(map); } configFile.setFileContents( "metadata.transform.pipeline = trans1, trans2 ,trans3\n" + "metadata.transform.pipeline.trans1.key1=value1\n" + "metadata.transform.pipeline.trans2.key2=value2\n" + "metadata.transform.pipeline.trans2.key3=value3\n"); config.setValue("gsa.hostname", "notreal"); config.load(configFile); assertEquals(golden, config.getMetadataTransformPipelineSpec()); }
@Test public void testConfigModificationDetection() throws Exception { configFile.setFileContents("adaptor.fullListingSchedule=1\n"); config.setValue("gsa.hostname", "notreal"); config.load(configFile); assertEquals("notreal", config.getGsaHostname()); assertEquals("1", config.getAdaptorFullListingSchedule()); assertEquals(configFile, config.getConfigFile()); final List<ConfigModificationEvent> events = new LinkedList<ConfigModificationEvent>(); ConfigModificationListener listener = new ConfigModificationListener() { @Override public void configModified(ConfigModificationEvent ev) { events.add(ev); } }; configFile.setFileContents("adaptor.fullListingSchedule=2\n"); config.addConfigModificationListener(listener); config.ensureLatestConfigLoaded(); assertEquals("1", config.getAdaptorFullListingSchedule()); assertEquals(0, events.size()); configFile.setLastModified(configFile.lastModified() + 1); config.ensureLatestConfigLoaded(); assertEquals("2", config.getAdaptorFullListingSchedule()); assertEquals("notreal", config.getGsaHostname()); assertEquals(1, events.size()); assertEquals(1, events.get(0).getModifiedKeys().size()); assertTrue(events.get(0).getModifiedKeys().contains("adaptor.fullListingSchedule")); events.clear(); // Change nothing. configFile.setLastModified(configFile.lastModified() + 1); config.ensureLatestConfigLoaded(); assertEquals(0, events.size()); assertEquals("2", config.getAdaptorFullListingSchedule()); assertEquals("notreal", config.getGsaHostname()); config.removeConfigModificationListener(listener); configFile.setFileContents("adaptor.fullListingSchedule=3\n"); configFile.setLastModified(configFile.lastModified() + 1); config.ensureLatestConfigLoaded(); assertEquals(0, events.size()); assertEquals("3", config.getAdaptorFullListingSchedule()); assertEquals("notreal", config.getGsaHostname()); }
@Test public void testPropertiesParseUtfValue() throws Exception { configFile.setFileContents( " gsa.hostname=not_used\n" + "howyou = \\u2202i am happy\\u2202. how are you?\\u2202\\u2202\n"); config.load(configFile); assertEquals("\u2202i am happy\u2202. how are you?\u2202\u2202", config.getValue("howyou")); }
@Test public void testGetTransformPipelineSpecInValid() throws Exception { configFile.setFileContents("metadata.transform.pipeline=name1, ,name3\n"); config.setValue("gsa.hostname", "notreal"); config.load(configFile); thrown.expect(RuntimeException.class); config.getMetadataTransformPipelineSpec(); }
// TODO(ejona): Enable test once config allows gsa.hostname changes. // **DISABLED** @Test public void testConfigModifiedInvalid() throws Exception { configFile.setFileContents("gsa.hostname=notreal\n"); config.load(configFile); assertEquals("notreal", config.getGsaHostname()); // Missing gsa.hostname. configFile.setFileContents(""); configFile.setLastModified(configFile.lastModified() + 1); boolean threwException = false; try { config.ensureLatestConfigLoaded(); } catch (IllegalStateException e) { threwException = true; } assertTrue(threwException); assertEquals("notreal", config.getGsaHostname()); }
@Test public void testPropertiesParseMultiline() throws Exception { configFile.setFileContents( " gsa.hostname=not_used\n" + "fruits apple, banana, pear, \\\n" + " cantaloupe, watermelon, \\\n" + " kiwi, mango\n\n"); config.load(configFile); String golden = "apple, banana, pear, cantaloupe, watermelon, kiwi, mango"; assertEquals(golden, config.getValue("fruits")); }
@Test public void testPropertiesParseEscapeASlash6() throws Exception { configFile.setFileContents(" gsa.hostname=not_used\n" + "slash= \\\\\\\t\\\\\\\f"); config.load(configFile); assertEquals("\\\t\\\f", config.getValue("slash")); }
@Test public void testPropertiesParseColon2() throws Exception { configFile.setFileContents(" gsa.hostname=not_used\n" + " Truth :Beauty"); config.load(configFile); assertEquals("Beauty", config.getValue("Truth")); }
@Test public void testSimplestPropertiesParse() throws Exception { configFile.setFileContents(" \t gsa.hostname \t = feedhost bob\n"); config.load(configFile); assertEquals("feedhost bob", config.getValue("gsa.hostname")); }
@Test public void testGetTransformPipelineSpecEmpty() throws Exception { configFile.setFileContents("metadata.transform.pipeline=\n"); config.load(configFile); assertEquals(Collections.emptyList(), config.getMetadataTransformPipelineSpec()); }
public void testNoAdminHostname() throws Exception { configFile.setFileContents("gsa.hostname=feedhost\n"); config.load(configFile); assertEquals(config.getGsaHostname(), config.getGsaAdminHostname()); }