View Javadoc

1   package org.kuali.ole.myaccount.renewal;
2   
3   import org.junit.Test;
4   import org.kuali.ole.myaccount.renewal.bo.OlePatronLoanDocuments;
5   
6   import javax.xml.bind.JAXBContext;
7   import javax.xml.bind.Marshaller;
8   import javax.xml.bind.Unmarshaller;
9   import java.io.StringReader;
10  import java.io.StringWriter;
11  
12  import static junit.framework.Assert.assertEquals;
13  
14  /**
15   * Created with IntelliJ IDEA.
16   * User: ?
17   * Date: 5/25/12
18   * Time: 3:08 PM
19   * To change this template use File | Settings | File Templates.
20   */
21  
22  
23  public class OlePatronLoanDocumentJaxb_UT {
24  
25  
26  
27      @Test
28      public void testMarshalAndUnmarshall() throws Exception {
29          JAXBContext jaxb = JAXBContext.newInstance(OlePatronLoanDocuments.class);
30          OlePatronLoanDocuments patronLoanDocuments = OlePatronLoanDocumentHelper.create();
31  
32          Marshaller marshaller = jaxb.createMarshaller();
33          StringWriter writer = new StringWriter();
34          marshaller.marshal(patronLoanDocuments, writer);
35          System.out.println("Marshalled Patron is: " + writer.toString());
36  
37          Unmarshaller unmarshaller = jaxb.createUnmarshaller();
38          OlePatronLoanDocuments unmarshalled = (OlePatronLoanDocuments)unmarshaller.unmarshal(new StringReader(writer.toString()));
39          assertEquals(patronLoanDocuments.getOlePatronLoanDocuments().get(0).getItemBarcode(), unmarshalled.getOlePatronLoanDocuments().get(0).getItemBarcode());
40          assertEquals(patronLoanDocuments.getOlePatronLoanDocuments().get(0).getTitle(), unmarshalled.getOlePatronLoanDocuments().get(0).getTitle());
41          assertEquals(patronLoanDocuments.getOlePatronLoanDocuments().get(0).getAuthor(), unmarshalled.getOlePatronLoanDocuments().get(0).getAuthor());
42          assertEquals(patronLoanDocuments.getOlePatronLoanDocuments().get(0).getCallNumber(), unmarshalled.getOlePatronLoanDocuments().get(0).getCallNumber());
43          assertEquals(patronLoanDocuments.getOlePatronLoanDocuments().get(0).getLocation(), unmarshalled.getOlePatronLoanDocuments().get(0).getLocation());
44  
45  
46      }
47  }