001package org.kuali.ole.deliver;
002
003import org.apache.log4j.Logger;
004import org.junit.Test;
005import org.kuali.ole.deliver.bo.OlePatronLoanDocuments;
006import javax.xml.bind.JAXBContext;
007import javax.xml.bind.Marshaller;
008import javax.xml.bind.Unmarshaller;
009import java.io.StringReader;
010import java.io.StringWriter;
011
012import static junit.framework.Assert.assertEquals;
013
014/**
015 * Created with IntelliJ IDEA.
016 * User: ?
017 * Date: 5/25/12
018 * Time: 3:08 PM
019 * To change this template use File | Settings | File Templates.
020 */
021
022
023public class OlePatronLoanDocumentJaxb_UT {
024
025    private static final Logger LOG = Logger.getLogger(OlePatronLoanDocumentJaxb_UT.class);
026
027    @Test
028    public void testMarshalAndUnmarshall() throws Exception {
029        LOG.debug("Inside the testMarshalAndUnmarshall method");
030        JAXBContext jaxb = JAXBContext.newInstance(OlePatronLoanDocuments.class);
031        OlePatronLoanDocuments patronLoanDocuments = OlePatronLoanDocumentHelper.create();
032
033        Marshaller marshaller = jaxb.createMarshaller();
034        StringWriter writer = new StringWriter();
035        marshaller.marshal(patronLoanDocuments, writer);
036        LOG.info("Marshalled Patron is: " + writer.toString());
037        Unmarshaller unmarshaller = jaxb.createUnmarshaller();
038        OlePatronLoanDocuments unmarshalled = (OlePatronLoanDocuments)unmarshaller.unmarshal(new StringReader(writer.toString()));
039        assertEquals(patronLoanDocuments.getOlePatronLoanDocuments().get(0).getItemBarcode(), unmarshalled.getOlePatronLoanDocuments().get(0).getItemBarcode());
040        assertEquals(patronLoanDocuments.getOlePatronLoanDocuments().get(0).getTitle(), unmarshalled.getOlePatronLoanDocuments().get(0).getTitle());
041        assertEquals(patronLoanDocuments.getOlePatronLoanDocuments().get(0).getAuthor(), unmarshalled.getOlePatronLoanDocuments().get(0).getAuthor());
042        assertEquals(patronLoanDocuments.getOlePatronLoanDocuments().get(0).getCallNumber(), unmarshalled.getOlePatronLoanDocuments().get(0).getCallNumber());
043        assertEquals(patronLoanDocuments.getOlePatronLoanDocuments().get(0).getLocation(), unmarshalled.getOlePatronLoanDocuments().get(0).getLocation());
044
045
046    }
047}