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