Exemplo n.º 1
0
  public void close(boolean store_output)
      throws IllegalArgumentException, IllegalStateException, IOException {
    if (closed) return;
    closed = true;

    started_pw.close();
    all_csv_pw.close();

    writeTestSuiteEnd();
    writeTally();
    main_serial.endTag(null, "testsuites");
    main_serial.endDocument();

    main_serial.flush();
    out.close();

    // @see PhpUnitReader#readTally
    {
      FileWriter fw = new FileWriter(new File(dir.getAbsolutePath() + "/tally.xml"));
      main_serial.setOutput(fw);
      writeTally(); // write again - this file is smaller and faster to read
      main_serial.flush();
      fw.close();
    }
    //

    // do this after finishing phpunit.xml since that's more important than alphabetizing text file
    // lists
    for (StatusListEntry e : status_list_map.values()) e.close();

    if (!store_output) output_by_name = null;
  } // end public void close
Exemplo n.º 2
0
  public void generateXmlListOfForms(PrintWriter output, CallingContext cc)
      throws IOException, ODKDatastoreException {
    Document d = new Document();
    d.setStandalone(true);
    d.setEncoding(HtmlConsts.UTF8_ENCODE);
    Element e = d.createElement(XML_TAG_NAMESPACE, XFormsTableConsts.XFORMS_TAG);
    e.setPrefix(null, XML_TAG_NAMESPACE);
    d.addChild(0, Node.ELEMENT, e);
    int idx = 0;
    e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);

    // build XML table of form information
    for (IForm form : forms) {
      if (!form.getDownloadEnabled()) continue;

      idx = generateFormXmlEntry(d, e, idx, form, cc);
    }

    KXmlSerializer serializer = new KXmlSerializer();
    serializer.setOutput(output);
    // setting the response content type emits the xml header.
    // just write the body here...
    d.writeChildren(serializer);
    serializer.flush();
  }
  private static void writeSubmissionManifest(
      EncryptedFormInformation formInfo, File submissionXml, List<File> mediaFiles)
      throws EncryptionException {

    Document d = new Document();
    d.setStandalone(true);
    d.setEncoding(UTF_8);
    Element e = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, DATA);
    e.setPrefix(null, XML_ENCRYPTED_TAG_NAMESPACE);
    e.setAttribute(null, ID, formInfo.formId);
    if (formInfo.formVersion != null) {
      e.setAttribute(null, VERSION, formInfo.formVersion);
    }
    e.setAttribute(null, ENCRYPTED, "yes");
    d.addChild(0, Node.ELEMENT, e);

    int idx = 0;
    Element c;
    c = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, BASE64_ENCRYPTED_KEY);
    c.addChild(0, Node.TEXT, formInfo.base64RsaEncryptedSymmetricKey);
    e.addChild(idx++, Node.ELEMENT, c);

    c = d.createElement(XML_OPENROSA_NAMESPACE, META);
    c.setPrefix("orx", XML_OPENROSA_NAMESPACE);
    {
      Element instanceTag = d.createElement(XML_OPENROSA_NAMESPACE, INSTANCE_ID);
      instanceTag.addChild(0, Node.TEXT, formInfo.instanceMetadata.instanceId);
      c.addChild(0, Node.ELEMENT, instanceTag);
    }
    e.addChild(idx++, Node.ELEMENT, c);
    e.addChild(idx++, Node.IGNORABLE_WHITESPACE, NEW_LINE);

    if (mediaFiles != null) {
      for (File file : mediaFiles) {
        c = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, MEDIA);
        Element fileTag = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, FILE);
        fileTag.addChild(0, Node.TEXT, file.getName() + ".enc");
        c.addChild(0, Node.ELEMENT, fileTag);
        e.addChild(idx++, Node.ELEMENT, c);
        e.addChild(idx++, Node.IGNORABLE_WHITESPACE, NEW_LINE);
      }
    }

    c = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, ENCRYPTED_XML_FILE);
    c.addChild(0, Node.TEXT, submissionXml.getName() + ".enc");
    e.addChild(idx++, Node.ELEMENT, c);

    c = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, BASE64_ENCRYPTED_ELEMENT_SIGNATURE);
    c.addChild(0, Node.TEXT, formInfo.getBase64EncryptedElementSignature());
    e.addChild(idx++, Node.ELEMENT, c);

    FileOutputStream fout = null;
    OutputStreamWriter writer = null;
    try {
      fout = new FileOutputStream(submissionXml);
      writer = new OutputStreamWriter(fout, UTF_8);

      KXmlSerializer serializer = new KXmlSerializer();
      serializer.setOutput(writer);
      // setting the response content type emits the xml header.
      // just write the body here...
      d.writeChildren(serializer);
      serializer.flush();
      writer.flush();
      fout.getChannel().force(true);
      writer.close();
    } catch (Exception ex) {
      ex.printStackTrace();
      String msg =
          "Error writing submission.xml for encrypted submission: "
              + submissionXml.getParentFile().getName();
      Log.e(t, msg);
      throw new EncryptionException(msg, ex);
    } finally {
      IOUtils.closeQuietly(writer);
      IOUtils.closeQuietly(fout);
    }
  }
Exemplo n.º 4
0
  // @see PHPUnit/Util/Log/JUnit.php#startTestSuite
  public void writeResult(boolean store_output, PhpUnitTestResult result)
      throws IllegalArgumentException, IllegalStateException, IOException {
    if (closed)
      throw new IllegalStateException("can not write to closed PhpUnitResultWriter. it is closed.");

    if (result.ini != null && (this.ini == null || !this.ini.equals(result.ini)))
      this.ini = result.ini;
    test_count++;

    final String test_name = result.getName();
    status_list_map.get(result.status).write(test_name, result);

    if ((store_output
            || (result.status == EPhpUnitTestStatus.FAILURE
                || result.status == EPhpUnitTestStatus.ERROR
                || result.status == EPhpUnitTestStatus.CRASH))
        && StringUtil.isNotEmpty(result.output)) {
      // store crash output too: for exit code and status
      output_by_name.put(test_name, result.output);
    }

    // write file header
    String test_suite_name =
        result.test_case.getPhpUnitDist() != null
                && result.test_case.getPhpUnitDist().getPath() != null
            ? result.test_case.getPhpUnitDist().getPath().getPath()
            : null;
    if (is_first_result) {
      main_serial.startDocument("utf-8", null);
      main_serial.setPrefix("pftt", "pftt");
      main_serial.startTag(null, "testsuites");
      writeTestSuiteStart(test_suite_name);

      is_first_result = false;
    } else if (test_suite_name != null
        && last_test_suite_name != null
        && !test_suite_name.equals(last_test_suite_name)) {
      writeTestSuiteEnd();
      writeTestSuiteStart(test_suite_name);
    }
    last_test_suite_name = test_suite_name;
    //

    // write result itself
    result.serial(main_serial);

    //
    if ((result.code_coverage != null || result.extra != null)
        && PhpUnitTestResult.shouldStoreAllInfo(result.status)) {
      // store this data in a separate file
      File f =
          new File(
              dir,
              result
                      .getName()
                      .replace("::", "_")
                      .replace("(", "_")
                      .replace(")", "")
                      .replace(".php", "")
                  + ".xml");
      f.getParentFile().mkdirs(); // ensure directory exists
      FileWriter fw = new FileWriter(f);
      extra_serial.setOutput(fw);
      extra_serial.startDocument("utf-8", Boolean.TRUE);
      extra_serial.startTag("pftt", "phpUnitTestResult");
      if (result.extra != null) result.extra.serial(extra_serial);
      if (result.code_coverage != null) result.code_coverage.serial(extra_serial);
      extra_serial.endTag("pftt", "phpUnitTestResult");
      extra_serial.endDocument();
      extra_serial.flush();
      fw.close();
    }
    //

    // store name, status and run-time in CSV format
    all_csv_pw.print("'");
    all_csv_pw.print(test_name);
    all_csv_pw.print("','");
    all_csv_pw.print(result.status);
    all_csv_pw.print("',");
    all_csv_pw.print(result.run_time_micros);
    all_csv_pw.println();
  } // end public void writeResult