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 }
93 catch (Exception e) {
94 LOG.info(e.getMessage());
95 fail("Failed in indexing : " + e);
96 }
97
98 }
99
100
101
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
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
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 }