View Javadoc

1   package org.kuali.ole;
2   
3   import org.junit.Test;
4   import org.kuali.ole.pojo.bib.*;
5   import org.kuali.ole.pojo.dublin.unqualified.*;
6   
7   import java.io.File;
8   import java.net.URL;
9   import java.util.ArrayList;
10  import java.util.Arrays;
11  import java.util.Iterator;
12  import java.util.List;
13  
14  import static junit.framework.Assert.*;
15  import static org.junit.Assert.assertEquals;
16  
17  /**
18   * Created by IntelliJ IDEA.
19   * User: poornima
20   * Date: 4/17/12
21   * Time: 8:40 PM
22   * To change this template use File | Settings | File Templates.
23   */
24  public class UnQualifiedDublinRecordHandler_UT {
25      @Test
26      public void testExtractUnQualifiedDublinRecordsFromXML() throws Exception {
27          UnQualifiedDublinRecordHandler unQualifiedDublinRecordHandler =
28                  new UnQualifiedDublinRecordHandler();
29  
30          URL resource = getClass().getResource("sample-dublin-unqualified.xml");
31          String xmlContent = new FileUtil().readFile(new File(resource.toURI()));
32  
33          UnQualifiedDublinRecord unQualifiedDublinRecord = unQualifiedDublinRecordHandler.fromXML(xmlContent);
34          assertNotNull(unQualifiedDublinRecord);
35      }
36  
37      @Test
38      public void testGenerateXML() throws Exception {
39          UnQualifiedDublinRecordHandler unQualifiedDublinRecordHandler =
40                  new UnQualifiedDublinRecordHandler();
41          UnQualifiedDublinRecord unQualifiedDublinRecord = generateMockUnqDublin();
42          String xml = unQualifiedDublinRecordHandler.toXml(unQualifiedDublinRecord);
43          System.out.println(xml);
44      }
45  
46      private UnQualifiedDublinRecord generateMockUnqDublin() {
47          UnQualifiedDublinRecord unQualifiedDublinRecord = new UnQualifiedDublinRecord();
48          unQualifiedDublinRecord.setRequest("http://quod.lib.umich.edu/cgi/o/oai/oai");
49          unQualifiedDublinRecord.setResponseDate("2010-07-25T08:14:49Z");
50  
51          ListRecords listRecords = new ListRecords();
52          Record record = new Record();
53          MetaData metaData = new MetaData();
54          OaiDcDoc oaiDcDoc = new OaiDcDoc();
55          List<OaiDcDoc> oaiDcDocList = new ArrayList<OaiDcDoc>();
56          oaiDcDoc.put("dc:title", "U.S. Marines in Vietnam");
57          oaiDcDoc.put("dc:creator", "Shulimson, Jack.");
58          oaiDcDoc.put("dc:subject", "Vietnam War, 1961-1975--Campaigns");
59          oaiDcDoc.put("dc:description", "xiii, 261 p. :");
60          oaiDcDoc.put("dc:identifier", "(LCCN)78600120");
61          oaiDcDocList.add(oaiDcDoc);
62          metaData.setOaiDcDocs(oaiDcDocList);
63          record.setMetadata(metaData);
64          listRecords.addRecord(record);
65  
66          unQualifiedDublinRecord.setListRecords(listRecords);
67          return unQualifiedDublinRecord;
68      }
69  }