public void testObjectToContentHandler() throws Exception {
    SAXDocumentBuilder builder = new SAXDocumentBuilder();
    xmlMarshaller.marshal(getWriteControlObject(), builder);

    log("**testObjectToXMLDocument**");
    log("Expected:");
    log(getWriteControlDocument());
    log("\nActual:");
    log(builder.getDocument());

    this.assertXMLIdentical(this.getWriteControlDocument(), builder.getDocument());
  }
コード例 #2
0
  public void testObjectToContentHandler() throws Exception {
    SAXDocumentBuilder builder = new SAXDocumentBuilder();
    Object objectToWrite = getWriteControlObject();
    XMLDescriptor desc = null;
    if (objectToWrite instanceof XMLRoot) {
      desc =
          (XMLDescriptor)
              xmlContext
                  .getSession(0)
                  .getProject()
                  .getDescriptor(((XMLRoot) objectToWrite).getObject().getClass());
    } else {
      desc =
          (XMLDescriptor)
              xmlContext.getSession(0).getProject().getDescriptor(objectToWrite.getClass());
    }
    int sizeBefore = getNamespaceResolverSize(desc);
    jaxbMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/xml");

    try {
      jaxbMarshaller.marshal(objectToWrite, builder);
    } catch (Exception e) {
      assertMarshalException(e);
      return;
    }
    if (expectsMarshalException) {
      fail("An exception should have occurred but didn't.");
      return;
    }

    int sizeAfter = getNamespaceResolverSize(desc);

    assertEquals(sizeBefore, sizeAfter);

    Document controlDocument = getWriteControlDocument();
    Document testDocument = builder.getDocument();

    log("**testObjectToContentHandler**");
    log("Expected:");
    log(controlDocument);
    log("\nActual:");
    log(testDocument);

    // Diff diff = new Diff(controlDocument, testDocument);
    // this.assertXMLEqual(diff, true);
    assertXMLIdentical(controlDocument, testDocument);
  }
  public void testObjectToContentHandler() throws Exception {
    SAXDocumentBuilder builder = new SAXDocumentBuilder();
    xmlMarshaller.marshal(getWriteControlObject(), builder);

    Document controlDocument = getWriteControlDocument();
    Document testDocument = builder.getDocument();

    log("**testObjectToContentHandler**");
    log("Expected:");
    log(controlDocument);
    log("\nActual:");
    log(testDocument);

    // for the purpose of these tests, order is not important
    // - a successful test will result in the same number of
    // address-id elements being written out
    NodeList controlIds = controlDocument.getElementsByTagName("address-id");
    NodeList testIds = testDocument.getElementsByTagName("address-id");
    assertTrue(controlIds.getLength() == testIds.getLength());
  }