Author: sascharodekamp
Date: Thu Nov 24 12:28:10 2011 New Revision: 1205803 URL: http://svn.apache.org/viewvc?rev=1205803&view=rev Log: Rewrite the test cases. Fix some small bugs. Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java (contents, props changed) - copied, changed from r1205750, ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java Removed: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java Modified: ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/AbstractJcrHelper.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrArticleHelper.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrContentHelper.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrFileHelper.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitTests.java Modified: ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java?rev=1205803&r1=1205802&r2=1205803&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/example/src/org/ofbiz/example/JackrabbitEvents.java Thu Nov 24 12:28:10 2011 @@ -37,7 +37,7 @@ import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.GenericValue; import org.ofbiz.jcr.access.JcrRepositoryAccessor; -import org.ofbiz.jcr.access.jackrabbit.RepositoryAccessJackrabbit; +import org.ofbiz.jcr.access.jackrabbit.JackrabbitRepositoryAccessor; import org.ofbiz.jcr.api.JcrArticleHelper; import org.ofbiz.jcr.api.JcrContentHelper; import org.ofbiz.jcr.api.JcrFileHelper; @@ -263,7 +263,7 @@ public class JackrabbitEvents { public static String getRepositoryFileTree(HttpServletRequest request, HttpServletResponse response) { GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - JcrRepositoryAccessor repositoryAccess = new RepositoryAccessJackrabbit(userLogin); + JcrRepositoryAccessor repositoryAccess = new JackrabbitRepositoryAccessor(userLogin); try { JSONArray fileTree = repositoryAccess.getJsonFileTree(); request.setAttribute("fileTree", StringUtil.wrapString(fileTree.toString())); @@ -289,7 +289,7 @@ public class JackrabbitEvents { public static String getRepositoryDataTree(HttpServletRequest request, HttpServletResponse response) { GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); - RepositoryAccessJackrabbit repositoryAccess = new RepositoryAccessJackrabbit(userLogin); + JackrabbitRepositoryAccessor repositoryAccess = new JackrabbitRepositoryAccessor(userLogin); try { JSONArray fileTree = repositoryAccess.getJsonDataTree(); request.setAttribute("dataTree", StringUtil.wrapString(fileTree.toString())); Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java?rev=1205803&r1=1205802&r2=1205803&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java Thu Nov 24 12:28:10 2011 @@ -10,7 +10,8 @@ import org.ofbiz.jcr.orm.OfbizRepository public interface ContentReader { /** - * Return an OfbizRepositoryMapping Object from the JCR Repository. + * Return an OfbizRepositoryMapping Object from the JCR Repository. The node + * path have to be an absolute path. * * @param nodePath * @return @@ -21,7 +22,7 @@ public interface ContentReader { * Return an OfbizRepositoryMapping Object in the specified language and * version from the JCR Repository. The Method checks if the requested * version for this node exist. If not the latest version of the node will - * be returned. + * be returned. The node path have to be an absolute path. * * @param nodePath * @param language Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java?rev=1205803&r1=1205802&r2=1205803&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentReaderJackrabbit.java Thu Nov 24 12:28:10 2011 @@ -16,6 +16,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.jcr.access.ContentReader; import org.ofbiz.jcr.access.VersioningManager; import org.ofbiz.jcr.orm.OfbizRepositoryMapping; +import org.ofbiz.jcr.util.jackrabbit.JcrUtilJackrabbit; public class ContentReaderJackrabbit implements ContentReader { @@ -35,9 +36,12 @@ public class ContentReaderJackrabbit imp */ @Override public OfbizRepositoryMapping getContentObject(String nodePath) { + nodePath = JcrUtilJackrabbit.createAbsoluteNodePath(nodePath); OfbizRepositoryMapping orm = (OfbizRepositoryMapping) ocm.getObject(nodePath); try { - orm.setVersion(ocm.getBaseVersion(nodePath).getName()); + if (orm != null) { + orm.setVersion(ocm.getBaseVersion(nodePath).getName()); + } } catch (VersionException e) { // -0.0 means we have no version information orm.setVersion("-0.0"); @@ -55,6 +59,7 @@ public class ContentReaderJackrabbit imp */ @Override public OfbizRepositoryMapping getContentObject(String nodePath, String version) { + nodePath = JcrUtilJackrabbit.createAbsoluteNodePath(nodePath); VersioningManager vm = new VersioningManagerJackrabbit(ocm); if (!vm.checkIfVersionExist(nodePath, version)) { Debug.logWarning("The version: " + version + " for content object: " + nodePath + " does not exist, the latest version for this object will be returned.", module); @@ -202,4 +207,5 @@ public class ContentReaderJackrabbit imp return qm.createQuery(statement, Query.JCR_JQOM).execute(); } } + } Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java?rev=1205803&r1=1205802&r2=1205803&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/ContentWriterJackrabbit.java Thu Nov 24 12:28:10 2011 @@ -12,6 +12,7 @@ import org.ofbiz.base.util.UtilValidate; import org.ofbiz.jcr.access.ContentWriter; import org.ofbiz.jcr.access.VersioningManager; import org.ofbiz.jcr.orm.OfbizRepositoryMapping; +import org.ofbiz.jcr.util.jackrabbit.JcrUtilJackrabbit; public class ContentWriterJackrabbit implements ContentWriter { @@ -134,6 +135,7 @@ public class ContentWriterJackrabbit imp */ @Override public void removeContentObject(String nodePath) throws ObjectContentManagerException { + nodePath = JcrUtilJackrabbit.createAbsoluteNodePath(nodePath); versioningManager.checkOutContentObject(nodePath, true); ocm.remove(nodePath); Copied: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java (from r1205750, ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java) URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java?p2=ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java&p1=ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java&r1=1205750&r2=1205803&rev=1205803&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/RepositoryAccessJackrabbit.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java Thu Nov 24 12:28:10 2011 @@ -21,9 +21,9 @@ import org.ofbiz.jcr.loader.JCRFactoryUt import org.ofbiz.jcr.loader.jackrabbit.JCRFactoryImpl; import org.ofbiz.jcr.orm.OfbizRepositoryMapping; -public class RepositoryAccessJackrabbit implements JcrRepositoryAccessor { +public class JackrabbitRepositoryAccessor implements JcrRepositoryAccessor { - private static String module = RepositoryAccessJackrabbit.class.getName(); + private static String module = JackrabbitRepositoryAccessor.class.getName(); Session session = null; ObjectContentManagerImpl ocm = null; @@ -33,7 +33,7 @@ public class RepositoryAccessJackrabbit * * @param userLogin */ - public RepositoryAccessJackrabbit(GenericValue userLogin) { + public JackrabbitRepositoryAccessor(GenericValue userLogin) { // TODO pass the userLogin to the getSession() method and perform some this(JCRFactoryUtil.getSession()); } @@ -43,7 +43,7 @@ public class RepositoryAccessJackrabbit * * @param userLogin */ - public RepositoryAccessJackrabbit(Session session) { + public JackrabbitRepositoryAccessor(Session session) { if (session == null) { Debug.logWarning("A repository session is needed to create an OfbizContentMapping Object.", module); return; Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/AbstractJcrHelper.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/AbstractJcrHelper.java?rev=1205803&r1=1205802&r2=1205803&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/AbstractJcrHelper.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/AbstractJcrHelper.java Thu Nov 24 12:28:10 2011 @@ -1,10 +1,10 @@ package org.ofbiz.jcr.api; -import org.ofbiz.jcr.access.jackrabbit.RepositoryAccessJackrabbit; +import org.ofbiz.jcr.access.jackrabbit.JackrabbitRepositoryAccessor; public abstract class AbstractJcrHelper { - protected static RepositoryAccessJackrabbit access = null; + protected static JackrabbitRepositoryAccessor access = null; /** * This will close the connection to the content repository and make sure Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrArticleHelper.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrArticleHelper.java?rev=1205803&r1=1205802&r2=1205803&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrArticleHelper.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrArticleHelper.java Thu Nov 24 12:28:10 2011 @@ -18,7 +18,7 @@ import org.ofbiz.base.util.UtilPropertie import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.GenericValue; import org.ofbiz.jcr.access.jackrabbit.ConstantsJackrabbit; -import org.ofbiz.jcr.access.jackrabbit.RepositoryAccessJackrabbit; +import org.ofbiz.jcr.access.jackrabbit.JackrabbitRepositoryAccessor; import org.ofbiz.jcr.orm.OfbizRepositoryMapping; import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitArticle; @@ -56,7 +56,7 @@ public class JcrArticleHelper extends Ab * Setup my content Object */ public JcrArticleHelper(GenericValue userLogin) { - access = new RepositoryAccessJackrabbit(userLogin); + access = new JackrabbitRepositoryAccessor(userLogin); } /** @@ -68,15 +68,7 @@ public class JcrArticleHelper extends Ab * @throws */ public OfbizRepositoryMappingJackrabbitArticle readContentFromRepository(String contentPath) throws ClassCastException { - OfbizRepositoryMapping orm = access.getContentObject(contentPath); - - if (orm instanceof OfbizRepositoryMappingJackrabbitArticle) { - article = (OfbizRepositoryMappingJackrabbitArticle) orm; - article.setVersion(access.getBaseVersion(contentPath)); - return article; - } else { - throw new ClassCastException("The content object for the path: " + contentPath + " is not an article content object. This Helper can only handle content objects with the type: " + OfbizRepositoryMappingJackrabbitArticle.class.getName()); - } + return readContentFromRepository(contentPath, ""); } /** @@ -91,7 +83,16 @@ public class JcrArticleHelper extends Ab */ public OfbizRepositoryMappingJackrabbitArticle readContentFromRepository(String contentPath, String language) throws ClassCastException { contentPath = determineContentLanguagePath(contentPath, language); - return readContentFromRepository(contentPath); + + OfbizRepositoryMapping orm = access.getContentObject(contentPath); + + if (orm instanceof OfbizRepositoryMappingJackrabbitArticle) { + article = (OfbizRepositoryMappingJackrabbitArticle) orm; + article.setVersion(access.getBaseVersion(contentPath)); + return article; + } else { + throw new ClassCastException("The content object for the path: " + contentPath + " is not an article content object. This Helper can only handle content objects with the type: " + OfbizRepositoryMappingJackrabbitArticle.class.getName()); + } } /** Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrContentHelper.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrContentHelper.java?rev=1205803&r1=1205802&r2=1205803&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrContentHelper.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrContentHelper.java Thu Nov 24 12:28:10 2011 @@ -13,7 +13,7 @@ import javolution.util.FastMap; import org.ofbiz.base.util.Debug; import org.ofbiz.entity.GenericValue; -import org.ofbiz.jcr.access.jackrabbit.RepositoryAccessJackrabbit; +import org.ofbiz.jcr.access.jackrabbit.JackrabbitRepositoryAccessor; /** * This Helper class encapsulate the jcr content access. It provide all @@ -37,7 +37,7 @@ public class JcrContentHelper extends Ab * @param userLogin */ public JcrContentHelper(GenericValue userLogin) { - access = new RepositoryAccessJackrabbit(userLogin); + access = new JackrabbitRepositoryAccessor(userLogin); } public List<Map<String, String>> queryData(String query) throws RepositoryException { Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrFileHelper.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrFileHelper.java?rev=1205803&r1=1205802&r2=1205803&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrFileHelper.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrFileHelper.java Thu Nov 24 12:28:10 2011 @@ -14,7 +14,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.GenericValue; import org.ofbiz.jcr.access.jackrabbit.ConstantsJackrabbit; -import org.ofbiz.jcr.access.jackrabbit.RepositoryAccessJackrabbit; +import org.ofbiz.jcr.access.jackrabbit.JackrabbitRepositoryAccessor; import org.ofbiz.jcr.orm.OfbizRepositoryMapping; import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitFile; import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitFolder; @@ -41,7 +41,7 @@ public class JcrFileHelper extends Abstr private OfbizRepositoryMappingJackrabbitHierarchyNode hierarchy = null; public JcrFileHelper(GenericValue userLogin) { - access = new RepositoryAccessJackrabbit(userLogin); + access = new JackrabbitRepositoryAccessor(userLogin); } /** @@ -97,6 +97,20 @@ public class JcrFileHelper extends Abstr * @throws RepositoryException */ public void storeContentInRepository(byte[] fileData, String fileName, String folderPath) throws ObjectContentManagerException, RepositoryException { + storeContentInRepository(new ByteArrayInputStream(fileData), fileName, folderPath); + } + + /** + * Stores a new file content object in the repository. + * + * @param fileData + * @param fileName + * @param folderPath + * @param mimeType + * @throws ObjectContentManagerException + * @throws RepositoryException + */ + public void storeContentInRepository(InputStream fileData, String fileName, String folderPath) throws ObjectContentManagerException, RepositoryException { if (UtilValidate.isEmpty(folderPath)) { throw new ObjectContentManagerException("Please specify a folder path, the folder path should not be empty!"); } else if (ConstantsJackrabbit.ROOTPATH.equals(folderPath)) { @@ -105,8 +119,8 @@ public class JcrFileHelper extends Abstr // create an ORM Resource Object OfbizRepositoryMappingJackrabbitResource ormResource = new OfbizRepositoryMappingJackrabbitResource(); - ormResource.setData(new ByteArrayInputStream(fileData)); - ormResource.setMimeType(getMimeTypeFromInputStream(new ByteArrayInputStream(fileData))); + ormResource.setData(fileData); + ormResource.setMimeType(getMimeTypeFromInputStream(fileData)); ormResource.setLastModified(new GregorianCalendar()); // create an ORM File Object Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java?rev=1205803&r1=1205802&r2=1205803&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/services/JackrabbitServices.java Thu Nov 24 12:28:10 2011 @@ -11,7 +11,7 @@ import javax.jcr.version.VersionManager; import org.ofbiz.base.util.Debug; import org.ofbiz.entity.GenericValue; -import org.ofbiz.jcr.access.jackrabbit.RepositoryAccessJackrabbit; +import org.ofbiz.jcr.access.jackrabbit.JackrabbitRepositoryAccessor; import org.ofbiz.jcr.loader.JCRFactoryUtil; import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitNews; import org.ofbiz.service.DispatchContext; @@ -54,7 +54,7 @@ public class JackrabbitServices { diff = (new Date().getTime() - start); result.put("repositoryDirectAccessTime", diff.toString()); - RepositoryAccessJackrabbit access = new RepositoryAccessJackrabbit(userLogin); + JackrabbitRepositoryAccessor access = new JackrabbitRepositoryAccessor(userLogin); start = new Date().getTime(); for (int i = 0; i <= maxNodes; i++) { try { Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitTests.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitTests.java?rev=1205803&r1=1205802&r2=1205803&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitTests.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitTests.java Thu Nov 24 12:28:10 2011 @@ -29,168 +29,135 @@ import javolution.util.FastMap; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.entity.GenericValue; import org.ofbiz.jcr.access.JcrRepositoryAccessor; -import org.ofbiz.jcr.access.jackrabbit.RepositoryAccessJackrabbit; +import org.ofbiz.jcr.access.jackrabbit.JackrabbitRepositoryAccessor; import org.ofbiz.jcr.api.JcrArticleHelper; -import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitFile; -import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitFolder; -import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitNews; -import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitResource; +import org.ofbiz.jcr.api.JcrFileHelper; +import org.ofbiz.jcr.orm.jackrabbit.OfbizRepositoryMappingJackrabbitArticle; import org.ofbiz.jcr.util.jackrabbit.JcrUtilJackrabbit; import org.ofbiz.service.ServiceUtil; import org.ofbiz.service.testtools.OFBizTestCase; public class JackrabbitTests extends OFBizTestCase { - protected GenericValue userLogin = null; - JcrRepositoryAccessor repositoryAccess = null; + protected GenericValue userLogin = null; - public JackrabbitTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system")); - repositoryAccess = new RepositoryAccessJackrabbit(userLogin); - } - - @Override - protected void tearDown() throws Exception { - repositoryAccess.closeAccess(); - } - - public void testRepositoryConstructor() throws Exception { - assertNotNull(repositoryAccess); - } - - public void testCreateRepositoryNewsNode() throws Exception { - // Create New Object - // path, language, title, publication date, content string - OfbizRepositoryMappingJackrabbitNews orm = new OfbizRepositoryMappingJackrabbitNews("/news/today", "en", "News of Today", new GregorianCalendar(), "Hello World"); - assertNotNull(orm); - - repositoryAccess.storeContentObject(orm); - } - - public void testReadRepositoryNewsNode() throws Exception { - OfbizRepositoryMappingJackrabbitNews orm = (OfbizRepositoryMappingJackrabbitNews) repositoryAccess.getContentObject("/news/today/en"); - assertNotNull(orm); - - assertEquals(orm.getContent(), "Hello World"); - } - - public void testUpdateRepositoryNewsNode() throws Exception { - OfbizRepositoryMappingJackrabbitNews orm = (OfbizRepositoryMappingJackrabbitNews) repositoryAccess.getContentObject("/news/today/en"); - assertNotNull(orm); - - orm.setContent("Hello Visitors"); - repositoryAccess.updateContentObject(orm); - } - - public void testVersionning() throws Exception { - assertEquals("1.1", repositoryAccess.getBaseVersion("/news/today/en")); - - OfbizRepositoryMappingJackrabbitNews orm = (OfbizRepositoryMappingJackrabbitNews) repositoryAccess.getContentObject("/news/today/en"); - orm.setContent("May the force be with you!"); - repositoryAccess.updateContentObject(orm); - - orm = (OfbizRepositoryMappingJackrabbitNews) repositoryAccess.getContentObject("/news/today/en"); - assertEquals("1.2", repositoryAccess.getBaseVersion("/news/today/en")); - } - - public void testLanguageDetermination() throws Exception { - JcrArticleHelper helper = new JcrArticleHelper(userLogin); - - helper.storeContentInRepository("news/tomorrow", "en", "The news for tomorrow.", "Content.", new GregorianCalendar()); - helper.storeContentInRepository("superhero", "de", "Batman", "The best superhero!", new GregorianCalendar()); - - assertEquals("en", helper.readContentFromRepository("/news/tomorrow", "").getLanguage()); - assertEquals("en", helper.readContentFromRepository("/news/tomorrow", "de").getLanguage()); - assertEquals("en", helper.readContentFromRepository("/news/tomorrow", "en").getLanguage()); - - assertEquals("de", helper.readContentFromRepository("/superhero", "de").getLanguage()); - assertEquals("de", helper.readContentFromRepository("/superhero", "").getLanguage()); - assertEquals("de", helper.readContentFromRepository("/superhero", "fr").getLanguage()); - - helper.removeContentObject("/superhero"); - helper.closeContentSession(); - } - - public void testRemoveRepositoryNewsNode() throws Exception { - repositoryAccess.removeContentObject("/news/today"); - } - - /* - * Test the File upload - */ - public void testCreateRepositoryFileNode() throws Exception { - File f = new File("stopofbiz.sh"); - File f2 = new File("README"); - assertTrue(f.exists() && f2.exists()); - - InputStream file = new FileInputStream(f); - - OfbizRepositoryMappingJackrabbitResource ormResource = new OfbizRepositoryMappingJackrabbitResource(); - ormResource.setData(file); - - OfbizRepositoryMappingJackrabbitFile ormFile = new OfbizRepositoryMappingJackrabbitFile(); - ormFile.setResource(ormResource); - // have to be relative - ormFile.setPath("testFile"); - - OfbizRepositoryMappingJackrabbitFolder ormFolder = new OfbizRepositoryMappingJackrabbitFolder(); - ormFolder.setPath("/fileHome"); - ormFolder.addChild(ormFile); - - repositoryAccess.storeContentObject(ormFolder); - } - - /* - * Test the File upload - Add a second file to the same folder - */ - public void testCreateRepositoryFileNode_2() throws Exception { - File f = new File("README"); - assertTrue(f.exists()); - - InputStream file = new FileInputStream(f); - - OfbizRepositoryMappingJackrabbitResource ormResource = new OfbizRepositoryMappingJackrabbitResource(); - ormResource.setData(file); - - OfbizRepositoryMappingJackrabbitFile ormFile = new OfbizRepositoryMappingJackrabbitFile(); - ormFile.setResource(ormResource); - // have to be relative - ormFile.setPath(f.getName()); - - OfbizRepositoryMappingJackrabbitFolder ormFolder = (OfbizRepositoryMappingJackrabbitFolder) repositoryAccess.getContentObject("/fileHome"); - ormFolder.addChild(ormFile); - - // When we add a file to an existing folder we have to use the update - // method - this is something the FileHelper Api is doing for you. - repositoryAccess.updateContentObject(ormFolder); - } - - public void testRemoveRepositoryFileNode() throws Exception { - repositoryAccess.removeContentObject("/fileHome"); - } - - public void testSpeedTestService() throws Exception { - Map<String, Object> context = FastMap.newInstance(); - context.put("maxNodes", new Integer(10)); - context.put("userLogin", dispatcher.getDelegator().findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system"))); - - Map<String, Object> serviceResult = this.dispatcher.runSync("determineJackrabbitRepositorySpeed", context); - - if (ServiceUtil.isError(serviceResult)) { - assertFalse(true); - } else { - assertTrue(true); - } - - } - - public void testListRepositoryNodes() throws Exception { - assertNotNull(JcrUtilJackrabbit.getRepositoryNodes(userLogin, null)); - } + public JackrabbitTests(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system")); + + } + + @Override + protected void tearDown() throws Exception { + } + + public void testRepositoryConstructor() throws Exception { + JcrRepositoryAccessor repositoryAccess = new JackrabbitRepositoryAccessor(userLogin); + assertNotNull(repositoryAccess); + } + + public void testCrudArticleNode() throws Exception { + // Create New Object + JcrArticleHelper helper = new JcrArticleHelper(userLogin); + helper.storeContentInRepository("news/article", "en", "News Of Today", "Hello World", new GregorianCalendar()); + + OfbizRepositoryMappingJackrabbitArticle content = helper.readContentFromRepository("news/article"); + assertEquals("Hello World", content.getContent()); + + content.setContent("New World!"); + + helper.updateContentInRepository(content); + + OfbizRepositoryMappingJackrabbitArticle updatedContent = helper.readContentFromRepository("news/article"); + assertEquals("New World!", updatedContent.getContent()); + + helper.removeContentObject("news/article"); + + helper.closeContentSession(); + } + + public void testVersionning() throws Exception { + JcrArticleHelper helper = new JcrArticleHelper(userLogin); + helper.storeContentInRepository("news/versionArticle", "en", "News Of Today", "Hello World", new GregorianCalendar()); + + OfbizRepositoryMappingJackrabbitArticle content = helper.readContentFromRepository("news/versionArticle"); + assertEquals("1.0", content.getVersion()); + + content.setTitle("New Title"); + helper.updateContentInRepository(content); + + content = helper.readContentFromRepository("news/versionArticle"); + assertEquals("1.1", content.getVersion()); + + helper.closeContentSession(); + } + + public void testLanguageDetermination() throws Exception { + JcrArticleHelper helper = new JcrArticleHelper(userLogin); + + helper.storeContentInRepository("news/tomorrow", "en", "The news for tomorrow.", "Content.", new GregorianCalendar()); + helper.storeContentInRepository("superhero", "de", "Batman", "The best superhero!", new GregorianCalendar()); + + assertEquals("en", helper.readContentFromRepository("/news/tomorrow", "").getLanguage()); + assertEquals("en", helper.readContentFromRepository("/news/tomorrow", "de").getLanguage()); + assertEquals("en", helper.readContentFromRepository("/news/tomorrow", "en").getLanguage()); + + assertEquals("de", helper.readContentFromRepository("/superhero", "de").getLanguage()); + assertEquals("de", helper.readContentFromRepository("/superhero", "").getLanguage()); + assertEquals("de", helper.readContentFromRepository("/superhero", "fr").getLanguage()); + + helper.removeContentObject("/superhero"); + helper.closeContentSession(); + } + + /* + * Test the File upload + */ + public void testCreateRepositoryFileNode() throws Exception { + File f = new File("stopofbiz.sh"); + File f2 = new File("README"); + assertTrue(f.exists() && f2.exists()); + + InputStream file = new FileInputStream(f); + + JcrFileHelper helper = new JcrFileHelper(userLogin); + helper.storeContentInRepository(file, f.getName(), "/fileHome"); + + assertNotNull(helper.getRepositoryContent("/fileHome/" + f.getName())); + + // add a second file to the same folder + file = new FileInputStream(f2); + + helper.storeContentInRepository(file, f2.getName(), "/fileHome"); + assertNotNull(helper.getRepositoryContent("/fileHome/" + f2.getName())); + + // remove all files in folder + helper.removeContentObject("/fileHome"); + + helper.closeContentSession(); + } + + public void testSpeedTestService() throws Exception { + Map<String, Object> context = FastMap.newInstance(); + context.put("maxNodes", new Integer(10)); + context.put("userLogin", dispatcher.getDelegator().findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system"))); + + Map<String, Object> serviceResult = this.dispatcher.runSync("determineJackrabbitRepositorySpeed", context); + + if (ServiceUtil.isError(serviceResult)) { + assertFalse(true); + } else { + assertTrue(true); + } + + } + + public void testListRepositoryNodes() throws Exception { + assertNotNull(JcrUtilJackrabbit.getRepositoryNodes(userLogin, null)); + } } \ No newline at end of file |
Free forum by Nabble | Edit this page |