Java Code Examples for org.apache.commons.configuration.BaseConfiguration#addProperty()
The following examples show how to use
org.apache.commons.configuration.BaseConfiguration#addProperty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReloadablePropertySourceTest.java From herd with Apache License 2.0 | 6 votes |
/** * Asserts that when a property is requested from the configruation, and it fires an error event (ex. Database is not available), the previously stored * values are not cleared. */ @Test public void testAssertGetPropertyErrorReturnPreviousValue() throws Exception { // Get a reloadable property source that loads properties from the configuration every time a property is read. BaseConfiguration configuration = new BaseConfiguration() { @Override public Object getProperty(String key) { fireError(EVENT_READ_PROPERTY, key, null, new IllegalStateException("test exception")); return null; } }; configuration.addProperty(TEST_KEY, TEST_VALUE_1); ReloadablePropertySource reloadablePropertySource = getNewReloadablePropertiesSource(0L, configuration); verifyPropertySourceValue(reloadablePropertySource, TEST_VALUE_1); }
Example 2
Source File: GenericExternalProcessTest.java From proarc with GNU General Public License v3.0 | 6 votes |
@Test public void testAddInputFile() throws Exception { final String inputName = "input.txt"; final File input = temp.newFile(inputName); final BaseConfiguration conf = new BaseConfiguration(); conf.addProperty(ExternalProcess.PROP_EXEC, "test.sh"); conf.addProperty(ExternalProcess.PROP_ARG, "-i ${input.file.name}"); conf.addProperty(ExternalProcess.PROP_ARG, "-path ${input.file}[0]"); conf.addProperty(ExternalProcess.PROP_ARG, "-o ${input.folder}"); GenericExternalProcess gp = new GenericExternalProcess(conf).addInputFile(input); assertEquals(gp.getParameters().getMap().get(GenericExternalProcess.SRC_NAME_EXT), input.getName()); assertEquals(gp.getParameters().getMap().get(GenericExternalProcess.SRC_PATH), input.getAbsolutePath()); assertEquals(gp.getParameters().getMap().get(GenericExternalProcess.SRC_PARENT), input.getParentFile().getAbsolutePath()); List<String> cmdLines = gp.buildCmdLine(conf); // System.out.println(cmdLines.toString()); }
Example 3
Source File: Agent.java From BUbiNG with Apache License 2.0 | 5 votes |
public static void main(final String arg[]) throws Exception { final SimpleJSAP jsap = new SimpleJSAP(Agent.class.getName(), "Starts a BUbiNG agent (note that you must enable JMX by means of the standard Java system properties).", new Parameter[] { new FlaggedOption("weight", JSAP.INTEGER_PARSER, "1", JSAP.NOT_REQUIRED, 'w', "weight", "The agent weight."), new FlaggedOption("group", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'g', "group", "The JGroups group identifier (must be the same for all cooperating agents)."), new FlaggedOption("jmxHost", JSAP.STRING_PARSER, InetAddress.getLocalHost().getHostAddress(), JSAP.REQUIRED, 'h', "jmx-host", "The IP address (possibly specified by a host name) that will be used to expose the JMX RMI connector to other agents."), new FlaggedOption("rootDir", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'r', "root-dir", "The root directory."), new Switch("new", 'n', "new", "Start a new crawl"), new FlaggedOption("properties", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'P', "properties", "The properties used to configure the agent."), new UnflaggedOption("name", JSAP.STRING_PARSER, JSAP.REQUIRED, "The agent name (an identifier that must be unique across the group).") }); final JSAPResult jsapResult = jsap.parse(arg); if (jsap.messagePrinted()) System.exit(1); // JMX *must* be set up. final String portProperty = System.getProperty(JMX_REMOTE_PORT_SYSTEM_PROPERTY); if (portProperty == null) throw new IllegalArgumentException("You must specify a JMX service port using the property " + JMX_REMOTE_PORT_SYSTEM_PROPERTY); final String name = jsapResult.getString("name"); final int weight = jsapResult.getInt("weight"); final String group = jsapResult.getString("group"); final String host = jsapResult.getString("jmxHost"); final int port = Integer.parseInt(portProperty); final BaseConfiguration additional = new BaseConfiguration(); additional.addProperty("name", name); additional.addProperty("group", group); additional.addProperty("weight", Integer.toString(weight)); additional.addProperty("crawlIsNew", Boolean.valueOf(jsapResult.getBoolean("new"))); if (jsapResult.userSpecified("rootDir")) additional.addProperty("rootDir", jsapResult.getString("rootDir")); new Agent(host, port, new RuntimeConfiguration(new StartupConfiguration(jsapResult.getString("properties"), additional))); System.exit(0); // Kills remaining FetchingThread instances, if any. }
Example 4
Source File: CatalogConfigurationTest.java From proarc with GNU General Public License v3.0 | 5 votes |
@Before public void setUp() { conf = new BaseConfiguration(); // catalog1 String prefix = Catalogs.CATALOG_PREFIX + '.' + "catalog1"; conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_NAME, "catalog1Name"); conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_URL, "catalog1URL"); conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_TYPE, "catalog1Type"); catalog1ExtraOption = "extraOption"; conf.addProperty(prefix + '.' + catalog1ExtraOption, "catalog1ExtraOption"); // Invalid catalog prefix = Catalogs.CATALOG_PREFIX + '.' + "catalogInvalid"; conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_NAME, "catalogInvalidName"); conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_TYPE, "catalogInvalidType"); // Not listed catalog prefix = Catalogs.CATALOG_PREFIX + '.' + "catalogNotListed"; conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_NAME, "catalogNotListedName"); conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_URL, "catalogNotListedURL"); conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_TYPE, "catalogNotListedType"); // catalog2 prefix = Catalogs.CATALOG_PREFIX + '.' + "catalog2"; conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_NAME, "catalog2Name"); conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_URL, "catalog2URL"); conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_TYPE, "catalog2Type"); // catalogs declaration conf.addProperty(Catalogs.PROPERTY_CATALOGS, "catalog1, catalogInvalid, catalogMissing, catalog2"); conf.addProperty("dummyProperty", "dummy"); }
Example 5
Source File: StartSocketListener.java From otroslogviewer with Apache License 2.0 | 5 votes |
@Override protected void actionPerformedHook(ActionEvent arg0) { LogImporterAndPort chooseLogImporter = chooseLogImporter(); if (chooseLogImporter == null) { return; } StatusObserver observer = getOtrosApplication().getStatusObserver(); if (logViewPanelWrapper == null) { logViewPanelWrapper = new LogViewPanelWrapper("Socket", null, TableColumns.values(), getOtrosApplication()); logViewPanelWrapper.goToLiveMode(); BaseConfiguration configuration = new BaseConfiguration(); configuration.addProperty(ConfKeys.TAILING_PANEL_PLAY, true); configuration.addProperty(ConfKeys.TAILING_PANEL_FOLLOW, true); logDataCollector = new BufferingLogDataCollectorProxy(logViewPanelWrapper.getDataTableModel(), 4000, configuration); } getOtrosApplication().addClosableTab("Socket listener", "Socket listener", Icons.PLUGIN_CONNECT, logViewPanelWrapper, true); //TODO solve this warning SocketLogReader logReader = null; if (logReader == null || logReader.isClosed()) { logReader = new SocketLogReader(chooseLogImporter.logImporter, logDataCollector, observer, getOtrosApplication().getLogLoader(), chooseLogImporter.port); try { logReader.start(); logReaders.add(logReader); observer.updateStatus(String.format("Socket opened on port %d with %s.", chooseLogImporter.port, chooseLogImporter.logImporter)); } catch (Exception e) { LOGGER.error("Failed to open Socket listener", e); observer.updateStatus("Failed to open listener " + e.getMessage(), StatusObserver.LEVEL_ERROR); } } }
Example 6
Source File: OpenLogsSwingWorker.java From otroslogviewer with Apache License 2.0 | 5 votes |
@Override protected Void doInBackground() throws Exception { LoadingInfo[] loadingInfos = getLoadingInfo(); Collection<LogImporter> elements = pluginContext.getOtrosApplication().getAllPluginables().getLogImportersContainer().getElements(); LogImporter[] importers = elements.toArray(new LogImporter[elements.size()]); String[] names = new String[elements.size()]; for (int i = 0; i < names.length; i++) { names[i] = importers[i].getName(); } TableColumns[] visibleColumns = {TableColumns.ID,// TableColumns.TIME,// TableColumns.LEVEL,// TableColumns.MESSAGE,// TableColumns.CLASS,// TableColumns.METHOD,// TableColumns.THREAD,// TableColumns.MARK,// TableColumns.NOTE,// TableColumns.LOG_SOURCE }; BaseConfiguration configuration = new BaseConfiguration(); configuration.addProperty(ConfKeys.TAILING_PANEL_PLAY, true); configuration.addProperty(ConfKeys.TAILING_PANEL_FOLLOW, true); logViewPanelWrapper = new LogViewPanelWrapper(tabName, null, visibleColumns, pluginContext.getOtrosApplication()); BufferingLogDataCollectorProxy logDataCollector = new BufferingLogDataCollectorProxy(logViewPanelWrapper.getDataTableModel(), 4000, configuration); LogImporter importer = getLogImporter(elements); for (LoadingInfo loadingInfo : loadingInfos) { openLog(logDataCollector, importer, loadingInfo); } publish("All log files loaded"); return null; }
Example 7
Source File: Helpers.java From BUbiNG with Apache License 2.0 | 2 votes |
/** Returns a test configuration, contained in the file <code>bubing-test.properties</code> in the data directory. * * @param self the test that is requiring the configuration. * @param prop the additional properties that override (some of) those contained in the file. * @param newCrawl whether this configuration simulates a new crawl or not. * @return the configuration. * @throws ConfigurationException if some configuration error occurs. */ public static RuntimeConfiguration getTestConfiguration(Object self, BaseConfiguration prop, boolean newCrawl) throws ConfigurationException, IOException, IllegalArgumentException, ClassNotFoundException { prop.addProperty("crawlIsNew", Boolean.valueOf(newCrawl)); return new RuntimeConfiguration(getTestStartupConfiguration(self, prop)) ; }