コード例 #1
0
ファイル: ValidateCLI.java プロジェクト: wk-muenster/RDFUnit
  /**
   * main.
   *
   * @param args an array of {@link java.lang.String} objects.
   * @throws java.lang.Exception if any.
   */
  public static void main(String[] args) throws Exception {

    CommandLine commandLine = ValidateUtils.parseArguments(args);

    if (commandLine.hasOption("h")) {
      displayHelpAndExit();
    }

    String dataFolder = commandLine.getOptionValue("f", "../data/");

    if (!commandLine.hasOption('v')) { // explicitely do not use LOV
      RDFUnitUtils.fillSchemaServiceFromLOV();
    }
    // TODO hack until we fix this, configuration tries to laod schemas so they must be initialized
    // before
    RDFUnitUtils.fillSchemaServiceFromFile(dataFolder + "schemaDecl.csv");
    // RDFUnitUtils.fillSchemaServiceFromFile(configuration.getDataFolder() + "schemaDecl.csv");

    RDFUnitConfiguration configuration = null;
    try {
      configuration = ValidateUtils.getConfigurationFromArguments(commandLine);
    } catch (ParameterException e) {
      String message = e.getMessage();
      if (message != null) {
        displayHelpAndExit(message);
      } else {
        displayHelpAndExit();
      }
    }
    checkNotNull(configuration);

    if (!RDFUnitUtils.fileExists(configuration.getDataFolder())) {
      log.error("Path : " + configuration.getDataFolder() + " does not exists, use -f argument");
      System.exit(1);
    }

    RDFUnit rdfunit = new RDFUnit(configuration.getDataFolder());
    try {
      rdfunit.init();
    } catch (RDFReaderException e) {
      displayHelpAndExit("Cannot read patterns and/or pattern generators");
    }
    /*
    // Generates all tests from LOV
    for (Source s: SchemaService.getSourceListAll()) {
        s.setBaseCacheFolder("../data/tests/");
        File f = new File(s.getTestFile());
        if (!f.exists()) {
            List<TestCase> testsAuto = TestUtils.instantiateTestsFromAG(rdfunit.getAutoGenerators(), s);
            TestUtils.writeTestsToFile(testsAuto,  s.getTestFile());
        }
    }
    // */

    final TestSource dataset = configuration.getTestSource();
    /* </cliStuff> */

    TestGeneratorExecutor testGeneratorExecutor =
        new TestGeneratorExecutor(
            configuration.isAutoTestsEnabled(),
            configuration.isTestCacheEnabled(),
            configuration.isManualTestsEnabled());
    TestSuite testSuite =
        testGeneratorExecutor.generateTestSuite(
            configuration.getTestFolder(), dataset, rdfunit.getAutoGenerators());

    TestExecutor testExecutor =
        TestExecutorFactory.createTestExecutor(configuration.getTestCaseExecutionType());
    if (testExecutor == null) {
      displayHelpAndExit("Cannot initialize test executor. Exiting");
    }
    SimpleTestExecutorMonitor testExecutorMonitor = new SimpleTestExecutorMonitor();
    testExecutorMonitor.setExecutionType(configuration.getTestCaseExecutionType());
    checkNotNull(testExecutor);
    testExecutor.addTestExecutorMonitor(testExecutorMonitor);

    // warning, caches intermediate results
    testExecutor.execute(dataset, testSuite);

    // Write results to RDFWriter ()
    String filename =
        "../data/results/"
            + dataset.getPrefix()
            + "."
            + configuration.getTestCaseExecutionType().toString();

    ArrayList<RDFWriter> outputWriters = new ArrayList<>();
    for (SerializationFormat serializationFormat : configuration.getOutputFormats()) {
      outputWriters.add(
          RDFWriterFactory.createWriterFromFormat(
              filename, serializationFormat, configuration.getTestCaseExecutionType()));
    }

    RDFWriter resultWriter = new RDFMultipleWriter(outputWriters);
    try {
      resultWriter.write(testExecutorMonitor.getModel());
      log.info("Results stored in: " + filename + ".*");
    } catch (RDFWriterException e) {
      log.error("Cannot write tests to file: " + e.getMessage());
    }

    // Calculate coverage
    if (configuration.isCalculateCoverageEnabled()) {
      Model model = ModelFactory.createDefaultModel();
      PrefixNSService.setNSPrefixesInModel(model);
      for (TestCase ut : testSuite.getTestCases()) {
        model.add(ut.getUnitTestModel());
      }

      TestCoverageEvaluator tce = new TestCoverageEvaluator();
      tce.calculateCoverage(
          new QueryExecutionFactoryModel(model),
          dataset.getPrefix() + ".property.count",
          dataset.getPrefix() + ".class.count");
    }
  }
コード例 #2
0
ファイル: ValidateCLI.java プロジェクト: wk-muenster/RDFUnit
 private static void displayHelpAndExit() {
   HelpFormatter formatter = new HelpFormatter();
   formatter.printHelp("rdfunit", ValidateUtils.getCliOptions());
   System.exit(1);
 }