List of usage examples for org.apache.commons.configuration HierarchicalINIConfiguration HierarchicalINIConfiguration
public HierarchicalINIConfiguration()
From source file:info.pancancer.arch3.test.TestWorker.java
@Test public void testWorker_endlessFromConfig() throws Exception { HierarchicalINIConfiguration configObj = new HierarchicalINIConfiguration(); configObj.addProperty("rabbit.rabbitMQQueueName", "seqware"); configObj.addProperty("rabbit.rabbitMQHost", "localhost"); configObj.addProperty("rabbit.rabbitMQUser", "guest"); configObj.addProperty("rabbit.rabbitMQPass", "guest"); configObj.addProperty("worker.heartbeatRate", "2.5"); configObj.addProperty("worker.max-runs", "1"); configObj.addProperty("worker.preworkerSleep", "1"); configObj.addProperty("worker.postworkerSleep", "1"); configObj.addProperty("worker.endless", "true"); configObj.addProperty("worker.hostUserName", System.getProperty("user.name")); byte[] body = setupMessage(); Delivery testDelivery = new Delivery(mockEnvelope, mockProperties, body); setupMockQueue(testDelivery);/*from w w w .ja v a2s.c o m*/ Mockito.when(Utilities.parseConfig(anyString())).thenReturn(configObj); //Because the code that does cleanup in calls resultHandler.waitFor(); we need to actually execute something, even if it does nothing. Mockito.doNothing().when(mockExecutor).execute(any(CommandLine.class), any(DefaultExecuteResultHandler.class)); // This is to mock the cleanup command - we don't really want to execute the command for deleting contents of /datastore, at least not when unit testing on a workstation! PowerMockito.whenNew(DefaultExecutor.class).withNoArguments().thenReturn(mockExecutor); Mockito.when(mockExecHandler.hasResult()).thenReturn(true); PowerMockito.whenNew(DefaultExecuteResultHandler.class).withNoArguments().thenReturn(mockExecHandler); final FutureTask<String> tester = new FutureTask<>(new Callable<String>() { @Override public String call() { LOG.info("tester thread started"); try { Worker.main(new String[] { "--config", "src/test/resources/workerConfig.ini", "--uuid", "vm123456", "--pidFile", "/var/run/arch3_worker.pid" }); } catch (CancellationException | InterruptedException e) { LOG.error("Exception caught: " + e.getMessage()); return e.getMessage(); } catch (Exception e) { e.printStackTrace(); fail("Unexpected exception"); return null; } finally { Mockito.verify(mockAppender, Mockito.atLeastOnce()).doAppend(argCaptor.capture()); String s = appendEventsIntoString(argCaptor.getAllValues()); return s; } } }); final Thread killer = new Thread(new Runnable() { @Override public void run() { LOG.info("killer thread started"); try { // The endless worker will not end on its own (because it's endless) so we need to wait a little bit (0.5 seconds) and // then kill it as if it were killed by the command-line script (kill_worker_daemon.sh). Thread.sleep(2500); } catch (InterruptedException e) { e.printStackTrace(); LOG.error(e.getMessage()); } tester.cancel(true); } }); ExecutorService es = Executors.newFixedThreadPool(2); es.execute(tester); es.execute(killer); try { tester.get(); } catch (CancellationException e) { Mockito.verify(mockAppender, Mockito.atLeastOnce()).doAppend(argCaptor.capture()); List<LoggingEvent> tmpList = new LinkedList<LoggingEvent>(argCaptor.getAllValues()); String output = this.appendEventsIntoString(tmpList); assertTrue("--endless flag was detected and set", output.contains("The \"--endless\" flag was set, this worker will run endlessly!")); int numJobsPulled = StringUtils.countMatches(output, " WORKER IS PREPARING TO PULL JOB FROM QUEUE "); LOG.info("Number of jobs attempted: " + numJobsPulled); assertTrue("number of jobs attempted > 1", numJobsPulled > 1); } catch (Exception e) { e.printStackTrace(); fail(); } }
From source file:io.datalayer.conf.HierarchicalIniConfigurationTest.java
/** * Test of getSections method, of class {@link HierarchicalINIConfiguration} * ./*w w w .j a v a 2 s . com*/ */ @Test public void testGetSections() { HierarchicalINIConfiguration instance = new HierarchicalINIConfiguration(); instance.addProperty("test1.foo", "bar"); instance.addProperty("test2.foo", "abc"); Set<String> expResult = new HashSet<String>(); expResult.add("test1"); expResult.add("test2"); Set<String> result = instance.getSections(); assertEquals(expResult, result); }
From source file:io.datalayer.conf.HierarchicalIniConfigurationTest.java
@Test public void testWriteValueWithCommentChar() throws Exception { HierarchicalINIConfiguration config = new HierarchicalINIConfiguration(); config.setProperty("section.key1", "1;2;3"); StringWriter writer = new StringWriter(); config.save(writer);/*from w ww .j a v a 2 s .c o m*/ HierarchicalINIConfiguration config2 = new HierarchicalINIConfiguration(); config2.load(new StringReader(writer.toString())); assertEquals("value", "1;2;3", config2.getString("section.key1")); }
From source file:com.baasbox.db.DbHelper.java
public static void populateConfiguration() throws IOException, ConfigurationException { BaasBoxLogger.info("Load initial configuration..."); InputStream is;// w w w . j a v a 2s .com if (Play.application().isProd()) is = Play.application().resourceAsStream(CONFIGURATION_FILE_NAME); else is = new FileInputStream(Play.application().getFile("conf/" + CONFIGURATION_FILE_NAME)); HierarchicalINIConfiguration c = new HierarchicalINIConfiguration(); c.setEncoding("UTF-8"); c.load(is); CharSequence doubleDot = ".."; CharSequence dot = "."; Set<String> sections = c.getSections(); for (String section : sections) { Class en = PropertiesConfigurationHelper.CONFIGURATION_SECTIONS.get(section); if (en == null) { BaasBoxLogger.warn(section + " is not a valid configuration section, it will be skipped!"); continue; } SubnodeConfiguration subConf = c.getSection(section); Iterator<String> it = subConf.getKeys(); while (it.hasNext()) { String key = (it.next()); Object value = subConf.getString(key); key = key.replace(doubleDot, dot);//bug on the Apache library: if the key contain a dot, it will be doubled! try { BaasBoxLogger.info("Setting " + value + " to " + key); PropertiesConfigurationHelper.setByKey(en, key, value); } catch (Exception e) { BaasBoxLogger.warn("Error loading initial configuration: Section " + section + ", key: " + key + ", value: " + value, e); } } } is.close(); BaasBoxLogger.info("...done"); }
From source file:info.pancancer.arch3.test.TestWorker.java
private void setupConfig() { HierarchicalINIConfiguration configObj = new HierarchicalINIConfiguration(); configObj.addProperty("rabbit.rabbitMQQueueName", "seqware"); configObj.addProperty("worker.heartbeatRate", "2.5"); configObj.addProperty("worker.preworkerSleep", "1"); configObj.addProperty("worker.postworkerSleep", "1"); configObj.addProperty("worker.hostUserName", System.getProperty("user.name")); Mockito.when(Utilities.parseConfig(anyString())).thenReturn(configObj); }
From source file:io.datalayer.conf.HierarchicalIniConfigurationTest.java
/** * Tests whether a configuration can be saved that contains section keys * with delimiter characters. This test is related to CONFIGURATION-409. *//*from ww w. j a va2 s .c om*/ @Test public void testSaveKeysWithDelimiters() throws ConfigurationException { HierarchicalINIConfiguration conf = new HierarchicalINIConfiguration(); final String section = "Section..with..dots"; conf.addProperty(section + ".test1", "test1"); conf.addProperty(section + ".test2", "test2"); conf.save(TEST_FILE); conf = new HierarchicalINIConfiguration(); conf.load(TEST_FILE); assertEquals("Wrong value (1)", "test1", conf.getString(section + ".test1")); assertEquals("Wrong value (2)", "test2", conf.getString(section + ".test2")); }
From source file:io.datalayer.conf.HierarchicalIniConfigurationTest.java
/** * Tests whether getSection() can deal with duplicate sections. *//* w ww . java2 s . c om*/ @Test public void testGetSectionDuplicate() { HierarchicalINIConfiguration config = new HierarchicalINIConfiguration(); config.addProperty("section.var1", "value1"); config.addProperty("section(-1).var2", "value2"); SubnodeConfiguration section = config.getSection("section"); Iterator<String> keys = section.getKeys(); assertEquals("Wrong key", "var1", keys.next()); assertFalse("Too many keys", keys.hasNext()); }
From source file:io.datalayer.conf.HierarchicalIniConfigurationTest.java
/** * Tests whether parsing of lists can be disabled. *///w w w .j a va 2 s.c o m @Test public void testListParsingDisabled() throws ConfigurationException { HierarchicalINIConfiguration config = new HierarchicalINIConfiguration(); config.setDelimiterParsingDisabled(true); load(config, "[test]" + LINE_SEPARATOR + "nolist=1,2,3"); assertEquals("Wrong value", "1,2,3", config.getString("test.nolist")); }
From source file:org.apache.taverna.robundle.Bundles.java
public static URI getReference(Path path) throws IOException { if (path == null || isMissing(path)) return null; if (!isReference(path)) throw new IllegalArgumentException("Not a reference: " + path); // Note: Latin1 is chosen here because it would not bail out on // "strange" characters. We actually parse the URL as ASCII path = withExtension(path, DOT_URL); try (BufferedReader r = newBufferedReader(path, LATIN1)) { HierarchicalINIConfiguration ini = new HierarchicalINIConfiguration(); ini.load(r);//from ww w .j a v a 2 s .co m String urlStr = ini.getSection(INI_INTERNET_SHORTCUT).getString(INI_URL); // String urlStr = ini.get(INI_INTERNET_SHORTCUT, INI_URL); if (urlStr == null) throw new IOException("Invalid/unsupported URL format: " + path); return URI.create(urlStr); } catch (ConfigurationException e) { throw new IOException("Can't parse reference: " + path, e); } }
From source file:org.midonet.config.ConfigProvider.java
public static HierarchicalConfiguration fromConfigFile(String path) { try {/* w w w . ja v a2s . c o m*/ HierarchicalINIConfiguration config = new HierarchicalINIConfiguration(); config.setDelimiterParsingDisabled(true); config.setFileName(path); config.load(); return config; } catch (ConfigurationException e) { throw new RuntimeException(e); } }