View Javadoc
1   package org.kuali.ole.docstore.model.converter;
2   
3   import org.apache.commons.io.FileUtils;
4   import org.junit.Test;
5   import org.kuali.ole.docstore.discovery.BaseTestCase;
6   import org.kuali.ole.docstore.model.bo.WorkBibDocument;
7   import org.kuali.ole.docstore.model.xmlpojo.work.bib.marc.WorkBibMarcRecord;
8   import org.kuali.ole.docstore.model.xmlpojo.work.bib.marc.WorkBibMarcRecords;
9   import org.kuali.ole.docstore.model.xstream.work.bib.marc.WorkBibMarcRecordProcessor;
10  import org.slf4j.Logger;
11  import org.slf4j.LoggerFactory;
12  
13  import java.io.File;
14  import java.net.URL;
15  import java.util.ArrayList;
16  import java.util.List;
17  
18  import static junit.framework.Assert.fail;
19  
20  /**
21   * Created with IntelliJ IDEA.
22   * User: PJ7789
23   * Date: 28/11/12
24   * Time: 11:13 AM
25   * To change this template use File | Settings | File Templates.
26   */
27  public class WorkBibDocConverter_UT extends BaseTestCase {
28      private static final Logger LOG = LoggerFactory.getLogger(WorkBibDocConverter_UT.class);
29  
30      @Test
31      public void testConvert() {
32          String resFile = "/bib/bib/marc/OneMarcRecord.xml";
33          WorkBibMarcRecordProcessor workBibMarcRecordProcessor = new WorkBibMarcRecordProcessor();
34          WorkBibDocConverter workBibDocConverter = new WorkBibDocConverter();
35          try {
36              URL resource = getClass().getResource(resFile);
37              File file = new File(resource.toURI());
38              String docContent = FileUtils.readFileToString(file);
39              WorkBibMarcRecords records = workBibMarcRecordProcessor.fromXML(docContent);
40              for (WorkBibMarcRecord marcRecord : records.getRecords()) {
41                  WorkBibDocument bibDoc = workBibDocConverter.convert(marcRecord);
42                  System.out.println("Author is..." + bibDoc.getAuthor());
43                  System.out.println("Title is..." + bibDoc.getTitle());
44                  System.out.println("Publication Date is..." + bibDoc.getPublicationDate());
45                  System.out.println("Publisher is..." + bibDoc.getPublisher());
46                  System.out.println("Publisher is..." + bibDoc.getEdition());
47              }
48          } catch (Exception e) {
49              LOG.error(e.getMessage(), e);
50              fail("Failed due to: " + e);
51          }
52      }
53  
54      @Test
55      public void testConvertRecords() {
56          String resFile = "/bib/bib/marc/OneMarcRecord.xml";
57          WorkBibMarcRecordProcessor workBibMarcRecordProcessor = new WorkBibMarcRecordProcessor();
58          WorkBibDocConverter workBibDocConverter = new WorkBibDocConverter();
59          try {
60              URL resource = getClass().getResource(resFile);
61              File file = new File(resource.toURI());
62              String docContent = FileUtils.readFileToString(file);
63              WorkBibMarcRecords records = workBibMarcRecordProcessor.fromXML(docContent);
64              List workBibDocumentList = new ArrayList<WorkBibDocument>();
65              workBibDocConverter.convert(records);
66              LOG.info("WorkBibDocumentRecords :" + workBibDocumentList);
67          } catch (Exception e) {
68              LOG.error(e.getMessage(), e);
69              fail("Failed due to: " + e);
70          }
71      }
72  
73  
74  }
75  
76  
77