1 package org.kuali.ole.docstore.repository;
2
3 import org.apache.commons.io.FileUtils;
4 import org.junit.Before;
5 import org.junit.Test;
6 import org.kuali.ole.BaseTestCase;
7 import org.kuali.ole.RepositoryManager;
8 import org.kuali.ole.docstore.model.xmlpojo.ingest.Request;
9 import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
10 import org.kuali.ole.docstore.model.xstream.ingest.RequestHandler;
11 import org.kuali.ole.docstore.service.DocumentIndexer;
12 import org.kuali.ole.docstore.service.DocumentIngester;
13 import org.kuali.ole.docstore.service.IngestNIndexHandlerService;
14
15 import org.mockito.Mock;
16 import org.mockito.Mockito;
17 import org.mockito.MockitoAnnotations;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 import javax.jcr.Node;
22 import javax.jcr.NodeIterator;
23 import javax.jcr.Session;
24 import java.io.File;
25 import java.util.Iterator;
26 import java.util.Map;
27
28 import static junit.framework.Assert.assertNotNull;
29 import static org.junit.Assert.assertTrue;
30
31
32
33
34
35
36
37
38 public class NodeCountManager_UT extends BaseTestCase {
39
40 private static Logger logger = LoggerFactory.getLogger(NodeCountManager_UT.class);
41 private Map<String, Long> nodeCountMap = null;
42 @Mock
43 private RepositoryManager mockRepositoryManager;
44 @Mock
45 private Session mockSession;
46 @Mock
47 private Node mockRootNode;
48 @Mock
49 private NodeIterator mockNodeIterator;
50 @Mock
51 private Node mockChildNode;
52
53 @Before
54 public void setUp() throws Exception{
55 super.setUp();
56 MockitoAnnotations.initMocks(this);
57
58 Mockito.when(mockRepositoryManager.getSession(Mockito.anyString(), Mockito.anyString())).thenReturn(mockSession);
59 Mockito.when(mockSession.getRootNode()).thenReturn(mockRootNode);
60 Mockito.when(mockRootNode.hasProperty("nodeType")).thenReturn(true);
61 Mockito.when(mockRootNode.getNodes()).thenReturn(mockNodeIterator);
62 Mockito.when(mockNodeIterator.hasNext()).thenReturn(true);
63 Mockito.when(mockNodeIterator.next()).thenReturn(mockChildNode);
64 Mockito.when(mockChildNode.getName()).thenReturn("MockFile");
65 }
66
67 @Test
68 public void testUpdateNodeCount() throws Exception {
69 NodeCountManager nodeCountManager = NodeCountManager.getNodeCountManager();
70 nodeCountManager.setRepositoryManager(mockRepositoryManager);
71 CustomNodeManager customNodeManager = CustomNodeManager.getInstance();
72 nodeCountMap = nodeCountManager.generateNodeCountMap();
73 assertNotNull(nodeCountMap);
74 assertTrue(!nodeCountMap.isEmpty());
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90 }
91 }