View Javadoc
1   package org.kuali.ole.docstore.engine.service.rest;
2   
3   import org.apache.commons.io.FileUtils;
4   import org.junit.Assert;
5   import org.junit.Before;
6   import org.junit.Ignore;
7   import org.junit.Test;
8   import org.kuali.ole.BaseTestCase;
9   import org.kuali.ole.DocumentUniqueIDPrefix;
10  import org.kuali.ole.docstore.common.client.DocstoreRestClient;
11  import org.kuali.ole.docstore.common.client.RestResponse;
12  import org.kuali.ole.docstore.common.document.*;
13  import org.kuali.ole.docstore.common.document.HoldingsTree;
14  import org.kuali.ole.docstore.common.document.Item;
15  import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecord;
16  import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecords;
17  import org.kuali.ole.docstore.common.document.content.bib.marc.DataField;
18  import org.kuali.ole.docstore.common.document.content.bib.marc.SubField;
19  import org.kuali.ole.docstore.common.document.content.bib.marc.xstream.BibMarcRecordProcessor;
20  import org.kuali.ole.docstore.common.document.content.instance.*;
21  import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
22  import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
23  import org.kuali.ole.docstore.common.search.BrowseParams;
24  import org.kuali.ole.docstore.common.search.SearchParams;
25  import org.kuali.ole.docstore.common.search.SearchResponse;
26  import org.kuali.ole.docstore.engine.service.index.solr.BibConstants;
27  import org.kuali.ole.docstore.model.enums.DocCategory;
28  import org.kuali.ole.docstore.model.enums.DocFormat;
29  import org.kuali.ole.docstore.model.enums.DocType;
30  import org.mockito.MockitoAnnotations;
31  import org.slf4j.Logger;
32  import org.slf4j.LoggerFactory;
33  
34  import java.io.File;
35  import java.text.SimpleDateFormat;
36  import java.util.*;
37  
38  /**
39   * Created with IntelliJ IDEA.
40   * User: rajeshbabuk
41   * Date: 1/20/14
42   * Time: 5:14 PM
43   * To change this template use File | Settings | File Templates.
44   */
45  public class DocstoreRestClient_UT extends BaseTestCase {
46  
47      private static final Logger LOG = LoggerFactory.getLogger(DocstoreRestClient_UT.class);
48      private DocstoreRestClient restClient = new DocstoreRestClient();
49  
50  
51      @Before
52      public void setUp() throws Exception {
53          super.setUp();
54          MockitoAnnotations.initMocks(this);
55      }
56  
57      @Ignore
58      @Test
59      public void createBib() {
60          String input = "";
61          File file = null;
62          try {
63              file = new File(getClass().getResource("/documents/BibMarc1.xml").toURI());
64              input = FileUtils.readFileToString(file);
65          } catch (Exception e) {
66              LOG.info("Exception :", e);
67          }
68          Bib bibMarc = new Bib();
69          bibMarc = (Bib) bibMarc.deserialize(input);
70          bibMarc.setId("");
71          restClient.createBib(bibMarc);
72          Assert.assertNotNull(bibMarc.getId());
73          Bib bib = restClient.retrieveBib(bibMarc.getId());
74          bib = (Bib) bib.deserializeContent(bib);
75          Assert.assertEquals(bib.getId(), bibMarc.getId());
76          SearchParams searchParams = new SearchParams();
77          searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "Title"));
78          searchParams.getSearchConditions().add(searchParams.buildSearchCondition("AND", searchParams.buildSearchField("bibliographic", "id", bibMarc.getId()), "OR"));
79          SearchResponse searchResponse = restClient.search(searchParams);
80          Assert.assertEquals("Thankfulness to Almighty God", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldValue());
81      }
82  
83      @Ignore
84      @Test
85      public void createBibUnicode() {
86          String input = "";
87          File file = null;
88          try {
89              file = new File(getClass().getResource("/documents/BibMarc1.xml").toURI());
90              input = FileUtils.readFileToString(file);
91          } catch (Exception e) {
92              LOG.info("Exception :", e);
93          }
94          Bib bibMarc = new Bib();
95          bibMarc = (Bib) bibMarc.deserialize(input);
96          bibMarc.setId("");
97          restClient.createBib(bibMarc);
98          Assert.assertNotNull(bibMarc.getId());
99          Bib bib = restClient.retrieveBib(bibMarc.getId());
100         System.out.println(bib.getContent());
101       //  Bib bib = bibtree.getBib();
102     }
103 
104     @Ignore
105     @Test
106     public void updateBib() {
107         String input = "";
108         File file = null;
109         try {
110             file = new File(getClass().getResource("/documents/BibMarc1.xml").toURI());
111             input = FileUtils.readFileToString(file);
112 
113         } catch (Exception e) {
114             LOG.info("Exception :", e);
115         }
116         Bib bibMarc = new Bib();
117         bibMarc = (Bib) bibMarc.deserialize(input);
118         restClient.createBib(bibMarc);
119         bibMarc = restClient.retrieveBib(bibMarc.getId());
120         setDate(bibMarc);
121         updateContent(bibMarc);
122         restClient.updateBib(bibMarc);
123         bibMarc = restClient.retrieveBib(bibMarc.getId());
124         Assert.assertNotNull(bibMarc.getId());
125         Assert.assertEquals("The Alchemist", bibMarc.getTitle());
126 
127         SearchParams searchParams = new SearchParams();
128         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "Title"));
129         searchParams.getSearchConditions().add(searchParams.buildSearchCondition("AND", searchParams.buildSearchField("bibliographic", "id", bibMarc.getId()), "OR"));
130         SearchResponse searchResponse = restClient.search(searchParams);
131         Assert.assertEquals("The Alchemist", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldValue());
132     }
133 
134     @Ignore
135     @Test
136     public void updateBibs() {
137         String input = "";
138         File file = null;
139         try {
140             file = new File(getClass().getResource("/documents/BibMarc1.xml").toURI());
141             input = FileUtils.readFileToString(file);
142 
143         } catch (Exception e) {
144             LOG.info("Exception :", e);
145         }
146         Bib bibMarc = new Bib();
147         bibMarc = (Bib) bibMarc.deserialize(input);
148         restClient.createBib(bibMarc);
149         bibMarc = restClient.retrieveBib(bibMarc.getId());
150         setDate(bibMarc);
151         updateContent(bibMarc);
152         List<Bib> bibs = new ArrayList<>();
153         bibs.add(bibMarc);
154         restClient.updateBibs(bibs);
155         bibMarc = restClient.retrieveBib(bibMarc.getId());
156         Assert.assertNotNull(bibMarc.getId());
157         Assert.assertEquals("The Alchemist", bibMarc.getTitle());
158 
159         SearchParams searchParams = new SearchParams();
160         searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "Title"));
161         searchParams.getSearchConditions().add(searchParams.buildSearchCondition("AND", searchParams.buildSearchField("bibliographic", "id", bibMarc.getId()), "OR"));
162         SearchResponse searchResponse = restClient.search(searchParams);
163         Assert.assertEquals("The Alchemist", searchResponse.getSearchResults().get(0).getSearchResultFields().get(0).getFieldValue());
164     }
165 
166     @Ignore
167     @Test
168     public void retrieveBib() {
169         String input = "";
170         File file = null;
171         try {
172             file = new File(getClass().getResource("/documents/BibMarc1.xml").toURI());
173             input = FileUtils.readFileToString(file);
174 
175         } catch (Exception e) {
176             LOG.info("Exception :", e);
177         }
178         Bib bibMarc = new Bib();
179         bibMarc = (Bib) bibMarc.deserialize(input);
180         restClient.createBib(bibMarc);
181 
182         Bib bib = restClient.retrieveBib(bibMarc.getId());
183         bib = (Bib) bib.deserializeContent(bib);
184         Assert.assertEquals(bibMarc.getId(), bib.getId());
185     }
186 
187     @Ignore
188     @Test
189     public void retrieveBibs() {
190         List<String> bibIds = new ArrayList<String>();
191         bibIds.add("wbm-10000001");
192         bibIds.add("wbm-10000002");
193         List<Bib> bibs = restClient.retrieveBibs(bibIds);
194         Assert.assertNotNull(bibs.get(0));
195         Assert.assertNotNull(bibs.get(1));
196 
197     }
198 
199     @Ignore
200     @Test
201     public void createBibTree() {
202         String input = "";
203         File file = null;
204         try {
205             file = new File(getClass().getResource("/documents/BibTree1.xml").toURI());
206             input = FileUtils.readFileToString(file);
207         } catch (Exception e) {
208             LOG.info("Exception :", e);
209         }
210         BibTree bibTree = new BibTree();
211         bibTree = (BibTree) bibTree.deserialize(input);
212         restClient.createBibTree(bibTree);
213         Assert.assertNotNull(bibTree.getBib().getId());
214         Map map = new HashMap();
215         map.put(BibConstants.DOC_TYPE, "bibliographic");
216         map.put("ID", bibTree.getBib().getId());
217         BibTree retrievedBibTree = restClient.findBibTree(map);
218         Map holdingsMap = new HashMap();
219         holdingsMap.put("ID", retrievedBibTree.getHoldingsTrees().get(0).getHoldings().getId());
220         holdingsMap.put(BibConstants.DOC_TYPE, "holdings");
221         HoldingsTree holdingsTree = restClient.findHoldingsTree(holdingsMap);
222         Assert.assertNotNull(holdingsTree.getHoldings().getId());
223         Assert.assertNotNull(holdingsTree.getItems().get(0).getId());
224         Assert.assertEquals(bibTree.getBib().getId(), retrievedBibTree.getBib().getId());
225         Assert.assertEquals(retrievedBibTree.getHoldingsTrees().get(0).getHoldings().getId(), holdingsTree.getHoldings().getId());
226     }
227 
228     @Ignore
229     @Test
230     public void retrieveBibTree() {
231         BibTree bibTree = restClient.retrieveBibTree("wbm-10000003");
232         Assert.assertEquals(bibTree.getId(), "wbm-10000003");
233     }
234 
235     @Ignore
236     @Test
237     public void findBib() {
238         createBib();
239         Map map = new HashMap();
240         map.put(BibConstants.DOC_TYPE, "bibliographic");
241         map.put("ID", "wbm-10000001");
242         Bib bib = restClient.findBib(map);
243         Assert.assertEquals(bib.getId(), "wbm-10000001");
244     }
245 
246     @Ignore
247     @Test
248     public void findBibTree() {
249         createBib();
250         Map map = new HashMap();
251         map.put(BibConstants.DOC_TYPE, "bibliographic");
252         map.put("ID", "wbm-10000001");
253         BibTree bibTree = restClient.findBibTree(map);
254         Assert.assertEquals(bibTree.getBib().getId(), "wbm-10000001");
255     }
256 
257     @Ignore
258     @Test
259     public void deleteBib() {
260         String input = "";
261         File file = null;
262         try {
263             file = new File(getClass().getResource("/documents/BibMarc1.xml").toURI());
264             input = FileUtils.readFileToString(file);
265 
266         } catch (Exception e) {
267             LOG.info("Exception :", e);
268         }
269         Bib bibMarc = new Bib();
270         bibMarc = (Bib) bibMarc.deserialize(input);
271         restClient.createBib(bibMarc);
272 
273         restClient.deleteBib(bibMarc.getId());
274     }
275 
276     @Ignore
277     @Test
278     public void deleteBibs() {
279         String input = "";
280         File file = null;
281         try {
282             file = new File(getClass().getResource("/documents/BibMarc1.xml").toURI());
283             input = FileUtils.readFileToString(file);
284 
285         } catch (Exception e) {
286             LOG.info("Exception :", e);
287         }
288         Bib bibMarc = new Bib();
289         bibMarc = (Bib) bibMarc.deserialize(input);
290         restClient.createBib(bibMarc);
291 
292         List bibIds = new ArrayList<>();
293         bibIds.add(bibMarc.getId());
294         restClient.deleteBibs(bibIds);
295 
296     }
297 
298     @Ignore
299     @Test
300     public void testCreateEHoldings() {
301         String input = "";
302         File file = null;
303         try {
304             file = new File(getClass().getResource("/documents/BibMarc1.xml").toURI());
305             input = FileUtils.readFileToString(file);
306 
307         } catch (Exception e) {
308             LOG.info("Exception :", e);
309         }
310         Bib bibMarc = new Bib();
311         bibMarc = (Bib) bibMarc.deserialize(input);
312         restClient.createBib(bibMarc);
313 
314         try {
315             file = new File(getClass().getResource("/documents/EHoldings1.xml").toURI());
316             input = FileUtils.readFileToString(file);
317         } catch (Exception e) {
318             LOG.info("Exception :", e);
319         }
320         Holdings holdings = new EHoldings();
321         holdings = (EHoldings) holdings.deserialize(input);
322         holdings.setBib(bibMarc);
323         restClient.createHoldings(holdings);
324 
325         HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
326         OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdings.getContent());
327         CallNumber callNumber = oleHoldings.getCallNumber();
328 
329         Assert.assertNotNull(holdings.getId());
330 
331         Holdings holdings1 = restClient.retrieveHoldings(holdings.getId());
332         OleHoldings oleHoldings1 = holdingOlemlRecordProcessor.fromXML(holdings.getContent());
333         CallNumber callNumber1 = oleHoldings1.getCallNumber();
334         Assert.assertEquals(callNumber.getNumber(),callNumber1.getNumber());
335 
336     }
337 
338     @Ignore
339     @Test
340     public void testUpdateEHoldings() {
341         String input = "";
342         File file = null;
343         try {
344             file = new File(getClass().getResource("/documents/EHoldings1.xml").toURI());
345             input = FileUtils.readFileToString(file);
346         } catch (Exception e) {
347             LOG.info("Exception :", e);
348         }
349         Holdings holdings = new EHoldings();
350         holdings = (EHoldings) holdings.deserialize(input);
351         restClient.createHoldings(holdings);
352         Assert.assertNotNull(holdings.getId());
353         HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
354         OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdings.getContent());
355         oleHoldings.setCopyNumber("1234567");
356         holdings.setContent(holdingOlemlRecordProcessor.toXML(oleHoldings));
357         restClient.updateHoldings(holdings);
358         Holdings holdings1 = restClient.retrieveHoldings(holdings.getId());
359         Assert.assertEquals(holdings1.getId(), holdings.getId());
360         Assert.assertNotNull(holdings.getId());
361     }
362 
363     @Ignore
364     @Test
365     public void testCreatePHoldings() {
366         String input = "";
367         File file = null;
368         try {
369             file = new File(getClass().getResource("/documents/PHoldings1.xml").toURI());
370             input = FileUtils.readFileToString(file);
371         } catch (Exception e) {
372             LOG.info("Exception :", e);
373         }
374         Holdings holdings = new PHoldings();
375         holdings = (PHoldings) holdings.deserialize(input);
376         restClient.createHoldings(holdings);
377         Assert.assertNotNull(holdings.getId());
378     }
379 
380     @Ignore
381     @Test
382     public void testUpdatePHoldings() {
383         String input = "";
384         File file = null;
385         try {
386             file = new File(getClass().getResource("/documents/PHoldings1.xml").toURI());
387             input = FileUtils.readFileToString(file);
388         } catch (Exception e) {
389             LOG.info("Exception :", e);
390         }
391         Holdings holdings = new PHoldings();
392         holdings = (PHoldings) holdings.deserialize(input);
393         restClient.createHoldings(holdings);
394         Assert.assertNotNull(holdings.getId());
395         HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
396         OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdings.getContent());
397         oleHoldings.setCopyNumber("1234567");
398         holdings.setContent(holdingOlemlRecordProcessor.toXML(oleHoldings));
399         restClient.updateHoldings(holdings);
400         Holdings holdings1 = restClient.retrieveHoldings(holdings.getId());
401         Assert.assertEquals(holdings1.getId(), holdings.getId());
402         Assert.assertNotNull(holdings.getId());
403     }
404 
405     @Ignore
406     @Test
407     public void retrievePHoldings() {
408         String input = "";
409         File file = null;
410         try {
411             file = new File(getClass().getResource("/documents/PHoldings1.xml").toURI());
412             input = FileUtils.readFileToString(file);
413         } catch (Exception e) {
414             LOG.info("Exception :", e);
415         }
416         Holdings holdings = new PHoldings();
417         holdings = (PHoldings) holdings.deserialize(input);
418         restClient.createHoldings(holdings);
419         Assert.assertNotNull(holdings.getId());
420 
421 
422         Holdings holdings1 = restClient.retrieveHoldings(holdings.getId());
423         Assert.assertEquals(holdings1.getId(), holdings.getId());
424     }
425 
426     @Ignore
427     @Test
428     public void retrieveEHoldings() {
429         String input = "";
430         File file = null;
431         try {
432             file = new File(getClass().getResource("/documents/EHoldings1.xml").toURI());
433             input = FileUtils.readFileToString(file);
434         } catch (Exception e) {
435             LOG.info("Exception :", e);
436         }
437         Holdings holdings = new EHoldings();
438         holdings = (EHoldings) holdings.deserialize(input);
439         restClient.createHoldings(holdings);
440         Assert.assertNotNull(holdings.getId());
441         Holdings holdings1 = restClient.retrieveHoldings(holdings.getId());
442         Assert.assertEquals(holdings1.getId(), holdings.getId());
443     }
444 
445     @Ignore
446     @Test
447     public void createHoldingsTree() {
448         String bibInput = "";
449         File bibFile = null;
450         String holdingsInput = "";
451         File holdingsFile = null;
452         try {
453             bibFile = new File(getClass().getResource("/documents/BibMarc1.xml").toURI());
454             bibInput = FileUtils.readFileToString(bibFile);
455             holdingsFile = new File(getClass().getResource("/documents/HoldingsTree2.xml").toURI());
456             holdingsInput = FileUtils.readFileToString(holdingsFile);
457         } catch (Exception e) {
458             LOG.info("Exception :", e);
459         }
460         HoldingsTree holdingsTree = new HoldingsTree();
461         Bib bibMarc = new Bib();
462         bibMarc = (Bib) bibMarc.deserialize(bibInput);
463         bibMarc.setId("");
464         restClient.createBib(bibMarc);
465         holdingsTree = (HoldingsTree) holdingsTree.deserialize(holdingsInput);
466         holdingsTree.getHoldings().setBib(bibMarc);
467         restClient.createHoldingsTree(holdingsTree);
468         HoldingsTree retrievedHoldingsTree = restClient.retrieveHoldingsTree(holdingsTree.getHoldings().getId());
469         Assert.assertNotNull(retrievedHoldingsTree);
470         Assert.assertEquals(holdingsTree.getHoldings().getId(), retrievedHoldingsTree.getHoldings().getId());
471     }
472 
473     @Ignore
474     @Test
475     public void retrieveHoldingsTree() {
476         HoldingsTree holdingsTree = new HoldingsTree();
477         holdingsTree = restClient.retrieveHoldingsTree("who-1");
478         Assert.assertEquals(holdingsTree.getHoldings().getId(), "who-1");
479     }
480 
481     @Ignore
482     @Test
483     public void findHoldings() {
484         testCreatePHoldings();
485         Map map = new HashMap();
486         map.put("ID", "who-1");
487         map.put(BibConstants.DOC_TYPE, "holdings");
488         Holdings holdings = restClient.findHoldings(map);
489         Assert.assertEquals(holdings.getId(), "who-1");
490 
491     }
492 
493     @Ignore
494     @Test
495     public void findHoldingsTree() {
496         testCreatePHoldings();
497         Map map = new HashMap();
498         map.put("ID", "who-1");
499         map.put(BibConstants.DOC_TYPE, "holdings");
500         HoldingsTree holdingsTree = restClient.findHoldingsTree(map);
501         Assert.assertEquals(holdingsTree.getHoldings().getId(), "who-1");
502 
503     }
504 
505     private HoldingsTree getHoldingsTreeRecord() {
506         HoldingsTree holdingsTree = new HoldingsTree();
507         holdingsTree.setHoldings(getHoldingsRecord());
508         holdingsTree.getItems().add(getItemRecord());
509         return holdingsTree;
510     }
511 
512     private Bib getBibRecord() {
513         Bib bib = new Bib();
514         bib.setCategory(DocCategory.WORK.getCode());
515         bib.setType(DocType.BIB.getCode());
516         bib.setFormat(DocFormat.MARC.getCode());
517         bib.setId("wbm-10000001");
518         return bib;
519     }
520 
521     private Item getItemRecord() {
522         Item item = new ItemOleml();
523         item.setCategory("work");
524         item.setType("item");
525         item.setFormat("oleml");
526         org.kuali.ole.docstore.common.document.content.instance.Item item1 = new org.kuali.ole.docstore.common.document.content.instance.Item();
527         item1.setVolumeNumber("123");
528         item1.setChronology("12344");
529         item1.setEnumeration("en");
530         item1.setBarcodeARSL("bararsl");
531         item.setContent(new ItemOlemlRecordProcessor().toXML(item1));
532         return item;
533     }
534 
535     private Holdings getHoldingsRecord() {
536         Holdings holdings = new PHoldings();
537         holdings.setCategory(DocCategory.WORK.getCode());
538         holdings.setType(DocType.HOLDINGS.getCode());
539         holdings.setFormat(DocFormat.OLEML.getCode());
540 
541         OleHoldings oleHoldings = new OleHoldings();
542         ShelvingScheme shelvingScheme = new ShelvingScheme();
543         shelvingScheme.setCodeValue("LCC");
544         CallNumber callNumber = new CallNumber();
545         callNumber.setNumber("1234");
546         callNumber.setShelvingScheme(shelvingScheme);
547         oleHoldings.setCallNumber(callNumber);
548         holdings.setContent(new HoldingOlemlRecordProcessor().toXML(oleHoldings));
549         holdings.setBib(getBibRecord());
550         return holdings;
551     }
552 
553     @Ignore
554     @Test
555     public void deletePHoldings() {
556         String input = "";
557         File file = null;
558         try {
559             file = new File(getClass().getResource("/documents/PHoldings1.xml").toURI());
560             input = FileUtils.readFileToString(file);
561         } catch (Exception e) {
562             LOG.info("Exception :", e);
563         }
564         Holdings holdings = new PHoldings();
565         holdings = (PHoldings) holdings.deserialize(input);
566         restClient.createHoldings(holdings);
567         Assert.assertNotNull(holdings.getId());
568         restClient.deleteHoldings(holdings.getId());
569 
570     }
571 
572     @Ignore
573     @Test
574     public void deleteEHoldings() {
575         String input = "";
576         File file = null;
577         try {
578             file = new File(getClass().getResource("/documents/EHoldings1.xml").toURI());
579             input = FileUtils.readFileToString(file);
580         } catch (Exception e) {
581             LOG.info("Exception :", e);
582         }
583         Holdings holdings = new EHoldings();
584         holdings = (EHoldings) holdings.deserialize(input);
585         restClient.createHoldings(holdings);
586         Assert.assertNotNull(holdings.getId());
587         restClient.deleteHoldings(holdings.getId());
588 
589     }
590 
591     @Ignore
592     @Test
593     public void testTransferHoldings() {
594         /*List<String> holdingsIds =new ArrayList<String>();
595         String bibId="wbm-10000005";
596         holdingsIds.add("who-5".toString());*/
597         String bibId = "wbm-10000005";
598         String holdingsId = "who-5";
599         List holdingIds = new ArrayList<String>();
600         holdingIds.add(holdingsId);
601         restClient.transferHoldings(holdingIds, bibId);
602 
603     }
604 
605     @Ignore
606     @Test
607     public void testBrowseHoldings() {
608         BrowseParams browseParams = getBrowseParams1();
609         SearchResponse searchResponse = restClient.browseHoldings(browseParams);
610         Assert.assertNotNull(searchResponse);
611     }
612 
613     public BrowseParams getBrowseParams1() {
614         BrowseParams browseParams = new BrowseParams();
615         String xml = getXmlAsString("/org/kuali/ole/browse/BrowseParams1.xml");
616         return (BrowseParams) browseParams.deserialize(xml);
617     }
618 
619     public String getXmlAsString(String filePath) {
620         String input = "";
621         File file = null;
622         try {
623             file = new File(getClass().getResource(filePath).toURI());
624             input = FileUtils.readFileToString(file);
625         } catch (Exception e) {
626             LOG.info("Exception :", e);
627         }
628         return input;
629     }
630 
631     @Ignore
632     @Test
633     public void createItem() {
634         Item item = getItemRecord();
635         String serializeXml = item.serialize(item);
636         RestResponse response = restClient.postRequest(serializeXml, "items/doc/");
637         Assert.assertEquals(200, response.getResponse().getStatusLine().getStatusCode());
638         Assert.assertNotNull(response.getResponseBody());
639     }
640 
641     @Ignore
642     @Test
643     public void retrieveBibContent() {
644         Bib bib1 = getBibRecord1();
645         restClient.createBib(bib1);
646         Bib bib2 = getBibRecord2();
647         restClient.createBib(bib2);
648         List<String> bibIds = new ArrayList<>();
649         bibIds.add(bib1.getId());
650         bibIds.add(bib2.getId());
651         BibMarcRecords bibMarcRecords = restClient.retrieveBibContent(bibIds);
652         Assert.assertNotNull(bibMarcRecords);
653         Assert.assertEquals(DocumentUniqueIDPrefix.getDocumentId(bib1.getId()), bibMarcRecords.getRecords().get(0).getControlFields().get(0).getValue());
654         Assert.assertEquals(DocumentUniqueIDPrefix.getDocumentId(bib2.getId()), bibMarcRecords.getRecords().get(1).getControlFields().get(0).getValue());
655     }
656 
657     @Ignore
658     @Test
659     public void retrieveItemByBarcode() {
660         BibTree bibTree = getBibTree1();
661         restClient.createBibTree(bibTree);
662         String barcode = bibTree.getHoldingsTrees().get(0).getItems().get(0).getBarcode();
663         Item item1 = restClient.retrieveItemByBarcode(barcode);
664         Assert.assertNotNull(item1);
665     }
666 
667     @Ignore
668     @Test
669     public void patchItem() {
670         Item item = getItemDoc();
671         restClient.createItem(item);
672         String itemXML = item.serialize(item);
673         String itemDoc = restClient.patchItem(itemXML);
674         item = (Item) item.deserialize(itemDoc);
675         ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
676         org.kuali.ole.docstore.common.document.content.instance.Item itemContent = itemOlemlRecordProcessor.fromXML(item.getContent());
677         Assert.assertEquals("testcn3", itemContent.getCopyNumber());
678         Assert.assertEquals("testenum3", itemContent.getEnumeration());
679         Assert.assertEquals("testchn3", itemContent.getChronology());
680     }
681 
682     @Ignore
683     @Test
684     public void updateItemByBarcode() {
685         Item item = getItemDoc();
686         restClient.createItem(item);
687         String itemXML = item.serialize(item);
688         String itemDoc = restClient.updateItemByBarcode(item.getBarcode(), itemXML);
689         item = (Item) item.deserialize(itemDoc);
690         ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
691         org.kuali.ole.docstore.common.document.content.instance.Item itemContent = itemOlemlRecordProcessor.fromXML(item.getContent());
692         Assert.assertEquals("testcn3", itemContent.getCopyNumber());
693         Assert.assertEquals("testenum3", itemContent.getEnumeration());
694         Assert.assertEquals("testchn3", itemContent.getChronology());
695     }
696 
697     private Item getItemDoc() {
698         Item item = new Item();
699         String xml = getXmlAsString("/org/kuali/ole/patch/ItemDoc1.xml");
700         return (Item) item.deserialize(xml);
701     }
702 
703     private Bib getBibRecord1() {
704         Bib bib = new BibMarc();
705         String xml = getXmlAsString("/org/kuali/ole/documents/BibMarcRecord1.xml");
706         return (Bib) bib.deserialize(xml);
707     }
708 
709     private Bib getBibRecord2() {
710         Bib bib = new BibMarc();
711         String xml = getXmlAsString("/org/kuali/ole/documents/BibMarcRecord2.xml");
712         return (Bib) bib.deserialize(xml);
713     }
714 
715     private BibTree getBibTree1() {
716         BibTree bibTree = new BibTree();
717         String xml = getXmlAsString("/org/kuali/ole/documents/BibTree1.xml");
718         return (BibTree) bibTree.deserialize(xml);
719     }
720 
721     @Ignore
722     @Test
723     public void updateItem() {
724         Item item = getItemRecord();
725         item.setId("wio-5");
726         String serializeXml = item.serialize(item);
727         RestResponse response = restClient.putRequest(serializeXml, "items/doc/");
728         Assert.assertEquals(200, response.getResponse().getStatusLine().getStatusCode());
729         Assert.assertNotNull(response.getResponseBody());
730     }
731 
732     @Ignore
733     @Test
734     public void retrieveItem() {
735         Item item = restClient.retrieveItem("wio-20");
736         Assert.assertEquals(item.getId(), "wio-20");
737     }
738 
739     @Ignore
740     @Test
741     public void retrieveItems() {
742         List<String> itemIds = new ArrayList<>();
743         itemIds.add("wio-1");
744         itemIds.add("wio-2");
745         List<Item> items = restClient.retrieveItems(itemIds);
746         Assert.assertNotNull(items.get(0));
747         Assert.assertNotNull(items.get(1));
748     }
749 
750     @Ignore
751     @Test
752     public void findItem() {
753         createItem();
754         Map map = new HashMap();
755         map.put("ID", "wio-1");
756         map.put(BibConstants.DOC_TYPE, "item");
757         Item item = restClient.findItem(map);
758         Assert.assertEquals(item.getId(), "wio-1");
759     }
760 
761     @Ignore
762     @Test
763     public void deleteItem() {
764         createItem();
765         restClient.deleteItem("wio-4");
766 
767     }
768 
769     @Ignore
770     @Test
771     public void testBrowseItems() {
772         BrowseParams browseParams = getBrowseParams2();
773         SearchResponse searchResponse = restClient.browseItems(browseParams);
774         Assert.assertNotNull(searchResponse);
775     }
776 
777     public BrowseParams getBrowseParams2() {
778         BrowseParams browseParams = new BrowseParams();
779         String xml = getXmlAsString("/org/kuali/ole/browse/BrowseParams2.xml");
780         return (BrowseParams) browseParams.deserialize(xml);
781     }
782 
783     @Ignore
784     @Test
785     public void testSearch1() {
786         SearchParams searchParams = getSearchParams1();
787         SearchResponse searchResponse = restClient.search(searchParams);
788         Assert.assertNotNull(searchResponse);
789     }
790 
791     public SearchParams getSearchParams1() {
792         SearchParams searchParams = new SearchParams();
793         String xml = getXmlAsString("/org/kuali/ole/search/SearchParams1.xml");
794         return (SearchParams) searchParams.deserialize(xml);
795     }
796 
797     @Ignore
798     @Test
799     public void testSearch2() {
800         SearchParams searchParams = getSearchParams2();
801         SearchResponse searchResponse = restClient.search(searchParams);
802         Assert.assertNotNull(searchResponse);
803     }
804 
805     public SearchParams getSearchParams2() {
806         SearchParams searchParams = new SearchParams();
807         String xml = getXmlAsString("/org/kuali/ole/search/SearchParams2.xml");
808         return (SearchParams) searchParams.deserialize(xml);
809     }
810 
811     @Ignore
812     @Test
813     public void testBoundHoldingsWithBibs() {
814         String bibId1 = "wbm-10000001";
815         BibTree bibTree1 = restClient.retrieveBibTree(bibId1);
816         System.out.println("Before Boundwith Bib id: " + bibId1 + " Holdings count: " + bibTree1.getHoldingsTrees().size());
817         String bibId2 = "wbm-10000002";
818         BibTree bibTree2 = restClient.retrieveBibTree(bibId2);
819         System.out.println("Before Boundwith Bib id: " + bibId2 + " Holdings count: " + bibTree2.getHoldingsTrees().size());
820         String holdingsId = "who-1";
821         List bibIds = new ArrayList<String>();
822         bibIds.add(bibId2);
823         restClient.boundWithBibs(holdingsId, bibIds);
824         bibTree1 = restClient.retrieveBibTree(bibId1);
825         System.out.println("After Boundwith Bib id: " + bibId1 + " Holdings count: " + bibTree1.getHoldingsTrees().size());
826         bibTree2 = restClient.retrieveBibTree(bibId2);
827         System.out.println("After Boundwith Bib id: " + bibId2 + " Holdings count: " + bibTree2.getHoldingsTrees().size());
828     }
829 
830     @Ignore
831     @Test
832     public void testTransferItem(){
833         /*List<String> holdingsIds =new ArrayList<String>();
834         String bibId="wbm-10000005";
835         holdingsIds.add("who-5".toString());*/
836         String holdingsId ="who-2";
837         String itemId ="wio-6";
838         List itemIds = new ArrayList<String>();
839         itemIds.add(itemId);
840         restClient.transferItems(itemIds,holdingsId);
841 
842 
843     }
844 
845     private void updateContent(Bib bib){
846         BibMarcRecordProcessor bibMarcRecordProcessor = new BibMarcRecordProcessor();
847         BibMarcRecords bibMarcRecords = bibMarcRecordProcessor.fromXML(bib.getContent());
848         BibMarcRecord bibMarcRecord = bibMarcRecords.getRecords().get(0);
849         List<DataField> dataFields = bibMarcRecord.getDataFields();
850         for(DataField dataField : dataFields){
851             if(dataField.getTag().equalsIgnoreCase("245")){
852                 List<SubField> subFields = dataField.getSubFields();
853                 subFields.get(0).setValue("The Alchemist");
854             }
855         }
856         bib.setContent(bibMarcRecordProcessor.generateXML(bibMarcRecord));
857     }
858 
859     @Ignore
860     @Test
861     public void createBibTrees() {
862         List bibTrees = new ArrayList();
863         BibTree bibTree = new BibTree();
864         String input = "";
865         File file = null;
866         try {
867             file = new File(getClass().getResource("/documents/BibTree1.xml").toURI());
868             input = FileUtils.readFileToString(file);
869         } catch (Exception e) {
870             LOG.info("Exception :", e);
871         }
872         bibTree = (BibTree) bibTree.deserialize(input);
873         bibTrees.add(bibTree);
874         try {
875             file = new File(getClass().getResource("/documents/BibTree2.xml").toURI());
876             input = FileUtils.readFileToString(file);
877         } catch (Exception e) {
878             LOG.info("Exception :", e);
879         }
880         bibTree = (BibTree) bibTree.deserialize(input);
881         bibTrees.add(bibTree);
882         try {
883             file = new File(getClass().getResource("/documents/BibTree3.xml").toURI());
884             input = FileUtils.readFileToString(file);
885         } catch (Exception e) {
886             LOG.info("Exception :", e);
887         }
888         bibTree = (BibTree) bibTree.deserialize(input);
889         bibTrees.add(bibTree);
890         BibTree bibTree1=new BibTree();
891 
892 
893         BibTrees bibTreesobj = new BibTrees();
894         Bib bibMarc = new Bib();
895         bibTreesobj.getBibTrees().addAll(bibTrees) ;
896         restClient.createBibTrees(bibTreesobj);
897         Assert.assertNotNull(bibTreesobj);
898     }
899 
900 
901     private void setDate(Bib bib){
902         Date date = new Date();
903         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
904         String dateStr = sdf.format(date);
905         bib.setCreatedOn(dateStr);
906     }
907 
908     @Ignore
909     @Test
910     public void testCreateLicenseAttachment() {
911         LicenseAttachment license = new LicenseAttachment();
912         license.setCategory("work");
913         license.setType("license");
914         license.setFormat("pdf");
915         license.setFileName("document.pdf");
916         license.setFilePath("/home/likewise-open/HTCINDIA/sambasivam/Downloads");
917         Licenses licenses = new Licenses();
918         licenses.getLicenses().add(license);
919 
920 
921 
922         licenses.getLicenses().add(license);
923         restClient.createLicenses(licenses);
924     }
925 
926     @Ignore
927     @Test
928     public void testUpdate() {
929         LicenseAttachment license = new LicenseAttachment();
930         license.setCategory("work");
931         license.setType("license");
932         license.setFormat("pdf");
933         license.setId("wl-1");
934         license.setDocumentNote("doc note");
935         license.setDocumentTitle("doc title");
936         restClient.updateLicense(license);
937     }
938 
939     @Ignore
940     @Test
941     public void testLicenseDelete() {
942         restClient.deleteLicense("wl-1");
943     }
944 
945 
946 }