1 package org.kuali.ole;
2
3 import org.apache.commons.io.FileUtils;
4 import org.junit.Test;
5 import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecord;
6 import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecords;
7 import org.kuali.ole.docstore.common.document.content.bib.marc.xstream.BibMarcRecordProcessor;
8 import org.kuali.ole.docstore.xstream.FileUtil;
9 import org.kuali.ole.pojo.ProfileAttribute;
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.Collections;
16 import java.util.Iterator;
17 import java.util.List;
18
19
20
21
22
23
24
25
26 public class OleItemRecordHandler_UT {
27 public static final Logger LOG = LoggerFactory.getLogger(OleItemRecordHandler_UT.class);
28
29 @Test
30 public void testGenerateItemXML() throws Exception {
31 URL resource = getClass().getResource("iu.mrc");
32 File file = new File(resource.toURI());
33 MarcXMLGenerator marcXMLGenerator = new MarcXMLGenerator();
34 String fileName = marcXMLGenerator.convertRawMarcToXML(file);
35
36 File xmlFile = new File(fileName);
37
38 BibMarcRecords bibliographicRecordCollection =
39 new BibMarcRecordProcessor().fromXML(new FileUtil().readFile(xmlFile));
40
41 List<BibMarcRecord> records = bibliographicRecordCollection.getRecords();
42 for (Iterator<BibMarcRecord> iterator = records.iterator(); iterator.hasNext(); ) {
43 BibMarcRecord bibMarcRecord = iterator.next();
44 OleItemRecordHandler oleItemRecordHandler = new OleItemRecordHandler();
45 String itemXML = oleItemRecordHandler.generateXML(bibMarcRecord, Collections.<ProfileAttribute>emptyList());
46 LOG.info(itemXML);
47 }
48 FileUtils.deleteQuietly(xmlFile);
49 }
50 }