Author: sascharodekamp
Date: Mon Dec 12 10:48:04 2011 New Revision: 1213183 URL: http://svn.apache.org/viewvc?rev=1213183&view=rev Log: Add a new test and change the exception handling when reading content from the repository. A Path not found exception will now be thrown, when a path not exist. Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/ContentReader.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/JcrRepositoryAccessor.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/JackrabbitRepositoryAccessor.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrDataHelper.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/test/JackrabbitTests.java 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=1213183&r1=1213182&r2=1213183&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 Mon Dec 12 10:48:04 2011 @@ -1,5 +1,6 @@ package org.ofbiz.jcr.access; +import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.query.QueryResult; @@ -15,8 +16,9 @@ public interface ContentReader { * * @param nodePath * @return + * @throws PathNotFoundException */ - OfbizRepositoryMapping getContentObject(String nodePath); + OfbizRepositoryMapping getContentObject(String nodePath) throws PathNotFoundException; /** * Return an OfbizRepositoryMapping Object in the specified language and @@ -28,8 +30,9 @@ public interface ContentReader { * @param language * @param version * @return + * @throws PathNotFoundException */ - OfbizRepositoryMapping getContentObject(String nodePath, String version); + OfbizRepositoryMapping getContentObject(String nodePath, String version) throws PathNotFoundException; /** * Returns a tree of all content nodes (except folders and files) in the Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/JcrRepositoryAccessor.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/JcrRepositoryAccessor.java?rev=1213183&r1=1213182&r2=1213183&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/JcrRepositoryAccessor.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/JcrRepositoryAccessor.java Mon Dec 12 10:48:04 2011 @@ -3,6 +3,7 @@ package org.ofbiz.jcr.access; import java.util.List; import javax.jcr.ItemExistsException; +import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.query.QueryResult; @@ -25,8 +26,9 @@ public interface JcrRepositoryAccessor { * * @param nodePath * @return + * @throws PathNotFoundException */ - OfbizRepositoryMapping getContentObject(String nodePath); + OfbizRepositoryMapping getContentObject(String nodePath) throws PathNotFoundException; /** * Return an OfbizRepositoryMapping Object in the specified version from the @@ -36,8 +38,9 @@ public interface JcrRepositoryAccessor { * @param language * @param version * @return + * @throws PathNotFoundException */ - OfbizRepositoryMapping getContentObject(String nodePath, String version); + OfbizRepositoryMapping getContentObject(String nodePath, String version) throws PathNotFoundException; /** * Stores the OfbizRepositoryMapping Class in the content repository. 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=1213183&r1=1213182&r2=1213183&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 Mon Dec 12 10:48:04 2011 @@ -2,6 +2,7 @@ package org.ofbiz.jcr.access.jackrabbit; import javax.jcr.Node; import javax.jcr.NodeIterator; +import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.query.Query; import javax.jcr.query.QueryManager; @@ -35,7 +36,7 @@ public class ContentReaderJackrabbit imp * org.ofbiz.jcr.access.ContentReader#getContentObject(java.lang.String) */ @Override - public OfbizRepositoryMapping getContentObject(String nodePath) { + public OfbizRepositoryMapping getContentObject(String nodePath) throws PathNotFoundException{ nodePath = JcrUtilJackrabbit.createAbsoluteNodePath(nodePath); OfbizRepositoryMapping orm = (OfbizRepositoryMapping) ocm.getObject(nodePath); try { @@ -58,7 +59,7 @@ public class ContentReaderJackrabbit imp * java.lang.String, java.lang.String) */ @Override - public OfbizRepositoryMapping getContentObject(String nodePath, String version) { + public OfbizRepositoryMapping getContentObject(String nodePath, String version) throws PathNotFoundException { nodePath = JcrUtilJackrabbit.createAbsoluteNodePath(nodePath); VersioningManager vm = new VersioningManagerJackrabbit(ocm); if (!vm.checkIfVersionExist(nodePath, version)) { Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java?rev=1213183&r1=1213182&r2=1213183&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/access/jackrabbit/JackrabbitRepositoryAccessor.java Mon Dec 12 10:48:04 2011 @@ -3,6 +3,7 @@ package org.ofbiz.jcr.access.jackrabbit; import java.util.List; import javax.jcr.ItemExistsException; +import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.query.QueryResult; @@ -85,7 +86,7 @@ public class JackrabbitRepositoryAccesso * org.ofbiz.jcr.orm.RepositoryAccess#getContentObject(java.lang.String) */ @Override - public OfbizRepositoryMapping getContentObject(String nodePath) { + public OfbizRepositoryMapping getContentObject(String nodePath) throws PathNotFoundException { ContentReader contentReader = new ContentReaderJackrabbit(this.ocm); return contentReader.getContentObject(nodePath); } @@ -98,7 +99,7 @@ public class JackrabbitRepositoryAccesso * java.lang.String) */ @Override - public OfbizRepositoryMapping getContentObject(String nodePath, String version) { + public OfbizRepositoryMapping getContentObject(String nodePath, String version) throws PathNotFoundException { ContentReader contentReader = new ContentReaderJackrabbit(this.ocm); return contentReader.getContentObject(nodePath, version); } Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrDataHelper.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrDataHelper.java?rev=1213183&r1=1213182&r2=1213183&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrDataHelper.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/JcrDataHelper.java Mon Dec 12 10:48:04 2011 @@ -4,6 +4,7 @@ import java.util.Calendar; import java.util.List; import javax.jcr.ItemExistsException; +import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException; @@ -17,11 +18,13 @@ public interface JcrDataHelper extends J * * @param contentPath * @return content article object - * @throws + * @throws PathNotFoundException + * @throws ClassCastException */ - public abstract JackrabbitArticle readContentFromRepository(String contentPath) throws ClassCastException; + public abstract JackrabbitArticle readContentFromRepository(String contentPath) throws ClassCastException, PathNotFoundException; /** + * @throws PathNotFoundException * Read the article content object, in the passed language, from the * repository. if the language is not available, the default language will * be choose. Throws an Exception when the read content type is not an @@ -29,11 +32,13 @@ public interface JcrDataHelper extends J * * @param contentPath * @return content article object - * @throws + * @throws PathNotFoundException + * @throws ClassCastException */ - public abstract JackrabbitArticle readContentFromRepository(String contentPath, String language) throws ClassCastException; + public abstract JackrabbitArticle readContentFromRepository(String contentPath, String language) throws ClassCastException, PathNotFoundException; /** + * @throws PathNotFoundException * Read the article content object, in the passed language and version, from * the repository. if the language is not available, the default language * will be choose. Throws an Exception when the read content type is not an @@ -43,9 +48,10 @@ public interface JcrDataHelper extends J * @param language * @param version * @return - * @throws + * @throws PathNotFoundException + * @throws ClassCastException */ - public abstract JackrabbitArticle readContentFromRepository(String contentPath, String language, String version) throws ClassCastException; + public abstract JackrabbitArticle readContentFromRepository(String contentPath, String language, String version) throws ClassCastException, PathNotFoundException; /** * Stores a new article content object in the repository. Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java?rev=1213183&r1=1213182&r2=1213183&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/api/jackrabbit/JackrabbitArticleHelper.java Mon Dec 12 10:48:04 2011 @@ -69,7 +69,7 @@ public class JackrabbitArticleHelper ext * .lang.String) */ @Override - public JackrabbitArticle readContentFromRepository(String contentPath) throws ClassCastException { + public JackrabbitArticle readContentFromRepository(String contentPath) throws ClassCastException, PathNotFoundException { return readContentFromRepository(contentPath, ""); } @@ -81,7 +81,7 @@ public class JackrabbitArticleHelper ext * .lang.String, java.lang.String) */ @Override - public JackrabbitArticle readContentFromRepository(String contentPath, String language) throws ClassCastException { + public JackrabbitArticle readContentFromRepository(String contentPath, String language) throws ClassCastException, PathNotFoundException { contentPath = determineContentLanguagePath(contentPath, language); OfbizRepositoryMapping orm = super.access.getContentObject(contentPath); @@ -102,7 +102,7 @@ public class JackrabbitArticleHelper ext * .lang.String, java.lang.String, java.lang.String) */ @Override - public JackrabbitArticle readContentFromRepository(String contentPath, String language, String version) throws ClassCastException { + public JackrabbitArticle readContentFromRepository(String contentPath, String language, String version) throws ClassCastException, PathNotFoundException { contentPath = determineContentLanguagePath(contentPath, language); OfbizRepositoryMapping orm = super.access.getContentObject(contentPath, version); @@ -224,8 +224,9 @@ public class JackrabbitArticleHelper ext * @param contentPath * @param contentLanguage * @return + * @throws PathNotFoundException */ - private String determineContentLanguagePath(String contentPath, String contentLanguage) { + private String determineContentLanguagePath(String contentPath, String contentLanguage) throws PathNotFoundException { // return if only the root node path is requested if (ConstantsJackrabbit.ROOTPATH.equals(contentPath)) { return contentPath; @@ -263,8 +264,9 @@ public class JackrabbitArticleHelper ext * * @param canonicalizedContentPath * @return + * @throws PathNotFoundException */ - private String determineFirstAvailableLanguageNode(String canonicalizedContentPath) { + private String determineFirstAvailableLanguageNode(String canonicalizedContentPath) throws PathNotFoundException { String contentPath = ""; try { @@ -278,6 +280,8 @@ public class JackrabbitArticleHelper ext } } childNodes = null; + } catch(PathNotFoundException pnf) { + throw new PathNotFoundException(pnf); } catch (RepositoryException e) { Debug.logError(e, module); } 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=1213183&r1=1213182&r2=1213183&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 Mon Dec 12 10:48:04 2011 @@ -25,6 +25,8 @@ import java.util.GregorianCalendar; import java.util.List; import java.util.Map; +import javax.jcr.ItemExistsException; +import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.query.QueryResult; @@ -32,6 +34,7 @@ import javax.jcr.query.QueryResult; import javolution.util.FastMap; import net.sf.json.JSONArray; +import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException; import org.apache.jackrabbit.ocm.manager.ObjectContentManager; import org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl; import org.apache.jackrabbit.ocm.mapper.Mapper; @@ -236,6 +239,7 @@ public class JackrabbitTests extends OFB helper.storeContentInRepository("superhero", "de", "Batman", "The best superhero!", new GregorianCalendar()); assertEquals("en", helper.readContentFromRepository("/news/tomorrow", "").getLanguage()); + assertEquals("en", helper.readContentFromRepository("/news/tomorrow/en", "").getLanguage()); assertEquals("en", helper.readContentFromRepository("/news/tomorrow", "de").getLanguage()); assertEquals("en", helper.readContentFromRepository("/news/tomorrow", "en").getLanguage()); @@ -248,6 +252,23 @@ public class JackrabbitTests extends OFB helper.closeContentSession(); } + public void testLanguageDeterminationExpectedPathNotFoundException() throws ObjectContentManagerException, ItemExistsException { + JcrDataHelper helper = new JackrabbitArticleHelper(userLogin); + helper.storeContentInRepository("news/tomorrow", "en", "The news for tomorrow.", "Content.", new GregorianCalendar()); + + try { + helper.readContentFromRepository("/news/tomorrow/fr", "").getLanguage(); + // if no exception is thrown, the test should fail + assertTrue("A PathNotFoundException is thrown as expected", false); + } catch (PathNotFoundException pnf) { + // check if the right excpetion is thrown (in jUnit 4 this could be replaced by annotations) + assertTrue("A PathNotFoundException is catched as expected.", true); + } + + helper.removeContentObject("/news"); + helper.closeContentSession(); + } + /* * Test the File upload */ |
Free forum by Nabble | Edit this page |