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