001/* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.ole.docstore.service; 017 018import org.apache.commons.io.FileUtils; 019import org.junit.After; 020import org.junit.Before; 021import org.kuali.ole.BaseTestCase; 022import org.kuali.ole.RepositoryManager; 023import org.kuali.ole.docstore.model.xmlpojo.ingest.Request; 024import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument; 025import org.kuali.ole.docstore.model.xstream.ingest.RequestHandler; 026import org.slf4j.Logger; 027import org.slf4j.LoggerFactory; 028 029import javax.jcr.Session; 030import java.io.File; 031import java.net.URL; 032import java.util.ArrayList; 033import java.util.List; 034 035import static org.junit.Assert.fail; 036 037/** 038 * Class to DocumentIndexer_UT. 039 * 040 * @author Rajesh Chowdary K 041 * @created Feb 23, 2012 042 */ 043public class DocumentIndexer_UT 044 extends BaseTestCase { 045 046 private static final Logger LOG = LoggerFactory.getLogger(DocumentIndexer_UT.class); 047 private DocumentIndexer documentIndexer = new DocumentIndexer(); 048 private List<RequestDocument> reqDocuments = new ArrayList<RequestDocument>(); 049 private Request req; 050 private Session session; 051 052 /** 053 * Method to setUp 054 * 055 * @throws java.lang.Exception 056 */ 057 @Before 058 public void setUp() throws Exception { 059 URL resource = getClass().getResource("/org/kuali/ole/repository/request.xml"); 060 File file = new File(resource.toURI()); 061 String fileContent = FileUtils.readFileToString(file); 062 RequestHandler rh = new RequestHandler(); 063 req = rh.toObject(fileContent); 064 reqDocuments = req.getRequestDocuments(); 065 session = RepositoryManager.getRepositoryManager().getSession(req.getUser(), req.getOperation()); 066 DocumentIngester ingester = new DocumentIngester(); 067 for (RequestDocument doc : reqDocuments) { 068 ingester.ingestBibNLinkedInstanceRequestDocuments(doc, session); 069 } 070 } 071 072 /** 073 * Method to tearDown 074 * 075 * @throws java.lang.Exception 076 */ 077 @After 078 public void tearDown() throws Exception { 079 if (session != null) { 080 session.logout(); 081 } 082 } 083 084 /** 085 * /** 086 * Test method for {@link org.kuali.ole.docstore.service.DocumentIndexer#indexDocuments(java.util.List)}. 087 */ 088 089 public final void testIndexDocuments() { 090 try { 091 documentIndexer.indexDocuments(reqDocuments); 092 } catch (Exception e) { 093 LOG.info(e.getMessage(),e); 094 fail("Failed in indexing : " + e); 095 } 096 097 } 098 099 /** 100 * Method to testIndexDocumentsForBulk 101 */ 102 public final void testIndexDocumentsForBulk() { 103 try { 104 documentIndexer.indexDocumentsForBulk(reqDocuments, true); 105 } catch (Exception e) { 106 LOG.info(e.getMessage(),e); 107 fail("Failed in indexing : " + e); 108 } 109 } 110 111 /** 112 * Test method for {@link org.kuali.ole.docstore.service.DocumentIndexer#indexDocument(org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument)}. 113 */ 114 115 public final void testIndexDocument() { 116 try { 117 documentIndexer.indexDocuments(reqDocuments); 118 } catch (Exception e) { 119 LOG.info(e.getMessage(),e); 120 fail("Failed in indexing : " + e); 121 } 122 } 123 124 /** 125 * Test method for {@link org.kuali.ole.docstore.service.DocumentIndexer#rollbackIndexedData(java.util.List)}. 126 */ 127 128 public final void testRollbackIndexedData() { 129 try { 130 documentIndexer.indexDocuments(reqDocuments); 131 } catch (Exception e) { 132 try { 133 documentIndexer.rollbackIndexedData(reqDocuments); 134 } catch (Exception ex) { 135 LOG.info(e.getMessage() , e); 136 fail("Failed in rolling back of indexing : " + ex); 137 } 138 } 139 140 } 141 142}