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.unqualified;
17  
18  import org.junit.After;
19  import org.junit.Before;
20  import org.junit.Test;
21  import org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.unqualified.WorkBibDublinUnQualifiedRecord;
22  import org.kuali.ole.docstore.model.xstream.work.bib.dublin.unqualified.WorkBibDublinUnQualifiedRecordProcessor;
23  import org.kuali.ole.docstore.xstream.BaseTestCase;
24  import org.kuali.ole.docstore.xstream.FileUtil;
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  
28  import java.io.File;
29  import java.net.URL;
30  
31  import static junit.framework.Assert.assertNotNull;
32  import static org.junit.Assert.fail;
33  
34  /**
35   * Class to Test WorkBibDublinUnqualifiedRecordProcessor.
36   *
37   * @author Rajesh Chowdary K
38   */
39  public class WorkBibDublinUnqualifiedRecordProcessor_UT extends BaseTestCase {
40      //    private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(WorkBibDublinUnqualifiedRecordProcessor_UT.class);
41      private static final Logger LOG = LoggerFactory.getLogger(WorkBibDublinUnqualifiedRecordProcessor_UT.class);
42  
43      @Before
44      public void setUp() throws Exception {
45      }
46  
47      @After
48      public void tearDown() throws Exception {
49      }
50  
51      @Test
52      public void testFromXML() {
53          try {
54              String resFile = "/bib/bib/dublin/unqualified/Bib-Bib-DublinUnQ-Test1.xml";
55              URL resource = getClass().getResource(resFile);
56              File file = new File(resource.toURI());
57              String fileContent;
58              fileContent = new FileUtil().readFile(file);
59              WorkBibDublinUnQualifiedRecordProcessor processor = new WorkBibDublinUnQualifiedRecordProcessor();
60              WorkBibDublinUnQualifiedRecord rec = processor.fromXML(fileContent);
61              LOG.info("record-->" + rec);
62              String xml = processor.toXml(rec);
63              LOG.info("XML-->" + xml);
64              LOG.info("record = " + rec);
65              assertNotNull(rec);
66          } catch (Exception e) {
67              e.printStackTrace();
68              fail("Failed Due to: " + e.getMessage());
69          }
70  
71      }
72  
73      @Test
74      public void testToXml() {
75          try {
76              String resFile = "/bib/bib/dublin/unqualified/Bib-Bib-DublinUnQ-Test1.xml";
77              URL resource = getClass().getResource(resFile);
78              File file = new File(resource.toURI());
79              String fileContent;
80              fileContent = new FileUtil().readFile(file);
81              WorkBibDublinUnQualifiedRecordProcessor processor = new WorkBibDublinUnQualifiedRecordProcessor();
82              WorkBibDublinUnQualifiedRecord rec = processor.fromXML(fileContent);
83              LOG.info("Output: " + rec);
84              assertNotNull(rec);
85              String xml = processor.toXml(rec);
86              LOG.info(xml);
87          } catch (Exception e) {
88              e.printStackTrace();
89              fail("Failed Due to: " + e.getMessage());
90          }
91      }
92  
93  }