1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
39
40
41
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
54
55
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
74
75
76
77 @After
78 public void tearDown() throws Exception {
79 if (session != null) {
80 session.logout();
81 }
82 }
83
84
85
86
87
88
89 public final void testIndexDocuments() {
90 try {
91 documentIndexer.indexDocuments(reqDocuments);
92 } catch (Exception e) {
93 LOG.info(e.getMessage(),e);
94 fail("Failed in indexing : " + e);
95 }
96
97 }
98
99
100
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
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
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 }