View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.docstore.xstream.work.bib.dublin;
17  
18  import org.junit.After;
19  import org.junit.Before;
20  import org.junit.Test;
21  import org.kuali.ole.QualifiedDublinRecordHandler;
22  import org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.DCValue;
23  import org.kuali.ole.docstore.xstream.BaseTestCase;
24  import org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.WorkBibDublinRecord;
25  import org.kuali.ole.docstore.xstream.FileUtil;
26  import org.kuali.ole.docstore.model.xstream.work.bib.dublin.WorkBibDublinRecordProcessor;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  
30  import java.io.File;
31  import java.net.URL;
32  import java.util.ArrayList;
33  import java.util.List;
34  
35  import static junit.framework.Assert.assertNotNull;
36  import static org.junit.Assert.fail;
37  
38  /**
39   * Class to Test WorkBibDublinRecordProcessor.
40   *
41   * @author Rajesh Chowdary K
42   */
43  public class WorkBibDublinRecordProcessor_UT extends BaseTestCase {
44      //    private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(WorkBibDublinRecordProcessor_UT.class);
45      private static final Logger LOG = LoggerFactory.getLogger(WorkBibDublinRecordProcessor_UT.class);
46  
47      @Before
48      public void setUp() throws Exception {
49      }
50  
51      @After
52      public void tearDown() throws Exception {
53      }
54  
55      @Test
56      public void testFromXML() {
57          try {
58              String resFile = "/bib/bib/dublin/Bib-Bib-DublinQ-Test2.xml";
59              URL resource = getClass().getResource(resFile);
60              File file = new File(resource.toURI());
61              String fileContent;
62              fileContent = new FileUtil().readFile(file);
63              WorkBibDublinRecordProcessor processor = new WorkBibDublinRecordProcessor();
64              WorkBibDublinRecord rec = processor.fromXML(fileContent);
65              LOG.info("rec content with WorkBibDublinRecordProcessor" + rec);
66              DCValue dcValue = new DCValue("element");
67              dcValue.setElement("element");
68              dcValue.setQualifier("qualifier");
69              dcValue.setValue("value");
70              DCValue dcValue2 = new DCValue("element");
71              dcValue2.setElement("element");
72              dcValue2.setQualifier("qualifier");
73              dcValue2.setValue("value");
74              DCValue dcValue3 = new DCValue("element");
75              dcValue3.setElement("elem");
76              dcValue3.setQualifier("qual");
77              dcValue3.setValue("val");
78              List<DCValue> dcValueList = new ArrayList<DCValue>();
79              dcValueList.add(dcValue);
80              dcValueList.add(dcValue2);
81              dcValueList.add(dcValue3);
82              rec.setDcValues(dcValueList);
83              if (dcValue.equals(dcValue2)) {
84                  LOG.info("objects are equal");
85              }
86              if (dcValue.equals(rec)) {
87                  LOG.info("incompatible objects");
88              }
89              if (dcValue.equals(dcValue3)) {
90                  LOG.info("objects are equal");
91              }
92              QualifiedDublinRecordHandler qualifiedDublinRecordHandler = new QualifiedDublinRecordHandler();
93              rec = qualifiedDublinRecordHandler.fromXML(fileContent);
94              LOG.info("rec content with QualifiedDublinRecordHandler" + rec);
95              assertNotNull(rec);
96              assertNotNull(qualifiedDublinRecordHandler.toXml(rec));
97          } catch (Exception e) {
98              e.printStackTrace();
99              fail("Failed Due to: " + e.getMessage());
100         }
101 
102     }
103 
104     @Test
105     public void testToXml() {
106         try {
107             String resFile = "/bib/bib/dublin/Bib-Bib-DublinQ-Test2.xml";
108             URL resource = getClass().getResource(resFile);
109             File file = new File(resource.toURI());
110             String fileContent;
111             fileContent = new FileUtil().readFile(file);
112             WorkBibDublinRecordProcessor processor = new WorkBibDublinRecordProcessor();
113             WorkBibDublinRecord rec = processor.fromXML(fileContent);
114             LOG.info("Output: " + rec);
115             assertNotNull(rec);
116             String xml = processor.toXml(rec);
117             LOG.info(xml);
118         } catch (Exception e) {
119             e.printStackTrace();
120             fail("Failed Due to: " + e.getMessage());
121         }
122     }
123 
124 }