View Javadoc
1   package org.kuali.ole.service;
2   
3   import org.junit.Before;
4   import org.junit.Ignore;
5   import org.junit.Test;
6   import org.kuali.ole.RepositoryBrowser;
7   import org.kuali.ole.RepositoryManager;
8   import org.kuali.ole.base.BaseTestCase;
9   import org.kuali.ole.docstore.service.BeanLocator;
10  import org.kuali.ole.docstore.service.IngestNIndexHandlerService;
11  import org.kuali.ole.pojo.OleException;
12  import org.mockito.Mock;
13  import org.mockito.Mockito;
14  import org.mockito.MockitoAnnotations;
15  import org.slf4j.Logger;
16  import org.slf4j.LoggerFactory;
17  
18  import javax.jcr.Node;
19  import javax.jcr.NodeIterator;
20  import javax.jcr.RepositoryException;
21  import javax.jcr.Session;
22  import java.util.Iterator;
23  
24  
25  /**
26   * Created with IntelliJ IDEA.
27   * User: ?
28   * Date: 2/19/13
29   * Time: 12:45 PM
30   * To change this template use File | Settings | File Templates.
31   */
32  @Ignore
33  @Deprecated
34  public class OleDocstoreDumpService_UT extends BaseTestCase {
35  
36      private static final Logger LOG = LoggerFactory.getLogger(OleDocstoreDumpService_UT.class);
37      private IngestNIndexHandlerService ingestNIndexHandlerService = BeanLocator.getIngestNIndexHandlerService();
38  
39      @Mock
40      private RepositoryManager mockRepositoryManager;
41      @Mock
42      private Session mockSession;
43      @Mock
44      private Node mockRootNode;
45      @Mock
46      private NodeIterator mockNodeIterator;
47      @Mock
48      private Node mockChildNode;
49  
50      @Before
51      public void setUp() throws Exception {
52          super.setUp();
53          MockitoAnnotations.initMocks(this);
54          System.getProperties().put("app.environment", "local");
55          Mockito.when(mockRepositoryManager.getSession(Mockito.anyString(), Mockito.anyString())).thenReturn(mockSession);
56          Mockito.when(mockSession.getRootNode()).thenReturn(mockRootNode);
57          Mockito.when(mockRootNode.hasProperty("nodeType")).thenReturn(true);
58          Mockito.when(mockRootNode.getNodes()).thenReturn(mockNodeIterator);
59          Mockito.when(mockNodeIterator.hasNext()).thenReturn(true);
60          Mockito.when(mockNodeIterator.next()).thenReturn(mockChildNode);
61          Mockito.when(mockChildNode.getName()).thenReturn("MockFile");
62      }
63  
64      @Ignore
65      @Test
66      public void OleExportMarcRequest() throws OleException, RepositoryException {
67          cleanRepository("work","bibliographic");
68          try{
69  /*         File file = new File(getClass().getResource("/org/kuali/ole/web/repository/exportProfileRequest.xml").toURI());
70           String input = FileUtils.readFileToString(file);
71           RequestHandler rh = new RequestHandler();
72           Request request = rh.toObject(input);
73           Response response = ingestNIndexHandlerService.ingestNIndexRequestDocuments(request);*/
74  
75          RepositoryBrowser repositoryBrowser = new RepositoryBrowser();
76          String dump = repositoryBrowser.getRepositoryDump();
77          LOG.info("dump" + dump);
78          /*File file = new File(getClass().getResource("/org/kuali/ole/web/repository/exportProfile.xml").toURI());
79          String requestXML = FileUtils.readFileToString(file);
80          OleDocstoreDumpService oleDocstoreDumpService = new OleDocstoreDumpService();
81          boolean dumpStatus = oleDocstoreDumpService.exportDocstoreData(requestXML);
82           assertTrue(dumpStatus);*/
83          }catch (Exception e){
84              LOG.error(e.getMessage(), e);
85          }
86      }
87  
88      private void cleanRepository(String category, String type) throws OleException, RepositoryException {
89          RepositoryManager repositoryManager = mockRepositoryManager;
90          Session session = repositoryManager.getSession("mockUser", "test");
91          Node rootNode = session.getRootNode();
92          Node catNode = rootNode.getNode(category);
93          //Node typeNode = catNode.getNode(type);
94          Node typeNode = mockRootNode;
95          /*for (Iterator<Node> typeiterator = typeNode.getNodes(); typeiterator.hasNext(); ) {
96              Node formatNode = typeiterator.next();
97              if (!formatNode.getName().equals("jcr:system")) {
98                  formatNode.remove();
99              }
100         }*/
101         session.save();
102         repositoryManager.logout(session);
103     }
104 }