You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by jo...@apache.org on 2004/07/08 09:04:12 UTC

cvs commit: ws-jaxme/src/jaxme/org/apache/ws/jaxme/junit MarshallerTest.java

jochen      2004/07/08 00:04:12

  Modified:    src/jaxme/org/apache/ws/jaxme/junit MarshallerTest.java
  Log:
  Added test cases for unmarshalling from a TRAX Source.
  
  Revision  Changes    Path
  1.10      +24 -5     ws-jaxme/src/jaxme/org/apache/ws/jaxme/junit/MarshallerTest.java
  
  Index: MarshallerTest.java
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/junit/MarshallerTest.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- MarshallerTest.java	16 Feb 2004 23:39:54 -0000	1.9
  +++ MarshallerTest.java	8 Jul 2004 07:04:12 -0000	1.10
  @@ -32,6 +32,8 @@
   import javax.xml.parsers.ParserConfigurationException;
   import javax.xml.parsers.SAXParser;
   import javax.xml.parsers.SAXParserFactory;
  +import javax.xml.transform.stream.StreamResult;
  +import javax.xml.transform.stream.StreamSource;
   
   import org.apache.ws.jaxme.JMMarshaller;
   import org.apache.ws.jaxme.JMUnmarshaller;
  @@ -261,18 +263,24 @@
       unmarshaller.init(jmUnmarshaller);
       xr.setContentHandler(unmarshaller);
       String s = getAllSimpleTypesElementString();
  +
       StringReader sr = new StringReader(s);
       xr.parse(new InputSource(sr));
       AllSimpleTypes result = (AllSimpleTypes) unmarshaller.getResult();
       verifyAllSimpleTypesElement(result);
     }
   
  +  /** <p>Tests, whether complex elements can be marshalled.</p>
  +   */
     public void testUnmarshalComplexElements() throws Exception {
       JAXBContext myFactory = getFactory();
       Unmarshaller unmarshaller = myFactory.createUnmarshaller();
  -    StringReader sr = new StringReader(getAllTypesElementString());
  +    String s = getAllTypesElementString();
  +    StringReader sr = new StringReader(s);
       AllTypesElement result = (AllTypesElement) unmarshaller.unmarshal(new InputSource(sr));
       verifyAllTypesElement(result);
  +    result = (AllTypesElement) myFactory.createUnmarshaller().unmarshal(new StreamSource(new StringReader(s)));
  +    verifyAllTypesElement(result);
     }
   
     public void testMarshalSimpleElements() throws Exception {
  @@ -335,16 +343,27 @@
         return sw.toString();
     }
   
  +  /** <p>Tests, whether elements with simple content can be marshalled.</p>
  +   */
     public void testMarshalSimpleContent() throws Exception {
         String expect = "<ex:Author rating=\"2\" xmlns:ex=\"http://ws.apache.org/jaxme/test/misc/types\">This is a test.</ex:Author>";
         String got = getMarshalledAuthor();
         assertStringEquals(expect, got);
     }
   
  +  private void verifyUnmarshalledAuthor(Author pAuthor) {
  +    assertEquals(2, pAuthor.getRating());
  +    assertEquals("This is a test.", pAuthor.getValue());
  +  }
  +
  +  /** <p>Tests, whether elements with simple content can be unmarshalled.</p>
  +   */
     public void testUnmarshalSimpleContent() throws Exception {
  -      Author author = (Author) getFactory().createUnmarshaller().unmarshal(new InputSource(new StringReader(getMarshalledAuthor())));
  -      assertEquals(2, author.getRating());
  -      assertEquals("This is a test.", author.getValue());
  +  	  String s = getMarshalledAuthor();
  +      Author author = (Author) getFactory().createUnmarshaller().unmarshal(new InputSource(new StringReader(s)));
  +      verifyUnmarshalledAuthor(author);
  +      author = (Author) getFactory().createUnmarshaller().unmarshal(new StreamSource(new StringReader(s)));
  +      verifyUnmarshalledAuthor(author);
     }
   
     /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org