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.docstore.model.bo.WorkBibDocument;
7 import org.kuali.ole.docstore.model.bo.WorkHoldingsDocument;
8 import org.kuali.ole.docstore.model.bo.WorkInstanceDocument;
9 import org.kuali.ole.docstore.model.bo.WorkItemDocument;
10 import org.kuali.rice.core.api.util.tree.Node;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 import static junit.framework.Assert.assertEquals;
16 import static junit.framework.Assert.assertNotNull;
17
18
19
20
21
22
23
24
25 public class DocumentSelectionTree_UT {
26 private static final Logger LOG = Logger.getLogger(DocumentSelectionTree_UT.class);
27
28 @Before
29 public void setUp() throws Exception {
30
31 }
32
33 @Test
34 public void testBuildNodeList() throws Exception {
35 DocumentSelectionTree dst = new DocumentSelectionTree();
36 List<Node<DocumentTreeNode, String>> nodeList = new ArrayList<Node<DocumentTreeNode, String>>();
37 List<WorkBibDocument> bibDocumentList = new ArrayList<WorkBibDocument>();
38 WorkBibDocument workBibDocument = prepareTestData(bibDocumentList);
39 nodeList = dst.buildNodeList(bibDocumentList);
40 assertNotNull(nodeList);
41 assertEquals(bibDocumentList.size(), nodeList.size());
42 for (Node<DocumentTreeNode, String> node : nodeList) {
43 assertNotNull(node.getNumberOfChildren());
44 assertEquals("History of Computers", workBibDocument.getTitle());
45 }
46 }
47 @Test
48 public void testBuildNodeListForTransfer() throws Exception {
49 DocumentSelectionTree dst = new DocumentSelectionTree();
50 List<Node<DocumentTreeNode, String>> nodeList = new ArrayList<Node<DocumentTreeNode, String>>();
51 List<WorkBibDocument> bibDocumentList = new ArrayList<WorkBibDocument>();
52 WorkBibDocument workBibDocument = prepareTestData(bibDocumentList);
53 nodeList = dst.buildNodeListForTransfer(bibDocumentList);
54 assertNotNull(nodeList);
55 assertEquals(bibDocumentList.size(), nodeList.size());
56 for (Node<DocumentTreeNode, String> node : nodeList) {
57 assertNotNull(node.getNumberOfChildren());
58 assertEquals("History of Computers", workBibDocument.getTitle());
59 }
60 }
61
62
63 private WorkBibDocument prepareTestData(List<WorkBibDocument> bibDocumentList) {
64 WorkBibDocument workBibDocument = new WorkBibDocument();
65 List<WorkInstanceDocument> instanceDocumentList = new ArrayList<WorkInstanceDocument>();
66 WorkInstanceDocument workInstanceDocument = new WorkInstanceDocument();
67 List<WorkItemDocument> workItemDocumentList = new ArrayList<WorkItemDocument>();
68 WorkItemDocument workItemDocument = new WorkItemDocument();
69 WorkHoldingsDocument workHoldingsDocument = new WorkHoldingsDocument();
70 workItemDocument.setItemIdentifier("Item-1");
71 workItemDocument.setCallNumber("Item callNumber");
72 workItemDocumentList.add(workItemDocument);
73 workHoldingsDocument.setHoldingsIdentifier("Holding-1");
74 workHoldingsDocument.setLocationName("Holding location");
75 workHoldingsDocument.setCallNumber("Holding callNumber");
76 workInstanceDocument.setHoldingsDocument(workHoldingsDocument);
77 workInstanceDocument.setItemDocumentList(workItemDocumentList);
78 workInstanceDocument.setInstanceIdentifier("Instance-1");
79 instanceDocumentList.add(workInstanceDocument);
80 workBibDocument.setWorkInstanceDocumentList(instanceDocumentList);
81 workBibDocument.setTitle("History of Computers");
82 workBibDocument.setId("Bib-1");
83 bibDocumentList.add(workBibDocument);
84 return workBibDocument;
85 }
86 }