View Javadoc
1   package org.kuali.ole.describe.bo;
2   
3   import org.apache.log4j.Logger;
4   import org.junit.Before;
5   import org.junit.Test;
6   import org.kuali.ole.describe.bo.DocumentSelectionTree;
7   import org.kuali.ole.describe.bo.DocumentTreeNode;
8   import org.kuali.ole.docstore.common.document.*;
9   import org.kuali.ole.docstore.common.document.HoldingsTree;
10  import org.kuali.ole.docstore.common.document.Item;
11  import org.kuali.ole.docstore.common.document.content.instance.*;
12  import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
13  import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
14  import org.kuali.ole.docstore.model.bo.WorkBibDocument;
15  import org.kuali.ole.docstore.model.bo.WorkHoldingsDocument;
16  import org.kuali.ole.docstore.model.bo.WorkInstanceDocument;
17  import org.kuali.ole.docstore.model.bo.WorkItemDocument;
18  import org.kuali.rice.core.api.util.tree.Node;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import static junit.framework.Assert.assertEquals;
24  import static junit.framework.Assert.assertNotNull;
25  
26  /**
27   * Created with IntelliJ IDEA.
28   * User: Sreekanth
29   * Date: 12/22/12
30   * Time: 3:29 PM
31   * To change this template use File | Settings | File Templates.
32   */
33  public class DocumentSelectionTree_UT {
34      private static final Logger LOG = Logger.getLogger(DocumentSelectionTree_UT.class);
35  
36      @Before
37      public void setUp() throws Exception {
38  
39      }
40  
41      @Test
42      public void testBuildNodeList() throws Exception {
43          DocumentSelectionTree dst = new DocumentSelectionTree();
44          List<Node<DocumentTreeNode, String>> nodeList = new ArrayList<Node<DocumentTreeNode, String>>();
45          List<BibTree> bibTreeList = new ArrayList<BibTree>();
46          BibTree bibTree = prepareTestData(bibTreeList);
47          nodeList = dst.buildNodeList(bibTreeList);
48          assertNotNull(nodeList);
49          assertEquals(bibTreeList.size(), nodeList.size());
50          for (Node<DocumentTreeNode, String> node : nodeList) {
51              assertNotNull(node.getNumberOfChildren());
52              assertEquals("History of Computers", bibTree.getBib().getTitle());
53          }
54      }
55      @Test
56      public void testBuildNodeListForTransfer() throws Exception {
57          DocumentSelectionTree dst = new DocumentSelectionTree();
58          List<Node<DocumentTreeNode, String>> nodeList = new ArrayList<Node<DocumentTreeNode, String>>();
59          List<BibTree> bibTreeList = new ArrayList<BibTree>();
60          BibTree  bibTree = prepareTestData(bibTreeList);
61          nodeList = dst.buildNodeListForTransfer(bibTreeList);
62          assertNotNull(nodeList);
63          assertEquals(bibTreeList.size(), nodeList.size());
64          for (Node<DocumentTreeNode, String> node : nodeList) {
65              assertNotNull(node.getNumberOfChildren());
66              assertEquals("History of Computers", bibTree.getBib().getTitle());
67          }
68  
69  
70      }
71  
72  
73      private BibTree prepareTestData(List<BibTree> bibTreeList) {
74          BibTree bibTree = new BibTree();
75          List<HoldingsTree> holdingsTreeList = new ArrayList<HoldingsTree>();
76          HoldingsTree holdingsTree = new HoldingsTree();
77          Holdings holdings = new Holdings();
78          List<Item> itemList = new ArrayList<Item>();
79          Item item = new Item();
80          WorkHoldingsDocument workHoldingsDocument = new WorkHoldingsDocument();
81          org.kuali.ole.docstore.common.document.content.instance.Item olemlItem= new org.kuali.ole.docstore.common.document.content.instance.Item();
82          olemlItem.setItemIdentifier("Item-1");
83  
84          item.setId("Item-1");
85          item.setCallNumber("Item callNumber");
86          itemList.add(item);
87  
88          item.setContent(new ItemOlemlRecordProcessor().toXML(olemlItem));
89          OleHoldings oleHoldings=new OleHoldings();
90          oleHoldings.setHoldingsIdentifier("Holding-1");
91  
92          holdings.setId("Holding-1");
93          holdings.setLocationName("Holding location");
94          holdings.setCallNumber("Holding callNumber");
95  
96          holdings.setHoldingsType("print");
97          holdings.setContent(new HoldingOlemlRecordProcessor().toXML(oleHoldings));
98          holdingsTree.setHoldings(holdings);
99          holdingsTree.getItems().add(item);
100         holdingsTree.setId("Instance-1");
101         holdingsTreeList.add(holdingsTree);
102         bibTree.getHoldingsTrees().add(holdingsTree);
103         Bib bib=new Bib();
104         bib.setId("Bib-1");
105         bib.setTitle("History of Computers");
106         bibTree.setBib(bib);
107         //bibTree.getBib().setTitle("History of Computers");
108         bibTree.setId("Bib-1");
109         //bibTree.getBib().setId("Bib-1");
110         bibTreeList.add(bibTree);
111         return bibTree;
112     }
113 }