1 package org.kuali.ole.docstore.engine.service;
2
3 import org.apache.commons.io.FileUtils;
4 import org.junit.Assert;
5 import org.junit.Before;
6 import org.junit.Ignore;
7 import org.junit.Test;
8 import org.kuali.ole.BaseTestCase;
9 import org.kuali.ole.docstore.common.document.*;
10 import org.kuali.ole.docstore.common.search.*;
11 import org.kuali.ole.docstore.common.service.DocstoreService;
12 import org.kuali.ole.docstore.model.enums.DocCategory;
13 import org.kuali.ole.docstore.model.enums.DocFormat;
14 import org.kuali.ole.docstore.model.enums.DocType;
15 import org.kuali.ole.docstore.service.BeanLocator;
16 import org.kuali.rice.krad.service.BusinessObjectService;
17 import org.mockito.Mock;
18 import org.mockito.MockitoAnnotations;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 import java.io.File;
23
24
25
26
27
28
29
30
31 public class DocstoreService_UT extends BaseTestCase {
32
33 private static final Logger LOG = LoggerFactory.getLogger(DocstoreService_UT.class);
34 DocstoreService docstoreService = BeanLocator.getDocstoreService();
35
36 @Mock
37 private BusinessObjectService businessObjectService;
38
39 @Before
40 public void setUp() throws Exception {
41 super.setUp();
42 MockitoAnnotations.initMocks(this);
43 }
44
45 @Ignore
46 @Test
47 public void testCreateBib() {
48 Bib bib = getBibRecord();
49 docstoreService.createBib(bib);
50 Assert.assertSame(bib.getId(), "123");
51
52
53
54
55
56
57
58
59
60
61 }
62
63 @Ignore
64 @Test
65 public void testCreateHoldings() {
66 Bib bib = getBibRecord();
67 docstoreService.createBib(bib);
68
69 Holdings holdings = getHoldingsRecord();
70 docstoreService.createHoldings(holdings);
71
72 Assert.assertEquals(holdings.getId(), "who-1");
73 }
74
75 @Ignore
76 @Test
77 public void testCreateItem() {
78 Bib bib = getBibRecord();
79 docstoreService.createBib(bib);
80
81 Holdings holdings = getHoldingsRecord();
82 docstoreService.createHoldings(holdings);
83 Item item = getItemRecord();
84 docstoreService.createItem(item);
85 Assert.assertEquals(item.getId(), "wio-1");
86 }
87
88 @Ignore
89 @Test
90 public void testCreateHoldingsTree() {
91 HoldingsTree holdingsTree = getHoldingsTreeRecord();
92
93 Bib bib = getBibRecord();
94 docstoreService.createBib(bib);
95
96 docstoreService.createHoldingsTree(holdingsTree);
97 Assert.assertEquals(holdingsTree.getHoldings().getId(), "who-1");
98 Assert.assertEquals(holdingsTree.getItems().get(0).getId(), "wio-1");
99
100 }
101
102 @Ignore
103 @Test
104 public void testCreateBibTree() {
105 BibTree bibTree = new BibTree();
106 bibTree.setBib(getBibRecord());
107 bibTree.getHoldingsTrees().add(getHoldingsTreeRecord());
108 docstoreService.createBibTree(bibTree);
109 Assert.assertEquals(bibTree.getBib().getId(), "123");
110 HoldingsTree holdingsTree = bibTree.getHoldingsTrees().get(0);
111 Assert.assertEquals(holdingsTree.getHoldings().getId(), "who-1");
112 Assert.assertEquals(holdingsTree.getItems().get(0).getId(), "wio-1");
113
114 }
115
116 @Ignore
117 @Test
118 public void testDeleteBib() {
119 Bib bib = getBibRecord();
120 docstoreService.deleteBib(bib.getId());
121 }
122
123 @Ignore
124 @Test
125 public void testDeleteHoldings() {
126 Holdings holdings = getHoldingsRecord();
127 docstoreService.deleteHoldings(holdings.getId());
128 }
129
130 @Ignore
131 @Test
132 public void testDeleteItem() {
133 Item item = getItemRecord();
134 docstoreService.deleteItem(item.getId());
135 }
136
137
138 private HoldingsTree getHoldingsTreeRecord() {
139 HoldingsTree holdingsTree = new HoldingsTree();
140 holdingsTree.setHoldings(getHoldingsRecord());
141 holdingsTree.getItems().add(getItemRecord());
142 return holdingsTree;
143 }
144
145 private Item getItemRecord() {
146 Item item = new ItemOleml();
147 item.setCategory(DocCategory.WORK.getCode());
148 item.setType(DocType.ITEM.getCode());
149 item.setFormat(DocFormat.OLEML.getCode());
150 return item;
151 }
152
153 private Holdings getHoldingsRecord() {
154 Holdings holdings = new PHoldingsOleml();
155 holdings.setCategory(DocCategory.WORK.getCode());
156 holdings.setType(DocType.HOLDINGS.getCode());
157 holdings.setFormat(DocFormat.OLEML.getCode());
158 return holdings;
159 }
160
161
162 private Bib getBibRecord() {
163 Bib bib = new BibMarc();
164 bib.setCategory(DocCategory.WORK.getCode());
165 bib.setType(DocType.BIB.getCode());
166 bib.setFormat(DocFormat.MARC.getCode());
167 bib.setContent("<collection xmlns=\"http://www.loc.gov/MARC21/slim\">\n" +
168 " <record>\n" +
169 " <leader>#####nam#a22######a#4500</leader>\n" +
170 "\t<controlfield tag=\"001\">3</controlfield>\n" +
171 " <controlfield tag=\"003\">OCoLC</controlfield>\n" +
172 " <controlfield tag=\"005\">20090213152530.7</controlfield>\n" +
173 "\t\t<controlfield tag=\"008\">131031s########xxu###########000#0#eng#d</controlfield>\n" +
174 " <datafield tag=\"035\" ind1=\" \" ind2=\" \">\n" +
175 " <subfield code=\"a\">(OCoLC)ocm62378465</subfield>\n" +
176 " </datafield>\n" +
177 " <datafield tag=\"040\" ind1=\" \" ind2=\" \">\n" +
178 " <subfield code=\"a\">DLC</subfield>\n" +
179 "\t\t\t <subfield code=\"c\">DLC</subfield>\n" +
180 "\t\t\t <subfield code=\"d\">DLC</subfield>\n" +
181 "\t\t\t <subfield code=\"d\">HLS</subfield>\n" +
182 "\t\t\t <subfield code=\"d\">IUL</subfield>\n" +
183 " </datafield>\n" +
184 " <datafield tag=\"022\" ind1=\" \" ind2=\" \">\n" +
185 " <subfield code=\"a\">1729-1070|20</subfield>\n" +
186 " </datafield>\n" +
187 " <datafield tag=\"029\" ind1=\"1\" ind2=\" \">\n" +
188 " <subfield code=\"a\">AU@|b000040176476</subfield>\n" +
189 "\t\t\t<subfield code=\"b\">000040176476</subfield>\n" +
190 " </datafield>\n" +
191 " <datafield tag=\"037\" ind1=\" \" ind2=\" \">\n" +
192 " <subfield code=\"b\">The Managing Editor, BIAC Journal, P.O. Box 10026, Gaborone, Botswana</subfield>\n" +
193 " </datafield>\n" +
194 " <datafield tag=\"042\" ind1=\" \" ind2=\" \">\n" +
195 " <subfield code=\"a\">lc</subfield>\n" +
196 " </datafield>\n" +
197 " <datafield tag=\"043\" ind1=\"1\" ind2=\"0\">\n" +
198 " <subfield code=\"a\">f-bs---</subfield>\n" +
199 " </datafield>\n" +
200 " <datafield tag=\"050\" ind1=\"0\" ind2=\"0\">\n" +
201 " <subfield code=\"a\">HD70.B55|bB53</subfield>\n" +
202 " </datafield>\n" +
203 " <datafield tag=\"049\" ind1=\" \" ind2=\" \">\n" +
204 " <subfield code=\"a\">IULA</subfield>\n" +
205 " </datafield>\n" +
206 " <datafield tag=\"210\" ind1=\"1\" ind2=\" \">\n" +
207 " <subfield code=\"a\">BIAC j.</subfield>\n" +
208 " </datafield>\n" +
209 " <datafield tag=\"222\" ind1=\" \" ind2=\"0\">\n" +
210 " <subfield code=\"a\">BIAC journal</subfield>\n" +
211 " </datafield>\n" +
212 " <datafield tag=\"245\" ind1=\"0\" ind2=\"0\">\n" +
213 " <subfield code=\"a\">BIAC journal</subfield>\n" +
214 " </datafield>\n" +
215 " <datafield tag=\"246\" ind1=\"1\" ind2=\"3\">\n" +
216 " <subfield code=\"a\">Botswana Institute of Administration and Commerce journal</subfield>\n" +
217 " </datafield>\n" +
218 " <datafield tag=\"260\" ind1=\" \" ind2=\" \">\n" +
219 " <subfield code=\"a\">Gaborone, Botswana :|bBotswana Institute of Administration and Commerce</subfield>\n" +
220 "\t\t\t<subfield code=\"b\">Botswana Institute of Administration and Commerce</subfield>\n" +
221 " </datafield>\n" +
222 " <datafield tag=\"300\" ind1=\" \" ind2=\" \">\n" +
223 " <subfield code=\"a\">v. ;</subfield>\n" +
224 "\t\t\t<subfield code=\"c\">24 cm.</subfield>\n" +
225 " </datafield>\n" +
226 "\t\t<datafield tag=\"300\" ind1=\" \" ind2=\" \">\n" +
227 " <subfield code=\"a\">v. ;</subfield>\n" +
228 "\t\t\t<subfield code=\"c\">24 cm.</subfield>\n" +
229 " </datafield>\n" +
230 "\t\t<datafield tag=\"300\" ind1=\" \" ind2=\" \">\n" +
231 " <subfield code=\"a\">v. ;</subfield>\n" +
232 "\t\t\t<subfield code=\"c\">24 cm.</subfield>\n" +
233 " </datafield>\n" +
234 "\t\t<datafield tag=\"310\" ind1=\" \" ind2=\" \">\n" +
235 " <subfield code=\"a\">Semiannual</subfield>\n" +
236 " </datafield>\n" +
237 "\t\t<datafield tag=\"362\" ind1=\"1\" ind2=\" \">\n" +
238 " <subfield code=\"a\"> Began in 2004.</subfield>\n" +
239 " </datafield>\n" +
240 "\t\t<datafield tag=\"500\" ind1=\" \" ind2=\" \">\n" +
241 " <subfield code=\"a\">Description based on: Vol. 1, no. 1 (May. 2004); title from cover.</subfield>\n" +
242 " </datafield>\n" +
243 "\t\t<datafield tag=\"500\" ind1=\" \" ind2=\" \">\n" +
244 " <subfield code=\"a\">Latest issue consulted: Vol. 3, no. 1 (May 2006).</subfield>\n" +
245 " </datafield>\n" +
246 "\t\t<datafield tag=\"650\" ind1=\"0\" ind2=\" \">\n" +
247 " <subfield code=\"a\">Industrial management</subfield>\n" +
248 "\t\t\t<subfield code=\"z\">Botswana</subfield>\n" +
249 "\t\t\t<subfield code=\"v\">Periodicals.</subfield>\n" +
250 " </datafield>\n" +
251 "\t\t<datafield tag=\"650\" ind1=\"0\" ind2=\" \">\n" +
252 " <subfield code=\"a\">Occupational training</subfield>\n" +
253 "\t\t\t<subfield code=\"z\">Botswana</subfield>\n" +
254 "\t\t\t<subfield code=\"v\">Periodicals.</subfield>\n" +
255 " </datafield>\n" +
256 "\t\t<datafield tag=\"710\" ind1=\"2\" ind2=\" \">\n" +
257 " <subfield code=\"a\">Botswana Institute of Administration and Commerce.</subfield>\n" +
258 " </datafield>\n" +
259 "\t\t<datafield tag=\"850\" ind1=\" \" ind2=\" \">\n" +
260 " <subfield code=\"a\">DLC</subfield>\n" +
261 " </datafield>\n" +
262 "\t\t<datafield tag=\"891\" ind1=\"2\" ind2=\"0\">\n" +
263 " <subfield code=\"a\">9853|81.1</subfield>\n" +
264 "\t\t\t<subfield code=\"a\">v.</subfield>\n" +
265 "\t\t\t<subfield code=\"b\">no</subfield>\n" +
266 "\t\t\t<subfield code=\"u\">2</subfield>\n" +
267 "\t\t\t<subfield code=\"v\">r</subfield>\n" +
268 "\t\t\t<subfield code=\"i\">(year)</subfield>\n" +
269 "\t\t\t<subfield code=\"j\">(month)</subfield>\n" +
270 "\t\t\t<subfield code=\"w\">f</subfield>\n" +
271 "\t\t\t<subfield code=\"x\">05</subfield>\n" +
272 " </datafield>\n" +
273 "\t\t<datafield tag=\"891\" ind1=\"4\" ind2=\"1\">\n" +
274 " <subfield code=\"a\">9863|81.1</subfield>\n" +
275 "\t\t\t<subfield code=\"a\">1</subfield>\n" +
276 "\t\t\t<subfield code=\"b\">1</subfield>\n" +
277 "\t\t\t<subfield code=\"i\">2004</subfield>\n" +
278 "\t\t\t<subfield code=\"j\">05</subfield>\n" +
279 " </datafield>\n" +
280 "\t\t<datafield tag=\"596\" ind1=\" \" ind2=\" \">\n" +
281 " <subfield code=\"a\">1</subfield>\n" +
282 " </datafield>\n" +
283 " </record>\n" +
284 "</collection>");
285 return bib;
286 }
287
288 @Ignore
289 @Test
290 public void testRetrieveBib() {
291 String bibId = "123";
292 Bib bib = docstoreService.retrieveBib(bibId);
293 Assert.assertNotNull(bibId);
294 }
295
296 @Ignore
297 @Test
298 public void testRetrieveHoldings() {
299 String holdingsId = "who-1";
300 Holdings holdings = docstoreService.retrieveHoldings(holdingsId);
301 Assert.assertNotNull(holdingsId);
302 }
303
304 @Ignore
305 @Test
306 public void testRetrieveItem() {
307 String itemId = "wio-1";
308 Item item = docstoreService.retrieveItem(itemId);
309 Assert.assertNotNull(itemId);
310 }
311
312 @Ignore
313 @Test
314 public void testRetrieveHoldingsTree() {
315 String holdingsId = "who-1";
316 HoldingsTree holdingsTree = docstoreService.retrieveHoldingsTree(holdingsId);
317 Assert.assertNotNull(holdingsId);
318 }
319
320 @Ignore
321 @Test
322 public void testRetrieveBibTree() {
323 String bibId = "123";
324 BibTree bibTree = docstoreService.retrieveBibTree(bibId);
325 Assert.assertNotNull(bibId);
326 }
327
328 @Ignore
329 @Test
330 public void testSearch1() {
331 SearchParams searchParams = getSearchParams1();
332 SearchResponse searchResponse = docstoreService.search(searchParams);
333 Assert.assertNotNull(searchResponse);
334 }
335
336 @Ignore
337 @Test
338 public void testSearch2() {
339 SearchParams searchParams = getSearchParams2();
340 SearchResponse searchResponse = docstoreService.search(searchParams);
341 Assert.assertNotNull(searchResponse);
342 }
343
344 @Ignore
345 @Test
346 public void testSearch3() {
347 SearchParams searchParams = getSearchParams3();
348 SearchResponse searchResponse = docstoreService.search(searchParams);
349 Assert.assertNotNull(searchResponse);
350 }
351
352 public SearchParams getSearchParams1() {
353 SearchParams searchParams = new SearchParams();
354 String xml = getXmlAsString("/org/kuali/ole/search/SearchParams1.xml");
355 return (SearchParams) searchParams.deserialize(xml);
356 }
357
358 public SearchParams getSearchParams2() {
359 SearchParams searchParams = new SearchParams();
360 String xml = getXmlAsString("/org/kuali/ole/search/SearchParams2.xml");
361 return (SearchParams) searchParams.deserialize(xml);
362 }
363
364 public SearchParams getSearchParams3() {
365 SearchParams searchParams = new SearchParams();
366 String xml = getXmlAsString("/org/kuali/ole/search/SearchParams3.xml");
367 return (SearchParams) searchParams.deserialize(xml);
368 }
369
370 public String getXmlAsString(String filePath) {
371 String input ="";
372 File file = null;
373 try {
374 file = new File(getClass().getResource(filePath).toURI());
375 input = FileUtils.readFileToString(file);
376 } catch (Exception e) {
377 LOG.error("Exception : ", e);
378 }
379 return input;
380 }
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409 @Ignore
410 @Test
411 public void testUpdateBib() {
412 Bib bib = getBibRecord();
413 bib.setContent("mock update content");
414 docstoreService.updateBib(bib);
415 }
416
417 @Ignore
418 @Test
419 public void testUpdateHoldings() {
420 Holdings holdings = getHoldingsRecord();
421 holdings.setContent("mock update content");
422 docstoreService.updateHoldings(holdings);
423 }
424
425 @Ignore
426 @Test
427 public void testUpdateItem() {
428 Item item = getItemRecord();
429 item.setContent("mock update content");
430 docstoreService.updateItem(item);
431 }
432
433 }