labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simo...@apache.org
Subject svn commit: r718601 - in /labs/magma/trunk/foundation-validation/src: main/java/org/apache/magma/validation/ main/java/org/apache/magma/validation/validators/ test/java/org/apache/magma/validation/ test/java/org/apache/magma/validation/validators/
Date Tue, 18 Nov 2008 14:21:08 GMT
Author: simoneg
Date: Tue Nov 18 06:21:07 2008
New Revision: 718601

URL: http://svn.apache.org/viewvc?rev=718601&view=rev
Log:
Minor validators refactoring

Modified:
    labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/AddValidationInHandler.aj
    labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/CompoundValidator.java
    labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/Validator.java
    labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/validators/LengthValidator.java
    labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/validators/RangeValidator.java
    labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/validators/RequiredValidator.java
    labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/BaseConverterValidationTest.java
    labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/LengthValidatorTest.java
    labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/RangeValidatorGoodValidations.java
    labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/RangeValidatorWrongValidations.java
    labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/RequiredValidatorTest.java

Modified: labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/AddValidationInHandler.aj
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/AddValidationInHandler.aj?rev=718601&r1=718600&r2=718601&view=diff
==============================================================================
--- labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/AddValidationInHandler.aj
(original)
+++ labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/AddValidationInHandler.aj
Tue Nov 18 06:21:07 2008
@@ -31,8 +31,8 @@
 		if (property == null) throw new MagmaException("Cannot find a property named {0} in class
{1}", field, bean.getClass().getName());
 		Validator v = property.getValidator();
 		if (v != null) {
-			List<LocalizableString> errs = v.validate(value);
-			if (errs != null) {
+			List<LocalizableString> errs = v.validate(bean,property,value);
+			if (errs != null && errs.size() > 0) {
 				ValidationError err = new ValidationError(errs);
 				err.setSubject(property);
 				throw err;

Modified: labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/CompoundValidator.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/CompoundValidator.java?rev=718601&r1=718600&r2=718601&view=diff
==============================================================================
--- labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/CompoundValidator.java
(original)
+++ labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/CompoundValidator.java
Tue Nov 18 06:21:07 2008
@@ -17,6 +17,7 @@
 package org.apache.magma.validation;
 
 import org.apache.magma.basics.LocalizableString;
+import org.apache.magma.beans.PropertyInfo;
 import org.apache.magma.validation.validators.LengthValidator;
 import org.apache.magma.validation.validators.RangeValidator;
 import org.apache.magma.validation.validators.Required;
@@ -34,11 +35,11 @@
 		validators.add(validator);
 	}
 
-	public List<LocalizableString> validate(C value) {
+	public List<LocalizableString> validate(Object bean, PropertyInfo property, C value)
{
 		List<LocalizableString> errs = null;
 		if (this.validators != null) {
 			for (Validator validator : this.validators) {
-				List<LocalizableString> err = validator.validate(value);
+				List<LocalizableString> err = validator.validate(bean, property, value);
 				if (err != null) {
 					if (errs == null) errs = new ArrayList<LocalizableString>();
 					errs.addAll(err);

Modified: labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/Validator.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/Validator.java?rev=718601&r1=718600&r2=718601&view=diff
==============================================================================
--- labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/Validator.java
(original)
+++ labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/Validator.java
Tue Nov 18 06:21:07 2008
@@ -19,9 +19,10 @@
 import java.util.List;
 
 import org.apache.magma.basics.LocalizableString;
+import org.apache.magma.beans.PropertyInfo;
 
 public interface Validator<T> {
 
-	public List<LocalizableString> validate(T value);
+	public List<LocalizableString> validate(Object bean, PropertyInfo property, T value);
 	
 }

Modified: labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/validators/LengthValidator.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/validators/LengthValidator.java?rev=718601&r1=718600&r2=718601&view=diff
==============================================================================
--- labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/validators/LengthValidator.java
(original)
+++ labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/validators/LengthValidator.java
Tue Nov 18 06:21:07 2008
@@ -20,6 +20,7 @@
 import java.util.List;
 
 import org.apache.magma.basics.LocalizableString;
+import org.apache.magma.beans.PropertyInfo;
 import org.apache.magma.validation.Validator;
 
 
@@ -68,7 +69,7 @@
 		this.myError.add(new LocalizableString(errorString, min, max));
 	}
 
-	public List<LocalizableString> validate(String value) {
+	public List<LocalizableString> validate(Object bean, PropertyInfo property, String
value) {
 		if (value == null) return null;
 		int len = value.length();
 		if (len < min || len > max) return myError;

Modified: labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/validators/RangeValidator.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/validators/RangeValidator.java?rev=718601&r1=718600&r2=718601&view=diff
==============================================================================
--- labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/validators/RangeValidator.java
(original)
+++ labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/validators/RangeValidator.java
Tue Nov 18 06:21:07 2008
@@ -17,6 +17,7 @@
 package org.apache.magma.validation.validators;
 
 import org.apache.magma.basics.LocalizableString;
+import org.apache.magma.beans.PropertyInfo;
 import org.apache.magma.validation.Validator;
 
 import java.math.BigDecimal;
@@ -79,7 +80,7 @@
 		this.myError.add(new LocalizableString(errorString, min, max));
 	}
 
-	public List<LocalizableString> validate(Number value) {
+	public List<LocalizableString> validate(Object bean, PropertyInfo property, Number
value) {
 		if (value == null) return null;
 		if (min != null) {
 			if (typeSafeCompare(value, min) < 0) return myError;

Modified: labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/validators/RequiredValidator.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/validators/RequiredValidator.java?rev=718601&r1=718600&r2=718601&view=diff
==============================================================================
--- labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/validators/RequiredValidator.java
(original)
+++ labs/magma/trunk/foundation-validation/src/main/java/org/apache/magma/validation/validators/RequiredValidator.java
Tue Nov 18 06:21:07 2008
@@ -20,6 +20,7 @@
 import java.util.List;
 
 import org.apache.magma.basics.LocalizableString;
+import org.apache.magma.beans.PropertyInfo;
 import org.apache.magma.validation.Validator;
 
 public class RequiredValidator implements Validator<Object> {
@@ -35,7 +36,7 @@
 	}
 	
 	
-	public List<LocalizableString> validate(Object value) {
+	public List<LocalizableString> validate(Object bean, PropertyInfo property, Object
value) {
 		if (value == null) return myError;
 		return null;
 	}

Modified: labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/BaseConverterValidationTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/BaseConverterValidationTest.java?rev=718601&r1=718600&r2=718601&view=diff
==============================================================================
--- labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/BaseConverterValidationTest.java
(original)
+++ labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/BaseConverterValidationTest.java
Tue Nov 18 06:21:07 2008
@@ -43,23 +43,23 @@
 	
 	@Test
 	public void workingValidations() {
-		nullOrthrow(compound.validate(2));
-		nullOrthrow(compound.validate(5));
+		nullOrthrow(compound.validate(null,null,2));
+		nullOrthrow(compound.validate(null,null,5));
 	}
 	
 	@Test(expected=ValidationError.class)
 	public void fails1() {
-		nullOrthrow(compound.validate(null));
+		nullOrthrow(compound.validate(null,null,null));
 	}
 
 	@Test(expected=ValidationError.class)
 	public void fails2() {
-		nullOrthrow(compound.validate(-1));
+		nullOrthrow(compound.validate(null,null,-1));
 	}
 	
 	@Test(expected=ValidationError.class)
 	public void fails3() {
-		nullOrthrow(compound.validate(11));
+		nullOrthrow(compound.validate(null,null,11));
 	}
 
 	private void nullOrthrow(List<LocalizableString> validate) {

Modified: labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/LengthValidatorTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/LengthValidatorTest.java?rev=718601&r1=718600&r2=718601&view=diff
==============================================================================
--- labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/LengthValidatorTest.java
(original)
+++ labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/LengthValidatorTest.java
Tue Nov 18 06:21:07 2008
@@ -36,17 +36,17 @@
 	
 	@Test
 	public void testValidateOk() {
-		List<LocalizableString> string = v.validate("testok");
+		List<LocalizableString> string = v.validate(null,null,"testok");
 		assertNull(string);
-		string = v.validate(null);
+		string = v.validate(null,null,null);
 		assertNull(string);
 	}
 	
 	@Test
 	public void testValidateError() throws Exception {
-		List<LocalizableString> string = v.validate("t");
+		List<LocalizableString> string = v.validate(null,null,"t");
 		assertNotNull(string);		
-		string = v.validate("test a string too long for the validator");
+		string = v.validate(null,null,"test a string too long for the validator");
 		assertNotNull(string);		
 	}
 

Modified: labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/RangeValidatorGoodValidations.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/RangeValidatorGoodValidations.java?rev=718601&r1=718600&r2=718601&view=diff
==============================================================================
--- labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/RangeValidatorGoodValidations.java
(original)
+++ labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/RangeValidatorGoodValidations.java
Tue Nov 18 06:21:07 2008
@@ -47,6 +47,6 @@
 	
 	@Theory public void validates(Number[] numbers) {
 		RangeValidator v = new RangeValidator(numbers[0], numbers[1]);
-		assertThat(v.validate(numbers[2]), nullValue());
+		assertThat(v.validate(null,null,numbers[2]), nullValue());
 	}
 }

Modified: labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/RangeValidatorWrongValidations.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/RangeValidatorWrongValidations.java?rev=718601&r1=718600&r2=718601&view=diff
==============================================================================
--- labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/RangeValidatorWrongValidations.java
(original)
+++ labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/RangeValidatorWrongValidations.java
Tue Nov 18 06:21:07 2008
@@ -48,6 +48,6 @@
 	
 	@Theory public void validates(Number[] numbers) {
 		RangeValidator v = new RangeValidator(numbers[0], numbers[1]);
-		assertThat(v.validate(numbers[2]), not(nullValue()));
+		assertThat(v.validate(null,null,numbers[2]), not(nullValue()));
 	}
 }

Modified: labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/RequiredValidatorTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/RequiredValidatorTest.java?rev=718601&r1=718600&r2=718601&view=diff
==============================================================================
--- labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/RequiredValidatorTest.java
(original)
+++ labs/magma/trunk/foundation-validation/src/test/java/org/apache/magma/validation/validators/RequiredValidatorTest.java
Tue Nov 18 06:21:07 2008
@@ -25,9 +25,9 @@
 	@Test
 	public void testValidate() {
 		RequiredValidator v = new RequiredValidator();
-		assertNull(v.validate(""));
-		assertNull(v.validate(Integer.valueOf(1)));
-		assertNotNull(v.validate(null));
+		assertNull(v.validate(null,null,""));
+		assertNull(v.validate(null,null,Integer.valueOf(1)));
+		assertNotNull(v.validate(null,null,null));
 	}
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message