View Javadoc
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   * Created with IntelliJ IDEA.
33   * User: ?
34   * Date: 12/21/12
35   * Time: 5:06 PM
36   * To change this template use File | Settings | File Templates.
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          //TODO: This section isn't complete, and not sure what its doing.
77  //        File inputDir = new File(this.getClass().getResource("/org/kuali/ole/repository/requestInstance.xml").toURI());
78  //        String input = FileUtils.readFileToString(inputDir);
79  //        RequestHandler requestHandler = new RequestHandler();
80  //        Request request = requestHandler.toObject(input);
81  //        IngestNIndexHandlerService ingestNIndexHandlerService = new IngestNIndexHandlerService();
82  //        ingestNIndexHandlerService.setRequestHandler(requestHandler);
83  //        ingestNIndexHandlerService.setDocumentIndexer(new DocumentIndexer());
84  //        ingestNIndexHandlerService.setDocumentIngester(new DocumentIngester());
85  //        ingestNIndexHandlerService.ingestNIndexRequestDocuments(request);
86  //        RequestDocument requestDocument = request.getRequestDocuments().get(0);
87  //        Session session = RepositoryManager.getRepositoryManager().getSession(requestDocument.getUser(), requestDocument.getOperation());
88  //        Node node = customNodeManager.getNodeByUUID(session, requestDocument.getUuid());
89  //        nodeCountManager.updateNodeCount(node, 6);
90      }
91  }