1 package org.kuali.ole;
2
3 import org.junit.Test;
4 import org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.unqualified.*;
5 import org.kuali.ole.docstore.xstream.FileUtil;
6 import org.kuali.ole.pojo.dublin.unqualified.UnQualifiedDublinRecord;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9 import sun.rmi.runtime.Log;
10
11 import java.io.File;
12 import java.net.URL;
13 import java.util.ArrayList;
14 import java.util.List;
15
16 import static junit.framework.Assert.assertNotNull;
17
18
19
20
21
22
23
24
25 public class UnQualifiedDublinRecordHandler_UT {
26
27 public static final Logger LOG = LoggerFactory.getLogger(UnQualifiedDublinRecordHandler_UT.class);
28
29 @Test
30 public void testExtractUnQualifiedDublinRecordsFromXML() throws Exception {
31 UnQualifiedDublinRecordHandler unQualifiedDublinRecordHandler =
32 new UnQualifiedDublinRecordHandler();
33
34 URL resource = getClass().getResource("sample-dublin-unqualified.xml");
35 String xmlContent = new FileUtil().readFile(new File(resource.toURI()));
36
37 UnQualifiedDublinRecord unQualifiedDublinRecord = unQualifiedDublinRecordHandler.fromXML(xmlContent);
38 assertNotNull(unQualifiedDublinRecord);
39 }
40
41 @Test
42 public void testGenerateXML() throws Exception {
43 UnQualifiedDublinRecordHandler unQualifiedDublinRecordHandler =
44 new UnQualifiedDublinRecordHandler();
45 UnQualifiedDublinRecord unQualifiedDublinRecord = generateMockUnqDublin();
46 String xml = unQualifiedDublinRecordHandler.toXml(unQualifiedDublinRecord);
47 LOG.info(xml);
48 }
49
50 private UnQualifiedDublinRecord generateMockUnqDublin() {
51 UnQualifiedDublinRecord unQualifiedDublinRecord = new UnQualifiedDublinRecord();
52 unQualifiedDublinRecord.setRequest("http://quod.lib.umich.edu/cgi/o/oai/oai");
53 unQualifiedDublinRecord.setResponseDate("2010-07-25T08:14:49Z");
54
55 ListRecords listRecords = new ListRecords();
56 Header header = new Header();
57 Tag tag = new Tag("dc:title");
58 Record record = new Record();
59 MetaData metaData = new MetaData();
60 OaiDcDoc oaiDcDoc = new OaiDcDoc();
61 List<OaiDcDoc> oaiDcDocList = new ArrayList<OaiDcDoc>();
62 header.put("dc:title", "U.S. Marines in Vietnam");
63 if (header.get("dc:title") != null) {
64 LOG.info(header.get("dc:title").toString());
65 }
66 oaiDcDoc.put("dc:title", "U.S. Marines in Vietnam");
67 oaiDcDoc.put("dc:creator", "Shulimson, Jack.");
68 oaiDcDoc.put("dc:subject", "Vietnam War, 1961-1975--Campaigns");
69 oaiDcDoc.put("dc:description", "xiii, 261 p. :");
70 oaiDcDoc.put("dc:identifier", "(LCCN)78600120");
71 if (oaiDcDoc.get("dc:title") != null) {
72 LOG.info("dc:title");
73 }
74 if (oaiDcDoc.get("dc:creator") != null) {
75 LOG.info("dc:creator");
76 }
77 oaiDcDocList.add(oaiDcDoc);
78 metaData.setOaiDcDocs(oaiDcDocList);
79 metaData.addOaiDcDoc(oaiDcDoc);
80 if (metaData.getOaiDcDocs() != null) {
81 LOG.info(metaData.getOaiDcDocs().toString());
82 }
83 record.setHeader(header);
84 record.setMetadata(metaData);
85 if (record.getMetadata() != null) {
86 LOG.info(record.getMetadata().toString());
87 }
88 listRecords.addRecord(record);
89
90 unQualifiedDublinRecord.setListRecords(listRecords);
91
92 listRecords = unQualifiedDublinRecord.getListRecords();
93 List<Record> recordList = listRecords.getRecords();
94 listRecords.setRecords(recordList);
95 for (Record record1 : recordList) {
96 LOG.info("" + record1.getHeader());
97 }
98 LOG.info(unQualifiedDublinRecord.toString());
99 LOG.info("Response Date:" + unQualifiedDublinRecord.getResponseDate());
100 LOG.info("Request:" + unQualifiedDublinRecord.getRequest());
101
102 tag.setName("dc:title");
103 tag.setValue("U.S. Marines in Vietnam");
104 tag.equals(oaiDcDoc);
105
106 WorkBibDublinUnQualifiedRecord workBibDublinUnQualifiedRecord = new WorkBibDublinUnQualifiedRecord();
107 workBibDublinUnQualifiedRecord.setListRecords(listRecords);
108 if (workBibDublinUnQualifiedRecord.getListRecords() != null) {
109 LOG.info(workBibDublinUnQualifiedRecord.getListRecords().toString());
110 }
111 workBibDublinUnQualifiedRecord.setResponseDate("12-12-2012");
112 if (workBibDublinUnQualifiedRecord.getResponseDate() != null) {
113 LOG.info(workBibDublinUnQualifiedRecord.getResponseDate());
114 }
115 workBibDublinUnQualifiedRecord.setRequest("request");
116 if (workBibDublinUnQualifiedRecord.getRequest() != null) {
117 LOG.info(workBibDublinUnQualifiedRecord.getRequest());
118 }
119 return unQualifiedDublinRecord;
120 }
121 }