1 package org.kuali.ole.repository;
2
3 import org.kuali.ole.BaseTestCase;
4 import org.kuali.ole.RepositoryBrowser;
5 import org.kuali.ole.RepositoryManager;
6 import org.kuali.ole.docstore.model.enums.DocCategory;
7 import org.kuali.ole.docstore.model.enums.DocType;
8 import org.kuali.ole.docstore.model.repopojo.RepositoryData;
9 import org.kuali.ole.pojo.OleException;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
12
13 import javax.jcr.Node;
14 import javax.jcr.RepositoryException;
15 import javax.jcr.Session;
16 import java.io.File;
17 import java.util.Iterator;
18
19 import static junit.framework.Assert.assertEquals;
20
21
22
23
24
25
26
27
28 public class RepositoryData_UT
29 extends BaseTestCase {
30 private static final Logger LOG = LoggerFactory.getLogger(RepositoryData_UT.class);
31
32 public void getRepositoryData() throws Exception {
33 RepositoryBrowser repositoryBrowser = new RepositoryBrowser();
34 cleanRepository(DocCategory.WORK.getCode(), DocType.BIB.getDescription());
35 cleanRepository(DocCategory.WORK.getCode(), DocType.INSTANCE.getDescription());
36 String dump = repositoryBrowser.getRepositoryDump();
37 bulkIngestBibData();
38 dump = repositoryBrowser.getRepositoryDump();
39 LOG.info("JCR Dump" + dump);
40 RepositoryData repositoryData = new RepositoryData();
41 RepositoryData repoData = repositoryData.loadDump(dump);
42 String repoDump = repositoryData.getRepositoryDump(repoData);
43 LOG.info("repoDump" + repoDump);
44 assertEquals(dump, repoDump);
45 }
46
47
48 public void cleanRepository(String category, String type) throws OleException, RepositoryException {
49 RepositoryManager repositoryManager = RepositoryManager.getRepositoryManager();
50 Session session = repositoryManager.getSession("mockUser", "test");
51 Node rootNode = session.getRootNode();
52 Node catNode = rootNode.getNode(category);
53 Node typeNode = catNode.getNode(type);
54 for (Iterator<Node> typeIterator = typeNode.getNodes(); typeIterator.hasNext(); ) {
55 Node formatNode = typeIterator.next();
56 if (!formatNode.getName().equals("jcr:system")) {
57 formatNode.remove();
58 }
59 }
60 session.save();
61 }
62
63 private void bulkIngestBibData() throws Exception {
64 File file = new File(
65 getClass().getResource("/org/kuali/ole/bulkhandler/OLE-Bib-bulkIngest-IU-Set1-split.xml").toURI());
66 try {
67 File file1 = new File("");
68
69
70
71
72 } catch (Exception e) {
73 LOG.info("in excep" + e.getMessage() , e);
74 }
75 }
76 }