Nuiton-utils-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
August 2011
- 5 participants
- 40 discussions
r2187 - trunk/nuiton-profiling/src/main/java/org/nuiton/profiling
by bpoussin@users.nuiton.org 24 Aug '11
by bpoussin@users.nuiton.org 24 Aug '11
24 Aug '11
Author: bpoussin
Date: 2011-08-24 18:07:45 +0200 (Wed, 24 Aug 2011)
New Revision: 2187
Url: http://nuiton.org/repositories/revision/nuiton-utils/2187
Log:
Evolution #1711: Add CSV export format data
Modified:
trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java
Modified: trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java
===================================================================
--- trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java 2011-08-24 15:54:43 UTC (rev 2186)
+++ trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java 2011-08-24 16:07:45 UTC (rev 2187)
@@ -230,6 +230,39 @@
// le temps reellement passé dans A est representé par les =====
}
+ /** @return les statistiques in CSV format*/
+ static public String getStatisticsCSVAndClear() {
+ StringBuilder result = new StringBuilder();
+ result.append("method;")
+ .append("call;")
+ // TIme is in nano not millis, we must divide by 1000000
+ .append("min;")
+ .append("mean;")
+ .append("max;")
+ .append("total;")
+ .append("call_nest;")
+ .append("total_with_nest\n");
+
+ for (NuitonTrace trace : instances) {
+ for (Method method : trace.statistics.keySet()) {
+ long[] stat = trace.getStatistics(method);
+ long meanTime = stat[STAT_TIME_TOTAL] / stat[STAT_CALL];
+ result.append(method)
+ .append(";").append(stat[STAT_CALL])
+ // Time is in nano not millis, we must divide by 1000000
+ .append(";").append(DurationFormatUtils.formatDuration(stat[STAT_TIME_MIN] / 1000000, "s'.'S"))
+ .append(";").append(DurationFormatUtils.formatDuration(meanTime / 1000000, "s'.'S"))
+ .append(";").append(DurationFormatUtils.formatDuration(stat[STAT_TIME_MAX] / 1000000, "s'.'S"))
+ .append(";").append(DurationFormatUtils.formatDuration(stat[STAT_TIME_TOTAL] / 1000000, "s'.'S"))
+ .append(";").append(stat[STAT_CALL_NEST_METHOD])
+ .append(";").append(DurationFormatUtils.formatDuration(stat[STAT_TIME_TOTAL_NEST_METHOD] / 1000000, "s'.'S"))
+ .append("\n");
+ }
+ }
+ instances.clear();
+ return result.toString();
+ }
+
/** @return les statistiques */
static public String getStatisticsAndClear() {
StringBuilder result = new StringBuilder();
1
0
Author: tchemit
Date: 2011-08-24 17:54:43 +0200 (Wed, 24 Aug 2011)
New Revision: 2186
Url: http://nuiton.org/repositories/revision/nuiton-utils/2186
Log:
optimize poms
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-08-24 15:53:53 UTC (rev 2185)
+++ trunk/pom.xml 2011-08-24 15:54:43 UTC (rev 2186)
@@ -72,47 +72,20 @@
<scope>runtime</scope>
</dependency>
- <!-- aspectwerkz dependencies -->
-
+ <!-- aspectJ dependencies -->
<dependency>
- <groupId>aspectwerkz</groupId>
- <artifactId>aspectwerkz-core</artifactId>
- <version>${aspectwerkzVersion}</version>
- <!-- These dependencies are not in maven central -->
- <exclusions>
- <exclusion>
- <groupId>asm</groupId>
- <artifactId>asm</artifactId>
- </exclusion>
- <exclusion>
- <groupId>asm-attrs</groupId>
- <artifactId>asm-attrs</artifactId>
- </exclusion>
- <exclusion>
- <groupId>asm-util</groupId>
- <artifactId>asm-util</artifactId>
- </exclusion>
- </exclusions>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjrt</artifactId>
+ <version>${aspectj.version}</version>
</dependency>
<dependency>
- <groupId>aspectwerkz</groupId>
- <artifactId>aspectwerkz</artifactId>
- <version>${aspectwerkzVersion}</version>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjweaver</artifactId>
+ <version>${aspectj.version}</version>
+ <scope>runtime</scope>
</dependency>
- <dependency>
- <groupId>aspectwerkz</groupId>
- <artifactId>aspectwerkz-jdk5</artifactId>
- <version>${aspectwerkzVersion}</version>
- </dependency>
-
- <dependency>
- <groupId>asm</groupId>
- <artifactId>asm</artifactId>
- <version>3.3.1</version>
- </dependency>
-
</dependencies>
</dependencyManagement>
@@ -206,7 +179,7 @@
<projectId>nuiton-utils</projectId>
<nuitonI18nVersion>2.4.1</nuitonI18nVersion>
- <aspectwerkzVersion>2.0</aspectwerkzVersion>
+ <aspectj.version>1.6.11</aspectj.version>
<xworkVersion>2.2.3</xworkVersion>
<!-- i18n configuration -->
1
0
r2185 - in trunk/nuiton-profiling: . src/test/java/org/nuiton/profiling src/test/resources/META-INF
by tchemit@users.nuiton.org 24 Aug '11
by tchemit@users.nuiton.org 24 Aug '11
24 Aug '11
Author: tchemit
Date: 2011-08-24 17:53:53 +0200 (Wed, 24 Aug 2011)
New Revision: 2185
Url: http://nuiton.org/repositories/revision/nuiton-utils/2185
Log:
optimize poms + clean aop.xml + remove verbose in tests
Modified:
trunk/nuiton-profiling/pom.xml
trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/NuitonTraceTest.java
trunk/nuiton-profiling/src/test/resources/META-INF/aop.xml
Modified: trunk/nuiton-profiling/pom.xml
===================================================================
--- trunk/nuiton-profiling/pom.xml 2011-08-24 15:39:42 UTC (rev 2184)
+++ trunk/nuiton-profiling/pom.xml 2011-08-24 15:53:53 UTC (rev 2185)
@@ -22,7 +22,9 @@
<http://www.gnu.org/licenses/lgpl-3.0.html>.
#L%
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -50,50 +52,19 @@
<artifactId>commons-lang</artifactId>
</dependency>
-
<!-- aspectJ -->
<dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjrt</artifactId>
- <version>${aspectj.version}</version>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjrt</artifactId>
</dependency>
<dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjweaver</artifactId>
- <version>${aspectj.version}</version>
- <scope>runtime</scope>
- </dependency>
-
-
- <!-- aspectwerkz use asm* dependencies which are not on central... -->
- <!-- Event if we relocated them to a org.nuiton.thirdparty groupId -->
-<!--
- <dependency>
- <groupId>aspectwerkz</groupId>
- <artifactId>aspectwerkz-core</artifactId>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjweaver</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
- <groupId>asm</groupId>
- <artifactId>asm</artifactId>
- <scope>runtime</scope>
- </dependency>
-
- <dependency>
- <groupId>aspectwerkz</groupId>
- <artifactId>aspectwerkz</artifactId>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>aspectwerkz</groupId>
- <artifactId>aspectwerkz-jdk5</artifactId>
- <scope>compile</scope>
- </dependency>
--->
- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
@@ -124,12 +95,12 @@
<!-- extra files to include in release -->
<redmine.releaseFiles>${redmine.libReleaseFiles}</redmine.releaseFiles>
- <aspectj.version>1.6.11</aspectj.version>
<!-- Configure aop -->
- <maven.surefire.debug>-javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-1.6.11.jar</maven.surefire.debug>
- <!--maven.surefire.debug>-javaagent:target/lib/aspectwerkz-jdk5-2.0.jar</maven.surefire.debug-->
- <!--<maven.surefire.debug>-javaagent:target/lib/aspectwerkz-jdk5-2.0.jar -Daspectwerkz.definition.file=src/test/resources/aop.xml</maven.surefire.debug>-->
+ <maven.surefire.debug>
+ -javaagent:target/lib/aspectjweaver-${aspectj.version}.jar
+ </maven.surefire.debug>
+ <!--<maven.surefire.debug>-javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-1.6.11.jar</maven.surefire.debug>-->
</properties>
<!-- ************************************************************* -->
Modified: trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/NuitonTraceTest.java
===================================================================
--- trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/NuitonTraceTest.java 2011-08-24 15:39:42 UTC (rev 2184)
+++ trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/NuitonTraceTest.java 2011-08-24 15:53:53 UTC (rev 2185)
@@ -31,7 +31,7 @@
import org.junit.Test;
/**
- * Launch this test with -javaagent:target/lib/aspectwerkz-jdk5-2.0.jar
+ * Launch this test with -javaagent:target/lib/aspectjweaver-1.6.11.jar
*
* @author tchemit <chemit(a)codelutin.com>
* @since 2.3
Modified: trunk/nuiton-profiling/src/test/resources/META-INF/aop.xml
===================================================================
--- trunk/nuiton-profiling/src/test/resources/META-INF/aop.xml 2011-08-24 15:39:42 UTC (rev 2184)
+++ trunk/nuiton-profiling/src/test/resources/META-INF/aop.xml 2011-08-24 15:53:53 UTC (rev 2185)
@@ -3,18 +3,19 @@
"http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
- <aspects>
- <!-- creation d'un aspect pour definir les methodes a intercepter -->
- <concrete-aspect name="org.nuiton.profiling.NuitonTraceTestAspect"
- extends="org.nuiton.profiling.NuitonTrace">
- <pointcut name="executeMethod" expression="execution(public * org.apache..*.*(..)) AND !within(org.apache.log4j..*) AND !within(org.apache.maven..*) AND !within(org.apache.commons.lang..*)"/>
+ <!-- quelques options pour voir ce qu'il se passe (non obligatoire) -->
+ <weaver>
+ <!--<weaver options="-verbose -showWeaveInfo ">-->
+ <!-- quelque restriction sur les classes a prendre en compte, pour avec un exemple -->
+ <include within="org.apache.commons.logging..*" />
+ <!-- la config pour que aspectj ecrive sur le disque les fichiers java qu'il genere -->
+ <!-- <dump within="*"/> -->
+ </weaver>
+ <aspects>
+ <!-- creation d'un aspect pour definir les methodes a intercepter -->
+ <concrete-aspect name="org.nuiton.profiling.NuitonTraceTestAspect"
+ extends="org.nuiton.profiling.NuitonTrace">
+ <pointcut name="executeMethod" expression="execution(public * org.apache..*.*(..)) AND !within(org.apache.log4j..*)"/>
</concrete-aspect>
</aspects>
- <!-- quelques options pour voir ce qu'il se passe (non obligatoire) -->
- <weaver options="-verbose -showWeaveInfo ">
- <!-- quelque restriction sur les classes a prendre en compte, pour avec un exemple -->
- <include within="org.apache.commons.logging.*" />
- <!-- la config pour que aspectj ecrive sur le disque les fichiers java qu'il genere -->
- <!-- <dump within="*"/> -->
- </weaver>
</aspectj>
1
0
24 Aug '11
Author: tchemit
Date: 2011-08-24 17:39:42 +0200 (Wed, 24 Aug 2011)
New Revision: 2184
Url: http://nuiton.org/repositories/revision/nuiton-utils/2184
Log:
remove java.sql.Date import :)
Modified:
trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java
Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java 2011-08-24 15:30:32 UTC (rev 2183)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java 2011-08-24 15:39:42 UTC (rev 2184)
@@ -54,11 +54,11 @@
import java.lang.reflect.Modifier;
import java.net.URI;
import java.net.URL;
-import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
@@ -581,7 +581,7 @@
if (dirCreated && log.isDebugEnabled()) {
log.debug("Creation of config directory " + file.getParent());
}
- saveResource(file, prop, "Last saved " + new java.util.Date());
+ saveResource(file, prop, "Last saved " + new Date());
}
/**
@@ -1914,7 +1914,7 @@
if (log.isDebugEnabled()) {
log.debug("Saving configuration fired by property [" +
evt.getPropertyName() + "] at " +
- new java.util.Date());
+ new Date());
}
saveForUser();
}
1
0
r2183 - in trunk/nuiton-profiling: . src/main/java/org/nuiton/profiling src/test/java/org/nuiton/profiling src/test/resources/META-INF
by bpoussin@users.nuiton.org 24 Aug '11
by bpoussin@users.nuiton.org 24 Aug '11
24 Aug '11
Author: bpoussin
Date: 2011-08-24 17:30:32 +0200 (Wed, 24 Aug 2011)
New Revision: 2183
Url: http://nuiton.org/repositories/revision/nuiton-utils/2183
Log:
Evolution #1253: Switch from aspectwerkz to aspectj
Modified:
trunk/nuiton-profiling/pom.xml
trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java
trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/NuitonTraceTest.java
trunk/nuiton-profiling/src/test/resources/META-INF/aop.xml
Modified: trunk/nuiton-profiling/pom.xml
===================================================================
--- trunk/nuiton-profiling/pom.xml 2011-08-24 13:13:11 UTC (rev 2182)
+++ trunk/nuiton-profiling/pom.xml 2011-08-24 15:30:32 UTC (rev 2183)
@@ -50,8 +50,25 @@
<artifactId>commons-lang</artifactId>
</dependency>
+
+ <!-- aspectJ -->
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjrt</artifactId>
+ <version>${aspectj.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjweaver</artifactId>
+ <version>${aspectj.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+
+
<!-- aspectwerkz use asm* dependencies which are not on central... -->
<!-- Event if we relocated them to a org.nuiton.thirdparty groupId -->
+<!--
<dependency>
<groupId>aspectwerkz</groupId>
<artifactId>aspectwerkz-core</artifactId>
@@ -75,13 +92,13 @@
<artifactId>aspectwerkz-jdk5</artifactId>
<scope>compile</scope>
</dependency>
-
+-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
-
+
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
@@ -107,9 +124,11 @@
<!-- extra files to include in release -->
<redmine.releaseFiles>${redmine.libReleaseFiles}</redmine.releaseFiles>
+ <aspectj.version>1.6.11</aspectj.version>
<!-- Configure aop -->
- <maven.surefire.debug>-javaagent:target/lib/aspectwerkz-jdk5-2.0.jar</maven.surefire.debug>
+ <maven.surefire.debug>-javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-1.6.11.jar</maven.surefire.debug>
+ <!--maven.surefire.debug>-javaagent:target/lib/aspectwerkz-jdk5-2.0.jar</maven.surefire.debug-->
<!--<maven.surefire.debug>-javaagent:target/lib/aspectwerkz-jdk5-2.0.jar -Daspectwerkz.definition.file=src/test/resources/aop.xml</maven.surefire.debug>-->
</properties>
@@ -141,6 +160,7 @@
</plugin>
</plugins>
</build>
+
<profiles>
<profile>
<id>reporting</id>
Modified: trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java
===================================================================
--- trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java 2011-08-24 13:13:11 UTC (rev 2182)
+++ trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java 2011-08-24 15:30:32 UTC (rev 2183)
@@ -22,14 +22,6 @@
package org.nuiton.profiling;
import org.apache.commons.lang.time.DurationFormatUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codehaus.aspectwerkz.annotation.After;
-import org.codehaus.aspectwerkz.annotation.AfterThrowing;
-import org.codehaus.aspectwerkz.annotation.Aspect;
-import org.codehaus.aspectwerkz.annotation.Before;
-import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
-import org.codehaus.aspectwerkz.joinpoint.MethodSignature;
import java.io.PrintStream;
import java.lang.reflect.Method;
@@ -38,8 +30,18 @@
import java.util.List;
import java.util.Map;
import java.util.Stack;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.After;
+import org.aspectj.lang.annotation.AfterThrowing;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+import org.aspectj.lang.reflect.MethodSignature;
/**
+ * TODO poussin 20110824 check documentation: this documentation is for aspectwerkz, there are little
+ * change for aspectj. see example file aop.xml
+ *
* Permet de tracer les appels aux methodes.
* <p/>
* Pour l'utiliser il faut définir un fichier XML qui intercepte les methodes
@@ -96,16 +98,20 @@
* <p/>
* Voir la classe de test {@code org.nuiton.profiling.NuitonTraceTest}.
*
+ * @see http://aspectwerkz.codehaus.org/definition_issues.html
+ *
* @author bpoussin <poussin(a)codelutin.com>
* @author tchemit <chemit(a)codelutin.com>
*/
-@Aspect("perJVM")
-public class NuitonTrace {
+@Aspect
+public abstract class NuitonTrace {
static private final List<NuitonTrace> instances = new ArrayList<NuitonTrace>();
+ // poussin 20110824: ne pas mettre de logger, car sinon, ca pose des problemes
+ // avec l'AOP. NoClassDefFound :(
/** to use log facility, just put in your code: log.info("..."); */
- static private Log log = LogFactory.getLog(NuitonTrace.class);
+// static private Log log = LogFactory.getLog(NuitonTrace.class);
/** nombre d'appel */
final static public int STAT_CALL = 0;
@@ -154,7 +160,11 @@
return result;
}
- @Before("executeMethod")
+ // abstract pointcut: no expression is defined
+ @Pointcut
+ abstract void executeMethod();
+
+ @Before("executeMethod()")
public void traceBeforeExecute(JoinPoint jp) {
// ajout dans le stack
long current = System.nanoTime();
@@ -164,20 +174,20 @@
}
- @AfterThrowing("executeMethod")
+ @AfterThrowing("executeMethod()")
public void traceAfterThrowingExecute(JoinPoint jp) {
// si une exeption est leve, il faut faire la meme chose
traceAfterExecute(jp);
}
- @After("executeMethod")
+ @After("executeMethod()")
public void traceAfterExecute(JoinPoint jp) {
Method method = ((MethodSignature) jp.getSignature()).getMethod();
long current = System.nanoTime();
if (callStack.isEmpty()) {
- log.warn("Empty stack in afterExecute for method " + method.getName());
+// log.warn("Empty stack in afterExecute for method " + method.getName());
} else {
long[] stackItem = callStack.pop();
long timeSpent = current - stackItem[STACK_TIME_START];
Modified: trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/NuitonTraceTest.java
===================================================================
--- trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/NuitonTraceTest.java 2011-08-24 13:13:11 UTC (rev 2182)
+++ trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/NuitonTraceTest.java 2011-08-24 15:30:32 UTC (rev 2183)
@@ -38,11 +38,9 @@
*/
public class NuitonTraceTest {
- /** Logger. */
- private static final Log log = LogFactory.getLog(NuitonTraceTest.class);
-
@Test
public void testAOP() {
+ Log log = LogFactory.getLog(NuitonTraceTest.class);
if (log.isDebugEnabled()) {
log.debug("DEBUG");
@@ -72,4 +70,13 @@
}
}
+ // pour pouvoir tester la meme chose avec un simple java -javaagent:...
+ // par exemple:
+ // java -javaagent:target/lib/aspectjweaver-1.6.11.jar -classpath target/classes:target/lib/aspectjrt-1.6.11.jar:target/lib/aspectjweaver-1.6.11.jar:target/lib/commons-lang-2.6.jar:target/lib/commons-logging-1.1.1.jar:target/lib/junit-4.8.2.jar:target/lib/log4j-1.2.16.jar:target/test-classes org.nuiton.profiling.NuitonTraceTest
+
+ public static void main(String... args) {
+ NuitonTraceTest t = new NuitonTraceTest();
+ t.testAOP();
+ }
+
}
Modified: trunk/nuiton-profiling/src/test/resources/META-INF/aop.xml
===================================================================
--- trunk/nuiton-profiling/src/test/resources/META-INF/aop.xml 2011-08-24 13:13:11 UTC (rev 2182)
+++ trunk/nuiton-profiling/src/test/resources/META-INF/aop.xml 2011-08-24 15:30:32 UTC (rev 2183)
@@ -1,45 +1,20 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- #%L
- Nuiton Utils :: Nuiton Profiling
-
- $Id$
- $HeadURL$
- %%
- Copyright (C) 2004 - 2011 CodeLutin
- %%
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Lesser Public License for more details.
-
- You should have received a copy of the GNU General Lesser Public
- License along with this program. If not, see
- <http://www.gnu.org/licenses/lgpl-3.0.html>.
- #L%
- -->
+<!DOCTYPE aspectj PUBLIC
+ "-//AspectJ//DTD//EN"
+ "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
-<!DOCTYPE aspectwerkz PUBLIC
- "-//AspectWerkz//DTD//EN"
- "http://aspectwerkz.codehaus.org/dtd/aspectwerkz2.dtd">
-<aspectwerkz>
- <system id="webapp">
- <aspect class="org.nuiton.profiling.NuitonTrace">
- <pointcut name="executeMethod">
- <![CDATA[ execution(public * org.apache..*.*(..)) && !within(org.apache.log4j..*) && !within(org.apache.commons.lang..*)]]>
- <!--<![CDATA[ execution(public * *..*.*(..))]]>-->
- </pointcut>
- <!--<pointcut name="executeMethod" expression="execution(public * org.apache..*(..))"/>-->
- <!--<pointcut name="executeMethod"-->
- <!--expression="execution(public * org.apache..*(..))"/>-->
- <!--expression="execution(public * org.apache.commons..*(..)) && !within(org.apache.log4j..*) && !within(org.nuiton.profiling..*)"/>-->
- </aspect>
- <!--</package>-->
-
- </system>
-</aspectwerkz>
\ No newline at end of file
+<aspectj>
+ <aspects>
+ <!-- creation d'un aspect pour definir les methodes a intercepter -->
+ <concrete-aspect name="org.nuiton.profiling.NuitonTraceTestAspect"
+ extends="org.nuiton.profiling.NuitonTrace">
+ <pointcut name="executeMethod" expression="execution(public * org.apache..*.*(..)) AND !within(org.apache.log4j..*) AND !within(org.apache.maven..*) AND !within(org.apache.commons.lang..*)"/>
+ </concrete-aspect>
+ </aspects>
+ <!-- quelques options pour voir ce qu'il se passe (non obligatoire) -->
+ <weaver options="-verbose -showWeaveInfo ">
+ <!-- quelque restriction sur les classes a prendre en compte, pour avec un exemple -->
+ <include within="org.apache.commons.logging.*" />
+ <!-- la config pour que aspectj ecrive sur le disque les fichiers java qu'il genere -->
+ <!-- <dump within="*"/> -->
+ </weaver>
+</aspectj>
1
0
r2182 - in trunk/nuiton-validator/src: main/java/org/nuiton/validator/xwork2/field test/java/org/nuiton/validator test/java/org/nuiton/validator/model test/java/org/nuiton/validator/xwork2/field test/resources test/resources/org/nuiton/validator/model
by tchemit@users.nuiton.org 24 Aug '11
by tchemit@users.nuiton.org 24 Aug '11
24 Aug '11
Author: tchemit
Date: 2011-08-24 15:13:11 +0200 (Wed, 24 Aug 2011)
New Revision: 2182
Url: http://nuiton.org/repositories/revision/nuiton-utils/2182
Log:
reformat code
add svn properties
Evolution #1707: Introduce a NuitonFieldValidatorSupport
Normalize validators and rename some...
Added:
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldExpressionValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldValidatorSupport.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidator.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidatorTest.java
Removed:
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CityNameFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/LastNameFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIntraFieldValidator.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CityNameFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/LastNameFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/SiretFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VatIntraFieldValidatorTest.java
Modified:
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CollectionFieldExpressionValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CollectionUniqueKeyValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/EmailFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/ExistingDirectoryFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/ExistingFileFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FieldExpressionWithParamsValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NotExistingDirectoryFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NotExistingFileFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/RequiredFileFieldValidator.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/AbstractValidatorDetectorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Company.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Contact.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CollectionUniqueKeyValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/EmailFieldValidatorTest.java
trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Company-error-validation.xml
trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Contact-error-validation.xml
trunk/nuiton-validator/src/test/resources/validators.xml
Deleted: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CityNameFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CityNameFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CityNameFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -1,70 +0,0 @@
-/*
- * #%L
- * Nuiton Utils :: Nuiton Validator
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.validator.xwork2.field;
-
-import com.opensymphony.xwork2.validator.ValidationException;
-import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Validator for French cities names :
- * - No number accepted
- * - Accept spaces, - and '
- */
-public class CityNameFieldValidator extends FieldValidatorSupport {
-
- protected static String CITY_NAME_REGEXP = "[^\\d]+";
- protected static Pattern p = Pattern.compile(CITY_NAME_REGEXP);
-
- //TODO JC18082011 - Deal with cedex
-
- @Override
- public void validate(Object object) throws ValidationException {
-
- String fieldName = getFieldName();
- Object value = getFieldValue(fieldName, object);
-
- if (value == null) {
- // no value defined
- return;
- }
- if (value instanceof String) {
- Matcher m = p.matcher((String) value);
- if (!m.matches()) {
- addFieldError(fieldName, object);
- return;
- }
- } else {
- addFieldError(fieldName, object);
- return;
- }
- }
-
- @Override
- public String getValidatorType() {
- return "cityName";
- }
-}
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CollectionFieldExpressionValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CollectionFieldExpressionValidator.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CollectionFieldExpressionValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -40,7 +40,7 @@
*
* @author tchemit <chemit(a)codelutin.com>
*/
-public class CollectionFieldExpressionValidator extends FieldExpressionValidator {
+public class CollectionFieldExpressionValidator extends NuitonFieldExpressionValidator {
public enum Mode {
@@ -160,7 +160,7 @@
}
@Override
- public void validate(Object object) throws ValidationException {
+ public void validateWhenNotSkip(Object object) throws ValidationException {
if (mode == null) {
throw new ValidationException("no mode defined!");
}
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CollectionUniqueKeyValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CollectionUniqueKeyValidator.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CollectionUniqueKeyValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -42,7 +42,7 @@
*
* @author tchemit <chemit(a)codelutin.com>
*/
-public class CollectionUniqueKeyValidator extends FieldExpressionValidator {
+public class CollectionUniqueKeyValidator extends NuitonFieldValidatorSupport {
/**
* pour indiquer la propriété qui contient la liste à valider.
@@ -145,7 +145,7 @@
}
@Override
- public void validate(Object object) throws ValidationException {
+ public void validateWhenNotSkip(Object object) throws ValidationException {
if (keys == null || keys.length == 0) {
throw new ValidationException("no unique keys defined");
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/EmailFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/EmailFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/EmailFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -25,17 +25,19 @@
package org.nuiton.validator.xwork2.field;
import com.opensymphony.xwork2.validator.ValidationException;
-import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
import org.nuiton.util.StringUtil;
/**
* Validator for email addresses :
* - Deal with + in addresses
+ *
+ * @author jcouteau <couteau(a)codelutin.com>
+ * @since 2.3
*/
-public class EmailFieldValidator extends FieldValidatorSupport {
+public class EmailFieldValidator extends NuitonFieldValidatorSupport {
@Override
- public void validate(Object object) throws ValidationException {
+ public void validateWhenNotSkip(Object object) throws ValidationException {
String fieldName = getFieldName();
Object value = getFieldValue(fieldName, object);
@@ -45,18 +47,16 @@
return;
}
if (value instanceof String) {
- if (!StringUtil.isEmail((String)value)) {
+ if (!StringUtil.isEmail((String) value)) {
addFieldError(fieldName, object);
- return;
}
} else {
addFieldError(fieldName, object);
- return;
}
}
@Override
public String getValidatorType() {
- return "email";
+ return "emailNuiton";
}
}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/EmailFieldValidator.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/ExistingDirectoryFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/ExistingDirectoryFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/ExistingDirectoryFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -25,7 +25,6 @@
package org.nuiton.validator.xwork2.field;
import com.opensymphony.xwork2.validator.ValidationException;
-import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
import java.io.File;
@@ -50,7 +49,7 @@
* <param name="fieldName">tmp</param>
* <message>tmp is not an existing directory</message>
* </validator>
- * <p/>
+ *
* <!-- Field-Validator Syntax -->
* <field name="tmp">
* <field-validator type="existingDirectory">
@@ -63,10 +62,10 @@
*
* @author tchemit <chemit(a)codelutin.com>
*/
-public class ExistingDirectoryFieldValidator extends FieldValidatorSupport {
+public class ExistingDirectoryFieldValidator extends NuitonFieldValidatorSupport {
@Override
- public void validate(Object object) throws ValidationException {
+ public void validateWhenNotSkip(Object object) throws ValidationException {
String fieldName = getFieldName();
Object value = getFieldValue(fieldName, object);
if (value == null) {
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/ExistingFileFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/ExistingFileFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/ExistingFileFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -25,7 +25,6 @@
package org.nuiton.validator.xwork2.field;
import com.opensymphony.xwork2.validator.ValidationException;
-import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
import java.io.File;
@@ -50,7 +49,7 @@
* <param name="fieldName">tmp</param>
* <message>tmp is not an existing file</message>
* </validator>
- * <p/>
+ *
* <!-- Field-Validator Syntax -->
* <field name="tmp">
* <field-validator type="fileExisting">
@@ -63,10 +62,10 @@
*
* @author tchemit <chemit(a)codelutin.com>
*/
-public class ExistingFileFieldValidator extends FieldValidatorSupport {
+public class ExistingFileFieldValidator extends NuitonFieldValidatorSupport {
@Override
- public void validate(Object object) throws ValidationException {
+ public void validateWhenNotSkip(Object object) throws ValidationException {
String fieldName = getFieldName();
Object value = getFieldValue(fieldName, object);
if (value == null) {
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FieldExpressionWithParamsValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FieldExpressionWithParamsValidator.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FieldExpressionWithParamsValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -42,7 +42,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 1.3
*/
-public class FieldExpressionWithParamsValidator extends FieldExpressionValidator {
+public class FieldExpressionWithParamsValidator extends NuitonFieldExpressionValidator {
protected static final Pattern EXTRA_BOOLEAN_PARAM_ENTRY_PATTERN = Pattern.compile("(\\w+)\\:(false|true)");
@@ -167,7 +167,12 @@
@Override
public void validate(Object object) throws ValidationException {
+ super.validate(object);
+ }
+ @Override
+ public void validateWhenNotSkip(Object object) throws ValidationException {
+
booleans = initParams(Boolean.class, booleanParams, EXTRA_BOOLEAN_PARAM_ENTRY_PATTERN);
shorts = initParams(Short.class, shortParams, EXTRA_SHORT_PARAM_ENTRY_PATTERN);
ints = initParams(Integer.class, intParams, EXTRA_INT_PARAM_ENTRY_PATTERN);
@@ -182,7 +187,7 @@
}
try {
- super.validate(object);
+ super.validateWhenNotSkip(object);
} finally {
if (pop) {
stack.pop();
Copied: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidator.java (from rev 2180, trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CityNameFieldValidator.java)
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidator.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -0,0 +1,72 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2.field;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Validator for French cities names :
+ * - No number accepted
+ * - Accept spaces, - and '
+ *
+ * @author jcouteau <couteau(a)codelutin.com>
+ * @since 2.3
+ */
+public class FrenchCityNameFieldValidator extends NuitonFieldValidatorSupport {
+
+ protected static String CITY_NAME_REGEXP = "[^\\d]+";
+
+ protected static Pattern p = Pattern.compile(CITY_NAME_REGEXP);
+
+ //TODO JC18082011 - Deal with cedex
+
+ @Override
+ public void validateWhenNotSkip(Object object) throws ValidationException {
+
+ String fieldName = getFieldName();
+ Object value = getFieldValue(fieldName, object);
+
+ if (value == null) {
+ // no value defined
+ return;
+ }
+ if (value instanceof String) {
+ Matcher m = p.matcher((String) value);
+ if (!m.matches()) {
+ addFieldError(fieldName, object);
+ }
+ } else {
+ addFieldError(fieldName, object);
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "frenchCityName";
+ }
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidator.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidator.java (from rev 2180, trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/LastNameFieldValidator.java)
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidator.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -0,0 +1,70 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2.field;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Validator for French last names :
+ * - No number accepted
+ * - Accept spaces, - and '
+ *
+ * @author jcouteau <couteau(a)codelutin.com>
+ * @since 2.3
+ */
+public class FrenchLastNameFieldValidator extends NuitonFieldValidatorSupport {
+
+ protected static String LAST_NAME_REGEXP = "[^\\d]+";
+
+ protected static Pattern p = Pattern.compile(LAST_NAME_REGEXP);
+
+ @Override
+ public void validateWhenNotSkip(Object object) throws ValidationException {
+
+ String fieldName = getFieldName();
+ Object value = getFieldValue(fieldName, object);
+
+ if (value == null) {
+ // no value defined
+ return;
+ }
+ if (value instanceof String) {
+ Matcher m = p.matcher((String) value);
+ if (!m.matches()) {
+ addFieldError(fieldName, object);
+ }
+ } else {
+ addFieldError(fieldName, object);
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "frenchLastName";
+ }
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidator.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidator.java (from rev 2180, trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidator.java)
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidator.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -0,0 +1,73 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2.field;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Validator used to validate French phone numbers like :
+ * - 0000000000
+ * - 00.00.00.00.00
+ * - 00-00-00-00-00
+ * - 00 00 00 00 00
+ *
+ * @author jcouteau <couteau(a)codelutin.com>
+ * @since 2.3
+ */
+public class FrenchPhoneNumberFieldValidator extends NuitonFieldValidatorSupport {
+
+ protected static String PHONE_NUMBER_REGEXP =
+ "[0-9]{10}|(([0-9]{2}[-\\.\\s]){4})[0-9]{2}";
+
+ protected static Pattern p = Pattern.compile(PHONE_NUMBER_REGEXP);
+
+ @Override
+ public void validateWhenNotSkip(Object object) throws ValidationException {
+
+ String fieldName = getFieldName();
+ Object value = getFieldValue(fieldName, object);
+
+ if (value == null) {
+ // no value defined
+ return;
+ }
+ if (value instanceof String) {
+ Matcher m = p.matcher((String) value);
+ if (!m.matches()) {
+ addFieldError(fieldName, object);
+ }
+ } else {
+ addFieldError(fieldName, object);
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "frenchPhoneNumber";
+ }
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidator.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidator.java (from rev 2180, trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidator.java)
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidator.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -0,0 +1,73 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2.field;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Validate post codes for French cities
+ * <p/>
+ * - Take into account 2A and 2B
+ * - Take into account DOMs and TOMs
+ * - Postcodes starting with 99 are not valid
+ *
+ * @author jcouteau <couteau(a)codelutin.com>
+ * @since 2.3
+ */
+public class FrenchPostCodeFieldValidator extends NuitonFieldValidatorSupport {
+
+ protected static String POST_CODE_REGEXP =
+ "^((0[1-9])|([1-8][0-9])|(9[0-8])|(2A)|(2B))[0-9]{3}$";
+
+ protected static Pattern p = Pattern.compile(POST_CODE_REGEXP);
+
+ @Override
+ public void validateWhenNotSkip(Object object) throws ValidationException {
+
+ String fieldName = getFieldName();
+ Object value = getFieldValue(fieldName, object);
+
+ if (value == null) {
+ // no value defined
+ return;
+ }
+ if (value instanceof String) {
+ Matcher m = p.matcher((String) value);
+ if (!m.matches()) {
+ addFieldError(fieldName, object);
+ }
+ } else {
+ addFieldError(fieldName, object);
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "frenchPostCode";
+ }
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidator.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidator.java (from rev 2180, trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java)
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidator.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -0,0 +1,168 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2.field;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+
+import java.lang.reflect.Array;
+import java.util.Collection;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Validator for French SIRET numbers
+ * <p/>
+ * Siret can be in:
+ * <li>String format: "44211670300038"
+ * <li>long, int: 44211670300038
+ * <li>Array or Collection of something: [4,4,2,1,1,6,7,0,,3,0,0,0,3,8] or ["442","116","703", "0003", "8"]
+ *
+ * @author jcouteau <couteau(a)codelutin.com>
+ * @since 2.3
+ * Validation do the Luhn checksum too
+ */
+public class FrenchSiretFieldValidator extends NuitonFieldValidatorSupport {
+
+ protected static final String SIRET_REGEXP = "[0-9]{14}";
+
+ protected static final Pattern p = Pattern.compile(SIRET_REGEXP);
+
+ @Override
+ public void validateWhenNotSkip(Object object) throws ValidationException {
+
+ String fieldName = getFieldName();
+ Object value = getFieldValue(fieldName, object);
+
+ if (value == null) {
+ // no value defined
+ return;
+ }
+ String siret;
+
+ if (value.getClass().isArray()) {
+ // le siret est stocker dans un tableau, par exemple un byte[]
+ siret = "";
+ for (int i = 0; i < Array.getLength(value); i++) {
+ siret += String.valueOf(Array.get(value, i));
+ }
+ } else if (value instanceof Collection<?>) {
+ // le siret est stocker dans une collection,
+ // ca doit pas arriver souvent :D, mais autant le gerer
+ siret = "";
+ for (Object o : (Collection<?>) value) {
+ siret += String.valueOf(o);
+ }
+ } else {
+ // sinon dans tous les autres cas (String, int, long, BigInteger ...)
+ // on prend le toString
+ siret = String.valueOf(value);
+ }
+
+ Matcher m = p.matcher(siret);
+ if (!m.matches() || !luhnChecksum(siret)) {
+ addFieldError(fieldName, object);
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "frenchSiret";
+ }
+
+ /**
+ * Verifie la validite d'un numero en suivant l'algorithme Luhn tel que d'ecrit
+ * dans <a href="http://fr.wikipedia.org/wiki/Luhn">wikipedia</a>
+ * <p/>
+ * Algo:
+ * en fonction de la position du numero dans la sequence,
+ * on multiplie pas 1 (pour les impaires) ou par 2 pour les paires
+ * (1 etant le numero le plus a droite)
+ * On fait la somme de tous les chiffres qui resulte de ces multiplications
+ * (si un resultat etait 14, on ne fait pas +14 mais +1+4)
+ * <p/>
+ * Si le résultat de cette somme donne un reste de 0 une fois divisé par 10
+ * le numero est valide.
+ *
+ * @param siret une chaine composer que de chiffre
+ * @return vrai si on a reussi a valider le numero
+ */
+ public static boolean luhnChecksum(String siret) {
+
+ char[] tab = siret.toCharArray();
+ int sum = 0;
+ for (int i = tab.length - 1; i >= 0; i--) {
+ // recuperation de la valeur
+ int n = getDigit(tab[i]);
+
+ // 1ere phase il faut faire la multiplication par 1 ou 2
+
+ // il faut faire x1 pour les paires et x2 sur les impaires.
+ // en prenant en compte que le numero siret le plus a droite est le
+ // 1 et le plus a gauche le 14.
+ // mais comme en informatique on commence a 0 :D
+ // il faut faire +1 sur l'indice puis un simple module 2 + 1
+ // nous convient
+ n *= (i + 1) % 2 + 1;
+
+ // 2eme phase il faut faire l'addition
+
+ // si une fois multiplie il est superieur a 9, il faut additionner
+ // toutes ces constituante, mais comme il ne peut pas etre superieur
+ // a 18, cela revient a retrancher 9
+ if (n > 9) {
+ n -= 9;
+ }
+
+ // on peut directement faire la somme
+ sum += n;
+ }
+
+ // 3eme phase on verifie que c'est bien un multiple de 10
+ boolean result = sum % 10 == 0;
+
+ return result;
+ }
+
+
+ /**
+ * Converti un char en un entier '0' => 0 et '9' => 9, et 'A' => 10 a 'Z' => 36,
+ * les autres caractere sont aussi convertis pour que 'a' = 10 et 'z' = 36.
+ * Pour les autres c'est un indedermine
+ *
+ * @param c le caractere qui doit etre converti
+ * @return le chiffre
+ */
+ public static int getDigit(char c) {
+ int result = 0;
+ if (c >= '0' && c <= '9') {
+ result = c - '0';
+ } else if (c >= 'A' && c <= 'Z') {
+ result = c - 'A' + 10;
+ } else {
+ result = c - 'a' + 10;
+ }
+ return result;
+ }
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidator.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/LastNameFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/LastNameFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/LastNameFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -1,68 +0,0 @@
-/*
- * #%L
- * Nuiton Utils :: Nuiton Validator
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.validator.xwork2.field;
-
-import com.opensymphony.xwork2.validator.ValidationException;
-import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Validator for French last names :
- * - No number accepted
- * - Accept spaces, - and '
- */
-public class LastNameFieldValidator extends FieldValidatorSupport {
-
- protected static String LAST_NAME_REGEXP = "[^\\d]+";
- protected static Pattern p = Pattern.compile(LAST_NAME_REGEXP);
-
- @Override
- public void validate(Object object) throws ValidationException {
-
- String fieldName = getFieldName();
- Object value = getFieldValue(fieldName, object);
-
- if (value == null) {
- // no value defined
- return;
- }
- if (value instanceof String) {
- Matcher m = p.matcher((String) value);
- if (!m.matches()) {
- addFieldError(fieldName, object);
- return;
- }
- } else {
- addFieldError(fieldName, object);
- return;
- }
- }
-
- @Override
- public String getValidatorType() {
- return "lastName";
- }
-}
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NotExistingDirectoryFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NotExistingDirectoryFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NotExistingDirectoryFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -25,7 +25,6 @@
package org.nuiton.validator.xwork2.field;
import com.opensymphony.xwork2.validator.ValidationException;
-import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
import java.io.File;
@@ -50,7 +49,7 @@
* <param name="fieldName">tmp</param>
* <message>tmp is an existing directory</message>
* </validator>
- * <p/>
+ *
* <!-- Field-Validator Syntax -->
* <field name="tmp">
* <field-validator type="notExistingDirectory">
@@ -63,10 +62,10 @@
*
* @author tchemit <chemit(a)codelutin.com>
*/
-public class NotExistingDirectoryFieldValidator extends FieldValidatorSupport {
+public class NotExistingDirectoryFieldValidator extends NuitonFieldValidatorSupport {
@Override
- public void validate(Object object) throws ValidationException {
+ public void validateWhenNotSkip(Object object) throws ValidationException {
String fieldName = getFieldName();
Object value = getFieldValue(fieldName, object);
if (value == null) {
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NotExistingFileFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NotExistingFileFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NotExistingFileFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -25,7 +25,6 @@
package org.nuiton.validator.xwork2.field;
import com.opensymphony.xwork2.validator.ValidationException;
-import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
import java.io.File;
@@ -50,7 +49,7 @@
* <param name="fieldName">tmp</param>
* <message>tmp is an existing file</message>
* </validator>
- * <p/>
+ *
* <!-- Field-Validator Syntax -->
* <field name="tmp">
* <field-validator type="notExistingFile">
@@ -63,10 +62,10 @@
*
* @author tchemit <chemit(a)codelutin.com>
*/
-public class NotExistingFileFieldValidator extends FieldValidatorSupport {
+public class NotExistingFileFieldValidator extends NuitonFieldValidatorSupport {
@Override
- public void validate(Object object) throws ValidationException {
+ public void validateWhenNotSkip(Object object) throws ValidationException {
String fieldName = getFieldName();
Object value = getFieldValue(fieldName, object);
if (value == null) {
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldExpressionValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldExpressionValidator.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldExpressionValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -0,0 +1,137 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2.field;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+import com.opensymphony.xwork2.validator.validators.FieldExpressionValidator;
+
+/**
+ * Nuiton default field validator.
+ * <p/>
+ * This validator offers a {@link #skip} property that can be used to skip or
+ * not the validator, this property is a OGNL expression.
+ * <p/>
+ * To use this new field validator support, just now implements the method
+ * {@link #validateWhenNotSkip(Object)}. This method will be invoked only if the skip
+ * parameter is evaluated to {@code false}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.3
+ */
+public abstract class NuitonFieldExpressionValidator extends FieldExpressionValidator {
+
+ /**
+ * extra parameter at the very beginning of the
+ * {@link #validate(Object)} method to be able to skip (or not) the
+ * validator execution.
+ * <p/>
+ * by default the value is {@code false} : it seems fair to want to
+ * validate if the validator is used :D...
+ */
+ protected String skip = "false";
+
+ /**
+ * Sets the value of the {@link #skip} parameter.
+ *
+ * @param skip the new value of the {@link #skip} parameter
+ */
+ public void setSkip(String skip) {
+ this.skip = skip;
+ }
+
+ /**
+ * Method to be invoked when skip parameter was not evaludated to {@code true}.
+ *
+ * @param object the object to be validated.
+ * @throws ValidationException is thrown if there is validation error(s).
+ */
+
+ protected void validateWhenNotSkip(Object object) throws ValidationException {
+ super.validate(object);
+ }
+
+ @Override
+ public void validate(Object object) throws ValidationException {
+
+ // evaluate the skip parameter
+ boolean mustSkip = evaluateSkipParameter(object);
+
+ if (mustSkip) {
+
+ // skip is set to true, so skip the validation
+ if (log.isDebugEnabled()) {
+ log.debug("Skip the validation from " + this +
+ ", due to skip parameter evaluated to true");
+ }
+ return;
+ }
+
+ // must validate
+ validateWhenNotSkip(object);
+ }
+
+ /**
+ * Evaluate the skip parameter value against the object to validate.
+ * <p/>
+ * This parameter can be an OGNL expression.
+ *
+ * @param object the object to validate
+ * @return the evaluation of the skip parameter.
+ * @throws ValidationException if could not evaluate the parameter
+ */
+ protected boolean evaluateSkipParameter(Object object) throws ValidationException {
+
+ skip = skip.trim();
+
+ if ("false".equals(skip)) {
+
+ return false;
+ }
+
+ if ("true".equals(skip)) {
+
+ return true;
+ }
+
+ try {
+ Boolean answer = Boolean.FALSE;
+ Object obj;
+ obj = getFieldValue(skip, object);
+ if (obj != null && obj instanceof Boolean) {
+ answer = (Boolean) obj;
+ }
+ return answer;
+ } catch (ValidationException e) {
+ throw e;
+ } catch (Exception e) {
+ // let this pass, but it will be logged right below
+ throw new ValidationException(
+ "Can not evaluate boolean expression [" + skip +
+ "] for reason " + e.getMessage());
+ }
+
+ }
+
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldExpressionValidator.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldValidatorSupport.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldValidatorSupport.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldValidatorSupport.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -0,0 +1,140 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2.field;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
+
+/**
+ * Nuiton default field validator.
+ * <p/>
+ * This validator offers a {@link #skip} property that can be used to skip or
+ * not the validator, this property is a OGNL expression.
+ * <p/>
+ * To use this new field validator support, just now implements the method
+ * {@link #validateWhenNotSkip(Object)}. This method will be invoked only if the skip
+ * parameter is evaluated to {@code false}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.3
+ */
+public abstract class NuitonFieldValidatorSupport extends FieldValidatorSupport {
+
+ /**
+ * extra parameter at the very beginning of the
+ * {@link #validate(Object)} method to be able to skip (or not) the
+ * validator execution.
+ * <p/>
+ * by default the value is {@code false} : it seems fair to want to
+ * validate if the validator is used :D...
+ */
+ protected String skip = "false";
+
+ /**
+ * Sets the value of the {@link #skip} parameter.
+ *
+ * @param skip the new value of the {@link #skip} parameter
+ */
+ public void setSkip(String skip) {
+ this.skip = skip;
+ }
+
+ /**
+ * Method to be invoked when skip parameter was not evaludated to {@code true}.
+ *
+ * @param object the object to be validated.
+ * @throws ValidationException is thrown if there is validation error(s).
+ */
+
+ protected abstract void validateWhenNotSkip(Object object) throws ValidationException;
+
+ @Override
+ public void validate(Object object) throws ValidationException {
+
+ // evaluate the skip parameter
+ boolean mustSkip = evaluateSkipParameter(object);
+
+ if (mustSkip) {
+
+ // skip is set to true, so skip the validation
+ if (log.isDebugEnabled()) {
+ log.debug("Skip the validation from " + this +
+ ", due to skip parameter evaluated to true");
+ }
+ return;
+ }
+
+ // must validate
+ validateWhenNotSkip(object);
+ }
+
+ /**
+ * Evaluate the skip parameter value against the object to validate.
+ * <p/>
+ * This parameter can be an OGNL expression.
+ *
+ * @param object the object to validate
+ * @return the evaluation of the skip parameter.
+ * @throws ValidationException if could not evaluate the parameter
+ */
+ protected boolean evaluateSkipParameter(Object object) throws ValidationException {
+
+ skip = skip.trim();
+
+ if ("false".equals(skip)) {
+
+ return false;
+ }
+
+ if ("true".equals(skip)) {
+
+ return true;
+ }
+
+ try {
+ Boolean answer = Boolean.FALSE;
+ Object obj;
+ obj = getFieldValue(skip, object);
+ if (obj != null && obj instanceof Boolean) {
+ answer = (Boolean) obj;
+ }
+ return answer;
+ } catch (ValidationException e) {
+ throw e;
+ } catch (Exception e) {
+ // let this pass, but it will be logged right below
+ throw new ValidationException(
+ "Can not evaluate boolean expression [" + skip +
+ "] for reason " + e.getMessage());
+ }
+
+ }
+
+ @Override
+ public Object getFieldValue(String name,
+ Object object) throws ValidationException {
+ return super.getFieldValue(name, object);
+ }
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldValidatorSupport.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -1,71 +0,0 @@
-/*
- * #%L
- * Nuiton Utils :: Nuiton Validator
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.validator.xwork2.field;
-
-import com.opensymphony.xwork2.validator.ValidationException;
-import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- *
- * Validator used to validate French phone numbers like :
- * - 0000000000
- * - 00.00.00.00.00
- * - 00-00-00-00-00
- * - 00 00 00 00 00
- */
-public class PhoneNumberFieldValidator extends FieldValidatorSupport {
-
- protected static String PHONE_NUMBER_REGEXP = "[0-9]{10}|(([0-9]{2}[-\\.\\s]){4})[0-9]{2}";
- protected static Pattern p = Pattern.compile(PHONE_NUMBER_REGEXP);
-
- @Override
- public void validate(Object object) throws ValidationException {
-
- String fieldName = getFieldName();
- Object value = getFieldValue(fieldName, object);
-
- if (value == null) {
- // no value defined
- return;
- }
- if (value instanceof String) {
- Matcher m = p.matcher((String)value);
- if (!m.matches()){
- addFieldError(fieldName, object);
- return;
- }
- } else {
- addFieldError(fieldName, object);
- return;
- }
- }
-
- @Override
- public String getValidatorType() {
- return "phoneNumber";
- }
-}
Deleted: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -1,70 +0,0 @@
-/*
- * #%L
- * Nuiton Utils :: Nuiton Validator
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.validator.xwork2.field;
-
-import com.opensymphony.xwork2.validator.ValidationException;
-import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Validate post codes for French cities
- *
- * - Take into account 2A and 2B
- * - Take into account DOMs and TOMs
- * - Postcodes starting with 99 are not valid
- */
-public class PostCodeFieldValidator extends FieldValidatorSupport {
-
- protected static String POST_CODE_REGEXP = "^((0[1-9])|([1-8][0-9])|(9[0-8])|(2A)|(2B))[0-9]{3}$";
- protected static Pattern p = Pattern.compile(POST_CODE_REGEXP);
-
- @Override
- public void validate(Object object) throws ValidationException {
-
- String fieldName = getFieldName();
- Object value = getFieldValue(fieldName, object);
-
- if (value == null) {
- // no value defined
- return;
- }
- if (value instanceof String) {
- Matcher m = p.matcher((String) value);
- if (!m.matches()) {
- addFieldError(fieldName, object);
- return;
- }
- } else {
- addFieldError(fieldName, object);
- return;
- }
- }
-
- @Override
- public String getValidatorType() {
- return "postCode";
- }
-}
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/RequiredFileFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/RequiredFileFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/RequiredFileFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -25,7 +25,6 @@
package org.nuiton.validator.xwork2.field;
import com.opensymphony.xwork2.validator.ValidationException;
-import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
import java.io.File;
@@ -50,7 +49,7 @@
* <param name="fieldName">tmp</param>
* <message>tmp is required</message>
* </validator>
- * <p/>
+ *
* <!-- Field-Validator Syntax -->
* <field name="tmp">
* <field-validator type="requiredFile">
@@ -63,10 +62,10 @@
*
* @author tchemit <chemit(a)codelutin.com>
*/
-public class RequiredFileFieldValidator extends FieldValidatorSupport {
+public class RequiredFileFieldValidator extends NuitonFieldValidatorSupport {
@Override
- public void validate(Object object) throws ValidationException {
+ public void validateWhenNotSkip(Object object) throws ValidationException {
String fieldName = getFieldName();
Object value = getFieldValue(fieldName, object);
if (value == null) {
Deleted: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -1,165 +0,0 @@
-/*
- * #%L
- * Nuiton Utils :: Nuiton Validator
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.validator.xwork2.field;
-
-import com.opensymphony.xwork2.validator.ValidationException;
-import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
-import java.lang.reflect.Array;
-import java.util.Collection;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Validator for French SIRET numbers
- *
- * Siret can be in:
- * <li>String format: "44211670300038"
- * <li>long, int: 44211670300038
- * <li>Array or Collection of something: [4,4,2,1,1,6,7,0,,3,0,0,0,3,8] or ["442","116","703", "0003", "8"]
- *
- * Validation do the Luhn checksum too
- */
-public class SiretFieldValidator extends FieldValidatorSupport {
-
- protected static final String SIRET_REGEXP = "[0-9]{14}";
- protected static final Pattern p = Pattern.compile(SIRET_REGEXP);
-
- @Override
- public void validate(Object object) throws ValidationException {
-
- String fieldName = getFieldName();
- Object value = getFieldValue(fieldName, object);
-
- if (value == null) {
- // no value defined
- return;
- }
- String siret;
-
- if (value.getClass().isArray()) {
- // le siret est stocker dans un tableau, par exemple un byte[]
- siret = "";
- for (int i=0; i<Array.getLength(value); i++) {
- siret += String.valueOf(Array.get(value, i));
- }
- } else if (value instanceof Collection) {
- // le siret est stocker dans une collection,
- // ca doit pas arriver souvent :D, mais autant le gerer
- siret = "";
- for (Object o : (Collection)value) {
- siret += String.valueOf(o);
- }
- } else {
- // sinon dans tous les autres cas (String, int, long, BigInteger ...)
- // on prend le toString
- siret = String.valueOf(value);
- }
-
- Matcher m = p.matcher(siret);
- if (!m.matches() || !luhnChecksum(siret)) {
- addFieldError(fieldName, object);
- }
- }
-
- @Override
- public String getValidatorType() {
- return "siret";
- }
-
- /**
- * Verifie la validite d'un numero en suivant l'algorithme Luhn tel que d'ecrit
- * dans <a href="http://fr.wikipedia.org/wiki/Luhn">wikipedia</a>
- *
- * Algo:
- * en fonction de la position du numero dans la sequence,
- * on multiplie pas 1 (pour les impaires) ou par 2 pour les paires
- * (1 etant le numero le plus a droite)
- * On fait la somme de tous les chiffres qui resulte de ces multiplications
- * (si un resultat etait 14, on ne fait pas +14 mais +1+4)
- *
- * Si le résultat de cette somme donne un reste de 0 une fois divisé par 10
- * le numero est valide.
- *
- * @param siret une chaine composer que de chiffre
- * @return vrai si on a reussi a valider le numero
- */
- static public boolean luhnChecksum(String siret) {
-
- char[] tab = siret.toCharArray();
- int sum = 0;
- for (int i=tab.length-1; i>=0; i--) {
- // recuperation de la valeur
- int n = getDigit(tab[i]);
-
- // 1ere phase il faut faire la multiplication par 1 ou 2
-
- // il faut faire x1 pour les paires et x2 sur les impaires.
- // en prenant en compte que le numero siret le plus a droite est le
- // 1 et le plus a gauche le 14.
- // mais comme en informatique on commence a 0 :D
- // il faut faire +1 sur l'indice puis un simple module 2 + 1
- // nous convient
- n *= (i+1)%2+1;
-
- // 2eme phase il faut faire l'addition
-
- // si une fois multiplie il est superieur a 9, il faut additionner
- // toutes ces constituante, mais comme il ne peut pas etre superieur
- // a 18, cela revient a retrancher 9
- if (n > 9) {
- n -= 9;
- }
-
- // on peut directement faire la somme
- sum += n;
- }
-
- // 3eme phase on verifie que c'est bien un multiple de 10
- boolean result = (sum % 10 == 0);
-
- return result;
- }
-
-
- /**
- * Converti un char en un entier '0' => 0 et '9' => 9, et 'A' => 10 a 'Z' => 36,
- * les autres caractere sont aussi convertis pour que 'a' = 10 et 'z' = 36.
- * Pour les autres c'est un indedermine
- *
- * @param c le caractere qui doit etre converti
- * @return le chiffre
- */
- static public int getDigit(char c) {
- int result = 0;
- if (c >= '0' && c <= '9') {
- result = c - '0';
- } else if (c >= 'A' && c <= 'Z'){
- result = c - 'A' + 10;
- } else {
- result = c - 'a' + 10;
- }
- return result;
- }
-}
Copied: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidator.java (from rev 2180, trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIntraFieldValidator.java)
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidator.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -0,0 +1,68 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2.field;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Validator for EU VAT number.
+ *
+ * @author jcouteau <couteau(a)codelutin.com>
+ * @since 2.3
+ */
+public class VATIdentificationNumberFieldValidator extends NuitonFieldValidatorSupport {
+
+ protected static String VAT_INTRA_REGEXP = "^(RO\\d{2,10}|GB\\d{5}|(ATU|DK|FI|HU|LU|MT|CZ|SI)\\d{8}|IE[A-Z\\d]{8}|(DE|BG|EE|EL|LT|BE0|PT|CZ)\\d{9}|CY\\d{8}[A-Z]|(ES|GB)[A-Z\\d]{9}|(BE0|PL|SK|CZ)\\d{10}|(FR|IT|LV)\\d{11}|(LT|SE)\\d{12}|(NL|GB)[A-Z\\d]{12})$";
+
+ protected static Pattern p = Pattern.compile(VAT_INTRA_REGEXP);
+
+ @Override
+ public void validateWhenNotSkip(Object object) throws ValidationException {
+
+ String fieldName = getFieldName();
+ Object value = getFieldValue(fieldName, object);
+
+ if (value == null) {
+ // no value defined
+ return;
+ }
+ if (value instanceof String) {
+ Matcher m = p.matcher((String) value);
+ if (!m.matches()) {
+ addFieldError(fieldName, object);
+ }
+ } else {
+ addFieldError(fieldName, object);
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "VATIdentificationNumber";
+ }
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidator.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIntraFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIntraFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIntraFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -1,66 +0,0 @@
-/*
- * #%L
- * Nuiton Utils :: Nuiton Validator
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.validator.xwork2.field;
-
-import com.opensymphony.xwork2.validator.ValidationException;
-import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Validator for EU VAT number
- */
-public class VATIntraFieldValidator extends FieldValidatorSupport {
-
- protected static String VAT_INTRA_REGEXP = "^(RO\\d{2,10}|GB\\d{5}|(ATU|DK|FI|HU|LU|MT|CZ|SI)\\d{8}|IE[A-Z\\d]{8}|(DE|BG|EE|EL|LT|BE0|PT|CZ)\\d{9}|CY\\d{8}[A-Z]|(ES|GB)[A-Z\\d]{9}|(BE0|PL|SK|CZ)\\d{10}|(FR|IT|LV)\\d{11}|(LT|SE)\\d{12}|(NL|GB)[A-Z\\d]{12})$";
- protected static Pattern p = Pattern.compile(VAT_INTRA_REGEXP);
-
- @Override
- public void validate(Object object) throws ValidationException {
-
- String fieldName = getFieldName();
- Object value = getFieldValue(fieldName, object);
-
- if (value == null) {
- // no value defined
- return;
- }
- if (value instanceof String) {
- Matcher m = p.matcher((String) value);
- if (!m.matches()) {
- addFieldError(fieldName, object);
- return;
- }
- } else {
- addFieldError(fieldName, object);
- return;
- }
- }
-
- @Override
- public String getValidatorType() {
- return "VATIntra";
- }
-}
Modified: trunk/nuiton-validator/src/test/java/org/nuiton/validator/AbstractValidatorDetectorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/AbstractValidatorDetectorTest.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/AbstractValidatorDetectorTest.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -98,15 +98,15 @@
}
public void assertValidatorEffectiveFields(NuitonValidator<?> validator,
- String... expectedFields) {
+ String... expectedFields) {
ValidatorTestHelper.assertValidatorEffectiveFields(validator,
expectedFields);
}
public void assertValidatorEffectiveFields(NuitonValidator<?> validator,
- NuitonValidatorScope scope,
- String... expectedFields) {
+ NuitonValidatorScope scope,
+ String... expectedFields) {
ValidatorTestHelper.assertValidatorEffectiveFields(validator,
scope,
expectedFields);
Modified: trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Company.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Company.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Company.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -25,7 +25,8 @@
package org.nuiton.validator.model;
/**
- *
+ * @author jcouteau <couteau(a)codelutin.com>
+ * @since 2.3
*/
public class Company {
Property changes on: trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Company.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Contact.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Contact.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Contact.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -25,7 +25,8 @@
package org.nuiton.validator.model;
/**
- *
+ * @author jcouteau <couteau(a)codelutin.com>
+ * @since 2.3
*/
public class Contact {
Property changes on: trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Contact.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CityNameFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CityNameFieldValidatorTest.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CityNameFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -1,96 +0,0 @@
-/*
- * #%L
- * Nuiton Utils :: Nuiton Validator
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.validator.xwork2.field;
-
-import org.junit.Test;
-import org.nuiton.validator.model.Contact;
-
-/**
- *
- */
-public class CityNameFieldValidatorTest extends AbstractFieldValidatorTest<Contact> {
-
- public CityNameFieldValidatorTest() {
- super(Contact.class);
- }
-
- @Test
- @Override
- public void testValidator() throws Exception {
-
- assertNull(bean.getCity());
-
- // Valid city
- bean.setCity("Nantes");
- assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
- false);
-
- // Valid city
- bean.setCity("Couëron");
- assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
- false);
-
- // Valid city
- bean.setCity("Saint Sébastien Sur Loire");
- assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
- false);
-
- // Valid city
- bean.setCity("St Sebastien sur Loire");
- assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
- false);
-
- // Valid city
- bean.setCity("St-Sebastien-sur-Loire");
- assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
- false);
-
- // Valid city
- bean.setCity("Y");
- assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
- false);
-
- // Valid city
- bean.setCity("Saint-Remy-en-Bouzemont-Saint-Genest-et-Isson");
- assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
- false);
-
- // Not Valid city name
- bean.setCity("2Ville");
- assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
- true);
-
- // Not Valid city name
- bean.setCity("Ville2Merde");
- assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
- true);
-
- // Not Valid city name
- bean.setCity("Ville 2 Merde");
- assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
- true);
-
- }
-}
Modified: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CollectionUniqueKeyValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CollectionUniqueKeyValidatorTest.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CollectionUniqueKeyValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -24,8 +24,8 @@
*/
package org.nuiton.validator.xwork2.field;
+import org.junit.Test;
import org.nuiton.validator.xwork2.field.ValidatorBean.ValidatorBeanEntry;
-import org.junit.Test;
import java.util.Arrays;
Modified: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/EmailFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/EmailFieldValidatorTest.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/EmailFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -28,7 +28,8 @@
import org.nuiton.validator.model.Contact;
/**
- *
+ * @author jcouteau <couteau(a)codelutin.com>
+ * @since 2.3
*/
public class EmailFieldValidatorTest extends AbstractFieldValidatorTest<Contact> {
Property changes on: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/EmailFieldValidatorTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidatorTest.java (from rev 2180, trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CityNameFieldValidatorTest.java)
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidatorTest.java (rev 0)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -0,0 +1,97 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2.field;
+
+import org.junit.Test;
+import org.nuiton.validator.model.Contact;
+
+/**
+ * @author jcouteau <couteau(a)codelutin.com>
+ * @since 2.3
+ */
+public class FrenchCityNameFieldValidatorTest extends AbstractFieldValidatorTest<Contact> {
+
+ public FrenchCityNameFieldValidatorTest() {
+ super(Contact.class);
+ }
+
+ @Test
+ @Override
+ public void testValidator() throws Exception {
+
+ assertNull(bean.getCity());
+
+ // Valid city
+ bean.setCity("Nantes");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ false);
+
+ // Valid city
+ bean.setCity("Couëron");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ false);
+
+ // Valid city
+ bean.setCity("Saint Sébastien Sur Loire");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ false);
+
+ // Valid city
+ bean.setCity("St Sebastien sur Loire");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ false);
+
+ // Valid city
+ bean.setCity("St-Sebastien-sur-Loire");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ false);
+
+ // Valid city
+ bean.setCity("Y");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ false);
+
+ // Valid city
+ bean.setCity("Saint-Remy-en-Bouzemont-Saint-Genest-et-Isson");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ false);
+
+ // Not Valid city name
+ bean.setCity("2Ville");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ true);
+
+ // Not Valid city name
+ bean.setCity("Ville2Merde");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ true);
+
+ // Not Valid city name
+ bean.setCity("Ville 2 Merde");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ true);
+
+ }
+}
Property changes on: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidatorTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidatorTest.java (from rev 2180, trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/LastNameFieldValidatorTest.java)
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidatorTest.java (rev 0)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -0,0 +1,79 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2.field;
+
+import org.junit.Test;
+import org.nuiton.validator.model.Contact;
+
+/**
+ * @author jcouteau <couteau(a)codelutin.com>
+ * Date: 18/08/11
+ * @since 2.3
+ */
+public class FrenchLastNameFieldValidatorTest extends AbstractFieldValidatorTest<Contact> {
+
+ public FrenchLastNameFieldValidatorTest() {
+ super(Contact.class);
+ }
+
+ @Test
+ @Override
+ public void testValidator() throws Exception {
+
+ assertNull(bean.getCity());
+
+ // Valid name
+ bean.setName("Couteau");
+ assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format",
+ false);
+
+ // Valid name
+ bean.setName("Le Ny");
+ assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format",
+ false);
+
+ // Valid name
+ bean.setName("Clémenceau");
+ assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format",
+ false);
+
+ // Valid name
+ bean.setName("Couteau--Viney");
+ assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format",
+ false);
+
+ // Not valid name
+ bean.setName("2Pac");
+ assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format",
+ true);
+
+ // Not valid name
+ bean.setName("Nom2Merde");
+ assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format",
+ true);
+
+
+ }
+}
Property changes on: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidatorTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidatorTest.java (from rev 2180, trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidatorTest.java)
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidatorTest.java (rev 0)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -0,0 +1,128 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2.field;
+
+import org.junit.Test;
+import org.nuiton.validator.model.Contact;
+
+/**
+ * @author jcouteau <couteau(a)codelutin.com>
+ * Date: 18/08/11
+ * @since 2.3
+ */
+public class FrenchPhoneNumberFieldValidatorTest extends AbstractFieldValidatorTest<Contact> {
+
+ public FrenchPhoneNumberFieldValidatorTest() {
+ super(Contact.class);
+ }
+
+ @Test
+ @Override
+ public void testValidator() throws Exception {
+
+ assertNull(bean.getPhone());
+
+ // Valid phone Number
+ bean.setPhone("0000000000");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ false);
+
+ // Valid phone Number
+ bean.setPhone("00 00 00 00 00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ false);
+
+ // Valid phone Number
+ bean.setPhone("00-00-00-00-00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ false);
+
+ // Valid phone Number
+ bean.setPhone("00.00.00.00.00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ false);
+
+ // Too long phone Number
+ bean.setPhone("00 00 00 00 00 00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Too long phone Number
+ bean.setPhone("00-00-00-00-00-00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Too long phone Number
+ bean.setPhone("000000000000");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Too long phone Number
+ bean.setPhone("00.00.00.00.00.00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Too short phone Number
+ bean.setPhone("00.00.00.00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Too short phone Number
+ bean.setPhone("00000000");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Too short phone Number
+ bean.setPhone("00-00-00-00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Too short phone Number
+ bean.setPhone("00 00 00 00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Invalid character in phone Number
+ bean.setPhone("00 00 ab 00 00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Invalid character in phone Number
+ bean.setPhone("0000ab0000");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Invalid character in phone Number
+ bean.setPhone("00.00.ab.00.00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Invalid character in phone Number
+ bean.setPhone("00-00-ab-00-00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ }
+}
Property changes on: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidatorTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidatorTest.java (from rev 2180, trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidatorTest.java)
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidatorTest.java (rev 0)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -0,0 +1,82 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2.field;
+
+import org.junit.Test;
+import org.nuiton.validator.model.Contact;
+
+/**
+ * @author jcouteau <couteau(a)codelutin.com>
+ * @since 2.3
+ */
+public class FrenchPostCodeFieldValidatorTest extends AbstractFieldValidatorTest<Contact> {
+
+ public FrenchPostCodeFieldValidatorTest() {
+ super(Contact.class);
+ }
+
+ @Test
+ @Override
+ public void testValidator() throws Exception {
+
+ assertNull(bean.getPostCode());
+
+ // Valid postCode
+ bean.setPostCode("44230");
+ assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
+ false);
+
+ // Valid postCode for Corsica
+ bean.setEmail("2A220");
+ assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
+ false);
+
+ // Valid postCode for DOM
+ bean.setEmail("97120");
+ assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
+ false);
+
+ // Valid postCode for TOM
+ bean.setPostCode("98120");
+ assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
+ false);
+
+ // Too long postCode
+ bean.setPostCode("442300");
+ assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
+ true);
+
+ // Too short postCode
+ bean.setPostCode("4423");
+ assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
+ true);
+
+ // postCode cannot start with 99
+ bean.setPostCode("99230");
+ assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
+ true);
+
+ }
+}
Property changes on: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidatorTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidatorTest.java (from rev 2180, trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/SiretFieldValidatorTest.java)
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidatorTest.java (rev 0)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -0,0 +1,89 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2.field;
+
+import org.junit.Test;
+import org.nuiton.validator.model.Company;
+
+/**
+ * @author jcouteau <couteau(a)codelutin.com>
+ * Date: 19/08/11
+ * @since 2.3
+ */
+public class FrenchSiretFieldValidatorTest extends AbstractFieldValidatorTest<Company> {
+
+ public FrenchSiretFieldValidatorTest() {
+ super(Company.class);
+ }
+
+ @Test
+ public void TestLuhnChecksum() throws Exception {
+ // verification sur de vrai numero siret (ca doit passer :)
+ assertTrue(FrenchSiretFieldValidator.luhnChecksum("44211670300038"));
+ assertTrue(FrenchSiretFieldValidator.luhnChecksum("73282932000074"));
+
+ // verification avec les memes, en ne modifiant que le dernier chiffre
+ // ca doit failer
+ assertFalse(FrenchSiretFieldValidator.luhnChecksum("44211670300030"));
+ assertFalse(FrenchSiretFieldValidator.luhnChecksum("73282932000070"));
+ }
+
+ @Test
+ @Override
+ public void testValidator() throws Exception {
+
+ assertNull(bean.getSiret());
+
+ // Valid siret
+ bean.setSiret("44211670300038");
+ assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
+ false);
+
+ // Valid siret
+ bean.setSiret("73282932000074");
+ assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
+ false);
+
+ // Not Valid siret, because bad checksum
+ bean.setSiret("73282932000071");
+ assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
+ true);
+
+ // Not valid siret
+ bean.setSiret("4421167030003");
+ assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
+ true);
+
+ // Not valid siret
+ bean.setSiret("442116703000389");
+ assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
+ true);
+
+ // Not valid siret
+ bean.setSiret("4421bf1670300038");
+ assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
+ true);
+ }
+}
Property changes on: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidatorTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/LastNameFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/LastNameFieldValidatorTest.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/LastNameFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -1,78 +0,0 @@
-/*
- * #%L
- * Nuiton Utils :: Nuiton Validator
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.validator.xwork2.field;
-
-import org.junit.Test;
-import org.nuiton.validator.model.Contact;
-
-/**
- * User: couteau
- * Date: 18/08/11
- */
-public class LastNameFieldValidatorTest extends AbstractFieldValidatorTest<Contact> {
-
- public LastNameFieldValidatorTest() {
- super(Contact.class);
- }
-
- @Test
- @Override
- public void testValidator() throws Exception {
-
- assertNull(bean.getCity());
-
- // Valid name
- bean.setName("Couteau");
- assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format",
- false);
-
- // Valid name
- bean.setName("Le Ny");
- assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format",
- false);
-
- // Valid name
- bean.setName("Clémenceau");
- assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format",
- false);
-
- // Valid name
- bean.setName("Couteau--Viney");
- assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format",
- false);
-
- // Not valid name
- bean.setName("2Pac");
- assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format",
- true);
-
- // Not valid name
- bean.setName("Nom2Merde");
- assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format",
- true);
-
-
- }
-}
Deleted: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidatorTest.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -1,127 +0,0 @@
-/*
- * #%L
- * Nuiton Utils :: Nuiton Validator
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.validator.xwork2.field;
-
-import org.junit.Test;
-import org.nuiton.validator.model.Contact;
-
-/**
- * User: couteau
- * Date: 18/08/11
- */
-public class PhoneNumberFieldValidatorTest extends AbstractFieldValidatorTest<Contact> {
-
- public PhoneNumberFieldValidatorTest() {
- super(Contact.class);
- }
-
- @Test
- @Override
- public void testValidator() throws Exception {
-
- assertNull(bean.getPhone());
-
- // Valid phone Number
- bean.setPhone("0000000000");
- assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
- false);
-
- // Valid phone Number
- bean.setPhone("00 00 00 00 00");
- assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
- false);
-
- // Valid phone Number
- bean.setPhone("00-00-00-00-00");
- assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
- false);
-
- // Valid phone Number
- bean.setPhone("00.00.00.00.00");
- assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
- false);
-
- // Too long phone Number
- bean.setPhone("00 00 00 00 00 00");
- assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
- true);
-
- // Too long phone Number
- bean.setPhone("00-00-00-00-00-00");
- assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
- true);
-
- // Too long phone Number
- bean.setPhone("000000000000");
- assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
- true);
-
- // Too long phone Number
- bean.setPhone("00.00.00.00.00.00");
- assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
- true);
-
- // Too short phone Number
- bean.setPhone("00.00.00.00");
- assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
- true);
-
- // Too short phone Number
- bean.setPhone("00000000");
- assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
- true);
-
- // Too short phone Number
- bean.setPhone("00-00-00-00");
- assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
- true);
-
- // Too short phone Number
- bean.setPhone("00 00 00 00");
- assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
- true);
-
- // Invalid character in phone Number
- bean.setPhone("00 00 ab 00 00");
- assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
- true);
-
- // Invalid character in phone Number
- bean.setPhone("0000ab0000");
- assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
- true);
-
- // Invalid character in phone Number
- bean.setPhone("00.00.ab.00.00");
- assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
- true);
-
- // Invalid character in phone Number
- bean.setPhone("00-00-ab-00-00");
- assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
- true);
-
- }
-}
Deleted: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidatorTest.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -1,81 +0,0 @@
-/*
- * #%L
- * Nuiton Utils :: Nuiton Validator
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.validator.xwork2.field;
-
-import org.junit.Test;
-import org.nuiton.validator.model.Contact;
-
-/**
- *
- */
-public class PostCodeFieldValidatorTest extends AbstractFieldValidatorTest<Contact> {
-
- public PostCodeFieldValidatorTest() {
- super(Contact.class);
- }
-
- @Test
- @Override
- public void testValidator() throws Exception {
-
- assertNull(bean.getPostCode());
-
- // Valid postCode
- bean.setPostCode("44230");
- assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
- false);
-
- // Valid postCode for Corsica
- bean.setEmail("2A220");
- assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
- false);
-
- // Valid postCode for DOM
- bean.setEmail("97120");
- assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
- false);
-
- // Valid postCode for TOM
- bean.setPostCode("98120");
- assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
- false);
-
- // Too long postCode
- bean.setPostCode("442300");
- assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
- true);
-
- // Too short postCode
- bean.setPostCode("4423");
- assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
- true);
-
- // postCode cannot start with 99
- bean.setPostCode("99230");
- assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
- true);
-
- }
-}
Deleted: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/SiretFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/SiretFieldValidatorTest.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/SiretFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -1,88 +0,0 @@
-/*
- * #%L
- * Nuiton Utils :: Nuiton Validator
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.validator.xwork2.field;
-
-import org.junit.Test;
-import org.nuiton.validator.model.Company;
-
-/**
- * User: couteau
- * Date: 19/08/11
- */
-public class SiretFieldValidatorTest extends AbstractFieldValidatorTest<Company> {
-
- public SiretFieldValidatorTest() {
- super(Company.class);
- }
-
- @Test
- public void TestLuhnChecksum () throws Exception {
- // verification sur de vrai numero siret (ca doit passer :)
- assertTrue(SiretFieldValidator.luhnChecksum("44211670300038"));
- assertTrue(SiretFieldValidator.luhnChecksum("73282932000074"));
-
- // verification avec les memes, en ne modifiant que le dernier chiffre
- // ca doit failer
- assertFalse(SiretFieldValidator.luhnChecksum("44211670300030"));
- assertFalse(SiretFieldValidator.luhnChecksum("73282932000070"));
- }
-
- @Test
- @Override
- public void testValidator() throws Exception {
-
- assertNull(bean.getSiret());
-
- // Valid siret
- bean.setSiret("44211670300038");
- assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
- false);
-
- // Valid siret
- bean.setSiret("73282932000074");
- assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
- false);
-
- // Not Valid siret, because bad checksum
- bean.setSiret("73282932000071");
- assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
- true);
-
- // Not valid siret
- bean.setSiret("4421167030003");
- assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
- true);
-
- // Not valid siret
- bean.setSiret("442116703000389");
- assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
- true);
-
- // Not valid siret
- bean.setSiret("4421bf1670300038");
- assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
- true);
- }
-}
Copied: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidatorTest.java (from rev 2180, trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VatIntraFieldValidatorTest.java)
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidatorTest.java (rev 0)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -0,0 +1,66 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2.field;
+
+import org.junit.Test;
+import org.nuiton.validator.model.Company;
+
+/**
+ * @author jcouteau <couteau(a)codelutin.com>
+ * @since 2.3
+ */
+public class VATIdentificationNumberFieldValidatorTest extends AbstractFieldValidatorTest<Company> {
+
+ public VATIdentificationNumberFieldValidatorTest() {
+ super(Company.class);
+ }
+
+ @Test
+ @Override
+ public void testValidator() throws Exception {
+
+ assertNull(bean.getVat());
+
+ // Valid vat
+ bean.setVat("FR57442116703");
+ assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format",
+ false);
+
+ // Not valid vat
+ bean.setVat("FR 57 44211670332");
+ assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format",
+ true);
+
+ // Not valid vat
+ bean.setVat("442116703000389");
+ assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format",
+ true);
+
+ // Not valid vat, spaces in it
+ bean.setVat("FR 57 442116703");
+ assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format",
+ true);
+ }
+}
Property changes on: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidatorTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VatIntraFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VatIntraFieldValidatorTest.java 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VatIntraFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182)
@@ -1,65 +0,0 @@
-/*
- * #%L
- * Nuiton Utils :: Nuiton Validator
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.validator.xwork2.field;
-
-import org.junit.Test;
-import org.nuiton.validator.model.Company;
-
-/**
- *
- */
-public class VatIntraFieldValidatorTest extends AbstractFieldValidatorTest<Company> {
-
- public VatIntraFieldValidatorTest() {
- super(Company.class);
- }
-
- @Test
- @Override
- public void testValidator() throws Exception {
-
- assertNull(bean.getVat());
-
- // Valid vat
- bean.setVat("FR57442116703");
- assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format",
- false);
-
- // Not valid vat
- bean.setVat("FR 57 44211670332");
- assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format",
- true);
-
- // Not valid vat
- bean.setVat("442116703000389");
- assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format",
- true);
-
- // Not valid vat, spaces in it
- bean.setVat("FR 57 442116703");
- assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format",
- true);
- }
-}
Modified: trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Company-error-validation.xml
===================================================================
--- trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Company-error-validation.xml 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Company-error-validation.xml 2011-08-24 13:13:11 UTC (rev 2182)
@@ -28,13 +28,13 @@
<validators>
<field name="siret">
- <field-validator type="siret">
+ <field-validator type="frenchSiret">
<message>company.siret.format</message>
</field-validator>
</field>
<field name="vat">
- <field-validator type="vat">
+ <field-validator type="vatIdentificationNumber">
<message>company.vat.format</message>
</field-validator>
</field>
Property changes on: trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Company-error-validation.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Contact-error-validation.xml
===================================================================
--- trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Contact-error-validation.xml 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Contact-error-validation.xml 2011-08-24 13:13:11 UTC (rev 2182)
@@ -2,8 +2,8 @@
#%L
Nuiton Utils :: Nuiton Validator
- $Id: Pet-error-validation.xml 2033 2011-01-23 17:28:26Z tchemit $
- $HeadURL: http://svn.nuiton.org/svn/nuiton-utils/trunk/nuiton-validator/src/test/reso… $
+ $Id$
+ $HeadURL$
%%
Copyright (C) 2011 CodeLutin
%%
@@ -34,25 +34,25 @@
</field>
<field name="postCode">
- <field-validator type="postCode">
+ <field-validator type="frenchPostCode">
<message>contact.postCode.format</message>
</field-validator>
</field>
<field name="city">
- <field-validator type="cityName">
+ <field-validator type="frenchCityName">
<message>contact.city.format</message>
</field-validator>
</field>
<field name="name">
- <field-validator type="lastName">
+ <field-validator type="frenchLastName">
<message>contact.name.format</message>
</field-validator>
</field>
<field name="phone">
- <field-validator type="phoneNumber">
+ <field-validator type="frenchPhoneNumber">
<message>contact.phoneNumber.format</message>
</field-validator>
</field>
Property changes on: trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Contact-error-validation.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/nuiton-validator/src/test/resources/validators.xml
===================================================================
--- trunk/nuiton-validator/src/test/resources/validators.xml 2011-08-24 11:34:31 UTC (rev 2181)
+++ trunk/nuiton-validator/src/test/resources/validators.xml 2011-08-24 13:13:11 UTC (rev 2182)
@@ -50,18 +50,26 @@
<!-- default nuiton-validator validators -->
<validator name="collectionFieldExpression" class="org.nuiton.validator.xwork2.field.CollectionFieldExpressionValidator"/>
<validator name="collectionUniqueKey" class="org.nuiton.validator.xwork2.field.CollectionUniqueKeyValidator"/>
+
+ <!-- io validators -->
<validator name="requiredFile" class="org.nuiton.validator.xwork2.field.RequiredFileFieldValidator"/>
<validator name="existingFile" class="org.nuiton.validator.xwork2.field.ExistingFileFieldValidator"/>
<validator name="notExistingFile" class="org.nuiton.validator.xwork2.field.NotExistingFileFieldValidator"/>
<validator name="existingDirectory" class="org.nuiton.validator.xwork2.field.ExistingDirectoryFieldValidator"/>
<validator name="notExistingDirectory" class="org.nuiton.validator.xwork2.field.NotExistingDirectoryFieldValidator"/>
<validator name="fieldexpressionwithparams" class="org.nuiton.validator.xwork2.field.FieldExpressionWithParamsValidator"/>
- <validator name="phoneNumber" class="org.nuiton.validator.xwork2.field.PhoneNumberFieldValidator"/>
+
+ <!-- much much better email validator :) -->
<validator name="emailNuiton" class="org.nuiton.validator.xwork2.field.EmailFieldValidator"/>
- <validator name="cityName" class="org.nuiton.validator.xwork2.field.CityNameFieldValidator"/>
- <validator name="lastName" class="org.nuiton.validator.xwork2.field.LastNameFieldValidator"/>
- <validator name="postCode" class="org.nuiton.validator.xwork2.field.PostCodeFieldValidator"/>
- <validator name="siret" class="org.nuiton.validator.xwork2.field.SiretFieldValidator"/>
- <validator name="vat" class="org.nuiton.validator.xwork2.field.VATIntraFieldValidator"/>
+ <!-- french specific validators -->
+ <validator name="frenchPhoneNumber" class="org.nuiton.validator.xwork2.field.FrenchPhoneNumberFieldValidator"/>
+ <validator name="frenchCityName" class="org.nuiton.validator.xwork2.field.FrenchCityNameFieldValidator"/>
+ <validator name="frenchLastName" class="org.nuiton.validator.xwork2.field.FrenchLastNameFieldValidator"/>
+ <validator name="frenchPostCode" class="org.nuiton.validator.xwork2.field.FrenchPostCodeFieldValidator"/>
+ <validator name="frenchSiret" class="org.nuiton.validator.xwork2.field.FrenchSiretFieldValidator"/>
+
+ <!-- eu specific validators -->
+ <validator name="vatIdentificationNumber" class="org.nuiton.validator.xwork2.field.VATIdentificationNumberFieldValidator"/>
+
</validators>
\ No newline at end of file
1
0
24 Aug '11
Author: tchemit
Date: 2011-08-24 13:34:31 +0200 (Wed, 24 Aug 2011)
New Revision: 2181
Url: http://nuiton.org/repositories/revision/nuiton-utils/2181
Log:
Anomalie #1706: [ApplicationConfig] Bad encoding while loading config files
Modified:
trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java
Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java 2011-08-23 07:37:25 UTC (rev 2180)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java 2011-08-24 11:34:31 UTC (rev 2181)
@@ -39,10 +39,12 @@
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
import java.io.PrintStream;
+import java.io.Reader;
import java.io.Serializable;
+import java.io.Writer;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -50,6 +52,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.net.URI;
import java.net.URL;
import java.sql.Date;
import java.sql.Time;
@@ -301,6 +304,9 @@
/** Configuration file key option. */
static final public String CONFIG_FILE_NAME = "config.file";
+ /** Configuration encoding key option. */
+ static final public String CONFIG_ENCODING = "config.encoding";
+
/**Permet d'associer un nom de contexte pour prefixer les options {@link #CONFIG_PATH} et {@link #CONFIG_FILE_NAME}. */
static final public String APP_NAME = "app.name";
@@ -410,6 +416,7 @@
*/
public ApplicationConfig() {
setConfigFileName(getClass().getSimpleName());
+ setEncoding("utf-8");
// init extra-converters
ConverterUtil.initConverters();
@@ -569,17 +576,12 @@
}
// Ano #687 : create parentFile before using it in FileWriter
- boolean dirCreated = FileUtil.createDirectoryIfNecessary(file.getParentFile());
+ boolean dirCreated =
+ FileUtil.createDirectoryIfNecessary(file.getParentFile());
if (dirCreated && log.isDebugEnabled()) {
log.debug("Creation of config directory " + file.getParent());
}
-
- OutputStream stream = new FileOutputStream(file);
- try {
- prop.store(stream, "Last saved " + new java.util.Date());
- } finally {
- stream.close();
- }
+ saveResource(file, prop, "Last saved " + new java.util.Date());
}
/**
@@ -702,6 +704,29 @@
}
/**
+ * Get the encoding used to read/write resources.
+ *
+ * This value is stored as an option using the
+ * {@link #getEncodingOption()} key.
+ *
+ * @return the encoding used to read/write resources.
+ * @since 2.3
+ */
+ public String getEncoding() {
+ return getOption(getEncodingOption());
+ }
+
+ /**
+ * Set the new encoding option.
+ *
+ * @param encoding the new value of the option encoding
+ * @since 2.3
+ */
+ public void setEncoding(String encoding) {
+ setDefaultOption(getEncodingOption(),encoding);
+ }
+
+ /**
* All argument in aliases as key is substitued by target.
*
* @param alias alias string as '-v'
@@ -763,6 +788,20 @@
}
/**
+ * Obtains the key used to store the option encoding.
+ *
+ * @return the encoding option'key
+ * @since 2.3
+ */
+ protected String getEncodingOption() {
+ String optionName = CONFIG_ENCODING;
+ if (getOption(APP_NAME) != null) {
+ optionName = getOption(APP_NAME) + "." + optionName;
+ }
+ return optionName;
+ }
+
+ /**
* Use appName to add a context in config.file and config.path options.
*
* Ex for an application named 'pollen' : {@code config.file} option becomes
@@ -1595,12 +1634,7 @@
log.info("Loading configuration file (classpath) : " +
inClasspath);
}
- InputStream stream = inClasspath.openStream();
- try {
- classpath.load(stream);
- } finally {
- stream.close();
- }
+ loadResource(inClasspath.toURI(), classpath);
}
// system directory
@@ -1610,12 +1644,7 @@
if (log.isInfoEnabled()) {
log.info("Loading configuration file (etc) : " + etcConfig);
}
- InputStream stream = etcConfig.toURI().toURL().openStream();
- try {
- etcfile.load(stream);
- } finally {
- stream.close();
- }
+ loadResource(etcConfig.toURI(), etcfile);
}
else {
if (log.isDebugEnabled()) {
@@ -1644,12 +1673,7 @@
log.info("Loading configuration file (home) : " +
homeConfig);
}
- InputStream stream = homeConfig.toURI().toURL().openStream();
- try {
- homefile.load(stream);
- } finally {
- stream.close();
- }
+ loadResource(homeConfig.toURI(), homefile);
}
else {
if (log.isDebugEnabled()) {
@@ -1664,12 +1688,7 @@
if (log.isInfoEnabled()) {
log.info("Loading configuration file (curr) : " + config);
}
- InputStream stream = config.toURI().toURL().openStream();
- try {
- curfile.load(stream);
- } finally {
- stream.close();
- }
+ loadResource(config.toURI(), curfile);
}
else {
if (log.isDebugEnabled()) {
@@ -1739,6 +1758,49 @@
}
/**
+ * Load a resources given by his {@code uri} to the given
+ * {@code properties} argument.
+ *
+ * @param uri the uri to load
+ * @param properties the properties file to load
+ * @throws IOException if something occurs bad while loading resource
+ * @since 2.3
+ * @see Properties#load(Reader)
+ */
+ protected void loadResource(URI uri, Properties properties) throws IOException {
+ InputStreamReader reader =
+ new InputStreamReader(uri.toURL().openStream(), getEncoding());
+ try {
+ properties.load(reader);
+ } finally {
+ reader.close();
+ }
+ }
+
+ /**
+ * Save the given {@code properties} into the given {@code file} with
+ * the given {@code comment}.
+ *
+ * @param file the location where to store the properties
+ * @param properties the properties file to save
+ * @param comment the comment to add in the saved file
+ * @throws IOException if something occurs bad while saving resource
+ * @since 2.3
+ * @see Properties#store(Writer, String)
+ */
+ protected void saveResource(File file,
+ Properties properties,
+ String comment) throws IOException {
+ Writer reader =
+ new OutputStreamWriter(new FileOutputStream(file), getEncoding());
+ try {
+ properties.store(reader, comment);
+ } finally {
+ reader.close();
+ }
+ }
+
+ /**
* For debugging.
*/
public void printConfig() {
1
0
r2180 - in trunk/nuiton-profiling: . src/license src/main/java/org/nuiton/profiling src/test/java/org/nuiton/profiling src/test/resources src/test/resources/META-INF
by tchemit@users.nuiton.org 23 Aug '11
by tchemit@users.nuiton.org 23 Aug '11
23 Aug '11
Author: tchemit
Date: 2011-08-23 09:37:25 +0200 (Tue, 23 Aug 2011)
New Revision: 2180
Url: http://nuiton.org/repositories/revision/nuiton-utils/2180
Log:
Evolution #1704: Make works NuitonTrace again
Added:
trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/NuitonTraceTest.java
trunk/nuiton-profiling/src/test/resources/META-INF/
trunk/nuiton-profiling/src/test/resources/META-INF/aop.xml
Removed:
trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java
Modified:
trunk/nuiton-profiling/pom.xml
trunk/nuiton-profiling/src/license/THIRD-PARTY.properties
trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java
trunk/nuiton-profiling/src/test/resources/log4j.properties
Modified: trunk/nuiton-profiling/pom.xml
===================================================================
--- trunk/nuiton-profiling/pom.xml 2011-08-22 17:35:46 UTC (rev 2179)
+++ trunk/nuiton-profiling/pom.xml 2011-08-23 07:37:25 UTC (rev 2180)
@@ -108,8 +108,9 @@
<!-- extra files to include in release -->
<redmine.releaseFiles>${redmine.libReleaseFiles}</redmine.releaseFiles>
- <!-- Configure aop configuration -->
- <maven.surefire.debug>-javaagent:target/lib/aspectwerkz-jdk5-2.0.jar -Daspectwerkz.definition.file=src/test/resources/aop.xml</maven.surefire.debug>
+ <!-- Configure aop -->
+ <maven.surefire.debug>-javaagent:target/lib/aspectwerkz-jdk5-2.0.jar</maven.surefire.debug>
+ <!--<maven.surefire.debug>-javaagent:target/lib/aspectwerkz-jdk5-2.0.jar -Daspectwerkz.definition.file=src/test/resources/aop.xml</maven.surefire.debug>-->
</properties>
<!-- ************************************************************* -->
Modified: trunk/nuiton-profiling/src/license/THIRD-PARTY.properties
===================================================================
--- trunk/nuiton-profiling/src/license/THIRD-PARTY.properties 2011-08-22 17:35:46 UTC (rev 2179)
+++ trunk/nuiton-profiling/src/license/THIRD-PARTY.properties 2011-08-23 07:37:25 UTC (rev 2180)
@@ -1,11 +1,11 @@
# Generated by org.codehaus.mojo.license.AddThirdPartyMojo
#-------------------------------------------------------------------------------
# Already used licenses in project :
-# - ASM License
# - Apache Software License
# - Apache Software License, Version 2.0
# - BSD License
# - COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+# - Common Public License Version 1.0
# - Indiana University Extreme! Lab Software License, vesion 1.1.1
# - Jaxen license
# - Lesser General Public License (LGPL)
@@ -18,7 +18,7 @@
# Please fill the missing licenses for dependencies :
#
#
-#Thu Aug 18 07:42:25 CEST 2011
+#Mon Aug 22 19:29:18 CEST 2011
aspectwerkz--aspectwerkz--2.0=GNU Lesser General Public License
aspectwerkz--aspectwerkz-core--2.0=GNU Lesser General Public License
aspectwerkz--aspectwerkz-jdk5--2.0=GNU Lesser General Public License
@@ -27,9 +27,6 @@
jaxen--jaxen--1.0-FCS=Jaxen license
jrexx--jrexx--1.1.1=Apache Software License
msv--msv--20020414=BSD License
-org.nuiton.thirdparty--asm--1.5.4-snapshot=ASM License
-org.nuiton.thirdparty--asm-attrs--1.5.4-snapshot=ASM License
-org.nuiton.thirdparty--asm-util--1.5.4-snapshot=ASM License
qdox--qdox--1.4=Apache Software License, Version 2.0
relaxngDatatype--relaxngDatatype--20020414=BSD License
saxpath--saxpath--1.0-FCS=SAXPath License
Modified: trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java
===================================================================
--- trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java 2011-08-22 17:35:46 UTC (rev 2179)
+++ trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java 2011-08-23 07:37:25 UTC (rev 2180)
@@ -67,10 +67,10 @@
* </pre>
* Ensuite il faut lancer la JVM avec deux options
* <pre>
- * -Djavaagent:path/to/aspectwerkz-jdk5-2.0.jar
+ * -javaagent:path/to/aspectwerkz-jdk5-2.0.jar
* -Daspectwerkz.definition.file=path/to/trace-aop.xml
* </pre>
- * il doit être possible d'utiliser des noms normalisé et
+ * Il est possible d'utiliser des noms normalisé et
* trouvable dans le classpath a la place de -Daspectwerkz.definition.file
* <li> /aspectwerkz.xml
* <li> META-INF/aop.xml
@@ -81,7 +81,7 @@
* <li> NuitonTrace.printStatistiqueAndClear();
* Il doit être possible, plutot que d'écrire un fichier XML, de sous classer
* NuitonTrace en ajoutant par exemple
- *
+ * <p/>
* <pre>
* \@Expression( "execution(* fr.ifremer.isisfish.datastore.ResultStorage.*(..))" +
* "|| execution(* fr.ifremer.isisfish.aspect.Cache.*(..))" +
@@ -93,38 +93,44 @@
* )
* Pointcut executeMethod;
* </pre>
- *
* <p/>
+ * Voir la classe de test {@code org.nuiton.profiling.NuitonTraceTest}.
*
- * @author poussin
- *
- * </p>
+ * @author bpoussin <poussin(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
*/
@Aspect("perJVM")
public class NuitonTrace {
+ static private final List<NuitonTrace> instances = new ArrayList<NuitonTrace>();
+
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(NuitonTrace.class);
- static private List<NuitonTrace> instances = new ArrayList<NuitonTrace>();
-
/** nombre d'appel */
final static public int STAT_CALL = 0;
+
/** nombre d'appel vers une autre method depuis cette methode */
final static public int STAT_CALL_NEST_METHOD = 1;
+
/** temps mini d'execution de cette methode (sans le temps des autres methodes) */
final static public int STAT_TIME_MIN = 2;
+
/** temps max d'execution de cette methode (sans le temps des autres methodes) */
final static public int STAT_TIME_MAX = 3;
+
/** temps total d'execution de cette methode (sans le temps des autres methodes) */
final static public int STAT_TIME_TOTAL = 4;
+
/** temps total d'execution de cette methode (avec le temps des autres methodes) */
final static public int STAT_TIME_TOTAL_NEST_METHOD = 5;
/** nombre d'appel vers une autre method depuis cette methode */
final static private int STACK_CALL_NEST_METHOD = 0;
+
/** heure de depart de l'appel a la methode (sans le temps des autres methodes) */
final static private int STACK_TIME_START = 1;
+
/** heure de depart de l'appel a la methode (avec le temps des autres methodes) */
final static private int STACK_TIME_START_NEST_METHOD = 2;
@@ -216,7 +222,7 @@
/** @return les statistiques */
static public String getStatisticsAndClear() {
- StringBuffer result = new StringBuffer();
+ StringBuilder result = new StringBuilder();
for (NuitonTrace trace : instances) {
result.append("--- Statistics ---\n");
for (Method method : trace.statistics.keySet()) {
Deleted: trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java
===================================================================
--- trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java 2011-08-22 17:35:46 UTC (rev 2179)
+++ trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java 2011-08-23 07:37:25 UTC (rev 2180)
@@ -1,64 +0,0 @@
-/*
- * #%L
- * Nuiton Utils :: Nuiton Profiling
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2011 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.profiling;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codehaus.aspectwerkz.annotation.Aspect;
-import org.codehaus.aspectwerkz.annotation.Expression;
-import org.codehaus.aspectwerkz.definition.Pointcut;
-
-/**
- * Lanch this main with -javaagent:target/lib/aspectwerkz-jdk5-2.0.jar
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.3
- */
-@Aspect("perJVM")
-public class MyNuitonTrace extends NuitonTrace {
-
- @Expression("execution(* org.apache.commons.logging.Log.*(..))")
- Pointcut executeMethod;
-
- /** Logger. */
- private static final Log log = LogFactory.getLog(MyNuitonTrace.class);
-
- public static void main(String[] args) {
-
- log.debug("DEBUG");
- log.info("INFO");
- log.warn("WARN");
- log.warn("TRACE");
-
- // trace should have somethin inside it...
- String statisticsAndClear = getStatisticsAndClear();
-// Assert.assertTrue(StringUtils.isNotEmpty(statisticsAndClear));
-
- if (log.isInfoEnabled()) {
- log.info("First trace = " + statisticsAndClear);
- }
- }
-
-}
Copied: trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/NuitonTraceTest.java (from rev 2178, trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java)
===================================================================
--- trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/NuitonTraceTest.java (rev 0)
+++ trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/NuitonTraceTest.java 2011-08-23 07:37:25 UTC (rev 2180)
@@ -0,0 +1,75 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Profiling
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2011 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.profiling;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Launch this test with -javaagent:target/lib/aspectwerkz-jdk5-2.0.jar
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.3
+ */
+public class NuitonTraceTest {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(NuitonTraceTest.class);
+
+ @Test
+ public void testAOP() {
+
+ if (log.isDebugEnabled()) {
+ log.debug("DEBUG");
+ }
+ if (log.isInfoEnabled()) {
+ log.info("INFO");
+ }
+
+ if (log.isErrorEnabled()) {
+ log.error("ERROR");
+ }
+
+ if (log.isWarnEnabled()) {
+ log.warn("WARN");
+ }
+
+ if (log.isTraceEnabled()) {
+ log.trace("TRACE");
+ }
+
+ // trace should have something inside it...
+ String statisticsAndClear = NuitonTrace.getStatisticsAndClear();
+ Assert.assertTrue(StringUtils.isNotEmpty(statisticsAndClear));
+
+ if (log.isInfoEnabled()) {
+ log.info(statisticsAndClear);
+ }
+ }
+
+}
Property changes on: trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/NuitonTraceTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/nuiton-profiling/src/test/resources/META-INF/aop.xml
===================================================================
--- trunk/nuiton-profiling/src/test/resources/META-INF/aop.xml (rev 0)
+++ trunk/nuiton-profiling/src/test/resources/META-INF/aop.xml 2011-08-23 07:37:25 UTC (rev 2180)
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ #%L
+ Nuiton Utils :: Nuiton Profiling
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2004 - 2011 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Lesser Public License for more details.
+
+ You should have received a copy of the GNU General Lesser Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ #L%
+ -->
+
+<!DOCTYPE aspectwerkz PUBLIC
+ "-//AspectWerkz//DTD//EN"
+ "http://aspectwerkz.codehaus.org/dtd/aspectwerkz2.dtd">
+<aspectwerkz>
+ <system id="webapp">
+ <aspect class="org.nuiton.profiling.NuitonTrace">
+ <pointcut name="executeMethod">
+ <![CDATA[ execution(public * org.apache..*.*(..)) && !within(org.apache.log4j..*) && !within(org.apache.commons.lang..*)]]>
+ <!--<![CDATA[ execution(public * *..*.*(..))]]>-->
+ </pointcut>
+ <!--<pointcut name="executeMethod" expression="execution(public * org.apache..*(..))"/>-->
+ <!--<pointcut name="executeMethod"-->
+ <!--expression="execution(public * org.apache..*(..))"/>-->
+ <!--expression="execution(public * org.apache.commons..*(..)) && !within(org.apache.log4j..*) && !within(org.nuiton.profiling..*)"/>-->
+ </aspect>
+ <!--</package>-->
+
+ </system>
+</aspectwerkz>
\ No newline at end of file
Property changes on: trunk/nuiton-profiling/src/test/resources/META-INF/aop.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/nuiton-profiling/src/test/resources/log4j.properties
===================================================================
--- trunk/nuiton-profiling/src/test/resources/log4j.properties 2011-08-22 17:35:46 UTC (rev 2179)
+++ trunk/nuiton-profiling/src/test/resources/log4j.properties 2011-08-23 07:37:25 UTC (rev 2180)
@@ -23,19 +23,12 @@
# #L%
###
# Global logging configuration
-log4j.rootLogger=DEBUG, stdout, fileout
+log4j.rootLogger=ERROR, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n
-log4j.appender.fileout=org.apache.log4j.FileAppender
-log4j.appender.fileout.File=target/nuitontrace.log
-log4j.appender.fileout.Append=true
-log4j.appender.fileout.Threshold=DEBUG
-log4j.appender.fileout.layout=org.apache.log4j.PatternLayout
-log4j.appender.fileout.layout.ConversionPattern=%5p (%F:%L) %m%n
-
# package level
-#log4j.logger.org.apache.commons.logging.Log=DEBUG
+log4j.logger.org.nuiton.profiling=TRACE
1
0
Author: tchemit
Date: 2011-08-22 19:35:46 +0200 (Mon, 22 Aug 2011)
New Revision: 2179
Url: http://nuiton.org/repositories/revision/nuiton-utils/2179
Log:
Anomalie #1703: nuiton-profiling is not central-safe
Modified:
trunk/nuiton-profiling/pom.xml
trunk/pom.xml
Modified: trunk/nuiton-profiling/pom.xml
===================================================================
--- trunk/nuiton-profiling/pom.xml 2011-08-22 15:16:39 UTC (rev 2178)
+++ trunk/nuiton-profiling/pom.xml 2011-08-22 17:35:46 UTC (rev 2179)
@@ -59,19 +59,12 @@
</dependency>
<dependency>
- <groupId>org.nuiton.thirdparty</groupId>
+ <groupId>asm</groupId>
<artifactId>asm</artifactId>
+ <scope>runtime</scope>
</dependency>
+
<dependency>
- <groupId>org.nuiton.thirdparty</groupId>
- <artifactId>asm-attrs</artifactId>
- </dependency>
- <dependency>
- <groupId>org.nuiton.thirdparty</groupId>
- <artifactId>asm-util</artifactId>
- </dependency>
-
- <dependency>
<groupId>aspectwerkz</groupId>
<artifactId>aspectwerkz</artifactId>
<scope>compile</scope>
@@ -115,6 +108,8 @@
<!-- extra files to include in release -->
<redmine.releaseFiles>${redmine.libReleaseFiles}</redmine.releaseFiles>
+ <!-- Configure aop configuration -->
+ <maven.surefire.debug>-javaagent:target/lib/aspectwerkz-jdk5-2.0.jar -Daspectwerkz.definition.file=src/test/resources/aop.xml</maven.surefire.debug>
</properties>
<!-- ************************************************************* -->
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-08-22 15:16:39 UTC (rev 2178)
+++ trunk/pom.xml 2011-08-22 17:35:46 UTC (rev 2179)
@@ -78,6 +78,7 @@
<groupId>aspectwerkz</groupId>
<artifactId>aspectwerkz-core</artifactId>
<version>${aspectwerkzVersion}</version>
+ <!-- These dependencies are not in maven central -->
<exclusions>
<exclusion>
<groupId>asm</groupId>
@@ -107,21 +108,11 @@
</dependency>
<dependency>
- <groupId>org.nuiton.thirdparty</groupId>
+ <groupId>asm</groupId>
<artifactId>asm</artifactId>
- <version>${asmVersion}</version>
+ <version>3.3.1</version>
</dependency>
- <dependency>
- <groupId>org.nuiton.thirdparty</groupId>
- <artifactId>asm-attrs</artifactId>
- <version>${asmVersion}</version>
- </dependency>
- <dependency>
- <groupId>org.nuiton.thirdparty</groupId>
- <artifactId>asm-util</artifactId>
- <version>${asmVersion}</version>
- </dependency>
-
+
</dependencies>
</dependencyManagement>
@@ -216,7 +207,6 @@
<projectId>nuiton-utils</projectId>
<nuitonI18nVersion>2.4.1</nuitonI18nVersion>
<aspectwerkzVersion>2.0</aspectwerkzVersion>
- <asmVersion>1.5.4-snapshot</asmVersion>
<xworkVersion>2.2.3</xworkVersion>
<!-- i18n configuration -->
1
0
r2178 - trunk/nuiton-profiling/src/test/java/org/nuiton/profiling
by tchemit@users.nuiton.org 22 Aug '11
by tchemit@users.nuiton.org 22 Aug '11
22 Aug '11
Author: tchemit
Date: 2011-08-22 17:16:39 +0200 (Mon, 22 Aug 2011)
New Revision: 2178
Url: http://nuiton.org/repositories/revision/nuiton-utils/2178
Log:
add javadoc
Modified:
trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java
Modified: trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java
===================================================================
--- trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java 2011-08-22 15:15:47 UTC (rev 2177)
+++ trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java 2011-08-22 15:16:39 UTC (rev 2178)
@@ -31,10 +31,10 @@
import org.codehaus.aspectwerkz.definition.Pointcut;
/**
- * TODO
+ * Lanch this main with -javaagent:target/lib/aspectwerkz-jdk5-2.0.jar
*
* @author tchemit <chemit(a)codelutin.com>
- * @since TODO
+ * @since 2.3
*/
@Aspect("perJVM")
public class MyNuitonTrace extends NuitonTrace {
1
0