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.service;
17  
18  import org.apache.commons.io.FileUtils;
19  import org.junit.After;
20  import org.junit.Before;
21  import org.kuali.ole.BaseTestCase;
22  import org.kuali.ole.RepositoryManager;
23  import org.kuali.ole.docstore.model.xmlpojo.ingest.Request;
24  import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
25  import org.kuali.ole.docstore.model.xstream.ingest.RequestHandler;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  import javax.jcr.Session;
30  import java.io.File;
31  import java.net.URL;
32  import java.util.ArrayList;
33  import java.util.List;
34  
35  import static org.junit.Assert.fail;
36  
37  /**
38   * Class to DocumentIndexer_UT.
39   *
40   * @author Rajesh Chowdary K
41   * @created Feb 23, 2012
42   */
43  public class DocumentIndexer_UT
44          extends BaseTestCase {
45  
46      private static final Logger                LOG             = LoggerFactory.getLogger(DocumentIndexer_UT.class);
47      private              DocumentIndexer       documentIndexer = new DocumentIndexer();
48      private              List<RequestDocument> reqDocuments    = new ArrayList<RequestDocument>();
49      private Request req;
50      private Session session;
51  
52      /**
53       * Method to setUp
54       *
55       * @throws java.lang.Exception
56       */
57      @Before
58      public void setUp() throws Exception {
59          URL resource = getClass().getResource("/org/kuali/ole/repository/request.xml");
60          File file = new File(resource.toURI());
61          String fileContent = FileUtils.readFileToString(file);
62          RequestHandler rh = new RequestHandler();
63          req = rh.toObject(fileContent);
64          reqDocuments = req.getRequestDocuments();
65          session = RepositoryManager.getRepositoryManager().getSession(req.getUser(), req.getOperation());
66          DocumentIngester ingester = new DocumentIngester();
67          for (RequestDocument doc : reqDocuments) {
68              ingester.ingestBibNLinkedInstanceRequestDocuments(doc, session);
69          }
70      }
71  
72      /**
73       * Method to tearDown
74       *
75       * @throws java.lang.Exception
76       */
77      @After
78      public void tearDown() throws Exception {
79          if (session != null) {
80              session.logout();
81          }
82      }
83  
84      /**
85       * /**
86       * Test method for {@link org.kuali.ole.docstore.service.DocumentIndexer#indexDocuments(java.util.List)}.
87       */
88  
89      public final void testIndexDocuments() {
90          try {
91              documentIndexer.indexDocuments(reqDocuments);
92          }
93          catch (Exception e) {
94              LOG.info(e.getMessage());
95              fail("Failed in indexing : " + e);
96          }
97  
98      }
99  
100     /**
101      * Method to testIndexDocumentsForBulk
102      */
103     public final void testIndexDocumentsForBulk() {
104         try {
105             documentIndexer.indexDocumentsForBulk(reqDocuments, true);
106         }
107         catch (Exception e) {
108             LOG.info(e.getMessage());
109             fail("Failed in indexing : " + e);
110         }
111     }
112 
113     /**
114      * Test method for {@link org.kuali.ole.docstore.service.DocumentIndexer#indexDocument(org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument)}.
115      */
116 
117     public final void testIndexDocument() {
118         try {
119             documentIndexer.indexDocuments(reqDocuments);
120         }
121         catch (Exception e) {
122             LOG.info(e.getMessage());
123             fail("Failed in indexing : " + e);
124         }
125     }
126 
127     /**
128      * Test method for {@link org.kuali.ole.docstore.service.DocumentIndexer#rollbackIndexedData(java.util.List)}.
129      */
130 
131     public final void testRollbackIndexedData() {
132         try {
133             documentIndexer.indexDocuments(reqDocuments);
134         }
135         catch (Exception e) {
136             try {
137                 documentIndexer.rollbackIndexedData(reqDocuments);
138             }
139             catch (Exception ex) {
140                 LOG.info(e.getMessage());
141                 fail("Failed in rolling back of indexing : " + ex);
142             }
143         }
144 
145     }
146 
147 }