@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 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")); }
public void init() throws ServletException { try { // Load configuration (from classpath or WEB-INF root path) String webInfPath = getServletContext().getRealPath("/") + "/WEB-INF"; Config.load(webInfPath); Log.init(); // Start Log.info( "init() Pushlet Webapp - version=" + Version.SOFTWARE_VERSION + " built=" + Version.BUILD_DATE); // Start session manager SessionManager.getInstance().start(); // Start event Dispatcher Dispatcher.getInstance().start(); if (Config.getBoolProperty(Config.SOURCES_ACTIVATE)) { EventSourceManager.start(webInfPath); } else { Log.info("Not starting local event sources"); } } catch (Throwable t) { throw new ServletException("Failed to initialize Pushlet framework " + t, t); } }
/** * Tests filtering of config props via a {@link IConfigFilter}. * * @throws Exception */ public void testConfigFiltering() throws Exception { Config config = Config.load(); // create a filter to extract only those keys beginning with: 'props.simple' IConfigFilter filter = new IConfigFilter() { @Override public boolean accept(String keyName) { return keyName.startsWith("props.simple"); } }; Config filtered = config.filter(filter); assert filtered != null && !filtered.isEmpty() : "Unable to obtain non-empty filtered config instance"; assert filtered.getProperty("props.simple.propA") != null; assert filtered.getProperty("props.simple.propB") != null; int num = 0; for (Iterator<String> itr = filtered.getKeys(); itr.hasNext(); ) { String key = itr.next(); assert key != null && key.startsWith("props.simple") : "Encountered invalid filtered key"; num++; } assert num == 2 : "Invalid number of filtered keys."; }
public void testLoadAll() throws Exception { Config config = Config.load(new ConfigRef(true)); for (String key : keys) { assert config.getProperty(key) != null; } }
@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 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(); }
/** * Verify Config default loading. * * @throws Exception */ public void testDefaultLoading() throws Exception { try { Config config = Config.load(); assert !config.isEmpty() : "Config instance is empty"; } catch (Throwable t) { Assert.fail(t.getMessage(), t); } }
/** * Loads the provided config file, if it exists. It squelches any errors so that you are free to * call it without error handling, since this is typically non-fatal. */ private static void loadConfigFile(Config config, File configFile) { if (null != configFile && configFile.exists() && configFile.isFile()) { try { config.load(configFile); } catch (IOException ex) { log.log(Level.WARNING, "could not read configuration properties file " + configFile, ex); } } }
@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")); }
@Mod.EventHandler public void load(FMLInitializationEvent event) { config.load(); this.worldType = new NewDawnWorldType(); this.thaumcraftSupportEnabled = config.getMiscBoolean("Enable internal Thaumcraft support", true); if (thaumcraftSupportEnabled) { ThaumcraftBiomeProvider.prepareThaumcraftSupport(config); } config.save(); }
/** * Verifies {@link Config}s asMap method(s) work given a pefix * * @throws Exception */ public void testNestedAsMap() throws Exception { Config config = Config.load(); Map<String, String> map = config.asMap("simple", "simple."); assert map != null; // ensure only log4j props are in the map for (String key : map.keySet()) { assert key.startsWith("simple.") : "Encountered non simple property in map"; } }
/** * Verifies {@link Config}s asMap method(s) work for all loaded properties * * @throws Exception */ public void testAllAsMap() throws Exception { Config config = Config.load(); Map<String, String> map = config.asMap(null, null); assert map != null; // ensure all properties are in the map for (String key : keys) { assert map.keySet().contains(key) : "Encountered property in map that was NOT in the loaded config properties file: " + key; } }
/** * Verifies the property values are properly interpolated * * @throws Exception */ public void testInterpolation() throws Exception { Config config = Config.load(); Iterator<?> itr = config.getKeys(); while (itr.hasNext()) { Object obj = itr.next(); assert obj != null; String key = obj.toString(); assert key.length() > 1; String val = config.getString(key); assert val != null && val.indexOf("${") < 0 : "Encountered non-interpolated property value: " + val; } }
public static void main(String[] args) throws InterruptedException, IOException { if (DebugOutput.init()) { if (Config.load()) { if (!Config.firstRun) { print("Beginning Lib parsing..."); if (ParseLib.parseTheLib()) { print("Lib parsing complete. Beginning Java parsing..."); if (FileCreator.createDir(FileCreator.recipeDir)) { if (ParseJava.parseTheJava()) { print("Java parsing complete. Beginning Javascript output..."); JavascriptOutput.outputJavascript(); print("Congratz, all done!"); DebugOutput.log.close(); Thread.sleep(15000); } else { DebugOutput.log.close(); Thread.sleep(15000); } } else { DebugOutput.log.close(); Thread.sleep(15000); } } else { DebugOutput.log.close(); Thread.sleep(15000); } } else { DebugOutput.out( "\n\n" + "#########################################################################\n" + "Program stopping due to this being the first run.\n" + "Please check that the config options are to your liking before rerunning.\n" + "Config location: " + Config.configFile.getAbsolutePath() + "\n" + "#########################################################################", 0); DebugOutput.log.close(); Thread.sleep(15000); } } else { DebugOutput.log.close(); Thread.sleep(15000); } } else { DebugOutput.log.close(); Thread.sleep(15000); } }
@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()); }
/** * Nachos main entry point. * * @param args the command line arguments. */ public static void main(final String[] args) { System.out.print("nachos 5.0j initializing..."); Lib.assertTrue(Machine.args == null); Machine.args = args; processArgs(); Config.load(configFileName); // get the current directory (.) baseDirectory = new File(new File("").getAbsolutePath()); // get the nachos directory (./nachos) nachosDirectory = new File(baseDirectory, "nachos"); String testDirectoryName = Config.getString("FileSystem.testDirectory"); // get the test directory if (testDirectoryName != null) { testDirectory = new File(testDirectoryName); } else { // use ../test testDirectory = new File(baseDirectory.getParentFile(), "test"); } securityManager = new NachosSecurityManager(testDirectory); privilege = securityManager.getPrivilege(); privilege.machine = new MachinePrivilege(); TCB.givePrivilege(privilege); privilege.stats = stats; securityManager.enable(); createDevices(); checkUserClasses(); autoGrader = (AutoGrader) Lib.constructObject(autoGraderClassName); new TCB() .start( new Runnable() { public void run() { autoGrader.start(privilege); } }); }
// 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()); }
/** * Verifies config saving to disk. * * @throws Exception */ public void testSaveSubsetToFile() throws Exception { Config config = Config.load(); File f = stubTestConfigOutputPropsFile(); config.saveAsPropFile(f, "props.commas", "props.commas."); Properties props = new Properties(); props.load(new FileReader(f)); Enumeration<?> enm = props.propertyNames(); while (enm.hasMoreElements()) { Object obj = enm.nextElement(); String key = obj == null ? null : obj.toString(); assert key != null && key.startsWith("props.commas.") : "Key doesn't start with commas."; assert keys.contains(key) : "The props keys list does not contain key: " + key; } }
private static boolean initServices() { Config obj_config = new Config(); if (obj_config.load("conf/config.xml")) { // ... switch (obj_config.getNodeDetail("type").toLowerCase()) { case "balancer": System.out.println("%> job:balancer"); // ... // break; case "node": // ... break; } return true; } return false; }
/** * Verifies config saving to disk. * * @throws Exception */ public void testSaveAllToFile() throws Exception { Config config = Config.load(); File f = stubTestConfigOutputPropsFile(); config.saveAsPropFile(f, null, null); Properties props = new Properties(); props.load(new FileReader(f)); Enumeration<?> enm = props.propertyNames(); while (enm.hasMoreElements()) { Object obj = enm.nextElement(); String key = obj == null ? null : obj.toString(); String val = props.getProperty(key); // verify comma having prop values if ("props.commas.propA".equals(key)) { assert val.equals("a,b,c") : "props.commas.propA - mismatch!"; } else if ("props.commas.propB".equals(key)) { assert val.equals("d,e,f") : "props.commas.propB - mismatch!"; } } }
@VisibleForTesting static void run(String[] args, FileSystem fileSystem) { Flags flags = Flags.parse(args, fileSystem); Config config = null; try (InputStream stream = newInputStream(flags.config)) { config = Config.load(stream, fileSystem); } catch (IOException e) { e.printStackTrace(System.err); System.exit(-1); } if (flags.printConfig) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); String header = " Configuration "; int len = header.length(); String pad = Strings.repeat("=", len / 2); System.err.println(pad + header + pad); System.err.println(gson.toJson(config.toJson())); System.err.println(Strings.repeat("=", 79)); System.exit(1); } Iterable<String> standardFlags = STANDARD_FLAGS; if (config.isStrict()) { standardFlags = transform( standardFlags, new Function<String, String>() { @Override public String apply(String input) { return input.replace("--jscomp_warning", "--jscomp_error"); } }); } ImmutableList<String> compilerFlags = ImmutableList.<String>builder() .addAll(transform(config.getSources(), toFlag("--js="))) .addAll(transform(config.getModules(), toFlag("--js="))) .addAll(transform(config.getExterns(), toFlag("--externs="))) .add("--language_in=" + config.getLanguage().getName()) .addAll(standardFlags) .build(); PrintStream nullStream = new PrintStream(ByteStreams.nullOutputStream()); args = compilerFlags.toArray(new String[compilerFlags.size()]); Logger log = Logger.getLogger(Main.class.getPackage().getName()); log.setLevel(Level.WARNING); log.addHandler( new Handler() { @Override public void publish(LogRecord record) { System.err.printf( "[%s][%s] %s\n", record.getLevel(), record.getLoggerName(), record.getMessage()); } @Override public void flush() {} @Override public void close() {} }); Main main = new Main(args, nullStream, System.err, config); main.runCompiler(); }
public void testNoAdminHostname() throws Exception { configFile.setFileContents("gsa.hostname=feedhost\n"); config.load(configFile); assertEquals(config.getGsaHostname(), config.getGsaAdminHostname()); }
/** * Verifies that properties are overridden when multiple property files are loaded. * * @throws Exception */ public void testConfigFileOverriding() throws Exception { Config config = Config.load(new ConfigRef(), new ConfigRef("config2.properties")); String pv = config.getString("props.simple.propB"); assert "val2-overridden".equals(pv); }
/** * Tests variable interpolation across a config file boundary. We want to be able to put a * variable encountered in a previously loaded config file into a config file loaded subsequently! * * @throws Exception */ public void testIntraConfigFileVariableInterpolation() throws Exception { Config config = Config.load(new ConfigRef(), new ConfigRef("config2.properties")); String pv = config.getString("props.simple.propA"); String iipv = config.getString("props.intrainterpolated.propA"); assert iipv != null && iipv.equals(pv); }
@Test public void testGetTransformPipelineSpecEmpty() throws Exception { configFile.setFileContents("metadata.transform.pipeline=\n"); config.load(configFile); assertEquals(Collections.emptyList(), config.getMetadataTransformPipelineSpec()); }
@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 testPropertiesParseColon2() throws Exception { configFile.setFileContents(" gsa.hostname=not_used\n" + " Truth :Beauty"); config.load(configFile); assertEquals("Beauty", config.getValue("Truth")); }
@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")); }