private void assertXMLFilesMatch(String label, IFile testFile, String expectedFileLocation)
     throws Exception {
   Reader testReader = null;
   Reader expectedReader = null;
   try {
     testReader = new InputStreamReader(testFile.getContents());
     expectedReader =
         new InputStreamReader(
             CreateSwitchYardProjectTest.class
                 .getClassLoader()
                 .getResourceAsStream(expectedFileLocation));
     Diff diff = XMLUnit.compareXML(testReader, expectedReader);
     assertTrue(label + ": " + diff.toString(), diff.identical());
   } finally {
     if (testReader != null) {
       try {
         testReader.close();
       } catch (Exception e) {
         // for codestyle check
         e.fillInStackTrace();
       }
       testReader = null;
     }
     if (expectedReader != null) {
       try {
         expectedReader.close();
       } catch (Exception e) {
         // for codestyle check
         e.fillInStackTrace();
       }
       expectedReader = null;
     }
   }
 }
  @Test
  public void testAudioMD_noMD5() throws Exception {

    Fits fits = new Fits();

    // First generate the FITS output
    File input = new File("testfiles/test.wav");
    FitsOutput fitsOut = fits.examine(input);

    XMLOutputter serializer = new XMLOutputter(Format.getPrettyFormat());
    String actualXmlStr = serializer.outputString(fitsOut.getFitsXml());

    // Read in the expected XML file
    Scanner scan = new Scanner(new File("testfiles/output/FITS_test_wav_NO_MD5.xml"));
    String expectedXmlStr = scan.useDelimiter("\\Z").next();
    scan.close();

    // Set up XMLUnit
    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setNormalizeWhitespace(true);

    Diff diff = new Diff(expectedXmlStr, actualXmlStr);

    // Initialize attributes or elements to ignore for difference checking
    diff.overrideDifferenceListener(
        new IgnoreNamedElementsDifferenceListener(
            "version",
            "toolversion",
            "dateModified",
            "fslastmodified",
            "lastmodified",
            "startDate",
            "startTime",
            "timestamp",
            "fitsExecutionTime",
            "executionTime",
            "filepath",
            "location"));

    DetailedDiff detailedDiff = new DetailedDiff(diff);

    // Display any Differences
    List<Difference> diffs = detailedDiff.getAllDifferences();
    if (!diff.identical()) {
      StringBuffer differenceDescription = new StringBuffer();
      differenceDescription.append(diffs.size()).append(" differences");

      System.out.println(differenceDescription.toString());
      for (Difference difference : diffs) {
        System.out.println(difference.toString());
      }
    }

    assertTrue("Differences in XML", diff.identical());
  }
 @Test
 public void testWriteComplete() throws Exception {
   String old_xml = new StringPuller().pull(COMPLETE_XML, getClass());
   SwitchYardModel switchyard = _puller.pull(new StringReader(old_xml));
   String new_xml = switchyard.toString();
   XMLUnit.setIgnoreWhitespace(true);
   Diff diff = XMLUnit.compareXML(old_xml, new_xml);
   Assert.assertTrue(diff.toString(), diff.identical());
 }
  public static void assertAsExpected(String documentString, String expectedFileLocation)
      throws IOException, SAXException {
    File expectedReponseFile = new File(expectedFileLocation);
    String expectedResponseAsString = FileUtils.readFileToString(expectedReponseFile);

    // Use XML Unit to compare these files
    Diff myDiff = new Diff(documentString, expectedResponseAsString);
    Assert.assertTrue("XML identical " + myDiff.toString(), myDiff.identical());
  }
  public void testEncode_WithAllAttributes() throws Exception {
    TViewRoot root = new TViewRoot();
    root.addScript(THtmlInputCommaText.class.getName(), new JavaScriptContext());
    htmlInputCommaText.getAttributes().put("accesskey", "a");
    htmlInputCommaText.getAttributes().put("alt", "b");
    htmlInputCommaText.getAttributes().put("dir", "c");
    htmlInputCommaText.getAttributes().put("disabled", Boolean.TRUE);
    htmlInputCommaText.getAttributes().put("lang", "e");
    htmlInputCommaText.getAttributes().put("maxlength", new Integer(5));
    htmlInputCommaText.getAttributes().put("onblur", "g");
    htmlInputCommaText.getAttributes().put("onchange", "h");
    htmlInputCommaText.getAttributes().put("onclick", "i");
    htmlInputCommaText.getAttributes().put("ondblclick", "j");
    htmlInputCommaText.getAttributes().put("onfocus", "k");
    htmlInputCommaText.getAttributes().put("onkeydown", "l");
    htmlInputCommaText.getAttributes().put("onkeypress", "m");
    htmlInputCommaText.getAttributes().put("onkeyup", "n");
    htmlInputCommaText.getAttributes().put("onmousedown", "o");
    htmlInputCommaText.getAttributes().put("onmousemove", "p");
    htmlInputCommaText.getAttributes().put("onmouseout", "q");
    htmlInputCommaText.getAttributes().put("onmouseover", "r");
    htmlInputCommaText.getAttributes().put("onmouseup", "s");
    htmlInputCommaText.getAttributes().put("onselect", "t");
    htmlInputCommaText.getAttributes().put("readonly", Boolean.TRUE);
    htmlInputCommaText.getAttributes().put("size", new Integer(2));
    htmlInputCommaText.getAttributes().put("style", "w");
    htmlInputCommaText.getAttributes().put("styleClass", "u");
    htmlInputCommaText.getAttributes().put("tabindex", "x");
    htmlInputCommaText.getAttributes().put("title", "y");
    htmlInputCommaText.getAttributes().put("id", "A");
    htmlInputCommaText.getAttributes().put("value", "123");
    htmlInputCommaText.getAttributes().put("fraction", "4");

    MockFacesContext context = getFacesContext();
    root.setLocale(Locale.JAPAN);
    context.setViewRoot(root);

    encodeByRenderer(renderer, context, htmlInputCommaText);

    Diff diff =
        new Diff(
            "<input type=\"text\" id=\"A\" name=\"A\" value=\"123\" disabled=\"disabled\" "
                + "onfocus=\"k;Teeda.THtmlInputCommaText.removeComma(this, ',');this.select();\" "
                + "onblur=\"g;Teeda.THtmlInputCommaText.convertByKey(this);Teeda.THtmlInputCommaText.addComma(this, 4, ',', '.');\" "
                + "onkeydown=\"l;return Teeda.THtmlInputCommaText.keycheckForNumber(event, this, 4, '.');\" "
                + "onkeypress=\"m;return Teeda.THtmlInputCommaText.keycheckForNumber(event, this, 4, '.');\" onkeyup=\"n;Teeda.THtmlInputCommaText.convertByKey(this);\" "
                + "style=\"w;ime-mode:disabled;\" title=\"y\" onchange=\"h\" dir=\"c\" readonly=\"readonly\" "
                + "class=\"u\" accesskey=\"a\" ondblclick=\"j\" size=\"2\" onmouseover=\"r\" "
                + "tabindex=\"x\" maxlength=\"5\" lang=\"e\" onclick=\"i\" alt=\"b\" "
                + "onmouseout=\"q\" onmousedown=\"o\" onselect=\"t\" onmouseup=\"s\" "
                + "onmousemove=\"p\" />",
            getResponseText());

    assertEquals(diff.toString(), true, diff.identical());
  }
  public void test_should_parse_2nd_document()
      throws IOException, ParserConfigurationException, SAXException {

    final XMLSerializer xmlSerializer = getXmlSerializer();

    String fixture = toString("net/sf/json/xml/idml_document2.idms");

    JSON json = xmlSerializer.read(fixture);
    final String result = xmlSerializer.write(json);

    final Diff diff = compareXML(stripWhiteSpace(fixture), stripWhiteSpace(result));

    assertTrue("Found difference: " + diff.toString(), diff.identical());
  }
Exemple #7
0
  /*
   * (non-Javadoc)
   *
   * @see org.exist.xquery.BasicFunction#eval(org.exist.xquery.value.Sequence[],
   *      org.exist.xquery.value.Sequence)
   */
  public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {

    if (context.getProfiler().isEnabled()) {
      context.getProfiler().start(this);
      context
          .getProfiler()
          .message(
              this,
              Profiler.DEPENDENCIES,
              "DEPENDENCIES",
              Dependency.getDependenciesName(this.getDependencies()));
      if (contextSequence != null)
        context
            .getProfiler()
            .message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
      if (contextItem != null)
        context
            .getProfiler()
            .message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
    }

    Expression arg1 = getArgument(0);
    Sequence s1 = arg1.eval(contextSequence, contextItem);

    Expression arg2 = getArgument(1);
    context.pushDocumentContext();
    Sequence s2 = arg2.eval(contextSequence, contextItem);
    context.popDocumentContext();

    if (s1.isEmpty()) {
      return BooleanValue.valueOf(s2.isEmpty());
    } else if (s2.isEmpty()) {
      return BooleanValue.valueOf(s1.isEmpty());
    }

    Sequence result = null;
    StringBuffer v1 = new StringBuffer();
    StringBuffer v2 = new StringBuffer();
    try {
      if (s1.hasMany()) {
        for (int i = 0; i < s1.getItemCount(); i++) {
          v1.append(serialize((NodeValue) s1.itemAt(i)));
        }
      } else {
        v1.append(serialize((NodeValue) s1.itemAt(0)));
      }
      if (s2.hasMany()) {
        for (int i = 0; i < s2.getItemCount(); i++) {
          v2.append(serialize((NodeValue) s2.itemAt(i)));
        }
      } else {
        v2.append(serialize((NodeValue) s2.itemAt(0)));
      }
      Diff d = new Diff(v1.toString(), v2.toString());
      boolean identical = d.identical();
      if (!identical) {
        logger.warn("Diff result: " + d.toString());
      }
      result = new BooleanValue(identical);
    } catch (Exception e) {
      throw new XPathException(
          this,
          "An exception occurred while serializing node " + "for comparison: " + e.getMessage(),
          e);
    }

    if (context.getProfiler().isEnabled()) context.getProfiler().end(this, "", result);

    return result;
  }