Ejemplo n.º 1
0
  /**
   * This test case builds a custom suite, containing a collection of smaller suites (one for each
   * file in src/parser-tests).
   */
  public static Test suite() throws Exception {
    TestSuite result = new TestSuite(HTMLPageParserTest.class.getName());

    Properties props = new Properties();
    props.load(new FileInputStream("src/parser-tests/parsers.properties"));

    Collection<String> parsers = new ArrayList<String>();
    for (String key : props.stringPropertyNames()) {
      Matcher matcher = PARSER_PATTERN.matcher(key);
      if (matcher.matches()) {
        parsers.add(matcher.group(1));
      }
    }

    for (String p : parsers) {
      String name = props.getProperty("parser." + p + ".class");
      Class<? extends PageParser> parserClass = Class.forName(name).asSubclass(PageParser.class);
      PageParser parser = parserClass.newInstance();

      String filesPath = props.getProperty("parser." + p + ".tests", "src/parser-tests");
      List<File> files = new ArrayList<File>(Arrays.asList(listParserTests(new File(filesPath))));
      Collections.sort(files);

      TestSuite suiteForParser = new TestSuite(name);
      for (File file : files) {
        TestSuite suiteForFile = new TestSuite(file.getName().replace('.', '_'));
        suiteForFile.addTest(new HTMLPageParserTest(parser, file, "testTitle"));
        suiteForFile.addTest(new HTMLPageParserTest(parser, file, "testBody"));
        suiteForFile.addTest(new HTMLPageParserTest(parser, file, "testHead"));
        suiteForFile.addTest(new HTMLPageParserTest(parser, file, "testFullPage"));
        suiteForFile.addTest(new HTMLPageParserTest(parser, file, "testProperties"));
        suiteForFile.addTest(new HTMLPageParserTest(parser, file, "testContentSanity"));
        suiteForParser.addTest(suiteForFile);
      }
      result.addTest(suiteForParser);
    }

    return result;
  }
Ejemplo n.º 2
0
 /**
  * Given a file that the preferences are supposedly stored in, this function will try to load the
  * preferences. If the preferences don't exist, or they are incomplete, this will also fill in the
  * missing values, and store the now complete preferences in the file location specified.
  *
  * @param prefFile
  * @throws Exception
  */
 public void init(File prefFile) throws IOException {
   this.prefFile = prefFile;
   if (prefFile.exists()) {
     Properties userProperties = new Properties();
     FileInputStream in = new FileInputStream(prefFile);
     userProperties.load(in);
     in.close();
     for (String key : userProperties.stringPropertyNames()) {
       String val = userProperties.getProperty(key);
       String value = getObject(val, ((Preference) prefs.get(key))).toString();
       Object ovalue = getObject(val, ((Preference) prefs.get(key)));
       Preference p1 = prefs.get(key);
       Preference p2;
       if (p1 != null) {
         p2 = new Preference(p1.name, value, p1.allowed, p1.description);
       } else {
         p2 = new Preference(key, val, Type.STRING, "");
       }
       p2.objectValue = ovalue;
       prefs.put(key, p2);
     }
   }
   save();
 }