1 package org.kuali.ole.patron.api;
2
3 import org.junit.Test;
4
5 import javax.xml.bind.JAXBContext;
6 import javax.xml.bind.Marshaller;
7 import javax.xml.bind.Unmarshaller;
8 import java.io.StringReader;
9 import java.io.StringWriter;
10
11 import static junit.framework.Assert.assertEquals;
12 import static junit.framework.Assert.assertNotNull;
13
14
15
16
17
18
19
20
21
22
23 public class OlePatronJaxb_UT {
24
25
26 private static final String EXPECTED_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
27 "<olePatron xmlns:ns2=\"http://rice.kuali.org/kim/v2_0\" xmlns=\"http://org.kuali.ole.patron.api\">" +
28 "<olePatronId>P1001</olePatronId><entityId>190192</entityId>" +
29 "<barcode>1234</barcode><borrowerType>19019</borrowerType>" +
30 "<activeIndicator>true</activeIndicator>" +
31 "<generalBlock>true</generalBlock>" +
32 "<pagingPrivilege>true" +
33 "</pagingPrivilege>" +
34 "<courtesyNotice>true</courtesyNotice>" +
35 "<deliveryPrivilege>true</deliveryPrivilege>" +
36 "<expirationDate>2012-05-31</expirationDate>" +
37 "<phones><phone>" +
38 "<ns2:id>1</ns2:id><ns2:entityTypeCode>PERSON</ns2:entityTypeCode><ns2:entityId>190192</ns2:entityId>" +
39 "<ns2:phoneType><ns2:code>Home</ns2:code><ns2:name>Home-y</ns2:name><ns2:sortCode>0</ns2:sortCode><ns2:active>true</ns2:active><ns2:versionNumber>1</ns2:versionNumber><ns2:objectId>90f96605-d0f2-4908-a7d6-06f4b2a1f2cd</ns2:objectId>" +
40 "</ns2:phoneType><ns2:countryCode>1</ns2:countryCode><ns2:phoneNumber>439-0116</ns2:phoneNumber><ns2:extensionNumber>12</ns2:extensionNumber><ns2:formattedPhoneNumber>439-0116 x12</ns2:formattedPhoneNumber>" +
41 "<ns2:countryCodeUnmasked>1</ns2:countryCodeUnmasked><ns2:phoneNumberUnmasked>439-0116</ns2:phoneNumberUnmasked><ns2:extensionNumberUnmasked>12</ns2:extensionNumberUnmasked><ns2:formattedPhoneNumberUnmasked>439-0116 x12</ns2:formattedPhoneNumberUnmasked>" +
42 "<ns2:suppressPhone>false</ns2:suppressPhone><ns2:defaultValue>true</ns2:defaultValue><ns2:active>true</ns2:active><ns2:versionNumber>1</ns2:versionNumber><ns2:objectId>3770bebf-bc48-41aa-9b0e-a592552bdf06</ns2:objectId>" +
43 "</phone></phones>" +
44 "<addresses><address><ns2:id>1</ns2:id><ns2:entityTypeCode>PERSON</ns2:entityTypeCode><ns2:entityId>190192</ns2:entityId>" +
45 "<ns2:addressType><ns2:code>Home</ns2:code><ns2:name>Home-y</ns2:name><ns2:sortCode>0</ns2:sortCode><ns2:active>true</ns2:active><ns2:versionNumber>1</ns2:versionNumber>" +
46 "<ns2:objectId>44ebdf54-b97f-4cfb-9089-65d225cbcf27</ns2:objectId></ns2:addressType>" +
47 "<ns2:attentionLine>Attn Line</ns2:attentionLine><ns2:line1>Line 1</ns2:line1><ns2:line2>Line 2</ns2:line2><ns2:line3>Line 3</ns2:line3>" +
48 "<ns2:city>Super Sweet City</ns2:city><ns2:stateProvinceCode>CA</ns2:stateProvinceCode><ns2:postalCode>55555</ns2:postalCode><ns2:countryCode>USA</ns2:countryCode>" +
49 "<ns2:attentionLineUnmasked>Attn Line</ns2:attentionLineUnmasked><ns2:line1Unmasked>Line 1</ns2:line1Unmasked><ns2:line2Unmasked>Line 2</ns2:line2Unmasked><ns2:line3Unmasked>Line 3</ns2:line3Unmasked>" +
50 "<ns2:cityUnmasked>Super Sweet City</ns2:cityUnmasked><ns2:stateProvinceCodeUnmasked>CA</ns2:stateProvinceCodeUnmasked><ns2:postalCodeUnmasked>55555</ns2:postalCodeUnmasked>" +
51 "<ns2:countryCodeUnmasked>USA</ns2:countryCodeUnmasked><ns2:addressFormat>address format</ns2:addressFormat><ns2:modifiedDate>2012-05-31T17:31:39.539+05:30</ns2:modifiedDate>" +
52 "<ns2:validatedDate>2012-05-31T17:31:39.594+05:30</ns2:validatedDate><ns2:validated>true</ns2:validated><ns2:noteMessage>note message</ns2:noteMessage>" +
53 "<ns2:suppressAddress>false</ns2:suppressAddress><ns2:defaultValue>true</ns2:defaultValue><ns2:active>true</ns2:active><ns2:versionNumber>1</ns2:versionNumber><ns2:objectId>d29e4266-e889-439f-a03d-a13a317a2681</ns2:objectId></address></addresses><name><ns2:id>190192</ns2:id><ns2:entityId>1</ns2:entityId><ns2:nameType><ns2:code>Home</ns2:code><ns2:name>Home-y</ns2:name><ns2:sortCode>0</ns2:sortCode><ns2:active>true</ns2:active><ns2:versionNumber>1</ns2:versionNumber><ns2:objectId>3e164629-07b8-4fdc-8c54-2656f496a998</ns2:objectId></ns2:nameType><ns2:namePrefix>Mr</ns2:namePrefix><ns2:nameTitle>DVM</ns2:nameTitle><ns2:firstName>Bob</ns2:firstName><ns2:middleName>Mob</ns2:middleName><ns2:lastName>Sob</ns2:lastName><ns2:nameSuffix>Jr</ns2:nameSuffix><ns2:compositeName>Sob, Bob Mob</ns2:compositeName><ns2:namePrefixUnmasked>Mr</ns2:namePrefixUnmasked><ns2:nameTitleUnmasked>DVM</ns2:nameTitleUnmasked><ns2:firstNameUnmasked>Bob</ns2:firstNameUnmasked><ns2:middleNameUnmasked>Mob</ns2:middleNameUnmasked><ns2:lastNameUnmasked>Sob</ns2:lastNameUnmasked><ns2:nameSuffixUnmasked>Jr</ns2:nameSuffixUnmasked><ns2:compositeNameUnmasked>Sob, Bob Mob</ns2:compositeNameUnmasked><ns2:noteMessage>note message</ns2:noteMessage><ns2:nameChangedDate>2012-05-31T17:31:39.665+05:30</ns2:nameChangedDate><ns2:suppressName>false</ns2:suppressName><ns2:defaultValue>true</ns2:defaultValue><ns2:active>true</ns2:active><ns2:versionNumber>1</ns2:versionNumber><ns2:objectId>a7614db3-fdb1-4413-a493-228ac43d181f</ns2:objectId></name><emails><email><ns2:id>1</ns2:id><ns2:entityTypeCode>PERSON</ns2:entityTypeCode><ns2:entityId>190192</ns2:entityId><ns2:emailType><ns2:code>Home</ns2:code><ns2:name>Home-y</ns2:name><ns2:sortCode>0</ns2:sortCode><ns2:active>true</ns2:active><ns2:versionNumber>1</ns2:versionNumber><ns2:objectId>9a552219-20e3-45ca-b07b-cb90334a7fdc</ns2:objectId></ns2:emailType><ns2:emailAddress>test@kuali.org</ns2:emailAddress><ns2:emailAddressUnmasked>test@kuali.org</ns2:emailAddressUnmasked><ns2:suppressEmail>false</ns2:suppressEmail><ns2:defaultValue>true</ns2:defaultValue><ns2:active>true</ns2:active><ns2:versionNumber>1</ns2:versionNumber><ns2:objectId>902571ee-d70d-4675-8507-b0bb4b3ae31d</ns2:objectId></email></emails><notes><note><patronNoteId>19018</patronNoteId><olePatronId>P1001</olePatronId><patronNoteText>Patron Test</patronNoteText><olePatronNoteType><patronNoteTypeId>19017</patronNoteTypeId><patronNoteTypeCode>NT</patronNoteTypeCode><patronNoteTypeName>Note Test</patronNoteTypeName><active>false</active></olePatronNoteType><active>true</active><objectId>7af3bf07-c631-45aa-90a5-d5879ce3488c</objectId><versionNumber>1</versionNumber></note></notes><versionNumber>1</versionNumber></olePatron>\n";
54
55 @Test
56 public void testMarshalAndUnmarshall() throws Exception {
57 JAXBContext jaxb = JAXBContext.newInstance(OlePatronDefinition.class);
58 OlePatronDefinition patron = OlePatronDefintionHelper.create();
59
60 Marshaller marshaller = jaxb.createMarshaller();
61 StringWriter writer = new StringWriter();
62 marshaller.marshal(patron, writer);
63 System.out.println("Marshalled Patron is: " + writer.toString());
64
65 Unmarshaller unmarshaller = jaxb.createUnmarshaller();
66 OlePatronDefinition unmarshalled = (OlePatronDefinition)unmarshaller.unmarshal(new StringReader(writer.toString()));
67 assertEquals(patron, unmarshalled);
68 OlePatronDefinition unmarshalledFromExpected = (OlePatronDefinition)unmarshaller.unmarshal(new StringReader(EXPECTED_XML));
69 assertEquals(patron, unmarshalledFromExpected);
70
71 }
72 }