View Javadoc
1   package org.kuali.ole;
2   
3   import org.apache.commons.io.FileUtils;
4   import org.apache.commons.lang.StringUtils;
5   import org.apache.solr.client.solrj.SolrQuery;
6   import org.apache.solr.client.solrj.SolrRequest;
7   import org.apache.solr.client.solrj.SolrServer;
8   import org.apache.solr.client.solrj.SolrServerException;
9   import org.apache.solr.client.solrj.response.QueryResponse;
10  import org.junit.Assert;
11  import org.junit.Test;
12  import org.kuali.ole.docstore.common.document.*;
13  import org.kuali.ole.docstore.common.document.HoldingsTree;
14  import org.kuali.ole.docstore.common.document.Item;
15  import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecord;
16  import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecords;
17  import org.kuali.ole.docstore.common.document.content.bib.marc.DataField;
18  import org.kuali.ole.docstore.common.document.content.bib.marc.SubField;
19  import org.kuali.ole.docstore.common.document.content.bib.marc.xstream.BibMarcRecordProcessor;
20  import org.kuali.ole.docstore.common.document.content.instance.*;
21  import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
22  import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
23  import org.kuali.ole.docstore.common.exception.DocstoreException;
24  import org.kuali.ole.docstore.common.exception.DocstoreResources;
25  import org.kuali.ole.docstore.common.exception.DocstoreValidationException;
26  import org.kuali.ole.docstore.common.search.*;
27  import org.kuali.ole.docstore.common.service.DocstoreService;
28  import org.kuali.ole.docstore.common.util.ParseXml;
29  import org.kuali.ole.docstore.discovery.service.SolrServerManager;
30  import org.kuali.ole.docstore.engine.service.index.solr.BibConstants;
31  import org.kuali.ole.docstore.engine.service.search.DocstoreSolrSearchService;
32  import org.kuali.ole.docstore.engine.service.storage.rdbms.RdbmsItemDocumentManager;
33  import org.kuali.ole.docstore.model.enums.DocCategory;
34  import org.kuali.ole.docstore.model.enums.DocFormat;
35  import org.kuali.ole.docstore.model.enums.DocType;
36  import org.kuali.ole.docstore.service.BeanLocator;
37  
38  import java.io.File;
39  import java.text.SimpleDateFormat;
40  import java.util.*;
41  
42  /**
43   * Created with IntelliJ IDEA.
44   * User: sambasivam
45   * Date: 12/16/13
46   * Time: 6:17 PM
47   * To change this template use File | Settings | File Templates.
48   */
49  
50  
51  
52  public class DocstoreService_UT extends SpringBaseTestCase {
53  
54      DocstoreService docstoreService = BeanLocator.getDocstoreService();
55  
56      @Test
57      public void testCreateBib() {
58          String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml");
59          Bib bib = new BibMarc();
60          bib = (Bib) bib.deserialize(xml);
61          bib.setId(null);
62          docstoreService.createBib(bib);
63          Assert.assertNotNull(bib.getId());
64      }
65  
66      @Test
67      public void testCreateBibFails() {
68          String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml");
69          Bib bib = new BibMarc();
70          bib = (Bib) bib.deserialize(xml);
71          bib.setId(null);
72          docstoreService.createBib(bib);
73  
74          String xml2 = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml");
75          Bib bib2 = new BibMarc();
76          bib2 = (Bib) bib2.deserialize(xml2);
77          bib2.setId(bib.getId());
78          try {
79              docstoreService.createBib(bib2);
80          }
81          catch (Exception e) {
82              DocstoreException docstoreException = (DocstoreException) e;
83              if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
84                  Assert.assertNotNull(docstoreException.getErrorCode());
85              } else {
86                  Assert.assertNotNull(e.getMessage());
87              }
88          }
89      }
90  
91      @Test
92      public void testCreatePHoldings() {
93          String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml");
94          Bib bib = new BibMarc();
95          bib = (Bib) bib.deserialize(xml);
96          bib.setId(null);
97          docstoreService.createBib(bib);
98          Assert.assertNotNull(bib.getId());
99  
100         xml = getXmlAsString("/org/kuali/ole/documents/PHoldings1.xml");
101         Holdings holdings = new PHoldings();
102         holdings = (PHoldings) holdings.deserialize(xml);
103         holdings.setBib(bib);
104         docstoreService.createHoldings(holdings);
105 
106         Assert.assertNotNull(holdings.getId());
107     }
108 
109     @Test
110     public void testCreatePHoldingsFails() {
111         Bib bib = getBibRecord();
112         docstoreService.createBib(bib);
113         Holdings holdings = getHoldingsRecord();
114         holdings.setBib(null);
115         try {
116             docstoreService.createHoldings(holdings);
117         }
118         catch (Exception e) {
119             DocstoreException docstoreException = (DocstoreException) e;
120             if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
121                 Assert.assertNotNull(docstoreException.getErrorCode());
122             } else {
123                 Assert.assertNotNull(e.getMessage());
124             }
125         }
126     }
127 
128 
129     @Test
130     public void testCreateEHoldings() {
131         String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml");
132         Bib bib = new BibMarc();
133         bib = (Bib) bib.deserialize(xml);
134         bib.setId(null);
135         docstoreService.createBib(bib);
136         Assert.assertNotNull(bib.getId());
137 
138         xml = getXmlAsString("/org/kuali/ole/documents/EHoldings1.xml");
139         Holdings holdings = new EHoldings();
140         holdings = (PHoldings) holdings.deserialize(xml);
141         holdings.setBib(bib);
142         docstoreService.createHoldings(holdings);
143 
144         Assert.assertNotNull(holdings.getId());
145     }
146 
147     @Test
148     public void testCreateEHoldingsFails() {
149         String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml");
150         Bib bib = new BibMarc();
151         bib = (Bib) bib.deserialize(xml);
152         bib.setId(null);
153         docstoreService.createBib(bib);
154         Assert.assertNotNull(bib.getId());
155 
156         xml = getXmlAsString("/org/kuali/ole/documents/EHoldings1.xml");
157         Holdings holdings = new EHoldings();
158         holdings = (PHoldings) holdings.deserialize(xml);
159         holdings.setBib(null);
160         try {
161             docstoreService.createHoldings(holdings);
162         }
163         catch (Exception e) {
164             DocstoreException docstoreException = (DocstoreException) e;
165             if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
166                 Assert.assertNotNull(docstoreException.getErrorCode());
167             } else {
168                 Assert.assertNotNull(e.getMessage());
169             }
170         }
171     }
172     @Test
173     public void testCreateItem() {
174         Bib bib = getBibRecord();
175         docstoreService.createBib(bib);
176 
177         Holdings holdings = getHoldingsRecord();
178         holdings.setBib(bib);
179         docstoreService.createHoldings(holdings);
180         Item item = getItemRecord();
181         item.setHolding(holdings);
182         docstoreService.createItem(item);
183         Assert.assertNotNull(item.getId());
184     }
185 
186     @Test
187     public void testCreateItemFails() {
188         Bib bib = getBibRecord();
189         docstoreService.createBib(bib);
190 
191         Holdings holdings = getHoldingsRecord();
192         holdings.setBib(bib);
193         docstoreService.createHoldings(holdings);
194         Item item = getItemRecord();
195         item.setHolding(null);
196          try {
197             docstoreService.createItem(item);
198          }
199          catch (Exception e) {
200             DocstoreException docstoreException = (DocstoreException) e;
201             if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
202                  Assert.assertNotNull(docstoreException.getErrorCode());
203             }else {
204                  Assert.assertNotNull(e.getMessage());
205              }
206          }
207 
208     }
209 
210     @Test
211     public void testCreateHoldingsTree() {
212         HoldingsTree holdingsTree = getHoldingsTreeRecord();
213         Bib bib = getBibRecord();
214         docstoreService.createBib(bib);
215         holdingsTree.getHoldings().setBib(bib);
216         docstoreService.createHoldingsTree(holdingsTree);
217         Assert.assertNotNull(holdingsTree.getHoldings().getId());
218         Assert.assertNotNull(holdingsTree.getItems().get(0).getId());
219         Holdings holdings = docstoreService.retrieveHoldings(holdingsTree.getHoldings().getId());
220         Item item = docstoreService.retrieveItem(holdingsTree.getItems().get(0).getId());
221         Assert.assertEquals(holdingsTree.getHoldings().getId(), holdings.getId());
222         Assert.assertEquals(holdingsTree.getItems().get(0).getId(), item.getId());
223     }
224 
225 
226     @Test
227     public void testCreateHoldingsTreeFails() {
228         HoldingsTree holdingsTree = getHoldingsTreeRecord();
229         holdingsTree.getHoldings().setBib(null);
230 
231 
232         try {
233             docstoreService.createHoldingsTree(holdingsTree);
234         }
235         catch (Exception e) {
236             DocstoreException docstoreException = (DocstoreException) e;
237             if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
238                 Assert.assertNotNull(docstoreException.getErrorCode());
239             }else {
240                 Assert.assertNotNull(e.getMessage());
241             }
242         }
243 
244     }
245 
246     @Test
247     public void testCreateBibTree() {
248         BibTree bibTree = getBibTree();
249         docstoreService.createBibTree(bibTree);
250         Assert.assertNotNull(bibTree.getBib().getId());
251         HoldingsTree holdingsTree = bibTree.getHoldingsTrees().get(0);
252         Assert.assertNotNull(holdingsTree.getHoldings().getId());
253         Assert.assertNotNull(holdingsTree.getItems().get(0).getId());
254         Map map = new HashMap();
255         map.put(BibConstants.DOC_TYPE, "bibliographic");
256         map.put("ID", bibTree.getBib().getId());
257         BibTree retrievedBibTree = docstoreService.findBibTree(map);
258         Map holdingsMap = new HashMap();
259         holdingsMap.put("ID", holdingsTree.getHoldings().getId());
260         holdingsMap.put(BibConstants.DOC_TYPE, "holdings");
261         HoldingsTree retrievedHoldingsTree = docstoreService.findHoldingsTree(holdingsMap);
262         Assert.assertEquals(bibTree.getBib().getId(), retrievedBibTree.getBib().getId());
263         Assert.assertEquals(holdingsTree.getHoldings().getId(), retrievedHoldingsTree.getHoldings().getId());
264     }
265 
266     @Test
267     public void testCreateBibTreeFails() {
268         BibTree bibTree = getBibTree();
269         docstoreService.createBibTree(bibTree);
270 
271         BibTree bibTree2 = getBibTree();
272         bibTree2.getBib().setId(bibTree.getBib().getId());
273 
274 
275         try {
276             docstoreService.createBibTree(bibTree2);
277         }
278         catch (Exception e) {
279             DocstoreException docstoreException = (DocstoreException) e;
280             if (org.apache.commons.lang3.StringUtils.isNotEmpty(docstoreException.getErrorCode())) {
281                 Assert.assertNotNull(docstoreException.getErrorCode());
282             }else {
283                 Assert.assertNotNull(e.getMessage());
284             }
285         }
286 
287     }
288 
289     private HoldingsTree getHoldingsTreeRecord() {
290         HoldingsTree holdingsTree = new HoldingsTree();
291         holdingsTree.setHoldings(getHoldingsRecord());
292         List<Item> items = new ArrayList<Item>(0);
293         Item item = getItemRecord();
294         item.setHolding(holdingsTree.getHoldings());
295         items.add(item);
296         holdingsTree.getItems().addAll(items);
297         return holdingsTree;
298     }
299 
300     private Item getItemRecord() {
301         Item item = new ItemOleml();
302         item.setCategory("work");
303         item.setType("item");
304         item.setFormat("oleml");
305         org.kuali.ole.docstore.common.document.content.instance.Item item1 = new org.kuali.ole.docstore.common.document.content.instance.Item();
306         item1.setVolumeNumber("12345");
307         ShelvingScheme shelvingScheme = new ShelvingScheme();
308         shelvingScheme.setCodeValue("LCC");
309 
310         CallNumber callNumber = new CallNumber();
311         callNumber.setNumber("1234");
312         callNumber.setShelvingScheme(shelvingScheme);
313         item1.setCallNumber(callNumber);
314         item1.setChronology("1234");
315         item1.setEnumeration("en");
316         item1.setBarcodeARSL("bararsl");
317         Location location = new Location();
318         LocationLevel locationLevel1 = new LocationLevel();
319         locationLevel1.setName("ARCH");
320         locationLevel1.setLevel("1");
321         LocationLevel locationLevel2 = new LocationLevel();
322         locationLevel2.setName("PA");
323         locationLevel2.setLevel("2");
324         location.setLocationLevel(locationLevel1);
325         item1.setLocation(location);
326         item.setContent(new ItemOlemlRecordProcessor().toXML(item1));
327         return item;
328     }
329 
330 
331     @Test
332     public void testRetrieveBib() {
333 //        Bib bib = getBibRecord();
334 //        docstoreService.createBib(bib);
335         Bib retrievedBib = docstoreService.retrieveBib("wbm-10000001");
336         Assert.assertNotNull(retrievedBib);
337 //        Assert.assertEquals(bib.getId(), retrievedBib.getId());
338     }
339 
340     @Test
341     public void testRetrieveBibFails() {
342 
343        Bib retrievedBib = null;
344        String bibId = "";
345         try {
346             retrievedBib = docstoreService.retrieveBib(bibId);
347         }
348         catch (Exception e) {
349             DocstoreException docstoreException = new DocstoreValidationException(DocstoreResources.BIB_ID_NOT_FOUND, DocstoreResources.BIB_ID_NOT_FOUND);
350             docstoreException.addErrorParams("bibId", bibId );
351             throw docstoreException;
352         }
353     }
354 
355     @Test
356     public void testRetrieveBibs() {
357         Bib bib = getBibRecord();
358         docstoreService.createBib(bib);
359         List<String> bibIds = new ArrayList<String>();
360         bibIds.add(bib.getId());
361         List<Bib> retrievedBibs = docstoreService.retrieveBibs(bibIds);
362         Assert.assertNotNull(retrievedBibs);
363         Assert.assertEquals(bib.getId(), retrievedBibs.get(0).getId());
364 
365     }
366 
367     @Test
368     public void testUpdateBib() {
369         Bib bib = getBibRecord();
370         docstoreService.createBib(bib);
371         Bib retrievedBib = docstoreService.retrieveBib(bib.getId());
372         Assert.assertNotNull(retrievedBib);
373         updateContent(retrievedBib);
374         setDate(retrievedBib);
375         docstoreService.updateBib(retrievedBib);
376         retrievedBib = docstoreService.retrieveBib(retrievedBib.getId());
377         if (bib.getId().equalsIgnoreCase(retrievedBib.getId()))
378             Assert.assertEquals("The Alchemist", retrievedBib.getTitle());
379         else
380             Assert.fail();
381     }
382 
383     @Test
384     public void testUpdateBibs() {
385         Bib bib = getBibRecord();
386         docstoreService.createBib(bib);
387         List<String> bibIds = new ArrayList<String>();
388         bibIds.add(bib.getId());
389         Bib retrievedBib = docstoreService.retrieveBib(bib.getId());
390         Assert.assertNotNull(retrievedBib);
391         updateContent(retrievedBib);
392         setDate(retrievedBib);
393         docstoreService.updateBib(retrievedBib);
394         List<Bib> bibs = new ArrayList<Bib>();
395         bibs.add(retrievedBib);
396         docstoreService.updateBibs(bibs);
397         retrievedBib = docstoreService.retrieveBib(retrievedBib.getId());
398         if (bib.getId().equalsIgnoreCase(retrievedBib.getId()))
399             Assert.assertEquals("The Alchemist", retrievedBib.getTitle());
400         else
401             Assert.fail();
402     }
403 
404     @Test
405     public void testRetrieveHoldings() {
406         String holdingsId = "";
407         Holdings holdings = docstoreService.retrieveHoldings(holdingsId);
408         OleHoldings oleHoldings = (OleHoldings) holdings.getContentObject();
409         Assert.assertNotNull(holdings);
410     }
411  @Test
412     public void testRetrieveHoldingsFails() {
413         String holdingsId = "";
414      Holdings holdings = null;
415      try {
416         holdings = docstoreService.retrieveHoldings(holdingsId);
417      }
418      catch (Exception e) {
419          DocstoreException docstoreException = new DocstoreValidationException(DocstoreResources.HOLDING_ID_NOT_FOUND, DocstoreResources.HOLDING_ID_NOT_FOUND);
420          docstoreException.addErrorParams("holdingsId", holdingsId );
421          throw docstoreException;
422      }
423 
424     }
425 
426     @Test
427     public void testRetrieveItem() {
428         String itemId = "";
429         Item item = docstoreService.retrieveItem(itemId);
430         item.getCallNumber();
431         item.getHolding().getBib().getAuthor();
432         Assert.assertNotNull(item);
433     }
434   @Test
435     public void testRetrieveItemFails() {
436         String itemId = null;
437       Item item = null;
438       try {
439         item= docstoreService.retrieveItem(itemId);
440       }
441       catch (Exception e) {
442           DocstoreException docstoreException = new DocstoreValidationException(DocstoreResources.ITEM_ID_NOT_FOUND, DocstoreResources.ITEM_ID_NOT_FOUND);
443           docstoreException.addErrorParams("itemId", itemId );
444           throw docstoreException;
445       }
446     }
447 
448     @Test
449     public void testRetrieveItems() {
450         List<String> itemIds = new ArrayList<String>();
451         itemIds.add("1");
452         itemIds.add("2");
453         List<Item> items = docstoreService.retrieveItems(itemIds);
454         for (Item item : items) {
455             item.getCallNumber();
456             item.getHolding().getBib().getAuthor();
457             Assert.assertNotNull(item);
458         }
459     }
460 
461     @Test
462     public void testRetrieveHoldingsTree() {
463         String holdingsId = "";
464         HoldingsTree holdingsTree = docstoreService.retrieveHoldingsTree(holdingsId);
465         Assert.assertNotNull(holdingsTree);
466     }
467 
468     @Test
469     public void testRetrieveBibTree() {
470         String bibId = "wbm-10000001";
471         BibTree bibTree = docstoreService.retrieveBibTree(bibId);
472         Assert.assertNotNull(bibTree);
473     }
474 
475     @Test
476     public void testSortHoldings() {
477         String xml = getXmlAsString("/org/kuali/ole/documents/BibTree1.xml");
478         BibTree bibTree = new BibTree();
479         String strHoldings = new String();
480         bibTree = (BibTree) bibTree.deserialize(xml);
481 
482         docstoreService.createBibTree(bibTree);
483         HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
484         System.out.println("BEFORE SORTING HOLDINGS:");
485         System.out.println("HOLDINGS : Loc | ShlOrd");
486         for(HoldingsTree holdingsTree :bibTree.getHoldingsTrees()){
487             OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdingsTree.getHoldings().getContent());
488 //            System.out.println(strHoldings.format("%s | %s", Holdings.buildLocationString(oleHoldings.getLocation()), oleHoldings.getCallNumber().getShelvingOrder().getCodeValue() + "\n"));
489         }
490         bibTree = docstoreService.retrieveBibTree(bibTree.getBib().getId());
491         System.out.println("AFTER SORTING HOLDINGS:");
492         System.out.println("HOLDINGS : Loc | ShlOrd ");
493         for(HoldingsTree holdingsTree :bibTree.getHoldingsTrees()){
494             OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdingsTree.getHoldings().getContent());
495 //            System.out.println(strHoldings.format("%s | %s", Holdings.buildLocationString(oleHoldings.getLocation()), oleHoldings.getCallNumber().getShelvingOrder().getCodeValue() + "\n"));
496 
497         }
498     }
499 
500 
501     @Test
502     public void testSortItems() {
503         String xml = getXmlAsString("/org/kuali/ole/documents/BibTree1.xml");
504         BibTree bibTree = new BibTree();
505         String strItems = new String();
506         bibTree = (BibTree) bibTree.deserialize(xml);
507         docstoreService.createBibTree(bibTree);
508         ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
509 
510         System.out.println("BEFORE SORTING ITEMS:");
511         for (HoldingsTree holdingsTree : bibTree.getHoldingsTrees()) {
512             System.out.println("***HOLDINGS***");
513             System.out.println("ITEMS : Loc | Prefix | ShlOrd | Enum | Chro | Copy | bar");
514             for (Item item : holdingsTree.getItems()) {
515                 org.kuali.ole.docstore.common.document.content.instance.Item item1 = itemOlemlRecordProcessor.fromXML(item.getContent());
516 //                System.out.println(strItems.format("%s | %s | %s | %s | %s | %s | %s", Holdings.buildLocationString(item1.getLocation()), item1.getCallNumber().getPrefix(),
517 //                        item1.getCallNumber().getShelvingOrder().getCodeValue(), item1.getEnumeration(), item1.getChronology(), item1.getCopyNumber(), item1.getAccessInformation().getBarcode() + "\n"));
518             }
519         }
520         bibTree = docstoreService.retrieveBibTree(bibTree.getBib().getId());
521         System.out.println("AFTER SORTING ITEMS:");
522         for (HoldingsTree holdingsTree : bibTree.getHoldingsTrees()) {
523             System.out.println("***HOLDINGS***");
524             System.out.println("ITEMS : Loc | Prefix | ShlOrd | Enum | Chro | Copy | bar");
525             for (Item item : holdingsTree.getItems()) {
526                 org.kuali.ole.docstore.common.document.content.instance.Item item1 = itemOlemlRecordProcessor.fromXML(item.getContent());
527 //                System.out.println(strItems.format("%s | %s | %s | %s | %s | %s | %s", Holdings.buildLocationString(item1.getLocation()), item1.getCallNumber().getPrefix(),
528 //                        item1.getCallNumber().getShelvingOrder().getCodeValue(), item1.getEnumeration(), item1.getChronology(), item1.getCopyNumber(), item1.getAccessInformation().getBarcode() + "\n"));
529             }
530         }
531     }
532 
533 
534 
535     /*@Test
536     public void testSortItems() {
537         String xml = getXmlAsString("/org/kuali/ole/documents/BibTree1.xml");
538         BibTree bibTree = new BibTree();
539         bibTree = (BibTree) bibTree.deserialize(xml);
540         docstoreService.createBibTree(bibTree);
541         bibTree = docstoreService.retrieveBibTree(bibTree.getBib().getId());
542         String serialize = bibTree.serialize(bibTree);
543         serialize = ParseXml.formatXml(serialize);
544         System.out.println(serialize);
545 
546     }*/
547 
548 
549     @Test
550     public void createBibTrees2() {
551         List bibTrees = new ArrayList();
552         BibTree bibTree = new BibTree();
553         String xml = getXmlAsString("/org/kuali/ole/search/BibTree1.xml");
554         bibTree = (BibTree) bibTree.deserialize(xml);
555         bibTrees.add(bibTree);
556         bibTree = new BibTree();
557         xml = getXmlAsString("/org/kuali/ole/search/BibTree2.xml");
558         bibTree = (BibTree) bibTree.deserialize(xml);
559         bibTrees.add(bibTree);
560         bibTree = new BibTree();
561         xml = getXmlAsString("/org/kuali/ole/search/BibTree3.xml");
562         bibTree = (BibTree) bibTree.deserialize(xml);
563         bibTrees.add(bibTree);
564         bibTree = new BibTree();
565         xml = getXmlAsString("/org/kuali/ole/search/BibTree4.xml");
566         bibTree = (BibTree) bibTree.deserialize(xml);
567         bibTrees.add(bibTree);
568         bibTree = new BibTree();
569         xml = getXmlAsString("/org/kuali/ole/search/BibTree5.xml");
570         bibTree = (BibTree) bibTree.deserialize(xml);
571         bibTrees.add(bibTree);
572         bibTree = new BibTree();
573         xml = getXmlAsString("/org/kuali/ole/search/BibTree6.xml");
574         bibTree = (BibTree) bibTree.deserialize(xml);
575         bibTrees.add(bibTree);
576         bibTree = new BibTree();
577         xml = getXmlAsString("/org/kuali/ole/search/BibTree7.xml");
578         bibTree = (BibTree) bibTree.deserialize(xml);
579         bibTrees.add(bibTree);
580         bibTree = new BibTree();
581         xml = getXmlAsString("/org/kuali/ole/search/BibTree8.xml");
582         bibTree = (BibTree) bibTree.deserialize(xml);
583         bibTrees.add(bibTree);
584         bibTree = new BibTree();
585         xml = getXmlAsString("/org/kuali/ole/search/BibTree9.xml");
586         bibTree = (BibTree) bibTree.deserialize(xml);
587         bibTrees.add(bibTree);
588         bibTree = new BibTree();
589         xml = getXmlAsString("/org/kuali/ole/search/BibTree10.xml");
590         bibTree = (BibTree) bibTree.deserialize(xml);
591         bibTrees.add(bibTree);
592         bibTree = new BibTree();
593         xml = getXmlAsString("/org/kuali/ole/search/BibTree11.xml");
594         bibTree = (BibTree) bibTree.deserialize(xml);
595         bibTrees.add(bibTree);
596         bibTree = new BibTree();
597         xml = getXmlAsString("/org/kuali/ole/search/BibTree12.xml");
598         bibTree = (BibTree) bibTree.deserialize(xml);
599         bibTrees.add(bibTree);
600         bibTree = new BibTree();
601         xml = getXmlAsString("/org/kuali/ole/search/BibTree13.xml");
602         bibTree = (BibTree) bibTree.deserialize(xml);
603         bibTrees.add(bibTree);
604         bibTree = new BibTree();
605         xml = getXmlAsString("/org/kuali/ole/search/BibTree14.xml");
606         bibTree = (BibTree) bibTree.deserialize(xml);
607         bibTrees.add(bibTree);
608         bibTree = new BibTree();
609         xml = getXmlAsString("/org/kuali/ole/search/BibTree15.xml");
610         bibTree = (BibTree) bibTree.deserialize(xml);
611         bibTrees.add(bibTree);
612         BibTrees bibTreesobj = new BibTrees();
613         bibTreesobj.getBibTrees().add(bibTree);
614         bibTreesobj.getBibTrees().addAll(bibTrees);
615         docstoreService.createBibTrees(bibTreesobj);
616     }
617 
618     @Test
619     public void testSearch1() {
620         Bib bib = getBibMarc1();
621         docstoreService.createBib(bib);
622         Assert.assertNotNull(bib.getId());
623         SearchParams searchParams = getSearchParams1();
624         SearchField searchField = searchParams.buildSearchField("bibliographic", "bibIdentifier", bib.getId());
625         searchParams.getSearchConditions().add(searchParams.buildSearchCondition("AND", searchField, "AND"));
626 
627         Assert.assertEquals("bibliographic", searchParams.getSearchConditions().get(0).getSearchField().getDocType());
628         Assert.assertEquals("Title", searchParams.getSearchConditions().get(0).getSearchField().getFieldName());
629         Assert.assertEquals("This Title is for Test1", searchParams.getSearchConditions().get(0).getSearchField().getFieldValue());
630         Assert.assertEquals("bibliographic", searchParams.getSearchConditions().get(1).getSearchField().getDocType());
631         Assert.assertEquals("Author", searchParams.getSearchConditions().get(1).getSearchField().getFieldName());
632         Assert.assertEquals("This Author is for Test1", searchParams.getSearchConditions().get(1).getSearchField().getFieldValue());
633         Assert.assertEquals("bibliographic", searchParams.getSearchConditions().get(2).getSearchField().getDocType());
634         Assert.assertEquals("bibIdentifier", searchParams.getSearchConditions().get(2).getSearchField().getFieldName());
635         Assert.assertEquals(bib.getId(), searchParams.getSearchConditions().get(2).getSearchField().getFieldValue());
636 
637         Assert.assertEquals("bibliographic", searchParams.getSearchResultFields().get(0).getDocType());
638         Assert.assertEquals("Title", searchParams.getSearchResultFields().get(0).getFieldName());
639         Assert.assertEquals("bibliographic", searchParams.getSearchResultFields().get(1).getDocType());
640         Assert.assertEquals("Author", searchParams.getSearchResultFields().get(1).getFieldName());
641 
642         SearchResponse searchResponse = docstoreService.search(searchParams);
643 
644         Assert.assertNotNull(searchResponse);
645         Assert.assertNotNull(searchResponse.getSearchResults());
646         Assert.assertNotNull(searchResponse.getSearchResults().get(0).getSearchResultFields());
647 
648         Assert.assertEquals("bibliographic", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getDocType());
649         Assert.assertEquals("Title", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldName());
650         Assert.assertEquals("This Title is for Test1", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldValue());
651         Assert.assertEquals("bibliographic", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getDocType());
652         Assert.assertEquals("Author", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getFieldName());
653         Assert.assertEquals("This Author is for Test1", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getFieldValue());
654     }
655 
656     public Bib getBibMarc1() {
657         Bib bib = new BibMarc();
658         return (Bib) bib.deserialize(getXmlAsString("/org/kuali/ole/search/BibMarc1.xml"));
659     }
660 
661     @Test
662     public void testSearch2() {
663         BibTree bibTree = getBibTree1();
664         docstoreService.createBibTree(bibTree);
665         Assert.assertNotNull(bibTree.getBib().getId());
666         SearchParams searchParams = getSearchParams2();
667         SearchField searchField = searchParams.buildSearchField("bibliographic", "bibIdentifier", bibTree.getBib().getId());
668         searchParams.getSearchConditions().add(searchParams.buildSearchCondition("AND", searchField, "AND"));
669 
670         Assert.assertEquals("bibliographic", searchParams.getSearchConditions().get(0).getSearchField().getDocType());
671         Assert.assertEquals("Title", searchParams.getSearchConditions().get(0).getSearchField().getFieldName());
672         Assert.assertEquals("This Title is for Test2", searchParams.getSearchConditions().get(0).getSearchField().getFieldValue());
673         Assert.assertEquals("bibliographic", searchParams.getSearchConditions().get(1).getSearchField().getDocType());
674         Assert.assertEquals("bibIdentifier", searchParams.getSearchConditions().get(1).getSearchField().getFieldName());
675         Assert.assertEquals(bibTree.getBib().getId(), searchParams.getSearchConditions().get(1).getSearchField().getFieldValue());
676 
677         Assert.assertEquals("bibliographic", searchParams.getSearchResultFields().get(0).getDocType());
678         Assert.assertEquals("Title", searchParams.getSearchResultFields().get(0).getFieldName());
679         Assert.assertEquals("holdings", searchParams.getSearchResultFields().get(1).getDocType());
680         Assert.assertEquals("CallNumber", searchParams.getSearchResultFields().get(1).getFieldName());
681         Assert.assertEquals("item", searchParams.getSearchResultFields().get(2).getDocType());
682         Assert.assertEquals("CallNumber", searchParams.getSearchResultFields().get(2).getFieldName());
683         Assert.assertEquals("item", searchParams.getSearchResultFields().get(3).getDocType());
684         Assert.assertEquals("chronology", searchParams.getSearchResultFields().get(3).getFieldName());
685         Assert.assertEquals("item", searchParams.getSearchResultFields().get(4).getDocType());
686         Assert.assertEquals("enumeration", searchParams.getSearchResultFields().get(4).getFieldName());
687 
688         SearchResponse searchResponse = docstoreService.search(searchParams);
689 
690         Assert.assertNotNull(searchResponse);
691         Assert.assertNotNull(searchResponse.getSearchResults());
692         Assert.assertNotNull(searchResponse.getSearchResults().get(0).getSearchResultFields());
693 
694         Assert.assertEquals("bibliographic", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getDocType());
695         Assert.assertEquals("Title", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldName());
696         Assert.assertEquals("This Title is for Test2", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldValue());
697         Assert.assertEquals("holdings", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getDocType());
698         Assert.assertEquals("CallNumber", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getFieldName());
699         Assert.assertEquals("CN Holdings Test2", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getFieldValue());
700         Assert.assertEquals("item", searchResponse.getSearchResults().get(0).getSearchResultFields().get(2).getDocType());
701         Assert.assertEquals("CallNumber", searchResponse.getSearchResults().get(0).getSearchResultFields().get(2).getFieldName());
702         Assert.assertEquals("CN Item Test2", searchResponse.getSearchResults().get(0).getSearchResultFields().get(2).getFieldValue());
703         Assert.assertEquals("item", searchResponse.getSearchResults().get(0).getSearchResultFields().get(3).getDocType());
704         Assert.assertEquals("chronology", searchResponse.getSearchResults().get(0).getSearchResultFields().get(3).getFieldName());
705         Assert.assertEquals("CHN Item Test2", searchResponse.getSearchResults().get(0).getSearchResultFields().get(3).getFieldValue());
706         Assert.assertEquals("item", searchResponse.getSearchResults().get(0).getSearchResultFields().get(4).getDocType());
707         Assert.assertEquals("enumeration", searchResponse.getSearchResults().get(0).getSearchResultFields().get(4).getFieldName());
708         Assert.assertEquals("ENUM Item Test2", searchResponse.getSearchResults().get(0).getSearchResultFields().get(4).getFieldValue());
709     }
710 
711     public BibTree getBibTree1() {
712         BibTree bibTree = new BibTree();
713         return (BibTree) bibTree.deserialize(getXmlAsString("/org/kuali/ole/search/BibTree1.xml"));
714     }
715 
716     @Test
717     public void testSearch3() {
718         BibTree bibTree = getBibTree2();
719         docstoreService.createBibTree(bibTree);
720         Assert.assertNotNull(bibTree.getHoldingsTrees().get(0).getHoldings().getId());
721         SearchParams searchParams = getSearchParams3();
722         SearchField searchField = searchParams.buildSearchField("holdings", "holdingsIdentifier", bibTree.getHoldingsTrees().get(0).getHoldings().getId());
723         searchParams.getSearchConditions().add(searchParams.buildSearchCondition("AND", searchField, "AND"));
724 
725         Assert.assertEquals("holdings", searchParams.getSearchConditions().get(0).getSearchField().getDocType());
726         Assert.assertEquals("CallNumber", searchParams.getSearchConditions().get(0).getSearchField().getFieldName());
727         Assert.assertEquals("CN Holdings Test3", searchParams.getSearchConditions().get(0).getSearchField().getFieldValue());
728         Assert.assertEquals("holdings", searchParams.getSearchConditions().get(1).getSearchField().getDocType());
729         Assert.assertEquals("ShelvingOrder_search", searchParams.getSearchConditions().get(1).getSearchField().getFieldName());
730         Assert.assertEquals("CN-Holdings-Test3", searchParams.getSearchConditions().get(1).getSearchField().getFieldValue());
731         Assert.assertEquals("holdings", searchParams.getSearchConditions().get(2).getSearchField().getDocType());
732         Assert.assertEquals("holdingsIdentifier", searchParams.getSearchConditions().get(2).getSearchField().getFieldName());
733         Assert.assertEquals(bibTree.getHoldingsTrees().get(0).getHoldings().getId(), searchParams.getSearchConditions().get(2).getSearchField().getFieldValue());
734 
735         Assert.assertEquals("holdings", searchParams.getSearchResultFields().get(0).getDocType());
736         Assert.assertEquals("CallNumber", searchParams.getSearchResultFields().get(0).getFieldName());
737         Assert.assertEquals("item", searchParams.getSearchResultFields().get(1).getDocType());
738         Assert.assertEquals("CallNumber", searchParams.getSearchResultFields().get(1).getFieldName());
739         Assert.assertEquals("item", searchParams.getSearchResultFields().get(2).getDocType());
740         Assert.assertEquals("chronology", searchParams.getSearchResultFields().get(2).getFieldName());
741         Assert.assertEquals("item", searchParams.getSearchResultFields().get(3).getDocType());
742         Assert.assertEquals("enumeration", searchParams.getSearchResultFields().get(3).getFieldName());
743         Assert.assertEquals("bibliographic", searchParams.getSearchResultFields().get(4).getDocType());
744         Assert.assertEquals("Title", searchParams.getSearchResultFields().get(4).getFieldName());
745 
746         SearchResponse searchResponse = docstoreService.search(searchParams);
747 
748         Assert.assertNotNull(searchResponse);
749         Assert.assertNotNull(searchResponse.getSearchResults());
750         Assert.assertNotNull(searchResponse.getSearchResults().get(0).getSearchResultFields());
751 
752         Assert.assertEquals("holdings", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getDocType());
753         Assert.assertEquals("CallNumber", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldName());
754         Assert.assertEquals("CN Holdings Test3", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldValue());
755         Assert.assertEquals("item", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getDocType());
756         Assert.assertEquals("CallNumber", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getFieldName());
757         Assert.assertEquals("CN Item Test3", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getFieldValue());
758         Assert.assertEquals("item", searchResponse.getSearchResults().get(0).getSearchResultFields().get(2).getDocType());
759         Assert.assertEquals("chronology", searchResponse.getSearchResults().get(0).getSearchResultFields().get(2).getFieldName());
760         Assert.assertEquals("CHN Item Test3", searchResponse.getSearchResults().get(0).getSearchResultFields().get(2).getFieldValue());
761         Assert.assertEquals("item", searchResponse.getSearchResults().get(0).getSearchResultFields().get(3).getDocType());
762         Assert.assertEquals("enumeration", searchResponse.getSearchResults().get(0).getSearchResultFields().get(3).getFieldName());
763         Assert.assertEquals("ENUM Item Test3", searchResponse.getSearchResults().get(0).getSearchResultFields().get(3).getFieldValue());
764         Assert.assertEquals("bibliographic", searchResponse.getSearchResults().get(0).getSearchResultFields().get(4).getDocType());
765         Assert.assertEquals("Title", searchResponse.getSearchResults().get(0).getSearchResultFields().get(4).getFieldName());
766         Assert.assertEquals("This Title is for Test3", searchResponse.getSearchResults().get(0).getSearchResultFields().get(4).getFieldValue());
767     }
768 
769     public BibTree getBibTree2() {
770         BibTree bibTree = new BibTree();
771         return (BibTree) bibTree.deserialize(getXmlAsString("/org/kuali/ole/search/BibTree2.xml"));
772     }
773 
774     @Test
775     public void testSearch4() {
776         BibTree bibTree = getBibTree3();
777         docstoreService.createBibTree(bibTree);
778         Assert.assertNotNull(bibTree.getHoldingsTrees().get(0).getItems().get(0).getId());
779         SearchParams searchParams = getSearchParams4();
780         SearchField searchField = searchParams.buildSearchField("item", "itemIdentifier", bibTree.getHoldingsTrees().get(0).getItems().get(0).getId());
781         searchParams.getSearchConditions().add(searchParams.buildSearchCondition("AND", searchField, "AND"));
782 
783         Assert.assertEquals("item", searchParams.getSearchConditions().get(0).getSearchField().getDocType());
784         Assert.assertEquals("enumeration", searchParams.getSearchConditions().get(0).getSearchField().getFieldName());
785         Assert.assertEquals("ENUM Item Test4", searchParams.getSearchConditions().get(0).getSearchField().getFieldValue());
786         Assert.assertEquals("item", searchParams.getSearchConditions().get(1).getSearchField().getDocType());
787         Assert.assertEquals("itemIdentifier", searchParams.getSearchConditions().get(1).getSearchField().getFieldName());
788         Assert.assertEquals(bibTree.getHoldingsTrees().get(0).getItems().get(0).getId(), searchParams.getSearchConditions().get(1).getSearchField().getFieldValue());
789 
790         Assert.assertEquals("holdings", searchParams.getSearchResultFields().get(0).getDocType());
791         Assert.assertEquals("CallNumber", searchParams.getSearchResultFields().get(0).getFieldName());
792         Assert.assertEquals("item", searchParams.getSearchResultFields().get(1).getDocType());
793         Assert.assertEquals("CallNumber", searchParams.getSearchResultFields().get(1).getFieldName());
794         Assert.assertEquals("item", searchParams.getSearchResultFields().get(2).getDocType());
795         Assert.assertEquals("chronology", searchParams.getSearchResultFields().get(2).getFieldName());
796         Assert.assertEquals("item", searchParams.getSearchResultFields().get(3).getDocType());
797         Assert.assertEquals("enumeration", searchParams.getSearchResultFields().get(3).getFieldName());
798         Assert.assertEquals("bibliographic", searchParams.getSearchResultFields().get(4).getDocType());
799         Assert.assertEquals("Title", searchParams.getSearchResultFields().get(4).getFieldName());
800 
801         SearchResponse searchResponse = docstoreService.search(searchParams);
802 
803         Assert.assertNotNull(searchResponse);
804         Assert.assertNotNull(searchResponse.getSearchResults());
805         Assert.assertNotNull(searchResponse.getSearchResults().get(0).getSearchResultFields());
806 
807         Assert.assertEquals("holdings", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getDocType());
808         Assert.assertEquals("CallNumber", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldName());
809         Assert.assertEquals("CN Holdings Test4", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldValue());
810         Assert.assertEquals("item", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getDocType());
811         Assert.assertEquals("CallNumber", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getFieldName());
812         Assert.assertEquals("CN Item Test4", searchResponse.getSearchResults().get(0).getSearchResultFields().get(1).getFieldValue());
813         Assert.assertEquals("item", searchResponse.getSearchResults().get(0).getSearchResultFields().get(2).getDocType());
814         Assert.assertEquals("chronology", searchResponse.getSearchResults().get(0).getSearchResultFields().get(2).getFieldName());
815         Assert.assertEquals("CHN Item Test4", searchResponse.getSearchResults().get(0).getSearchResultFields().get(2).getFieldValue());
816         Assert.assertEquals("item", searchResponse.getSearchResults().get(0).getSearchResultFields().get(3).getDocType());
817         Assert.assertEquals("enumeration", searchResponse.getSearchResults().get(0).getSearchResultFields().get(3).getFieldName());
818         Assert.assertEquals("ENUM Item Test4", searchResponse.getSearchResults().get(0).getSearchResultFields().get(3).getFieldValue());
819         Assert.assertEquals("bibliographic", searchResponse.getSearchResults().get(0).getSearchResultFields().get(4).getDocType());
820         Assert.assertEquals("Title", searchResponse.getSearchResults().get(0).getSearchResultFields().get(4).getFieldName());
821         Assert.assertEquals("This Title is for Test4", searchResponse.getSearchResults().get(0).getSearchResultFields().get(4).getFieldValue());
822     }
823 
824     public BibTree getBibTree3() {
825         BibTree bibTree = new BibTree();
826         return (BibTree) bibTree.deserialize(getXmlAsString("/org/kuali/ole/search/BibTree3.xml"));
827     }
828 
829     @Test
830     public void testSearch5() {
831         createBibTrees2();
832         SearchParams searchParams = getSearchParams5();
833 
834         Assert.assertEquals("bibliographic", searchParams.getSearchConditions().get(0).getSearchField().getDocType());
835 
836         Assert.assertEquals("bibliographic", searchParams.getSearchResultFields().get(0).getDocType());
837         Assert.assertEquals("bibIdentifier", searchParams.getSearchResultFields().get(0).getFieldName());
838         Assert.assertEquals("bibliographic", searchParams.getSearchResultFields().get(1).getDocType());
839         Assert.assertEquals("Title", searchParams.getSearchResultFields().get(1).getFieldName());
840         Assert.assertEquals("0", String.valueOf(searchParams.getStartIndex()));
841         Assert.assertEquals("10", String.valueOf(searchParams.getPageSize()));
842 
843         SearchResponse searchResponse1 = docstoreService.search(searchParams);
844 
845         Assert.assertNotNull(searchResponse1);
846         Assert.assertNotNull(searchResponse1.getSearchResults());
847         Assert.assertNotNull(searchResponse1.getSearchResults().get(0).getSearchResultFields());
848 
849         Assert.assertTrue(searchResponse1.getTotalRecordCount() > 10);
850         Assert.assertNotNull(searchResponse1.getTotalRecordCount());
851         Assert.assertEquals("0", String.valueOf(searchResponse1.getStartIndex()));
852         Assert.assertEquals("10", String.valueOf(searchResponse1.getPageSize()));
853         Assert.assertEquals(searchResponse1.getStartIndex() + searchResponse1.getPageSize(), searchResponse1.getEndIndex());
854 
855         searchParams.setStartIndex(10);
856         searchParams.setPageSize(10);
857 
858         SearchResponse searchResponse2 = docstoreService.search(searchParams);
859 
860         Assert.assertNotNull(searchResponse2);
861         Assert.assertNotNull(searchResponse2.getSearchResults());
862         Assert.assertNotNull(searchResponse2.getSearchResults().get(0).getSearchResultFields());
863 
864         Assert.assertTrue(searchResponse2.getTotalRecordCount() > 10);
865         Assert.assertNotNull(searchResponse2.getTotalRecordCount());
866         Assert.assertEquals("10", String.valueOf(searchResponse2.getStartIndex()));
867         Assert.assertEquals("10", String.valueOf(searchResponse2.getPageSize()));
868         Assert.assertEquals(searchResponse1.getStartIndex() + searchResponse1.getPageSize(), searchResponse1.getEndIndex());
869     }
870 
871     public SearchParams getSearchParams1() {
872         SearchParams searchParams = new SearchParams();
873         String xml = getXmlAsString("/org/kuali/ole/search/SearchParams1.xml");
874         return (SearchParams) searchParams.deserialize(xml);
875     }
876 
877     public SearchParams getSearchParams2() {
878         SearchParams searchParams = new SearchParams();
879         String xml = getXmlAsString("/org/kuali/ole/search/SearchParams2.xml");
880         return (SearchParams) searchParams.deserialize(xml);
881     }
882 
883     public SearchParams getSearchParams3() {
884         SearchParams searchParams = new SearchParams();
885         String xml = getXmlAsString("/org/kuali/ole/search/SearchParams3.xml");
886         return (SearchParams) searchParams.deserialize(xml);
887     }
888 
889     public SearchParams getSearchParams4() {
890         SearchParams searchParams = new SearchParams();
891         String xml = getXmlAsString("/org/kuali/ole/search/SearchParams4.xml");
892         return (SearchParams) searchParams.deserialize(xml);
893     }
894 
895     public SearchParams getSearchParams5() {
896         SearchParams searchParams = new SearchParams();
897         String xml = getXmlAsString("/org/kuali/ole/search/SearchParams5.xml");
898         return (SearchParams) searchParams.deserialize(xml);
899     }
900 
901     @Test
902     public void createBibTrees1() {
903         List bibTrees = new ArrayList();
904         BibTree bibTree = new BibTree();
905         String xml = getXmlAsString("/org/kuali/ole/documents/BibTree1.xml");
906         bibTree = (BibTree) bibTree.deserialize(xml);
907         bibTrees.add(bibTree);
908         bibTree = new BibTree();
909         xml = getXmlAsString("/org/kuali/ole/documents/BibTree2.xml");
910         bibTree = (BibTree) bibTree.deserialize(xml);
911         bibTrees.add(bibTree);
912         bibTree = new BibTree();
913         xml = getXmlAsString("/org/kuali/ole/documents/BibTree3.xml");
914         bibTree = (BibTree) bibTree.deserialize(xml);
915         bibTrees.add(bibTree);
916         bibTree = new BibTree();
917         xml = getXmlAsString("/org/kuali/ole/documents/BibTree4.xml");
918         bibTree = (BibTree) bibTree.deserialize(xml);
919         bibTrees.add(bibTree);
920         bibTree = new BibTree();
921         xml = getXmlAsString("/org/kuali/ole/documents/BibTree5.xml");
922         bibTree = (BibTree) bibTree.deserialize(xml);
923         bibTrees.add(bibTree);
924         BibTrees bibTreesobj = new BibTrees();
925         //bibTreesobj.getBibTrees().add(bibTree);
926         bibTreesobj.getBibTrees().addAll(bibTrees);
927         docstoreService.createBibTrees(bibTreesobj);
928     }
929 
930     @Test
931     public void testBoundHoldingsWithBibs() {
932         String bibId1 = "wbm-10000001";
933         BibTree bibTree1 = docstoreService.retrieveBibTree(bibId1);
934         System.out.println("Before Boundwith Bib id: " + bibId1 + " Holdings count: " + bibTree1.getHoldingsTrees().size());
935         String bibId2 = "wbm-10000002";
936         BibTree bibTree2 = docstoreService.retrieveBibTree(bibId2);
937         System.out.println("Before Boundwith Bib id: " + bibId2 + " Holdings count: " + bibTree2.getHoldingsTrees().size());
938         String holdingsId = "who-1";
939         List bibIds = new ArrayList<String>();
940         bibIds.add(bibId2);
941         docstoreService.boundHoldingsWithBibs(holdingsId, bibIds);
942         bibTree1 = docstoreService.retrieveBibTree(bibId1);
943         System.out.println("After Boundwith Bib id: " + bibId1 + " Holdings count: " + bibTree1.getHoldingsTrees().size());
944         bibTree2 = docstoreService.retrieveBibTree(bibId2);
945         System.out.println("After Boundwith Bib id: " + bibId2 + " Holdings count: " + bibTree2.getHoldingsTrees().size());
946     }
947 
948     @Test
949     public void transferHoldings() {
950         String bibId = "wbm-10000001";
951         String holdingsId = "who-2";
952         List holdingIds = new ArrayList<String>();
953         holdingIds.add(holdingsId);
954         docstoreService.transferHoldings(holdingIds, bibId);
955     }
956 
957     @Test
958     public void transferItems() {
959         String holdingId = "wbm-10000001";
960         String itemId = "who-2";
961         List itemIds = new ArrayList<String>();
962         itemIds.add(itemId);
963         docstoreService.transferItems(itemIds, holdingId);
964     }
965 
966     @Test
967     public void findBib() {
968         testCreateBib();
969         Map map = new HashMap();
970         map.put(BibConstants.DOC_TYPE, "bibliographic");
971         map.put("ID", "wbm-10000001");
972         Bib bib = docstoreService.findBib(map);
973         Assert.assertEquals(bib.getId(), "wbm-10000001");
974     }
975 
976     @Test
977     public void findBibTree() {
978         testCreateBib();
979         Map map = new HashMap();
980         map.put(BibConstants.DOC_TYPE, "bibliographic");
981         map.put("ID", "wbm-10000001");
982         BibTree bibTree = docstoreService.findBibTree(map);
983         Assert.assertEquals(bibTree.getBib().getId(), "wbm-10000001");
984     }
985 
986     @Test
987     public void findHoldings() {
988         testCreatePHoldings();
989         Map map = new HashMap();
990         map.put("ID", "who-1");
991         map.put(BibConstants.DOC_TYPE, "holdings");
992         Holdings holdings = docstoreService.findHoldings(map);
993         Assert.assertEquals(holdings.getId(), "who-1");
994 
995     }
996 
997     @Test
998     public void findHoldingsTree() {
999         testCreatePHoldings();
1000         Map map = new HashMap();
1001         map.put("ID", "who-1");
1002         map.put(BibConstants.DOC_TYPE, "holdings");
1003         HoldingsTree holdingsTree = docstoreService.findHoldingsTree(map);
1004         Assert.assertEquals(holdingsTree.getHoldings().getId(), "who-1");
1005 
1006     }
1007 
1008     @Test
1009     public void findItem() {
1010         testCreateItem();
1011         Map map = new HashMap();
1012         map.put("ID", "wio-1");
1013         map.put(BibConstants.DOC_TYPE, "item");
1014         Item item = docstoreService.findItem(map);
1015         Assert.assertEquals(item.getId(), "wio-1");
1016     }
1017 
1018     @Test
1019     public void deleteBibs() {
1020         testCreateBib();
1021         List bibIds = new ArrayList();
1022         bibIds.add("wbm-10000001");
1023         docstoreService.deleteBibs(bibIds);
1024     }
1025 
1026     public String getXmlAsString(String filePath) {
1027         String input = "";
1028         File file = null;
1029         try {
1030             file = new File(getClass().getResource(filePath).toURI());
1031             input = FileUtils.readFileToString(file);
1032         } catch (Exception e) {
1033             e.printStackTrace();
1034         }
1035         return input;
1036     }
1037 
1038     public Bib getBibRecord() {
1039         Bib bib = new BibMarc();
1040         bib.setCategory(DocCategory.WORK.getCode());
1041         bib.setType(DocType.BIB.getCode());
1042         bib.setFormat(DocFormat.MARC.getCode());
1043         bib.setContent("<collection xmlns=\"http://www.loc.gov/MARC21/slim\">\n" +
1044                 "    <record>\n" +
1045                 "        <leader>#####nam#a22######a#4500</leader>\n" +
1046                 "\t<controlfield tag=\"001\"></controlfield>\n" +
1047                 "        <controlfield tag=\"003\">OCoLC</controlfield>\n" +
1048                 "        <controlfield tag=\"005\">20090213152530.7</controlfield>\n" +
1049                 "\t\t<controlfield tag=\"008\">131031s########xxu###########000#0#eng#d</controlfield>\n" +
1050                 "        <datafield tag=\"035\" ind1=\" \" ind2=\" \">\n" +
1051                 "            <subfield code=\"a\">(OCoLC)ocm62378465</subfield>\n" +
1052                 "        </datafield>\n" +
1053                 "        <datafield tag=\"040\" ind1=\" \" ind2=\" \">\n" +
1054                 "             <subfield code=\"a\">DLC</subfield>\n" +
1055                 "\t\t\t <subfield code=\"c\">DLC</subfield>\n" +
1056                 "\t\t\t <subfield code=\"d\">DLC</subfield>\n" +
1057                 "\t\t\t <subfield code=\"d\">HLS</subfield>\n" +
1058                 "\t\t\t <subfield code=\"d\">IUL</subfield>\n" +
1059                 "        </datafield>\n" +
1060                 "         <datafield tag=\"022\" ind1=\" \" ind2=\" \">\n" +
1061                 "            <subfield code=\"a\">1729-1070|20</subfield>\n" +
1062                 "        </datafield>\n" +
1063                 "        <datafield tag=\"029\" ind1=\"1\" ind2=\" \">\n" +
1064                 "            <subfield code=\"a\">AU@|b000040176476</subfield>\n" +
1065                 "\t\t\t<subfield code=\"b\">000040176476</subfield>\n" +
1066                 "        </datafield>\n" +
1067                 "        <datafield tag=\"037\" ind1=\" \" ind2=\" \">\n" +
1068                 "            <subfield code=\"b\">The Managing Editor, BIAC Journal, P.O. Box 10026, Gaborone, Botswana</subfield>\n" +
1069                 "        </datafield>\n" +
1070                 "        <datafield tag=\"042\" ind1=\" \" ind2=\" \">\n" +
1071                 "            <subfield code=\"a\">lc</subfield>\n" +
1072                 "        </datafield>\n" +
1073                 "        <datafield tag=\"043\" ind1=\"1\" ind2=\"0\">\n" +
1074                 "            <subfield code=\"a\">f-bs---</subfield>\n" +
1075                 "        </datafield>\n" +
1076                 "        <datafield tag=\"050\" ind1=\"0\" ind2=\"0\">\n" +
1077                 "            <subfield code=\"a\">HD70.B55|bB53</subfield>\n" +
1078                 "        </datafield>\n" +
1079                 "        <datafield tag=\"049\" ind1=\" \" ind2=\" \">\n" +
1080                 "            <subfield code=\"a\">IULA</subfield>\n" +
1081                 "        </datafield>\n" +
1082                 "         <datafield tag=\"210\" ind1=\"1\" ind2=\" \">\n" +
1083                 "            <subfield code=\"a\">BIAC j.</subfield>\n" +
1084                 "        </datafield>\n" +
1085                 "         <datafield tag=\"222\" ind1=\" \" ind2=\"0\">\n" +
1086                 "            <subfield code=\"a\">BIAC journal</subfield>\n" +
1087                 "        </datafield>\n" +
1088                 "         <datafield tag=\"245\" ind1=\"0\" ind2=\"0\">\n" +
1089                 "            <subfield code=\"a\">BIAC journal</subfield>\n" +
1090                 "        </datafield>\n" +
1091                 "         <datafield tag=\"246\" ind1=\"1\" ind2=\"3\">\n" +
1092                 "            <subfield code=\"a\">Botswana Institute of Administration and Commerce journal</subfield>\n" +
1093                 "        </datafield>\n" +
1094                 "        <datafield tag=\"260\" ind1=\" \" ind2=\" \">\n" +
1095                 "            <subfield code=\"a\">Gaborone, Botswana :|bBotswana Institute of Administration and Commerce</subfield>\n" +
1096                 "\t\t\t<subfield code=\"b\">Botswana Institute of Administration and Commerce</subfield>\n" +
1097                 "        </datafield>\n" +
1098                 "        <datafield tag=\"300\" ind1=\" \" ind2=\" \">\n" +
1099                 "            <subfield code=\"a\">v. ;</subfield>\n" +
1100                 "\t\t\t<subfield code=\"c\">24 cm.</subfield>\n" +
1101                 "        </datafield>\n" +
1102                 "\t\t<datafield tag=\"300\" ind1=\" \" ind2=\" \">\n" +
1103                 "            <subfield code=\"a\">v. ;</subfield>\n" +
1104                 "\t\t\t<subfield code=\"c\">24 cm.</subfield>\n" +
1105                 "        </datafield>\n" +
1106                 "\t\t<datafield tag=\"300\" ind1=\" \" ind2=\" \">\n" +
1107                 "            <subfield code=\"a\">v. ;</subfield>\n" +
1108                 "\t\t\t<subfield code=\"c\">24 cm.</subfield>\n" +
1109                 "        </datafield>\n" +
1110                 "\t\t<datafield tag=\"310\" ind1=\" \" ind2=\" \">\n" +
1111                 "            <subfield code=\"a\">Semiannual</subfield>\n" +
1112                 "        </datafield>\n" +
1113                 "\t\t<datafield tag=\"362\" ind1=\"1\" ind2=\" \">\n" +
1114                 "            <subfield code=\"a\"> Began in 2004.</subfield>\n" +
1115                 "        </datafield>\n" +
1116                 "\t\t<datafield tag=\"500\" ind1=\" \" ind2=\" \">\n" +
1117                 "            <subfield code=\"a\">Description based on: Vol. 1, no. 1 (May. 2004); title from cover.</subfield>\n" +
1118                 "        </datafield>\n" +
1119                 "\t\t<datafield tag=\"500\" ind1=\" \" ind2=\" \">\n" +
1120                 "            <subfield code=\"a\">Latest issue consulted: Vol. 3, no. 1 (May 2006).</subfield>\n" +
1121                 "        </datafield>\n" +
1122                 "\t\t<datafield tag=\"650\" ind1=\"0\" ind2=\" \">\n" +
1123                 "            <subfield code=\"a\">Industrial management</subfield>\n" +
1124                 "\t\t\t<subfield code=\"z\">Botswana</subfield>\n" +
1125                 "\t\t\t<subfield code=\"v\">Periodicals.</subfield>\n" +
1126                 "        </datafield>\n" +
1127                 "\t\t<datafield tag=\"650\" ind1=\"0\" ind2=\" \">\n" +
1128                 "            <subfield code=\"a\">Occupational training</subfield>\n" +
1129                 "\t\t\t<subfield code=\"z\">Botswana</subfield>\n" +
1130                 "\t\t\t<subfield code=\"v\">Periodicals.</subfield>\n" +
1131                 "        </datafield>\n" +
1132                 "\t\t<datafield tag=\"710\" ind1=\"2\" ind2=\" \">\n" +
1133                 "            <subfield code=\"a\">Botswana Institute of Administration and Commerce.</subfield>\n" +
1134                 "        </datafield>\n" +
1135                 "\t\t<datafield tag=\"850\" ind1=\" \" ind2=\" \">\n" +
1136                 "            <subfield code=\"a\">DLC</subfield>\n" +
1137                 "        </datafield>\n" +
1138                 "\t\t<datafield tag=\"891\" ind1=\"2\" ind2=\"0\">\n" +
1139                 "            <subfield code=\"a\">9853|81.1</subfield>\n" +
1140                 "\t\t\t<subfield code=\"a\">v.</subfield>\n" +
1141                 "\t\t\t<subfield code=\"b\">no</subfield>\n" +
1142                 "\t\t\t<subfield code=\"u\">2</subfield>\n" +
1143                 "\t\t\t<subfield code=\"v\">r</subfield>\n" +
1144                 "\t\t\t<subfield code=\"i\">(year)</subfield>\n" +
1145                 "\t\t\t<subfield code=\"j\">(month)</subfield>\n" +
1146                 "\t\t\t<subfield code=\"w\">f</subfield>\n" +
1147                 "\t\t\t<subfield code=\"x\">05</subfield>\n" +
1148                 "        </datafield>\n" +
1149                 "\t\t<datafield tag=\"891\" ind1=\"4\" ind2=\"1\">\n" +
1150                 "            <subfield code=\"a\">9863|81.1</subfield>\n" +
1151                 "\t\t\t<subfield code=\"a\">1</subfield>\n" +
1152                 "\t\t\t<subfield code=\"b\">1</subfield>\n" +
1153                 "\t\t\t<subfield code=\"i\">2004</subfield>\n" +
1154                 "\t\t\t<subfield code=\"j\">05</subfield>\n" +
1155                 "        </datafield>\n" +
1156                 "\t\t<datafield tag=\"596\" ind1=\" \" ind2=\" \">\n" +
1157                 "            <subfield code=\"a\">1</subfield>\n" +
1158                 "        </datafield>\n" +
1159                 "    </record>\n" +
1160                 "</collection>");
1161         return bib;
1162     }
1163 
1164     private Holdings getHoldingsRecord() {
1165         Holdings holdings = new PHoldings();
1166 //        Holdings holdings = new EHoldingsOleml();
1167         holdings.setCategory(DocCategory.WORK.getCode());
1168         holdings.setType(DocType.HOLDINGS.getCode());
1169         holdings.setFormat(DocFormat.OLEML.getCode());
1170 
1171         OleHoldings oleHoldings = new OleHoldings();
1172         ShelvingScheme shelvingScheme = new ShelvingScheme();
1173         shelvingScheme.setCodeValue("LCC");
1174 
1175         CallNumber callNumber = new CallNumber();
1176         callNumber.setNumber("123");
1177         callNumber.setShelvingScheme(shelvingScheme);
1178         oleHoldings.setCallNumber(callNumber);
1179 
1180         ExtentOfOwnership pHoldingsExtentOfOwnership = new ExtentOfOwnership();
1181         Note note = new Note();
1182         note.setType("public");
1183         note.setValue("123");
1184         pHoldingsExtentOfOwnership.setTextualHoldings("textual holdings");
1185         pHoldingsExtentOfOwnership.setType("public");
1186         pHoldingsExtentOfOwnership.getNote().add(note);
1187 
1188         ExtentOfOwnership pHoldingsExtentOfOwnership1 = new ExtentOfOwnership();
1189         pHoldingsExtentOfOwnership1.setTextualHoldings("textual holdings");
1190         pHoldingsExtentOfOwnership1.setType("public");
1191         pHoldingsExtentOfOwnership1.getNote().add(note);
1192 
1193         oleHoldings.getExtentOfOwnership().add(pHoldingsExtentOfOwnership);
1194         oleHoldings.getExtentOfOwnership().add(pHoldingsExtentOfOwnership1);
1195 
1196         oleHoldings.setReceiptStatus("1");
1197         oleHoldings.getNote().add(note);
1198         oleHoldings.getNote().add(note);
1199 
1200         oleHoldings.setCopyNumber("copy1");
1201 
1202         Uri uri = new Uri();
1203         uri.setValue("1");
1204 
1205         Uri uri1 = new Uri();
1206         uri1.setValue("2");
1207 
1208         oleHoldings.getUri().add(uri);
1209         oleHoldings.getUri().add(uri1);
1210 
1211 
1212         ExtentOfOwnership eofCoverage = new ExtentOfOwnership();
1213         Coverages coverages = new Coverages();
1214         Coverage coverage = new Coverage();
1215         coverage.setCoverageEndIssue("endIssue");
1216         coverage.setCoverageStartIssue("startIssue");
1217         coverages.getCoverage().add(coverage);
1218         eofCoverage.setCoverages(coverages);
1219 
1220         PerpetualAccesses perpetualAccesses = new PerpetualAccesses();
1221         PerpetualAccess perpetualAccess = new PerpetualAccess();
1222         perpetualAccess.setPerpetualAccessEndIssue("end issue");
1223         perpetualAccess.setPerpetualAccessStartIssue("end issue");
1224         perpetualAccesses.getPerpetualAccess().add(perpetualAccess);
1225         eofCoverage.setPerpetualAccesses(perpetualAccesses);
1226         if (holdings instanceof EHoldings) {
1227             oleHoldings.getExtentOfOwnership().clear();
1228             oleHoldings.getExtentOfOwnership().add(eofCoverage);
1229         }
1230 
1231         oleHoldings.setDonorNote("donor note");
1232         oleHoldings.setAccessStatus("active");
1233         StatisticalSearchingCode statisticalSearchingCode = new StatisticalSearchingCode();
1234         statisticalSearchingCode.setCodeValue("BETA");
1235         oleHoldings.setStatisticalSearchingCode(statisticalSearchingCode);
1236 
1237         oleHoldings.setDonorPublicDisplay("donor public display");
1238 //        oleHoldings.setStatusDate("");
1239         oleHoldings.setEResourceId("1001");
1240         oleHoldings.setStaffOnlyFlag(true);
1241         oleHoldings.setImprint("imprint");
1242         oleHoldings.setInterLibraryLoanAllowed(true);
1243         Link link = new Link();
1244         link.setText("text");
1245         link.setUrl("url");
1246         //oleHoldings.setLink(link);
1247         oleHoldings.setLocalPersistentLink("local persist link");
1248         oleHoldings.setPublisher("pub");
1249         Platform platform = new Platform();
1250         platform.setAdminPassword("apwd");
1251         platform.setAdminUrl("aurl");
1252         platform.setAdminUserName("ausr");
1253         platform.setPlatformName("platform");
1254         oleHoldings.setPlatform(platform);
1255 
1256         oleHoldings.setSubscriptionStatus("status");
1257 
1258         HoldingsAccessInformation holdingsAccessInformation = new HoldingsAccessInformation();
1259         holdingsAccessInformation.setAccessLocation("access location");
1260         holdingsAccessInformation.setAccessPassword("pwd");
1261         holdingsAccessInformation.setAccessUsername("usr");
1262         holdingsAccessInformation.setAuthenticationType("1");
1263         holdingsAccessInformation.setNumberOfSimultaneousUser("2");
1264         holdingsAccessInformation.setProxiedResource("proxied");
1265         oleHoldings.setHoldingsAccessInformation(holdingsAccessInformation);
1266 
1267         holdings.setContent(new HoldingOlemlRecordProcessor().toXML(oleHoldings));
1268 
1269         return holdings;
1270     }
1271 
1272     private BibTree getBibTree() {
1273         BibTree bibTree = new BibTree();
1274         bibTree.setBib(getBibRecord());
1275         HoldingsTree holdingsTree = getHoldingsTree();
1276         bibTree.getHoldingsTrees().add(holdingsTree);
1277         return bibTree;
1278     }
1279 
1280     private HoldingsTree getHoldingsTree() {
1281         HoldingsTree holdingsTree = new HoldingsTree();
1282         holdingsTree.setHoldings(getHoldingsRecord());
1283         holdingsTree.getItems().add(getItemRecord());
1284         return holdingsTree;
1285     }
1286 
1287     @Test
1288     public void testDeleteBib() {
1289         Bib bib = getBibRecord();
1290         docstoreService.deleteBib(bib.getId());
1291     }
1292 
1293     @Test
1294     public void testDeleteHoldings() {
1295         Holdings holdings = getHoldingsRecord();
1296         docstoreService.deleteHoldings(holdings.getId());
1297     }
1298 
1299     @Test
1300     public void testDeleteItem() {
1301         Item item = getItemRecord();
1302         docstoreService.deleteItem(item.getId());
1303     }
1304 
1305     @Test
1306     public void testUpdatePHoldings() {
1307         String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml");
1308         Bib bib = new BibMarc();
1309         bib = (Bib) bib.deserialize(xml);
1310         bib.setId(null);
1311         docstoreService.createBib(bib);
1312         Assert.assertNotNull(bib.getId());
1313 
1314         xml = getXmlAsString("/org/kuali/ole/documents/PHoldings1.xml");
1315         Holdings holdings = new PHoldings();
1316         holdings = (PHoldings) holdings.deserialize(xml);
1317         holdings.setBib(bib);
1318         docstoreService.createHoldings(holdings);
1319 
1320         Assert.assertNotNull(holdings.getId());
1321 
1322 
1323         HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
1324         OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdings.getContent());
1325         oleHoldings.setCopyNumber("1234567");
1326         holdings.setContent(holdingOlemlRecordProcessor.toXML(oleHoldings));
1327         docstoreService.updateHoldings(holdings);
1328 
1329         Holdings holdings1 = docstoreService.retrieveHoldings(holdings.getId());
1330         Assert.assertEquals(holdings1.getId(), holdings.getId());
1331         Assert.assertNotNull(holdings.getId());
1332     }
1333 
1334     @Test
1335     public void testUpdateEHoldings() {
1336         String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml");
1337         Bib bib = new BibMarc();
1338         bib = (Bib) bib.deserialize(xml);
1339         bib.setId(null);
1340         docstoreService.createBib(bib);
1341         Assert.assertNotNull(bib.getId());
1342 
1343         xml = getXmlAsString("/org/kuali/ole/documents/EHoldings1.xml");
1344         Holdings holdings = new EHoldings();
1345         holdings = (EHoldings) holdings.deserialize(xml);
1346         holdings.setBib(bib);
1347         docstoreService.createHoldings(holdings);
1348 
1349         Assert.assertNotNull(holdings.getId());
1350 
1351 
1352         HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
1353         OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdings.getContent());
1354         oleHoldings.setCopyNumber("1234567");
1355         holdings.setContent(holdingOlemlRecordProcessor.toXML(oleHoldings));
1356         docstoreService.updateHoldings(holdings);
1357 
1358         Holdings holdings1 = docstoreService.retrieveHoldings(holdings.getId());
1359         Assert.assertEquals(holdings1.getId(), holdings.getId());
1360         Assert.assertNotNull(holdings.getId());
1361     }
1362 
1363     @Test
1364     public void testUpdateItem() {
1365         Item item = getItemRecord();
1366         item.setContent("mock update content");
1367         docstoreService.updateItem(item);
1368     }
1369 
1370     @Test
1371     public void testBrowseHoldings1() {
1372         BrowseParams browseParams = getBrowseParams1();
1373         SearchResponse searchResponse = docstoreService.browseHoldings(browseParams);
1374         Assert.assertNotNull(searchResponse);
1375     }
1376 
1377     @Test
1378     public void testBrowseHoldings2() {
1379         BrowseParams browseParams = getBrowseParams2();
1380         SearchResponse searchResponse = docstoreService.browseHoldings(browseParams);
1381         Assert.assertNotNull(searchResponse);
1382     }
1383 
1384     @Test
1385     public void testBrowseItems1() {
1386         BrowseParams browseParams = getBrowseParams3();
1387         SearchResponse searchResponse = docstoreService.browseItems(browseParams);
1388         Assert.assertNotNull(searchResponse);
1389     }
1390 
1391     @Test
1392     public void testBrowseItems2() {
1393         BrowseParams browseParams = getBrowseParams4();
1394         SearchResponse searchResponse = docstoreService.browseItems(browseParams);
1395         Assert.assertNotNull(searchResponse);
1396     }
1397 
1398 
1399     @Test
1400     public void testCreateDc() {
1401         String xml = getXmlAsString("/org/kuali/ole/documents/BibDUnqualified1.xml");
1402         Bib bibDcUnqualified = new BibDcUnqualified();
1403         bibDcUnqualified.setCategory("work");
1404         bibDcUnqualified.setType(DocType.BIB.getCode());
1405         bibDcUnqualified.setFormat(DocFormat.DUBLIN_UNQUALIFIED.getCode());
1406         bibDcUnqualified = (BibDcUnqualified) bibDcUnqualified.deserialize(xml);
1407         docstoreService.createBib(bibDcUnqualified);
1408         Assert.assertNotNull(bibDcUnqualified.getId());
1409     }
1410 
1411     public BrowseParams getBrowseParams1() {
1412         BrowseParams browseParams = new BrowseParams();
1413         String xml = getXmlAsString("/org/kuali/ole/browse/BrowseParams1.xml");
1414         return (BrowseParams) browseParams.deserialize(xml);
1415     }
1416 
1417     public BrowseParams getBrowseParams2() {
1418         BrowseParams browseParams = new BrowseParams();
1419         String xml = getXmlAsString("/org/kuali/ole/browse/BrowseParams2.xml");
1420         return (BrowseParams) browseParams.deserialize(xml);
1421     }
1422 
1423     public BrowseParams getBrowseParams3() {
1424         BrowseParams browseParams = new BrowseParams();
1425         String xml = getXmlAsString("/org/kuali/ole/browse/BrowseParams3.xml");
1426         return (BrowseParams) browseParams.deserialize(xml);
1427     }
1428 
1429     public BrowseParams getBrowseParams4() {
1430         BrowseParams browseParams = new BrowseParams();
1431         String xml = getXmlAsString("/org/kuali/ole/browse/BrowseParams4.xml");
1432         return (BrowseParams) browseParams.deserialize(xml);
1433     }
1434 
1435     private void updateContent(Bib bib) {
1436         BibMarcRecordProcessor bibMarcRecordProcessor = new BibMarcRecordProcessor();
1437         BibMarcRecords bibMarcRecords = bibMarcRecordProcessor.fromXML(bib.getContent());
1438         BibMarcRecord bibMarcRecord = bibMarcRecords.getRecords().get(0);
1439         List<DataField> dataFields = bibMarcRecord.getDataFields();
1440         for (DataField dataField : dataFields) {
1441             if (dataField.getTag().equalsIgnoreCase("245")) {
1442                 List<SubField> subFields = dataField.getSubFields();
1443                 subFields.get(0).setValue("The Alchemist");
1444             }
1445         }
1446         bib.setContent(bibMarcRecordProcessor.generateXML(bibMarcRecord));
1447     }
1448 
1449     private void setDate(Bib bib) {
1450         Date date = new Date();
1451         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
1452         String dateStr = sdf.format(date);
1453         bib.setCreatedOn(dateStr);
1454     }
1455 
1456     @Test
1457     public void testCreateLicenseAttachment() {
1458         LicenseAttachment license = new LicenseAttachment();
1459         license.setCategory("work");
1460         license.setType("license");
1461         license.setFormat("pdf");
1462         license.setFileName("123.pdf");
1463         license.setFilePath("file path");
1464         license.setId("wl-1");
1465         Licenses licenses = new Licenses();
1466         licenses.getLicenses().add(license);
1467         docstoreService.createLicenses(licenses);
1468     }
1469     @Test
1470     public void testCreateLicense() {
1471         Licenses licenses = new Licenses();
1472         License license = new LicenseOnixpl();
1473         license = (License) license.deserialize(getXmlAsString("/org/kuali/ole/documents/license-onixpl.xml"));
1474         licenses.getLicenses().add(license);
1475         docstoreService.createLicenses(licenses);
1476     }
1477 
1478     @Test
1479     public void testBulkUpdatePHoldings() {
1480         String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml");
1481         Bib bib = new BibMarc();
1482         bib = (Bib) bib.deserialize(xml);
1483         bib.setId(null);
1484         docstoreService.createBib(bib);
1485         Assert.assertNotNull(bib.getId());
1486 
1487         xml = getXmlAsString("/org/kuali/ole/documents/PHoldings1.xml");
1488         Holdings holdings = new PHoldings();
1489         holdings = (PHoldings) holdings.deserialize(xml);
1490         holdings.setBib(bib);
1491         docstoreService.createHoldings(holdings);
1492         Assert.assertNotNull(holdings.getId());
1493         Holdings holdings1 = holdings;
1494         holdings.setId(null);
1495         docstoreService.createHoldings(holdings);
1496         Assert.assertNotNull(holdings.getId());
1497         Holdings holdings2 = holdings;
1498         Assert.assertNotNull(holdings.getId());
1499 
1500 
1501         List<String> holdingIds = new ArrayList<String>();
1502         holdingIds.add(holdings1.getId());
1503         holdingIds.add(holdings2.getId());
1504 
1505         HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
1506         OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdings.getContent());
1507         oleHoldings.setCopyNumber("1234567");
1508         holdings.setContent(holdingOlemlRecordProcessor.toXML(oleHoldings));
1509         docstoreService.bulkUpdateHoldings(holdings, holdingIds,"false");
1510 
1511         Holdings updatedHoldings1 = docstoreService.retrieveHoldings(holdings1.getId());
1512         Assert.assertEquals(updatedHoldings1.getId(), holdings1.getId());
1513         OleHoldings updateOleHoldings1 = holdingOlemlRecordProcessor.fromXML(updatedHoldings1.getContent());
1514         Assert.assertNotNull(updateOleHoldings1);
1515         Assert.assertEquals(updateOleHoldings1.getCopyNumber(),"1234567");
1516 
1517         Holdings updatedHoldings2 = docstoreService.retrieveHoldings(holdings2.getId());
1518         Assert.assertEquals(updatedHoldings2.getId(), holdings2.getId());
1519         OleHoldings updateOleHoldings2 = holdingOlemlRecordProcessor.fromXML(updatedHoldings2.getContent());
1520         Assert.assertNotNull(updateOleHoldings2);
1521         Assert.assertEquals(updateOleHoldings2.getCopyNumber(),"1234567");
1522 
1523     }
1524 
1525     @Test
1526     public void testBulkUpdateEHoldings() {
1527         String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml");
1528         Bib bib = new BibMarc();
1529         bib = (Bib) bib.deserialize(xml);
1530         bib.setId(null);
1531         docstoreService.createBib(bib);
1532         Assert.assertNotNull(bib.getId());
1533 
1534         xml = getXmlAsString("/org/kuali/ole/documents/EHoldings1.xml");
1535         Holdings holdings = new EHoldings();
1536         holdings = (EHoldings) holdings.deserialize(xml);
1537         holdings.setBib(bib);
1538         docstoreService.createHoldings(holdings);
1539         Assert.assertNotNull(holdings.getId());
1540         Holdings holdings1 = holdings;
1541         holdings.setId(null);
1542         docstoreService.createHoldings(holdings);
1543         Assert.assertNotNull(holdings.getId());
1544         Holdings holdings2 = holdings;
1545         Assert.assertNotNull(holdings.getId());
1546 
1547 
1548         List<String> holdingIds = new ArrayList<String>();
1549         holdingIds.add(holdings1.getId());
1550         holdingIds.add(holdings2.getId());
1551 
1552         HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
1553         OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdings.getContent());
1554         oleHoldings.setImprint("Mock Imprint");
1555         holdings.setContent(holdingOlemlRecordProcessor.toXML(oleHoldings));
1556         docstoreService.bulkUpdateHoldings(holdings,holdingIds,"false");
1557 
1558         Holdings updatedHoldings1 = docstoreService.retrieveHoldings(holdings1.getId());
1559         Assert.assertEquals(updatedHoldings1.getId(), holdings1.getId());
1560         OleHoldings updateOleHoldings1 = holdingOlemlRecordProcessor.fromXML(updatedHoldings1.getContent());
1561         Assert.assertNotNull(updateOleHoldings1);
1562         Assert.assertEquals(updateOleHoldings1.getImprint(),"Mock Imprint");
1563 
1564         Holdings updatedHoldings2 = docstoreService.retrieveHoldings(holdings2.getId());
1565         Assert.assertEquals(updatedHoldings2.getId(), holdings2.getId());
1566         OleHoldings updateOleHoldings2 = holdingOlemlRecordProcessor.fromXML(updatedHoldings2.getContent());
1567         Assert.assertNotNull(updateOleHoldings2);
1568         Assert.assertEquals(updateOleHoldings2.getImprint(),"Mock Imprint");
1569 
1570     }
1571 
1572     @Test
1573     public void testBulkUpdateItem() {
1574 
1575         String xml = getXmlAsString("/org/kuali/ole/documents/BibMarc1.xml");
1576         Bib bib = new BibMarc();
1577         bib = (Bib) bib.deserialize(xml);
1578         bib.setId(null);
1579         docstoreService.createBib(bib);
1580         Assert.assertNotNull(bib.getId());
1581 
1582         xml = getXmlAsString("/org/kuali/ole/documents/EHoldings1.xml");
1583         Holdings holdings = new EHoldings();
1584         holdings = (EHoldings) holdings.deserialize(xml);
1585         holdings.setBib(bib);
1586         docstoreService.createHoldings(holdings);
1587         Assert.assertNotNull(holdings.getId());
1588 
1589         xml = getXmlAsString("/org/kuali/ole/documents/ItemOleml1.xml");
1590         Item item = new Item();
1591         item = (Item)item.deserialize(xml);
1592         item.setHolding(holdings);
1593         docstoreService.createItem(item);
1594         Assert.assertNotNull(item);
1595 
1596         Item item1 = new Item();
1597         item1 = (Item)item1.deserialize(xml);
1598         item1.setHolding(holdings);
1599         docstoreService.createItem(item1);
1600         Assert.assertNotNull(item1.getId());
1601 
1602         Item item2 = new Item();
1603         item2 = (Item)item2.deserialize(xml);
1604         item2.setHolding(holdings);
1605         docstoreService.createItem(item2);
1606         Assert.assertNotNull(item2.getId());
1607 
1608         List<String> itemIds = new ArrayList<String>();
1609         itemIds.add(item1.getId());
1610         itemIds.add(item2.getId());
1611 
1612         ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
1613         org.kuali.ole.docstore.common.document.content.instance.Item oleItem = itemOlemlRecordProcessor.fromXML(item.getContent());
1614 
1615         oleItem.setBarcodeARSL("mock barcodeARSL");
1616         item.setContent(itemOlemlRecordProcessor.toXML(oleItem));
1617         docstoreService.bulkUpdateItem(item,itemIds,"false");
1618 
1619         Item updateItem1 = docstoreService.retrieveItem(item1.getId());
1620         Assert.assertNotNull(updateItem1);
1621         org.kuali.ole.docstore.common.document.content.instance.Item updateOleItem1 = itemOlemlRecordProcessor.fromXML(updateItem1.getContent());
1622         Assert.assertNotNull(updateOleItem1);
1623         Assert.assertEquals(updateOleItem1.getBarcodeARSL(),"mock barcodeARSL");
1624 
1625 
1626         Item updateItem2 = docstoreService.retrieveItem(item2.getId());
1627         Assert.assertNotNull(updateItem2);
1628         org.kuali.ole.docstore.common.document.content.instance.Item updateOleItem2 = itemOlemlRecordProcessor.fromXML(updateItem2.getContent());
1629         Assert.assertNotNull(updateOleItem2);
1630         Assert.assertEquals(updateOleItem2.getBarcodeARSL(),"mock barcodeARSL");
1631     }
1632     
1633     @Test
1634     public void testGetNormalised() {
1635         RdbmsItemDocumentManager rdbmsItemDocumentManager = new RdbmsItemDocumentManager();
1636         String value = "v. 1";
1637         System.out.println("Before Normalization: " +value);
1638         System.out.println("After Normalization: " + rdbmsItemDocumentManager.getNormalized(value));
1639         value = "v.2";
1640         System.out.println("Before Normalization: " +value);
1641         System.out.println("After Normalization: " +rdbmsItemDocumentManager.getNormalized(value));
1642         value = "v. 3";
1643         System.out.println("Before Normalization: " +value);
1644         System.out.println("After Normalization: " +rdbmsItemDocumentManager.getNormalized(value));
1645         BibTree bibTree = new BibTree();
1646         Bib bib = new Bib();
1647         bib.setId("wbm-10000001");
1648         bibTree.setBib(bib);
1649         ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
1650         bibTree = docstoreService.retrieveBibTree(bibTree.getBib().getId());
1651         System.out.println("AFTER SORTING ITEMS:");
1652         for (HoldingsTree holdingsTree : bibTree.getHoldingsTrees()) {
1653             System.out.println("***HOLDINGS***");
1654             System.out.println("ITEMS : Loc | Prefix | ShlOrd | Enum | Chro | Copy | bar");
1655             for (Item item : holdingsTree.getItems()) {
1656                 org.kuali.ole.docstore.common.document.content.instance.Item item1 = itemOlemlRecordProcessor.fromXML(item.getContent());
1657 //                System.out.println(strItems.format("%s | %s | %s | %s | %s | %s | %s", Holdings.buildLocationString(item1.getLocation()), item1.getCallNumber().getPrefix(),
1658 //                        item1.getCallNumber().getShelvingOrder().getCodeValue(), item1.getEnumeration(), item1.getChronology(), item1.getCopyNumber(), item1.getAccessInformation().getBarcode() + "\n"));
1659             }
1660         }
1661     }
1662 
1663     @Test
1664     public void processBibTrees() {
1665         BibTrees bibTrees = getBibTrees();
1666         docstoreService.processBibTrees(bibTrees);
1667         List<String> bibIds = new ArrayList<String>();
1668         for (BibTree bibTree : bibTrees.getBibTrees()) {
1669             if (null != bibTree.getBib()) {
1670                 bibIds.add(bibTree.getBib().getId());
1671             }
1672         }
1673         docstoreService.retrieveBibTrees(bibIds);
1674         SearchParams searchParams = buildSearchParams();
1675         docstoreService.search(searchParams);
1676 
1677         updateBibTree(bibTrees.getBibTrees().get(0));
1678         bibTrees.getBibTrees().get(0).getBib().setOperation(DocstoreDocument.OperationType.DELETE);
1679 
1680         updateBibTree(bibTrees.getBibTrees().get(1));
1681         docstoreService.processBibTrees(bibTrees);
1682         docstoreService.retrieveBibTrees(bibIds);
1683 
1684         docstoreService.search(searchParams);
1685 
1686 
1687     }
1688 
1689     private void updateBibTree(BibTree bibTree) {
1690         Bib bib=bibTree.getBib();
1691 
1692         bib.setOperation(DocstoreDocument.OperationType.UPDATE);
1693         bib.setResult(null);
1694         BibMarcRecordProcessor bibMarcRecordProcessor = new BibMarcRecordProcessor();
1695          BibMarcRecords bibMarcRecords= bibMarcRecordProcessor.fromXML(bib.getContent());
1696         for(BibMarcRecord bibMarcRecord: bibMarcRecords.getRecords()){
1697             for(DataField dataField:bibMarcRecord.getDataFields()){
1698                 if("245".equals(dataField.getTag())){
1699                    for(SubField subField:dataField.getSubFields()){
1700                        if(subField.getCode().equals("a")){
1701                            subField.setValue("Author-1 Updated");
1702                        }
1703                    }
1704                 }
1705             }
1706         }
1707         bib.setContent(bibMarcRecordProcessor.toXml(bibMarcRecords));
1708         List<HoldingsTree> holdingsTrees = bibTree.getHoldingsTrees();
1709 
1710         HoldingsTree holdingsTree=holdingsTrees.get(0);
1711         //creating another holding
1712         Holdings holdings=holdingsTree.getHoldings();
1713         holdings.setMessage(null);
1714         holdings.setResult(null);
1715         holdings.setOperation(DocstoreDocument.OperationType.CREATE);
1716         holdings.setId(null);
1717 
1718         for(Item item:holdingsTree.getItems()){
1719             item.setMessage(null);
1720             item.setResult(null);
1721             item.setId(null);
1722             item.setOperation(DocstoreDocument.OperationType.CREATE);
1723         }
1724 
1725          holdingsTree=holdingsTrees.get(1);
1726         //creating another holding
1727         holdings=holdingsTree.getHoldings();
1728         holdings.setOperation(Holdings.OperationType.UPDATE);
1729         holdings.setMessage(null);
1730         holdings.setResult(null);
1731 
1732         Item item =holdingsTree.getItems().get(0);
1733         item.setMessage(null);
1734         item.setResult(null);
1735         item.setOperation(DocstoreDocument.OperationType.DELETE);
1736 
1737         item =holdingsTree.getItems().get(1);
1738         item.setMessage(null);
1739         item.setResult(null);
1740         item.setOperation(DocstoreDocument.OperationType.UPDATE);
1741 
1742 
1743         holdingsTree=holdingsTrees.get(2);
1744         //creating another holding
1745         holdings=holdingsTree.getHoldings();
1746         holdings.setOperation(Holdings.OperationType.DELETE);
1747         holdings.setMessage(null);
1748         holdings.setResult(null);
1749 
1750 
1751 
1752     }
1753 
1754     private SearchParams buildSearchParams() {
1755         SearchParams searchParams = new SearchParams();
1756         String xml = getXmlAsString("/org/kuali/ole/search/BibTreesSearchParams1.xml");
1757         return (SearchParams) searchParams.deserialize(xml);
1758     }
1759 
1760     public BibTrees getBibTrees() {
1761         BibTrees bibTrees = new BibTrees();
1762         bibTrees= (BibTrees) bibTrees.deserialize(getXmlAsString("/org/kuali/ole/documents/BibTrees1.xml"));
1763         List<BibTree> removeBibtrees = new  ArrayList<BibTree>();
1764         for (BibTree bibTree : bibTrees.getBibTrees()) {
1765             if (null == bibTree.getBib()) {
1766                 removeBibtrees.add(bibTree);
1767             }
1768         }
1769         bibTrees.getBibTrees().removeAll(removeBibtrees);
1770         return bibTrees;
1771     }
1772 
1773     @Test
1774     public void updateBibsFailure() {
1775         List<String> bibIds = new ArrayList<String>();
1776         bibIds.add("10000016");
1777         bibIds.add("10000017");
1778         bibIds.add("10000018");
1779         bibIds.add("10000019");
1780         bibIds.add("10000020");
1781         List<Bib> bibs = docstoreService.retrieveBibs(bibIds);
1782         bibs.get(0).setStatus("None");
1783         try {
1784             docstoreService.updateBibs(bibs);
1785         } catch (Exception e) {
1786             bibs = docstoreService.retrieveBibs(bibIds);
1787             Assert.assertEquals("", bibs.get(0).getStatus());
1788         }
1789 
1790     }
1791 
1792 
1793     @Test
1794     public  void searchQuery() throws SolrServerException {
1795         SearchParams searchParams = new SearchParams();
1796         SolrQuery solrQuery = new SolrQuery();
1797         DocstoreSolrSearchService docstoreSolrSearchService = new DocstoreSolrSearchService();
1798         for(int bibCount = 0;bibCount<250;bibCount++){
1799             SearchCondition searchCondition = searchParams.buildSearchCondition("",searchParams.buildSearchField("bibliographic","LocalId_search", "1000000"+String.valueOf(bibCount)),"OR");
1800             searchParams.getSearchConditions().add(searchCondition);
1801         }
1802         SolrServer server = SolrServerManager.getInstance().getSolrServer();
1803         String query = docstoreSolrSearchService.buildQueryWithSearchParams(searchParams);
1804         solrQuery.setQuery(query);
1805         System.out.println("Executing solr query :" + solrQuery.toString().length());
1806         QueryResponse response = server.query(solrQuery, SolrRequest.METHOD.POST);
1807 
1808 
1809     }
1810 
1811     @Test
1812     public void testCreateAnalytics() {
1813 
1814         BibTree bibTree1 = getBibTree1();
1815         Assert.assertNotNull(bibTree1);
1816         docstoreService.createBibTree(bibTree1);
1817 
1818         BibTree bibTree2 = getBibTree2();
1819         Assert.assertNotNull(bibTree2);
1820         docstoreService.createBibTree(bibTree2);
1821 
1822         String seriesHoldingsId = bibTree1.getHoldingsTrees().get(0).getHoldings().getId();
1823         Assert.assertNotNull(seriesHoldingsId);
1824 
1825         List<String> itemIds = new ArrayList<String>();
1826         List<Item> items = bibTree2.getHoldingsTrees().get(0).getItems();
1827         Assert.assertNotNull(items);
1828 
1829         for (Item item : items) {
1830             itemIds.add(item.getId());
1831         }
1832         Assert.assertNotNull(itemIds);
1833         docstoreService.createAnalyticsRelation(seriesHoldingsId, itemIds);
1834         Assert.assertEquals(docstoreService.retrieveHoldings(seriesHoldingsId).isSeries(), Boolean.TRUE);
1835         items = docstoreService.retrieveItems(itemIds);
1836         for (Item item : items) {
1837             Assert.assertEquals(item.isAnalytic(), Boolean.TRUE);
1838         }
1839     }
1840 
1841     @Test
1842     public void testBreakAnalytics() {
1843 
1844         BibTree bibTree1 = getBibTree3();
1845         Assert.assertNotNull(bibTree1);
1846         docstoreService.createBibTree(bibTree1);
1847 
1848         BibTree bibTree2 = getBibTree4();
1849         Assert.assertNotNull(bibTree2);
1850         docstoreService.createBibTree(bibTree2);
1851 
1852         String seriesHoldingsId = bibTree1.getHoldingsTrees().get(0).getHoldings().getId();
1853         Assert.assertNotNull(seriesHoldingsId);
1854 
1855         List<String> itemIds = new ArrayList<String>();
1856         List<Item> items = bibTree2.getHoldingsTrees().get(0).getItems();
1857         Assert.assertNotNull(items);
1858 
1859         for (Item item : items) {
1860             itemIds.add(item.getId());
1861         }
1862         Assert.assertNotNull(itemIds);
1863 
1864         docstoreService.createAnalyticsRelation(seriesHoldingsId, itemIds);
1865         Assert.assertEquals(docstoreService.retrieveHoldings(seriesHoldingsId).isSeries(), Boolean.TRUE);
1866         items = docstoreService.retrieveItems(itemIds);
1867         for (Item item : items) {
1868             Assert.assertEquals(item.isAnalytic(), Boolean.TRUE);
1869         }
1870         docstoreService.breakAnalyticsRelation(seriesHoldingsId, itemIds);
1871         Assert.assertEquals(docstoreService.retrieveHoldings(seriesHoldingsId).isSeries(), Boolean.FALSE);
1872         items = docstoreService.retrieveItems(itemIds);
1873         for (Item item : items) {
1874             Assert.assertEquals(item.isAnalytic(), Boolean.FALSE);
1875         }
1876     }
1877 
1878     public BibTree getBibTree4() {
1879         BibTree bibTree = new BibTree();
1880         return (BibTree) bibTree.deserialize(getXmlAsString("/org/kuali/ole/search/BibTree4.xml"));
1881     }
1882 
1883 }