From: <die...@us...> - 2010-05-13 06:18:06
|
Revision: 2435 http://openutils.svn.sourceforge.net/openutils/?rev=2435&view=rev Author: diego_schivo Date: 2010-05-13 06:18:00 +0000 (Thu, 13 May 2010) Log Message: ----------- CRIT-11 refactoring + javadocs Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java 2010-05-13 05:57:30 UTC (rev 2434) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java 2010-05-13 06:18:00 UTC (rev 2435) @@ -121,21 +121,25 @@ */ public Criteria setBasePath(String path) { - if (!StringUtils.endsWith(path, "*")) + // check if the specified path is already an xpath query + if (StringUtils.contains(path, "*")) { + this.path = path; + } + else + { + // convert the node handle to a xpath query if (StringUtils.isEmpty(StringUtils.remove(path, '/'))) { + // root node this.path = "//*"; } else { + // the handle already starts with a single '/', so prepend another one this.path = "/" + StringUtils.defaultString(StringUtils.removeEnd(path, "/")) + "//*"; } } - else - { - this.path = path; - } return this; } Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java 2010-05-13 05:57:30 UTC (rev 2434) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java 2010-05-13 06:18:00 UTC (rev 2435) @@ -41,6 +41,7 @@ /** + * Tests criteria queries with different values of basePath parameter. * @author dschivo * @version $Id$ */ @@ -77,8 +78,12 @@ MgnlContext.getHierarchyManager(ContentRepository.WEBSITE).save(); } + /** + * Passing a null basePath should search the entire repository. + * @throws Exception + */ @Test - public void testSearchEntireTree1() throws Exception + public void testNullBasePath() throws Exception { Collection<String> paths = searchPaths(null, "AdvancedCriteriaImpl"); Assert.assertNotNull(paths); @@ -88,8 +93,12 @@ Assert.assertTrue(paths.contains("/Criteria/TranslatableCriteria/AbstractCriteriaImpl/AdvancedCriteriaImpl")); } + /** + * Passing an empty basePath should search the entire repository. + * @throws Exception + */ @Test - public void testSearchEntireTree2() throws Exception + public void testEmptyBasePath() throws Exception { Collection<String> paths = searchPaths(StringUtils.EMPTY, "AdvancedCriteriaImpl"); Assert.assertNotNull(paths); @@ -99,8 +108,12 @@ Assert.assertTrue(paths.contains("/Criteria/TranslatableCriteria/AbstractCriteriaImpl/AdvancedCriteriaImpl")); } + /** + * Passing an xpath query ending with /* as the basePath should search the children. + * @throws Exception + */ @Test - public void testSearchSingleBranchChildren() throws Exception + public void testSearchXpathBasePathWithSingleSlash() throws Exception { Collection<String> paths = searchPaths("//Criteria/AbstractCriteriaImpl/*", StringUtils.EMPTY); Assert.assertNotNull(paths); @@ -109,8 +122,12 @@ Assert.assertTrue(paths.contains("/Criteria/AbstractCriteriaImpl/AdvancedCriteriaImpl")); } + /** + * Passing an xpath query ending with //* as the basePath should search the descendants. + * @throws Exception + */ @Test - public void testSearchSingleBranchDescendants1() throws Exception + public void testSearchXpathBasePathWithDoubleSlash() throws Exception { Collection<String> paths = searchPaths("//Criteria/TranslatableCriteria//*", "AdvancedCriteriaImpl"); Assert.assertNotNull(paths); @@ -118,8 +135,12 @@ Assert.assertTrue(paths.contains("/Criteria/TranslatableCriteria/AbstractCriteriaImpl/AdvancedCriteriaImpl")); } + /** + * Passing an handle as the basePath should search the descendants. + * @throws Exception + */ @Test - public void testSearchSingleBranchDescendants2() throws Exception + public void testSearchHandleBasePath() throws Exception { Collection<String> paths = searchPaths("/Criteria/TranslatableCriteria", "AdvancedCriteriaImpl"); Assert.assertNotNull(paths); @@ -127,8 +148,13 @@ Assert.assertTrue(paths.contains("/Criteria/TranslatableCriteria/AbstractCriteriaImpl/AdvancedCriteriaImpl")); } + /** + * Passing an handle ending with / as the basePath should search the descendants. + * This test makes sure that the resulting xpath query does not end with ///* + * @throws Exception + */ @Test - public void testSearchSingleBranchDescendants3() throws Exception + public void testSearchHandleBasePathWithTrailingSlash() throws Exception { Collection<String> paths = searchPaths("/Criteria/TranslatableCriteria/", "AdvancedCriteriaImpl"); Assert.assertNotNull(paths); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |