View Javadoc

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