예제 #1
1
 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;
     }
   }
 }
예제 #2
0
 @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());
  }
 /**
  * Check is the source document is equal to the one produced by the method under test.
  *
  * @param message A message to print in case of failure.
  * @param expected The expected (source) document.
  * @param actual The actual (output) document.
  */
 private void assertEqual(String message, Document expected, Document actual) {
   expected.getDocumentElement().normalize();
   actual.getDocumentElement().normalize();
   // DIRTY HACK WARNING: we add the "xmlns:wi" attribute reported
   // by DOM, as expected, but not generated by the method under test,
   // otherwise the comparison would fail.
   actual.getDocumentElement().setAttribute(Constants.WI_PREFIX, Constants.WI_NS);
   Diff diff = new Diff(expected, actual);
   assertTrue(message + ", " + diff.toString(), diff.similar());
 }
  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 static void assertSimilarXml(String expectedXml, String xml) {
   XMLUnit.setIgnoreWhitespace(true);
   Diff diff;
   try {
     diff = XMLUnit.compareXML(xml, expectedXml);
   } catch (SAXException e) {
     throw new IllegalArgumentException("Could not run XML comparison", e);
   } catch (IOException e) {
     throw new IllegalArgumentException("Could not run XML comparison", e);
   }
   String message = "Diff: " + diff.toString() + CharUtils.LF + "XML: " + xml;
   assertTrue(message, diff.similar());
 }
예제 #7
0
  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());
  }
예제 #8
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;
  }
  private void runProjectTest(String projectName, boolean isWeb) throws Exception {
    ResolverConfiguration configuration = new ResolverConfiguration();
    IProject project =
        importProject("test-data/projects/" + projectName + "/pom.xml", configuration);
    waitForJobs();

    project.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
    waitForJobs();

    assertNoErrors(project);

    // make sure we get through an incremental build (SWITCHYARD-1108)
    project.touch(new NullProgressMonitor());
    project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
    waitForJobs();

    assertNoErrors(project);

    assertTrue(
        project
            .getFile("target/classes/META-INF/switchyard.xml")
            .isSynchronized(IResource.DEPTH_ZERO));
    assertTrue(project.getFile("target/classes/META-INF/switchyard.xml").isAccessible());

    assertTrue(!project.getFile("src/main/java/META-INF/MANIFEST.MF").exists());

    Reader sourceReader = null;
    Reader testReader = null;
    try {
      sourceReader =
          new InputStreamReader(
              project.getFile("target/classes/META-INF/switchyard.xml").getContents());
      testReader =
          new InputStreamReader(
              SwitchYardConfigurationTest.class
                  .getClassLoader()
                  .getResourceAsStream(
                      "test-data/validation/"
                          + projectName
                          + (isWeb ? "/WEB-INF/switchyard.xml" : "/META-INF/switchyard.xml")));
      XMLUnit.setIgnoreComments(true);
      XMLUnit.setIgnoreWhitespace(true);
      Diff diff = XMLUnit.compareXML(sourceReader, testReader);
      diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
      assertTrue(diff.toString(), diff.similar());
    } finally {
      if (sourceReader != null) {
        try {
          sourceReader.close();
        } catch (Exception e) {
          // for codestyle check
          e.fillInStackTrace();
        }
      }
      if (testReader != null) {
        try {
          testReader.close();
        } catch (Exception e) {
          // for codestyle check
          e.fillInStackTrace();
        }
      }
    }
  }
예제 #10
0
파일: TestUtils.java 프로젝트: velo/sonar
 public static void assertSimilarXml(String expectedXml, String xml) throws Exception {
   Diff diff = isSimilarXml(expectedXml, xml);
   String message = "Diff: " + diff.toString() + CharUtils.LF + "XML: " + xml;
   assertTrue(message, diff.similar());
 }