View Javadoc
1   package org.kuali.ole.deliver.api;
2   
3   import org.junit.Test;
4   import org.kuali.ole.deliver.api.OlePatronDefinition;
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  import static junit.framework.Assert.assertEquals;
12  
13  /**
14   * Created with IntelliJ IDEA.
15   * User: ?
16   * Date: 5/25/12
17   * Time: 3:08 PM
18   * To change this template use File | Settings | File Templates.
19   */
20  
21  
22  public class OlePatronJaxb_UT {
23  
24  
25      private static final String EXPECTED_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
26              "<olePatron xmlns:ns2=\"http://rice.kuali.org/kim/v2_0\" xmlns=\"http://org.kuali.ole.deliver.api\">" +
27              "<olePatronId>P1001</olePatronId><entityId>190192</entityId>" +
28              "<barcode>1234</barcode><borrowerType>19019</borrowerType>" +
29              "<activeIndicator>true</activeIndicator>" +
30              "<generalBlock>true</generalBlock>" +
31              "<pagingPrivilege>true" +
32              "</pagingPrivilege>" +
33              "<courtesyNotice>true</courtesyNotice>" +
34              "<deliveryPrivilege>true</deliveryPrivilege>" +
35              "<expirationDate>2012-05-31</expirationDate>" +
36              "<phones><phone>" +
37              "<ns2:id>1</ns2:id><ns2:entityTypeCode>PERSON</ns2:entityTypeCode><ns2:entityId>190192</ns2:entityId>" +
38              "<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>" +
39              "</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>" +
40              "<ns2:countryCodeUnmasked>1</ns2:countryCodeUnmasked><ns2:phoneNumberUnmasked>439-0116</ns2:phoneNumberUnmasked><ns2:extensionNumberUnmasked>12</ns2:extensionNumberUnmasked><ns2:formattedPhoneNumberUnmasked>439-0116 x12</ns2:formattedPhoneNumberUnmasked>" +
41              "<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>" +
42              "</phone></phones>" +
43              "<addresses><address><ns2:id>1</ns2:id><ns2:entityTypeCode>PERSON</ns2:entityTypeCode><ns2:entityId>190192</ns2:entityId>" +
44              "<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>" +
45              "<ns2:objectId>44ebdf54-b97f-4cfb-9089-65d225cbcf27</ns2:objectId></ns2:addressType>" +
46              "<ns2:attentionLine>Attn Line</ns2:attentionLine><ns2:line1>Line 1</ns2:line1><ns2:line2>Line 2</ns2:line2><ns2:line3>Line 3</ns2:line3>" +
47              "<ns2:city>Super Sweet City</ns2:city><ns2:stateProvinceCode>CA</ns2:stateProvinceCode><ns2:postalCode>55555</ns2:postalCode><ns2:countryCode>USA</ns2:countryCode>" +
48              "<ns2:attentionLineUnmasked>Attn Line</ns2:attentionLineUnmasked><ns2:line1Unmasked>Line 1</ns2:line1Unmasked><ns2:line2Unmasked>Line 2</ns2:line2Unmasked><ns2:line3Unmasked>Line 3</ns2:line3Unmasked>" +
49              "<ns2:cityUnmasked>Super Sweet City</ns2:cityUnmasked><ns2:stateProvinceCodeUnmasked>CA</ns2:stateProvinceCodeUnmasked><ns2:postalCodeUnmasked>55555</ns2:postalCodeUnmasked>" +
50              "<ns2:countryCodeUnmasked>USA</ns2:countryCodeUnmasked><ns2:addressFormat>address format</ns2:addressFormat><ns2:modifiedDate>2012-05-31T17:31:39.539+05:30</ns2:modifiedDate>" +
51              "<ns2:validatedDate>2012-05-31T17:31:39.594+05:30</ns2:validatedDate><ns2:validated>true</ns2:validated><ns2:noteMessage>note message</ns2:noteMessage>" +
52              "<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";
53  
54  
55      //private static final String EXPECTED_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><olePatron xmlns:ns2=\"http://rice.kuali.org/kim/v2_0\" xmlns=\"http://org.kuali.ole.deliver.api\"><olePatronId>P1001</olePatronId><barcode>1234</barcode><borrowerType>7</borrowerType><activeIndicator>true</activeIndicator><generalBlock>true</generalBlock><pagingPrivilege>true</pagingPrivilege><courtesyNotice>true</courtesyNotice><deliveryPrivilege>true</deliveryPrivilege><expirationDate>2013-09-20</expirationDate><activationDate>2013-09-20</activationDate><oleBorrowerType><borrowerTypeId>7</borrowerTypeId><borrowerTypeCode>UGRAD</borrowerTypeCode><borrowerTypeName>UnderGrad</borrowerTypeName><borrowerTypeName>UnderGrad</borrowerTypeName><versionNumber>1</versionNumber></oleBorrowerType><phones><phone><ns2:id>1</ns2:id><ns2:entityTypeCode>PERSON</ns2:entityTypeCode><ns2:entityId>190192</ns2:entityId><ns2:phoneType><ns2:code>HM</ns2:code><ns2:name>Home</ns2:name><ns2:sortCode>0</ns2:sortCode><ns2:active>true</ns2:active><ns2:versionNumber>1</ns2:versionNumber><ns2:objectId>f7f6a0e9-f60c-41c4-a0f6-87d67a1371bf</ns2:objectId></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><ns2:countryCodeUnmasked>1</ns2:countryCodeUnmasked><ns2:phoneNumberUnmasked>439-0116</ns2:phoneNumberUnmasked><ns2:extensionNumberUnmasked>12</ns2:extensionNumberUnmasked><ns2:formattedPhoneNumberUnmasked>439-0116 x12</ns2:formattedPhoneNumberUnmasked><ns2:suppressPhone>false</ns2:suppressPhone><ns2:defaultValue>true</ns2:defaultValue><ns2:active>true</ns2:active><ns2:versionNumber>1</ns2:versionNumber><ns2:objectId>c4dfad79-88d2-430c-973b-21a2584a38eb</ns2:objectId></phone></phones><addresses><address><ns2:id>1</ns2:id><ns2:entityTypeCode>PERSON</ns2:entityTypeCode><ns2:entityId>190192</ns2:entityId><ns2:addressType><ns2:code>HM</ns2:code><ns2:name>Home</ns2:name><ns2:sortCode>0</ns2:sortCode><ns2:active>true</ns2:active><ns2:versionNumber>1</ns2:versionNumber><ns2:objectId>aadb84f0-a7e8-41d6-9ae2-9c07109d4b9a</ns2:objectId></ns2:addressType><ns2:attentionLine>Attn Line</ns2:attentionLine><ns2:line1>Line 1</ns2:line1><ns2:line2>Line 2</ns2:line2><ns2:line3>Line 3</ns2:line3><ns2:city>Super Sweet City</ns2:city><ns2:stateProvinceCode>CA</ns2:stateProvinceCode><ns2:postalCode>55555</ns2:postalCode><ns2:countryCode>US</ns2:countryCode><ns2:attentionLineUnmasked>Attn Line</ns2:attentionLineUnmasked><ns2:line1Unmasked>Line 1</ns2:line1Unmasked><ns2:line2Unmasked>Line 2</ns2:line2Unmasked><ns2:line3Unmasked>Line 3</ns2:line3Unmasked><ns2:cityUnmasked>Super Sweet City</ns2:cityUnmasked><ns2:stateProvinceCodeUnmasked>CA</ns2:stateProvinceCodeUnmasked><ns2:postalCodeUnmasked>55555</ns2:postalCodeUnmasked><ns2:countryCodeUnmasked>US</ns2:countryCodeUnmasked><ns2:addressFormat>address format</ns2:addressFormat><ns2:modifiedDate>2013-09-20T15:43:32.730+05:30</ns2:modifiedDate><ns2:validatedDate>2013-09-20T15:43:32.770+05:30</ns2:validatedDate><ns2:validated>true</ns2:validated><ns2:noteMessage>note message</ns2:noteMessage><ns2:suppressAddress>false</ns2:suppressAddress><ns2:defaultValue>true</ns2:defaultValue><ns2:active>true</ns2:active><ns2:versionNumber>1</ns2:versionNumber><ns2:objectId>61528148-8fa0-4301-b1cf-b82a097bd3a0</ns2:objectId></address></addresses><name><ns2:id>190192</ns2:id><ns2:entityId>1</ns2:entityId><ns2:nameType><ns2:code>OTH</ns2:code><ns2:name>Other</ns2:name><ns2:sortCode>b</ns2:sortCode><ns2:active>true</ns2:active><ns2:versionNumber>1</ns2:versionNumber><ns2:objectId>7bbaf3fc-285a-4367-9d67-50d316c26ec5</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:suppressName>false</ns2:suppressName><ns2:defaultValue>true</ns2:defaultValue><ns2:active>true</ns2:active><ns2:versionNumber>1</ns2:versionNumber><ns2:objectId>96412809-61dd-43a1-80eb-25b9a2ef4442</ns2:objectId></name><emails><email><ns2:id>1</ns2:id><ns2:entityTypeCode>PERSON</ns2:entityTypeCode><ns2:entityId>190192</ns2:entityId><ns2:emailType><ns2:code>HM</ns2:code><ns2:name>Home</ns2:name><ns2:sortCode>0</ns2:sortCode><ns2:active>true</ns2:active><ns2:versionNumber>1</ns2:versionNumber><ns2:objectId>4bcf5958-afcc-472d-8b39-c1a645e8c661</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>75d2178b-4a11-4ea7-b399-a23d8483c82f</ns2:objectId></email></emails><notes><note><patronNoteId>P2</patronNoteId><olePatronId>P1001</olePatronId><patronNoteText>Patron Test</patronNoteText><olePatronNoteType><patronNoteTypeId>2</patronNoteTypeId><patronNoteTypeCode>NT</patronNoteTypeCode><patronNoteTypeName>Note Test</patronNoteTypeName><active>false</active></olePatronNoteType><active>true</active><objectId>41f33bdf-9578-447a-a401-61cf6430e4b7</objectId><versionNumber>1</versionNumber></note></notes><lostBarcodes><lostBarcode><olePatronLostBarcodeId>P11</olePatronLostBarcodeId><olePatronId>P1001</olePatronId><invalidOrLostBarcodeEffDate>2013-09-20</invalidOrLostBarcodeEffDate><invalidOrLostBarcodeNumber>222222</invalidOrLostBarcodeNumber><versionNumber>1</versionNumber><objectId>41f33bdf-9578-447a-a401-61cf6430e4b7</objectId></lostBarcode></lostBarcodes><oleEntityAddressBo><oleEntityAddress><oleAddressBo><oleAddressId>1</oleAddressId><olePatronId>P1001</olePatronId><id>1</id><addressVerified>true</addressVerified><addressValidFrom>2013-09-20</addressValidFrom><addressValidTo>2013-09-20</addressValidTo><addressSource>1</addressSource><addressSourceBo><oleAddressSourceId>1</oleAddressSourceId><oleAddressSourceCode>REG</oleAddressSourceCode><oleAddressSourceName>Registrar</oleAddressSourceName><oleAddressSourceDesc>Registrar</oleAddressSourceDesc><active>true</active><versionNumber>1</versionNumber></addressSourceBo><versionNumber>1</versionNumber></oleAddressBo><entityAddressBo><ns2:id>1</ns2:id><ns2:entityTypeCode>PERSON</ns2:entityTypeCode><ns2:entityId>190192</ns2:entityId><ns2:addressType><ns2:code>HM</ns2:code><ns2:name>Home</ns2:name><ns2:sortCode>0</ns2:sortCode><ns2:active>true</ns2:active><ns2:versionNumber>1</ns2:versionNumber><ns2:objectId>aadb84f0-a7e8-41d6-9ae2-9c07109d4b9a</ns2:objectId></ns2:addressType><ns2:attentionLine>Attn Line</ns2:attentionLine><ns2:line1>Line 1</ns2:line1><ns2:line2>Line 2</ns2:line2><ns2:line3>Line 3</ns2:line3><ns2:city>Super Sweet City</ns2:city><ns2:stateProvinceCode>CA</ns2:stateProvinceCode><ns2:postalCode>55555</ns2:postalCode><ns2:countryCode>US</ns2:countryCode><ns2:attentionLineUnmasked>Attn Line</ns2:attentionLineUnmasked><ns2:line1Unmasked>Line 1</ns2:line1Unmasked><ns2:line2Unmasked>Line 2</ns2:line2Unmasked><ns2:line3Unmasked>Line 3</ns2:line3Unmasked><ns2:cityUnmasked>Super Sweet City</ns2:cityUnmasked><ns2:stateProvinceCodeUnmasked>CA</ns2:stateProvinceCodeUnmasked><ns2:postalCodeUnmasked>55555</ns2:postalCodeUnmasked><ns2:countryCodeUnmasked>US</ns2:countryCodeUnmasked><ns2:addressFormat>address format</ns2:addressFormat><ns2:modifiedDate>2013-09-20T15:43:32.730+05:30</ns2:modifiedDate><ns2:validatedDate>2013-09-20T15:43:32.770+05:30</ns2:validatedDate><ns2:validated>true</ns2:validated><ns2:noteMessage>note message</ns2:noteMessage><ns2:suppressAddress>false</ns2:suppressAddress><ns2:defaultValue>true</ns2:defaultValue><ns2:active>true</ns2:active><ns2:versionNumber>1</ns2:versionNumber><ns2:objectId>61528148-8fa0-4301-b1cf-b82a097bd3a0</ns2:objectId></entityAddressBo></oleEntityAddress></oleEntityAddressBo><generalBlockNotes>General Block notes</generalBlockNotes><patronAffiliations/><oleProxyPatronDocuments><oleProxyPatronDocument><oleProxyPatronDocumentId>11</oleProxyPatronDocumentId><proxyPatronId>P1002</proxyPatronId><olePatronId>P1001</olePatronId><proxyPatronExpirationDate>2013-09-20</proxyPatronExpirationDate><proxyPatronActivationDate>2013-09-20</proxyPatronActivationDate><active>true</active><versionNumber>1</versionNumber></oleProxyPatronDocument></oleProxyPatronDocuments><source>1</source><statisticalCategory>1</statisticalCategory><oleAddresses><oleAddress><oleAddressId>1</oleAddressId><olePatronId>P1001</olePatronId><id>1</id><addressVerified>true</addressVerified><addressValidFrom>2013-09-20</addressValidFrom><addressValidTo>2013-09-20</addressValidTo><addressSource>1</addressSource><addressSourceBo><oleAddressSourceId>1</oleAddressSourceId><oleAddressSourceCode>REG</oleAddressSourceCode><oleAddressSourceName>Registrar</oleAddressSourceName><oleAddressSourceDesc>Registrar</oleAddressSourceDesc><active>true</active><versionNumber>1</versionNumber></addressSourceBo><versionNumber>1</versionNumber></oleAddress></oleAddresses><olePatronLocalIds><olePatronLocalId><patronLocalSeqId>P10</patronLocalSeqId><olePatronId>P1001</olePatronId><localId>222222</localId><versionNumber>1</versionNumber><objectId>5773ba41-81cc-43be-8327-988224667000</objectId></olePatronLocalId></olePatronLocalIds><versionNumber>1</versionNumber></olePatron>";
56  
57      @Test
58      public void testMarshalAndUnmarshall() throws Exception {
59          JAXBContext jaxb = JAXBContext.newInstance(OlePatronDefinition.class);
60          OlePatronDefinition patron = OlePatronDefintionHelper.create();
61  
62          Marshaller marshaller = jaxb.createMarshaller();
63          StringWriter writer = new StringWriter();
64          marshaller.marshal(patron, writer);
65          System.out.println("Marshalled Patron is: " + writer.toString());
66          System.out.println("test: "+EXPECTED_XML);
67  
68          Unmarshaller unmarshaller = jaxb.createUnmarshaller();
69          OlePatronDefinition unmarshalled = (OlePatronDefinition)unmarshaller.unmarshal(new StringReader(writer.toString()));
70          //assertEquals(patron, unmarshalled);
71          OlePatronDefinition unmarshalledFromExpected = (OlePatronDefinition)unmarshaller.unmarshal(new StringReader(EXPECTED_XML));
72          //assertEquals(patron, unmarshalledFromExpected);
73  
74      }
75  }