コード例 #1
0
ファイル: LdpTest.java プロジェクト: ja-fra/ldp-testsuite
  /**
   * Builds a model from a turtle representation in a file
   *
   * @param path
   */
  protected Model readModel(String path) {
    Model model = null;
    if (path != null) {
      model = ModelFactory.createDefaultModel();
      InputStream inputStream = getClass().getClassLoader().getResourceAsStream(path);

      String fakeUri = "http://w3c.github.io/ldp-testsuite/fakesubject";
      // Even though null relative URIs are used in the resource representation file,
      // the resulting model doesn't keep them intact. They are changed to "file://..." if
      // an empty string is passed as base to this method.
      model.read(inputStream, fakeUri, "TURTLE");

      // At this point, the model should contain a resource named
      // "http://w3c.github.io/ldp-testsuite/fakesubject" if
      // there was a null relative URI in the resource representation
      // file.
      Resource subject = model.getResource(fakeUri);
      if (subject != null) {
        ResourceUtils.renameResource(subject, "");
      }

      try {
        inputStream.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return model;
  }
コード例 #2
0
ファイル: LdpTest.java プロジェクト: ja-fra/ldp-testsuite
  /**
   * Initialization of generic resource model. This will run only once at the beginning of the test
   * suite, so postModel static field will be assigned once too.
   *
   * @param postTtl the resource with Turtle content to use for POST requests
   * @param httpLogging whether to log HTTP request and response details on errors
   */
  @BeforeSuite(alwaysRun = true)
  @Parameters({"output", "postTtl", "httpLogging", "skipLogging"})
  public void setup(
      String outputDir,
      @Optional String postTtl,
      @Optional String httpLogging,
      @Optional String skipLogging)
      throws IOException {
    postModel = readModel(postTtl);

    File dir = new File(outputDir);
    // FileUtils.deleteDirectory(dir);
    dir.mkdirs();

    if ("true".equals(httpLogging)) {
      File file = new File(dir, HTTP_LOG_FILENAME);
      try {
        httpLog = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
        httpLog.println(String.format("LDP Test Suite: HTTP Log (%s)", df.format(new Date())));
        httpLog.println("---------------------------------------------------");
      } catch (IOException e) {
        System.err.println(
            String.format("WARNING: Error creating %s for detailed errors", HTTP_LOG_FILENAME));
        e.printStackTrace();
      }
    }

    if ("true".equals(httpLogging)) {
      File file = new File(dir, SKIPPED_LOG_FILENAME);
      try {
        skipLog = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
        skipLog.println(
            String.format("LDP Test Suite: Skipped Tests Log (%s)", df.format(new Date())));
        skipLog.println("------------------------------------------------------------");
      } catch (IOException e) {
        System.err.println(
            String.format("WARNING: Error creating %s for detailed errors", SKIPPED_LOG_FILENAME));
        e.printStackTrace();
      }
    }
  }