/**
   * Tests XmlAnyObjectMapping configuration via eclipselink-oxm.xml. Here a marshal operation is
   * performed. In this case, the 'any' is marked write-only.
   *
   * <p>Positive test.
   */
  public void testAnyObjectWriteOnlyMarshal() {
    // setup control document
    String src = PATH + "write-only-employee.xml";
    Document testDoc = parser.newDocument();
    Document ctrlDoc = parser.newDocument();
    try {
      ctrlDoc = getControlDocument(src);
    } catch (Exception e) {
      e.printStackTrace();
      fail("An unexpected exception occurred loading control document [" + src + "].");
    }
    JAXBContext jCtx = null;
    try {
      jCtx =
          createContext(
              new Class[] {Employee.class}, CONTEXT_PATH, PATH + "write-only-employee-oxm.xml");
    } catch (JAXBException e1) {
      fail("JAXBContext creation failed: " + e1.getMessage());
    }

    // test marshal
    Employee ctrlEmp = getControlObject();
    Marshaller marshaller = jCtx.createMarshaller();
    try {
      marshaller.marshal(ctrlEmp, testDoc);
      // marshaller.marshal(ctrlEmp, System.out);
      assertTrue("Document comparison failed unxepectedly: ", compareDocuments(ctrlDoc, testDoc));
    } catch (JAXBException e) {
      e.printStackTrace();
      fail("Marshal operation failed.");
    }
  }
 private void marshal(JAXBContext jCtx, String inputType, Object foo, String instanceDoc) {
   // setup control document
   Document testDoc = parser.newDocument();
   Document ctrlDoc = parser.newDocument();
   try {
     ctrlDoc = getControlDocument(instanceDoc);
   } catch (Exception e) {
     e.printStackTrace();
     fail("An unexpected exception occurred loading control document [" + instanceDoc + "].");
   }
   // marshal
   try {
     jCtx.createMarshaller().marshal(foo, testDoc);
     // jCtx.createMarshaller().marshal(foo, System.out);
     // System.out.println("\n");
   } catch (JAXBException e) {
     e.printStackTrace();
     fail("An unexpected exception occurred during marshal [" + inputType + "]");
   }
   assertTrue(
       "Marshal [" + inputType + "] failed - documents are not equal: ",
       compareDocuments(ctrlDoc, testDoc));
 }
Пример #3
0
 public Marshaller createMarshaller() throws JAXBException {
   return jaxbContext.createMarshaller();
 }