001package org.kuali.ole.repository; 002 003import org.kuali.ole.BaseTestCase; 004import org.kuali.ole.RepositoryBrowser; 005import org.kuali.ole.RepositoryManager; 006import org.kuali.ole.docstore.model.enums.DocCategory; 007import org.kuali.ole.docstore.model.enums.DocType; 008import org.kuali.ole.docstore.model.repopojo.RepositoryData; 009import org.kuali.ole.pojo.OleException; 010import org.slf4j.Logger; 011import org.slf4j.LoggerFactory; 012 013import javax.jcr.Node; 014import javax.jcr.RepositoryException; 015import javax.jcr.Session; 016import java.io.File; 017import java.util.Iterator; 018 019import static junit.framework.Assert.assertEquals; 020 021/** 022 * Created by IntelliJ IDEA. 023 * User: Pranitha 024 * Date: 2/28/12 025 * Time: 3:13 PM 026 * To change this template use File | Settings | File Templates. 027 */ 028public class RepositoryData_UT 029 extends BaseTestCase { 030 private static final Logger LOG = LoggerFactory.getLogger(RepositoryData_UT.class); 031 032 public void getRepositoryData() throws Exception { 033 RepositoryBrowser repositoryBrowser = new RepositoryBrowser(); 034 cleanRepository(DocCategory.WORK.getCode(), DocType.BIB.getDescription()); 035 cleanRepository(DocCategory.WORK.getCode(), DocType.INSTANCE.getDescription()); 036 String dump = repositoryBrowser.getRepositoryDump(); 037 bulkIngestBibData(); 038 dump = repositoryBrowser.getRepositoryDump(); 039 LOG.info("JCR Dump" + dump); 040 RepositoryData repositoryData = new RepositoryData(); 041 RepositoryData repoData = repositoryData.loadDump(dump); 042 String repoDump = repositoryData.getRepositoryDump(repoData); 043 LOG.info("repoDump" + repoDump); 044 assertEquals(dump, repoDump); 045 } 046 047 048 public void cleanRepository(String category, String type) throws OleException, RepositoryException { 049 RepositoryManager repositoryManager = RepositoryManager.getRepositoryManager(); 050 Session session = repositoryManager.getSession("mockUser", "test"); 051 Node rootNode = session.getRootNode(); 052 Node catNode = rootNode.getNode(category); 053 Node typeNode = catNode.getNode(type); 054 for (Iterator<Node> typeIterator = typeNode.getNodes(); typeIterator.hasNext(); ) { 055 Node formatNode = typeIterator.next(); 056 if (!formatNode.getName().equals("jcr:system")) { 057 formatNode.remove(); 058 } 059 } 060 session.save(); 061 } 062 063 private void bulkIngestBibData() throws Exception { 064 File file = new File( 065 getClass().getResource("/org/kuali/ole/bulkhandler/OLE-Bib-bulkIngest-IU-Set1-split.xml").toURI()); 066 try { 067 File file1 = new File(""); 068 // BulkLoadHandler bulkLoadHandler = new BulkLoadHandler(); 069 // List<String> recordUUIDs = bulkLoadHandler 070 // .loadBulk(DocCategory.WORK.getCode(), DocType.BIB.getDescription(), DocFormat.MARC.getCode(), file, "testUser", "testLoadBulk"); 071 // LOG.info("recordUUIDs " + recordUUIDs); 072 } catch (Exception e) { 073 LOG.info("in excep" + e.getMessage() , e); 074 } 075 } 076}