Esempio n. 1
0
  @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());
  }
Esempio n. 2
0
 @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"));
 }
Esempio n. 3
0
  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);
    }
  }
Esempio n. 4
0
  /**
   * 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.";
  }
Esempio n. 5
0
  public void testLoadAll() throws Exception {
    Config config = Config.load(new ConfigRef(true));

    for (String key : keys) {
      assert config.getProperty(key) != null;
    }
  }
Esempio n. 6
0
 @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  "));
 }
Esempio n. 7
0
 @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"));
 }
Esempio n. 8
0
 @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();
 }
Esempio n. 9
0
 /**
  * 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);
   }
 }
Esempio n. 10
0
 /**
  * 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);
     }
   }
 }
Esempio n. 11
0
 @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"));
 }
Esempio n. 12
0
 @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();
 }
Esempio n. 13
0
  /**
   * 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";
    }
  }
Esempio n. 14
0
  /**
   * 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;
    }
  }
Esempio n. 15
0
  /**
   * 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;
    }
  }
Esempio n. 16
0
 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);
   }
 }
Esempio n. 17
0
  @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);
              }
            });
  }
Esempio n. 19
0
  // 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());
  }
Esempio n. 20
0
  /**
   * 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;
    }
  }
Esempio n. 21
0
  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;
  }
Esempio n. 22
0
  /**
   * 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!";
      }
    }
  }
Esempio n. 23
0
  @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();
  }
Esempio n. 24
0
 public void testNoAdminHostname() throws Exception {
   configFile.setFileContents("gsa.hostname=feedhost\n");
   config.load(configFile);
   assertEquals(config.getGsaHostname(), config.getGsaAdminHostname());
 }
Esempio n. 25
0
 /**
  * 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);
 }
Esempio n. 26
0
 /**
  * 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);
 }
Esempio n. 27
0
 @Test
 public void testGetTransformPipelineSpecEmpty() throws Exception {
   configFile.setFileContents("metadata.transform.pipeline=\n");
   config.load(configFile);
   assertEquals(Collections.emptyList(), config.getMetadataTransformPipelineSpec());
 }
Esempio n. 28
0
 @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"));
 }
Esempio n. 29
0
 @Test
 public void testPropertiesParseColon2() throws Exception {
   configFile.setFileContents(" gsa.hostname=not_used\n" + " Truth                    :Beauty");
   config.load(configFile);
   assertEquals("Beauty", config.getValue("Truth"));
 }
Esempio n. 30
0
 @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"));
 }