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.discovery.solr.work.bib.dublin.unqualified;
17  
18  import org.apache.commons.io.FileUtils;
19  import org.apache.solr.common.SolrInputDocument;
20  import org.junit.After;
21  import org.junit.Before;
22  import org.junit.Test;
23  import org.kuali.ole.docstore.discovery.BaseTestCase;
24  import org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.unqualified.OaiDcDoc;
25  import org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.unqualified.Record;
26  import org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.unqualified.WorkBibDublinUnQualifiedRecord;
27  import org.kuali.ole.docstore.model.xstream.work.bib.dublin.unqualified.WorkBibDublinUnQualifiedRecordProcessor;
28  import org.slf4j.Logger;
29  import org.slf4j.LoggerFactory;
30  
31  import java.io.File;
32  import java.net.URL;
33  
34  import static org.junit.Assert.assertNotNull;
35  import static org.junit.Assert.fail;
36  
37  /**
38   * Class to test WorkBibDublinUnQualifiedDocBuilder.
39   *
40   * @author Rajesh Chowdary K
41   */
42  public class WorkBibDublinUnQualifiedDocBuilder_UT extends BaseTestCase {
43  
44      private static final Logger LOG = LoggerFactory.getLogger(WorkBibDublinUnQualifiedDocBuilder_UT.class);
45      private WorkBibDublinUnQualifiedRecord record;
46  
47      /**
48       * @throws java.lang.Exception
49       */
50      @Before
51      public void setUp() throws Exception {
52          String resFile = "/bib/bib/dublin/unqualified/Bib-Bib-DublinUnQ-Test1.xml";
53          URL resource = getClass().getResource(resFile);
54          File file = new File(resource.toURI());
55          String fileContent;
56          fileContent = FileUtils.readFileToString(file);
57          WorkBibDublinUnQualifiedRecordProcessor processor = new WorkBibDublinUnQualifiedRecordProcessor();
58          record = processor.fromXML(fileContent);
59          LOG.info(record.getRequest());
60      }
61  
62      /**
63       * @throws java.lang.Exception
64       */
65      @After
66      public void tearDown() throws Exception {
67      }
68  
69      /**
70       * Test method for {@link org.kuali.ole.docstore.discovery.solr.work.bib.dublin.unqualified.WorkBibDublinUnQualifiedDocBuilder#buildSolrInputDocument(org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.unqualified.OaiDcDoc)}.
71       */
72      @Test
73      public final void testBuildSolrInputDocument() {
74          try {
75              WorkBibDublinUnQualifiedDocBuilder builder = new WorkBibDublinUnQualifiedDocBuilder();
76              for (Record rec : record.getListRecords().getRecords())
77                  for (OaiDcDoc doc : rec.getMetadata().getOaiDcDocs()) {
78                      SolrInputDocument solrDoc = builder.buildSolrInputDocument(doc);
79                      LOG.info(solrDoc.toString());
80                      assertNotNull(solrDoc);
81                  }
82          } catch (Exception e) {
83              LOG.error(e.getMessage() , e);
84              fail("Document Build Failed: " + e.getMessage());
85          }
86      }
87  
88  }