View Javadoc
1   package org.kuali.ole.docstore.common.document;
2   
3   import org.apache.commons.io.FileUtils;
4   import org.apache.log4j.Logger;
5   import org.junit.Assert;
6   import org.junit.Test;
7   import org.kuali.ole.docstore.common.document.content.bib.marc.*;
8   import org.kuali.ole.docstore.common.util.ParseXml;
9   
10  import java.io.File;
11  import java.net.URISyntaxException;
12  import java.util.ArrayList;
13  import java.util.List;
14  
15  /**
16   * Created with IntelliJ IDEA.
17   * User: srirams
18   * Date: 1/8/14
19   * Time: 11:40 AM
20   * To change this template use File | Settings | File Templates.
21   */
22  public class BibMarc_UT {
23  
24      private static final Logger LOG = Logger.getLogger(BibMarc_UT.class);
25  
26      @Test
27      public void deserializeAndSerialize(){
28          String input ="";
29          File file = null;
30          try {
31              file = new File(getClass().getResource("/documents/BibMarc1.xml").toURI());
32              input = FileUtils.readFileToString(file);
33          } catch (Exception e) {
34              LOG.error("Exception :", e);
35          }
36          BibMarc bibMarc = new BibMarc();
37          bibMarc = (BibMarc) bibMarc.deserialize(input);
38          bibMarc.setAuthor("author");
39          bibMarc.setTitle("title");
40          String serializeXml = bibMarc.serialize(bibMarc);
41          serializeXml = ParseXml.formatXml(serializeXml);
42          System.out.print(serializeXml);
43      }
44  
45      @Test
46      public void deserializeContentAndSerializeContent(){
47          String input ="";
48          File file = null;
49          try {
50              file = new File(getClass().getResource("/documents/BibMarc1.xml").toURI());
51              input = FileUtils.readFileToString(file);
52          } catch (Exception e) {
53              LOG.error("Exception :", e);
54          }
55          BibMarc bibMarc = new BibMarc();
56          bibMarc = (BibMarc) bibMarc.deserialize(input);
57          BibMarcRecords bibMarcRecords = (BibMarcRecords) bibMarc.deserializeContent(bibMarc.getContent());
58          String serializeXml = bibMarc.serializeContent(bibMarcRecords);
59          serializeXml = ParseXml.formatXml(serializeXml);
60          System.out.println(serializeXml);
61      }
62  }