@Test public void testWhitespaceOnlyGsaHostname() { // Requires gsa.hostname to be non-empty config.setValue("gsa.hostname", " "); thrown.expect(InvalidConfigurationException.class); config.validate(); }
@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()); }
/** * Load default configuration file and parse command line options. * * @return unused command line arguments * @throws IllegalStateException when not all configuration keys have values */ static String[] autoConfig(Config config, String[] args, File configFile) { File sysPropertiesAdditions = null; int i; for (i = 0; i < args.length; i++) { if (!args[i].startsWith("-D")) { break; } String arg = args[i].substring(2); String[] parts = arg.split("=", 2); if (parts.length < 2) { break; } if ("adaptor.configfile".equals(parts[0])) { configFile = new File(parts[1]); } else if ("sys.properties.file".equals(parts[0])) { sysPropertiesAdditions = new File(parts[1]); } else { config.setValue(parts[0], parts[1]); } } processSystemProperties(sysPropertiesAdditions); loadConfigFile(config, configFile); config.validate(); if (i == 0) { return args; } else { return Arrays.copyOfRange(args, i, args.length); } }
@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(); }
public void skipRowToStartOffset( Config cfg, DataReader rdr, ILoaderProgress mon, boolean updateProgress) throws LoadException { try { cfg.setValue(LastRun.LAST_LOAD_BATCH_ROW, 0); rowToStart(cfg, rdr); if (updateProgress) { // set the last processed value to the starting row int currentRow = rdr.getCurrentRowNumber(); if (mon != null && currentRow > 0) mon.worked(currentRow); cfg.setValue(LastRun.LAST_LOAD_BATCH_ROW, currentRow); cfg.saveLastRun(); } } catch (final DataAccessObjectException e) { handleError(e, "errorDaoStartRow"); } catch (final IOException e) { handleError(e, "errorLastRun"); } }
@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()); }