On 10/12/2010 02:03 PM, tmortagne (SVN) wrote:
Author: tmortagne
Date: 2010-10-12 14:03:53 +0200 (Tue, 12 Oct 2010)
New Revision: 31733
Added:
platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-toc/src/test/resources/macrotoc11.test
Modified:
platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/parameter/ParameterValueTooHighException.java
platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/parameter/ParameterValueTooLowException.java
platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-toc/pom.xml
platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-toc/src/main/java/org/xwiki/rendering/macro/toc/TocMacroParameters.java
platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-toc/src/test/java/org/xwiki/rendering/RenderingTests.java
Log:
XWIKI-5571: Toc macro parameters bean should use standard Java bean validator
Also deprecated two exceptions that are useless since xwiki-properties is executing Java
bean validation
Modified:
platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/parameter/ParameterValueTooHighException.java
===================================================================
---
platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/parameter/ParameterValueTooHighException.java 2010-10-12
11:18:57 UTC (rev 31732)
+++
platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/parameter/ParameterValueTooHighException.java 2010-10-12
12:03:53 UTC (rev 31733)
@@ -23,7 +23,9 @@
* Exception used when the macro parameter is two high.
*
* @version $Id$
+ * @deprecated use {@link javax.validation.constraints.Max} instead
*/
+@Deprecated
public class ParameterValueTooHighException extends MacroParameterException
{
/**
Modified:
platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/parameter/ParameterValueTooLowException.java
===================================================================
---
platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/parameter/ParameterValueTooLowException.java 2010-10-12
11:18:57 UTC (rev 31732)
+++
platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/parameter/ParameterValueTooLowException.java 2010-10-12
12:03:53 UTC (rev 31733)
@@ -23,7 +23,9 @@
* Exception used when the macro parameter is two low.
*
* @version $Id$
+ * @deprecated use {@link javax.validation.constraints.Min} instead
*/
+@Deprecated
public class ParameterValueTooLowException extends MacroParameterException
{
/**
Modified:
platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-toc/pom.xml
===================================================================
---
platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-toc/pom.xml 2010-10-12
11:18:57 UTC (rev 31732)
+++
platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-toc/pom.xml 2010-10-12
12:03:53 UTC (rev 31733)
@@ -32,4 +32,12 @@
<artifactId>xwiki-core-rendering-macro-toc</artifactId>
<name>XWiki Platform - Core - Rendering - Macro - Toc</name>
<description>XWiki Platform - Core - Rendering - Macro -
Toc</description>
+<dependencies>
+<dependency>
+<groupId>org.hibernate</groupId>
+<artifactId>hibernate-validator</artifactId>
+<version>4.0.2.GA</version>
+<scope>test</scope>
+</dependency>
+</dependencies>
</project>
Modified:
platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-toc/src/main/java/org/xwiki/rendering/macro/toc/TocMacroParameters.java
===================================================================
---
platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-toc/src/main/java/org/xwiki/rendering/macro/toc/TocMacroParameters.java 2010-10-12
11:18:57 UTC (rev 31732)
+++
platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-toc/src/main/java/org/xwiki/rendering/macro/toc/TocMacroParameters.java 2010-10-12
12:03:53 UTC (rev 31733)
@@ -19,8 +19,9 @@
*/
package org.xwiki.rendering.macro.toc;
+import javax.validation.constraints.Min;
+
import org.xwiki.properties.annotation.PropertyDescription;
-import org.xwiki.rendering.macro.parameter.ParameterValueTooLowException;
/**
* Parameters for the {@link org.xwiki.rendering.internal.macro.toc.TocMacro} Macro.
@@ -49,6 +50,7 @@
/**
* The minimum section level. For example if 2 then level 1 sections will not be
listed.
*/
+ @Min(1)
private int start = 1;
/**
@@ -59,6 +61,7 @@
/**
* The maximum section level. For example if 3 then all section levels from 4 will
not be listed.
*/
+ @Min(1)
private int depth = 6;
/**
@@ -74,15 +77,10 @@
/**
* @param start the minimum section level. For example if 2 then level 1 sections
will not be listed.
- * @throws ParameterValueTooLowException the provided value is too low, it needs to
be>= 1.
*/
@PropertyDescription("the minimum section level. For example if 2 then level 1
sections will not be listed")
- public void setStart(int start) throws ParameterValueTooLowException
+ public void setStart(int start)
{
- if (start< 1) {
- throw new ParameterValueTooLowException(1);
- }
-
this.start = start;
this.customStart = true;
}
@@ -105,16 +103,11 @@
/**
* @param depth the maximum section level. For example if 3 then all section levels
from 4 will not be listed.
- * @throws ParameterValueTooLowException the provided value is too low, it needs to
be>= 1.
*/
@PropertyDescription("the maximum section level. "
+ "For example if 3 then all section levels from 4 will not be
listed")
- public void setDepth(int depth) throws ParameterValueTooLowException
+ public void setDepth(int depth)
{
- if (depth< 1) {
- throw new ParameterValueTooLowException(1);
- }
-
this.depth = depth;
}
Modified:
platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-toc/src/test/java/org/xwiki/rendering/RenderingTests.java
===================================================================
---
platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-toc/src/test/java/org/xwiki/rendering/RenderingTests.java 2010-10-12
11:18:57 UTC (rev 31732)
+++
platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-toc/src/test/java/org/xwiki/rendering/RenderingTests.java 2010-10-12
12:03:53 UTC (rev 31733)
@@ -35,7 +35,7 @@
{
public static Test suite() throws Exception
{
- RenderingTestSuite suite = new RenderingTestSuite("Test Toc Macro");
+ RenderingTestSuite suite = new RenderingTestSuite("Test Toc Macro",
"", "macrotoc11.test");
return new ComponentManagerTestSetup(suite);
}
}
Added:
platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-toc/src/test/resources/macrotoc11.test
===================================================================
---
platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-toc/src/test/resources/macrotoc11.test
(rev 0)
+++
platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-toc/src/test/resources/macrotoc11.test 2010-10-12
12:03:53 UTC (rev 31733)
@@ -0,0 +1,81 @@
+.runTransformations
+.#-----------------------------------------------------
+.input|xwiki/2.0
+.# Verify the TOC produce error when "start" or "depth" parameters
are too low
+.#-----------------------------------------------------
+{{toc start="0"/}}
+
+{{toc depth="0"/}}
+.#-----------------------------------------------------
+.expect|event/1.0
+.#-----------------------------------------------------
+beginDocument
+beginMacroMarkerStandalone [toc] [start=0]
+beginGroup [[class]=[xwikirenderingerror]]
+onWord [Invalid macro parameters used for the "toc" macro]
+endGroup [[class]=[xwikirenderingerror]]
+beginGroup [[class]=[xwikirenderingerrordescription hidden]]
This stacktrace looks really fragile, any changes in the source files
will prompt redoing the test file.
+onVerbatim [org.xwiki.properties.PropertyException:
Failed to validate bean: [must be greater than or equal to 1]
+ at
org.xwiki.properties.internal.DefaultBeanManager.validateBean(DefaultBeanManager.java:178)
+ at
org.xwiki.properties.internal.DefaultBeanManager.populate(DefaultBeanManager.java:113)
+ at
org.xwiki.rendering.internal.transformation.MacroTransformation.transformOnce(MacroTransformation.java:158)
+ at
org.xwiki.rendering.internal.transformation.MacroTransformation.transform(MacroTransformation.java:117)
+ at
org.xwiki.rendering.internal.transformation.DefaultTransformationManager.performTransformations(DefaultTransformationManager.java:85)
+ at
org.xwiki.rendering.scaffolding.RenderingTestCase.runTestInternal(RenderingTestCase.java:126)
+ at
org.xwiki.rendering.scaffolding.RenderingTestCase.runTest(RenderingTestCase.java:99)
+ at org.jmock.core.VerifyingTestCase.runBare(VerifyingTestCase.java:39)
+ at junit.framework.TestResult$1.protect(TestResult.java:110)
+ at junit.framework.TestResult.runProtected(TestResult.java:128)
+ at junit.framework.TestResult.run(TestResult.java:113)
+ at junit.framework.TestCase.run(TestCase.java:124)
+ at junit.framework.TestSuite.runTest(TestSuite.java:232)
+ at junit.framework.TestSuite.run(TestSuite.java:227)
+ at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24)
+ at junit.extensions.TestSetup$1.protect(TestSetup.java:23)
+ at junit.framework.TestResult.runProtected(TestResult.java:128)
+ at junit.extensions.TestSetup.run(TestSetup.java:27)
+ at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
+ at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
+ at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
+ at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
+ at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
+ at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
+ at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
+] [false]
+endGroup [[class]=[xwikirenderingerrordescription hidden]]
+endMacroMarkerStandalone [toc] [start=0]
+beginMacroMarkerStandalone [toc] [depth=0]
+beginGroup [[class]=[xwikirenderingerror]]
+onWord [Invalid macro parameters used for the "toc" macro]
+endGroup [[class]=[xwikirenderingerror]]
+beginGroup [[class]=[xwikirenderingerrordescription hidden]]
+onVerbatim [org.xwiki.properties.PropertyException: Failed to validate bean: [must be
greater than or equal to 1]
+ at
org.xwiki.properties.internal.DefaultBeanManager.validateBean(DefaultBeanManager.java:178)
+ at
org.xwiki.properties.internal.DefaultBeanManager.populate(DefaultBeanManager.java:113)
+ at
org.xwiki.rendering.internal.transformation.MacroTransformation.transformOnce(MacroTransformation.java:158)
+ at
org.xwiki.rendering.internal.transformation.MacroTransformation.transform(MacroTransformation.java:117)
+ at
org.xwiki.rendering.internal.transformation.DefaultTransformationManager.performTransformations(DefaultTransformationManager.java:85)
+ at
org.xwiki.rendering.scaffolding.RenderingTestCase.runTestInternal(RenderingTestCase.java:126)
+ at
org.xwiki.rendering.scaffolding.RenderingTestCase.runTest(RenderingTestCase.java:99)
+ at org.jmock.core.VerifyingTestCase.runBare(VerifyingTestCase.java:39)
+ at junit.framework.TestResult$1.protect(TestResult.java:110)
+ at junit.framework.TestResult.runProtected(TestResult.java:128)
+ at junit.framework.TestResult.run(TestResult.java:113)
+ at junit.framework.TestCase.run(TestCase.java:124)
+ at junit.framework.TestSuite.runTest(TestSuite.java:232)
+ at junit.framework.TestSuite.run(TestSuite.java:227)
+ at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24)
+ at junit.extensions.TestSetup$1.protect(TestSetup.java:23)
+ at junit.framework.TestResult.runProtected(TestResult.java:128)
+ at junit.extensions.TestSetup.run(TestSetup.java:27)
+ at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
+ at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
+ at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
+ at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
+ at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
+ at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
+ at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
+] [false]
+endGroup [[class]=[xwikirenderingerrordescription hidden]]
+endMacroMarkerStandalone [toc] [depth=0]
+endDocument
\ No newline at end of file
--
Sergiu Dumitriu
http://purl.org/net/sergiu/