You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by mb...@apache.org on 2014/01/03 01:04:24 UTC
svn commit: r1554975 - in /bval/sandbox/bval-jsr303-dynamic: ./
extval-shared-tests/ provider/
provider/src/main/java/org/apache/bval/constraints/dynamic/
provider/src/main/java/org/apache/bval/constraints/dynamic/appender/
provider/src/main/java/org/a...
Author: mbenson
Date: Fri Jan 3 00:04:23 2014
New Revision: 1554975
URL: http://svn.apache.org/r1554975
Log:
dependency management; compile against latest commons-proxy2 snapshot
Modified:
bval/sandbox/bval-jsr303-dynamic/extval-shared-tests/pom.xml
bval/sandbox/bval-jsr303-dynamic/pom.xml
bval/sandbox/bval-jsr303-dynamic/provider/pom.xml
bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/constraints/dynamic/NullValue.java
bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/constraints/dynamic/appender/AbstractValuesConstraintAppender.java
bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/constraints/dynamic/appender/ValuesConstraintAppender.java
bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/StubConstraint.java
bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/constraints/dynamic/NullValueValidationTest.java
bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/constraints/dynamic/ValuesConstraintValidationTest.java
bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicBeanDescriptorTest.java
bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicCollectionValidationTest.java
bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicJsr303Test.java
bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagementTest.java
bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicValidationTest.java
bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/NestedValidatorTest.java
bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/StubConstraintTest.java
Modified: bval/sandbox/bval-jsr303-dynamic/extval-shared-tests/pom.xml
URL: http://svn.apache.org/viewvc/bval/sandbox/bval-jsr303-dynamic/extval-shared-tests/pom.xml?rev=1554975&r1=1554974&r2=1554975&view=diff
==============================================================================
--- bval/sandbox/bval-jsr303-dynamic/extval-shared-tests/pom.xml (original)
+++ bval/sandbox/bval-jsr303-dynamic/extval-shared-tests/pom.xml Fri Jan 3 00:04:23 2014
@@ -84,7 +84,7 @@
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
- <artifactId>commons-proxy2-stub</artifactId>
+ <artifactId>commons-proxy2</artifactId>
</dependency>
</dependencies>
<build>
Modified: bval/sandbox/bval-jsr303-dynamic/pom.xml
URL: http://svn.apache.org/viewvc/bval/sandbox/bval-jsr303-dynamic/pom.xml?rev=1554975&r1=1554974&r2=1554975&view=diff
==============================================================================
--- bval/sandbox/bval-jsr303-dynamic/pom.xml (original)
+++ bval/sandbox/bval-jsr303-dynamic/pom.xml Fri Jan 3 00:04:23 2014
@@ -32,6 +32,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mftest.version>1.0.4</mftest.version>
+ <bval.version>0.6-SNAPSHOT</bval.version>
<!-- overridable defaults: -->
<jsf.version>1.2.5</jsf.version>
<extval.version>1.2.5-SNAPSHOT</extval.version>
@@ -40,6 +41,18 @@
<dependencies>
<dependency>
<groupId>org.apache.bval</groupId>
+ <artifactId>bval-jsr303</artifactId>
+ <version>${bval.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.bval</groupId>
+ <artifactId>bval-jsr303</artifactId>
+ <type>test-jar</type>
+ <version>${bval.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.bval</groupId>
<artifactId>bval-jsr303-dynamic-provider</artifactId>
<version>${project.version}</version>
</dependency>
@@ -68,7 +81,7 @@
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
- <artifactId>commons-proxy2-stub</artifactId>
+ <artifactId>commons-proxy2</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
Modified: bval/sandbox/bval-jsr303-dynamic/provider/pom.xml
URL: http://svn.apache.org/viewvc/bval/sandbox/bval-jsr303-dynamic/provider/pom.xml?rev=1554975&r1=1554974&r2=1554975&view=diff
==============================================================================
--- bval/sandbox/bval-jsr303-dynamic/provider/pom.xml (original)
+++ bval/sandbox/bval-jsr303-dynamic/provider/pom.xml Fri Jan 3 00:04:23 2014
@@ -40,12 +40,10 @@
<dependency>
<groupId>org.apache.bval</groupId>
<artifactId>bval-jsr303</artifactId>
- <version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.bval</groupId>
<artifactId>bval-jsr303</artifactId>
- <version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
@@ -56,7 +54,7 @@
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
- <artifactId>commons-proxy2-stub</artifactId>
+ <artifactId>commons-proxy2</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
Modified: bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/constraints/dynamic/NullValue.java
URL: http://svn.apache.org/viewvc/bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/constraints/dynamic/NullValue.java?rev=1554975&r1=1554974&r2=1554975&view=diff
==============================================================================
--- bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/constraints/dynamic/NullValue.java (original)
+++ bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/constraints/dynamic/NullValue.java Fri Jan 3 00:04:23 2014
@@ -47,13 +47,14 @@ import org.apache.bval.constraints.dynam
import org.apache.bval.jsr303.dynamic.ConstraintAppender;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.proxy2.stub.AnnotationFactory;
-import org.apache.commons.proxy2.stub.StubConfigurer;
+import org.apache.commons.proxy2.stub.AnnotationBuilder;
+import org.apache.commons.proxy2.stub.AnnotationTrainer;
/**
* Merges {@link Null} and {@link NotNull} with dynamic handling.
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2011-06-01 17:49:36 -0500 (Wed, 01 Jun 2011)
+ * $
*/
@Documented
@Target({ METHOD, FIELD, ANNOTATION_TYPE, PARAMETER })
@@ -62,8 +63,9 @@ import org.apache.commons.proxy2.stub.St
@ConstraintAppender.Use(NullValue.Appender.class)
public @interface NullValue {
/**
- * The behavior of this NullValue constraint. Defaults to {@link Rule#REQUIRE} for semantic reasons; i.e.
- * "NullValue" by itself implies a null value.
+ * The behavior of this NullValue constraint. Defaults to
+ * {@link Rule#REQUIRE} for semantic reasons; i.e. "NullValue" by itself
+ * implies a null value.
*
* @return Rule
*/
@@ -99,7 +101,8 @@ public @interface NullValue {
}
/**
- * {@link ConstraintValidator} implementation for {@link NullValue} constraints.
+ * {@link ConstraintValidator} implementation for {@link NullValue}
+ * constraints.
*/
public static class Validator implements ConstraintValidator<NullValue, Object> {
private Rule rule;
@@ -108,7 +111,7 @@ public @interface NullValue {
* {@inheritDoc}
*/
public void initialize(NullValue constraintAnnotation) {
- this.rule = constraintAnnotation.value();
+ rule = constraintAnnotation.value();
}
/**
@@ -166,7 +169,8 @@ public @interface NullValue {
// then, replace the rule for this constraint's groups:
addRulesByGroup(rulesByGroup, constraint);
- // now map group to constraint set, discarding constraints whose rule no longer matches the group's rule:
+ // now map group to constraint set, discarding constraints whose
+ // rule no longer matches the group's rule:
Map<Class<?>, Set<NullValue>> constraintsByGroup = new HashMap<Class<?>, Set<NullValue>>();
for (NullValue a : found) {
addConstraintByGroup(constraintsByGroup, a, rulesByGroup);
@@ -207,31 +211,32 @@ public @interface NullValue {
@SuppressWarnings("unchecked")
final Class<? extends Payload>[] payload = payloads.toArray(new Class[payloads.size()]);
- result.add(AnnotationFactory.INSTANCE.create(new StubConfigurer<NullValue>() {
+ result.add(AnnotationBuilder.of(NullValue.class).train(new AnnotationTrainer<NullValue>() {
@Override
- protected void configure(NullValue stub) {
+ protected void train(NullValue stub) {
when(stub.value()).thenReturn(rule).when(stub.groups()).thenReturn(groupsArray)
.when(stub.message()).thenReturn(message).when(stub.payload()).thenReturn(payload);
}
- }));
+ }).build());
}
if (result.size() == 0) {
- // apparently all constraints were annihilated by contact with anti-particles:
+ // apparently all constraints were annihilated by contact with
+ // anti-particles:
return true;
}
Annotation toAdd;
if (result.size() == 1) {
toAdd = result.get(0);
} else {
- toAdd = AnnotationFactory.INSTANCE.create(new StubConfigurer<NullValue.List>() {
+ toAdd = AnnotationBuilder.of(NullValue.List.class).train(new AnnotationTrainer<NullValue.List>() {
@Override
- protected void configure(List stub) {
+ protected void train(List stub) {
when(stub.value()).thenReturn(result.toArray(new NullValue[result.size()]));
}
- });
+ }).build();
}
return collection.add(toAdd);
}
@@ -264,7 +269,7 @@ public @interface NullValue {
set.add(constraint);
}
}
-
+
private static Class<?>[] groups(NullValue fromConstraint) {
Class<?>[] result = fromConstraint.groups();
return ArrayUtils.isEmpty(result) ? ArrayUtils.<Class<?>> toArray(Default.class) : result;
Modified: bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/constraints/dynamic/appender/AbstractValuesConstraintAppender.java
URL: http://svn.apache.org/viewvc/bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/constraints/dynamic/appender/AbstractValuesConstraintAppender.java?rev=1554975&r1=1554974&r2=1554975&view=diff
==============================================================================
--- bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/constraints/dynamic/appender/AbstractValuesConstraintAppender.java (original)
+++ bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/constraints/dynamic/appender/AbstractValuesConstraintAppender.java Fri Jan 3 00:04:23 2014
@@ -34,13 +34,13 @@ import javax.validation.ConstraintDefini
import javax.validation.Payload;
import org.apache.bval.constraints.dynamic.Values;
-import org.apache.bval.constraints.dynamic.Values.Strategy;
import org.apache.bval.constraints.dynamic.Values.Rule;
+import org.apache.bval.constraints.dynamic.Values.Strategy;
import org.apache.bval.jsr303.groups.GroupsComputer;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.proxy2.stub.AnnotationFactory;
-import org.apache.commons.proxy2.stub.StubConfigurer;
+import org.apache.commons.proxy2.stub.AnnotationBuilder;
+import org.apache.commons.proxy2.stub.AnnotationTrainer;
/**
* Templated implementation for managing values-based constraints.
@@ -52,17 +52,13 @@ import org.apache.commons.proxy2.stub.St
* @param <V>
* <code>A.value()</code> component type
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2011-06-01 17:49:36 -0500 (Wed, 01 Jun 2011)
+ * $
*/
public abstract class AbstractValuesConstraintAppender<A extends Annotation, M extends Annotation, V> extends
AbstractGenericMultivaluedConstraintAppender<A, M> {
/**
- * {@link AnnotationFactory} instance for annotation generation.
- */
- protected final AnnotationFactory annotationFactory = new AnnotationFactory();
-
- /**
* Prototype for <code>Values.value()</code>.
*/
protected final V[] emptyValueArray;
@@ -124,7 +120,8 @@ public abstract class AbstractValuesCons
*
* @param constraint
* @param applyingModification
- * whether the constraint being applied is (one of) the constraint(s) that began this append process
+ * whether the constraint being applied is (one of) the
+ * constraint(s) that began this append process
*/
public void apply(A constraint, boolean applyingModification) {
// when we are applying the modification, the meaning of the rule
@@ -139,11 +136,11 @@ public abstract class AbstractValuesCons
CumulativeValues includes = null;
CumulativeValues excludes = null;
if (strategy == Strategy.REPLACE) {
- //keep null
+ // keep null
includedValuesByGroup.remove(group);
excludedValuesByGroup.remove(group);
} else {
- //get existing values
+ // get existing values
includes = includedValuesByGroup.get(group);
excludes = excludedValuesByGroup.get(group);
}
@@ -234,6 +231,7 @@ public abstract class AbstractValuesCons
/**
* {@inheritDoc}
*/
+ @Override
protected boolean appendTyped(A constraint, Collection<Annotation> collection) {
throw new UnsupportedOperationException("we have intercepted doAppend() so this should never be called");
}
@@ -310,15 +308,19 @@ public abstract class AbstractValuesCons
@SuppressWarnings("unchecked")
Class<? extends Payload>[] payload = payloads.toArray(new Class[payloads.size()]);
A constraint =
- annotationFactory.create(new AnnotationStubConfigurer(values.values.toArray(emptyValueArray), rule,
- message, groups.toArray(new Class[groups.size()]), payload, values.strategy));
+ AnnotationBuilder
+ .of(constraintType)
+ .train(
+ new AnnotationStubConfigurer(values.values.toArray(emptyValueArray), rule, message, groups
+ .toArray(new Class[groups.size()]), payload, values.strategy)).build();
constraints.add(constraint);
}
return valuesMerger.includedValuesByGroup.size() + valuesMerger.excludedValuesByGroup.size() > 0;
}
/**
- * In a given set of groups, find the first one that does not extend any other group in the set.
+ * In a given set of groups, find the first one that does not extend any
+ * other group in the set.
*
* @param groups
* @return Group
@@ -345,7 +347,7 @@ public abstract class AbstractValuesCons
/**
* The annotation stub configurer we use.
*/
- private final class AnnotationStubConfigurer extends StubConfigurer<A> {
+ private final class AnnotationStubConfigurer extends AnnotationTrainer<A> {
final V[] values;
final Rule rule;
final String message;
@@ -378,7 +380,7 @@ public abstract class AbstractValuesCons
* {@inheritDoc}
*/
@Override
- protected void configure(A stub) {
+ protected void train(A stub) {
when(getConstraintValue(stub)).thenReturn(values).when(getRule(stub)).thenReturn(rule)
.when(getMessage(stub)).thenReturn(message).when(getGroups(stub)).thenReturn(groups)
.when(getPayload(stub)).thenReturn(payloads).when(getStrategy(stub)).thenReturn(strategy);
Modified: bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/constraints/dynamic/appender/ValuesConstraintAppender.java
URL: http://svn.apache.org/viewvc/bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/constraints/dynamic/appender/ValuesConstraintAppender.java?rev=1554975&r1=1554974&r2=1554975&view=diff
==============================================================================
--- bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/constraints/dynamic/appender/ValuesConstraintAppender.java (original)
+++ bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/constraints/dynamic/appender/ValuesConstraintAppender.java Fri Jan 3 00:04:23 2014
@@ -19,15 +19,18 @@ package org.apache.bval.constraints.dyna
import javax.validation.Payload;
import org.apache.bval.constraints.dynamic.Values;
+import org.apache.bval.constraints.dynamic.Values.Labeled.List;
import org.apache.bval.constraints.dynamic.Values.Rule;
import org.apache.bval.constraints.dynamic.Values.Strategy;
import org.apache.bval.jsr303.dynamic.ConstraintAppender;
-import org.apache.commons.proxy2.stub.StubConfigurer;
+import org.apache.commons.proxy2.stub.AnnotationBuilder;
+import org.apache.commons.proxy2.stub.AnnotationTrainer;
/**
* {@link ConstraintAppender} for {@link Values} constraints.
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2011-06-02 12:52:02 -0500 (Thu, 02 Jun 2011)
+ * $
*/
public class ValuesConstraintAppender extends AbstractValuesConstraintAppender<Values, Values.List, String> {
@@ -51,13 +54,13 @@ public class ValuesConstraintAppender ex
*/
@Override
protected Values.List createMultipleConstraint(final Values[] value) {
- return annotationFactory.create(new StubConfigurer<Values.List>() {
+ return AnnotationBuilder.of(Values.List.class).train(new AnnotationTrainer<Values.List>() {
@Override
- protected void configure(Values.List stub) {
+ protected void train(Values.List stub) {
when(stub.value()).thenReturn(value);
}
- });
+ }).build();
}
/**
@@ -118,13 +121,14 @@ public class ValuesConstraintAppender ex
*/
@Override
protected Values.Labeled.List createMultipleConstraint(final Values.Labeled[] value) {
- return annotationFactory.create(new StubConfigurer<Values.Labeled.List>() {
+ return AnnotationBuilder.of(Values.Labeled.List.class).train(new AnnotationTrainer<Values.Labeled.List>() {
@Override
- protected void configure(Values.Labeled.List stub) {
+ protected void train(List stub) {
when(stub.value()).thenReturn(value);
}
- });
+
+ }).build();
}
/**
Modified: bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/StubConstraint.java
URL: http://svn.apache.org/viewvc/bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/StubConstraint.java?rev=1554975&r1=1554974&r2=1554975&view=diff
==============================================================================
--- bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/StubConstraint.java (original)
+++ bval/sandbox/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/StubConstraint.java Fri Jan 3 00:04:23 2014
@@ -35,15 +35,12 @@ import org.apache.bval.jsr303.Constraint
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.reflect.MethodUtils;
import org.apache.commons.lang3.reflect.TypeUtils;
-import org.apache.commons.proxy2.stub.AnnotationConfigurer;
-import org.apache.commons.proxy2.stub.AnnotationFactory;
-import org.apache.commons.proxy2.stub.StubConfigurer;
+import org.apache.commons.proxy2.stub.AnnotationBuilder;
+import org.apache.commons.proxy2.stub.AnnotationTrainer;
+import org.apache.commons.proxy2.stub.Trainer;
/**
* Fluent interface for building constraints.
- *
- * @version $Rev$ $Date: 2010-10-10 10:35:19 -0500 (Sun, 10 Oct 2010)
- * $
*/
public class StubConstraint {
/**
@@ -51,70 +48,70 @@ public class StubConstraint {
*/
public static class Builder {
- private EnumMap<ConstraintAnnotationAttributes, Object> attributes =
+ private final EnumMap<ConstraintAnnotationAttributes, Object> attributes =
new EnumMap<ConstraintAnnotationAttributes, Object>(
ConstraintAnnotationAttributes.class);
- private class Config<A extends Annotation> extends
- AnnotationConfigurer<A> {
+ private class Config<A extends Annotation> extends AnnotationTrainer<A> {
/**
* Create a new StubConstraint.Builder.Config instance.
*/
protected Config() {
super();
- validateConstraintType(getStubType());
+ validateConstraintType(traineeType);
}
private Config(Class<A> type) {
super(type);
- validateConstraintType(getStubType());
+ validateConstraintType(traineeType);
}
/**
* {@inheritDoc}
*/
@Override
- protected void configure(final A stub) {
- for (final Map.Entry<ConstraintAnnotationAttributes, Object> e : StubConstraint.Builder.this.attributes
+ protected void train(final A stub) {
+ for (final Map.Entry<ConstraintAnnotationAttributes, Object> e : attributes
.entrySet()) {
when(
getAttribute(e.getKey().getAttributeName(),
- getStubType(), stub)).thenReturn(e.getValue());
+ traineeType, stub)).thenReturn(e.getValue());
}
}
private A build() {
- return AnnotationFactory.INSTANCE.create(this);
+ return AnnotationBuilder.of(traineeType).train(this).build();
}
}
/**
- * Custom constraint configurer.
- *
+ * Custom constraint trainer.
+ *
* @param <A>
*/
- public abstract class CustomConfig<A extends Annotation> extends
+ public abstract class CustomTrainer<A extends Annotation> extends
Config<A> {
/**
* {@inheritDoc}
*/
- protected final void configure(A stub) {
- super.configure(stub);
- customConfigure(stub);
+ @Override
+ protected final void train(A stub) {
+ super.train(stub);
+ customTrain(stub);
}
/**
- * Perform configuration specific to the constraint type.
- *
+ * Perform training specific to the constraint type.
+ *
* @param stub
*/
- protected abstract void customConfigure(A stub);
+ protected abstract void customTrain(A stub);
/**
* Build the constraint annotation.
- *
+ *
* @return A
*/
public A build() {
@@ -130,7 +127,7 @@ public class StubConstraint {
/**
* Set the groups that will be set on built constraints.
- *
+ *
* @param groups
* @return this, per fluent/chained idiom
*/
@@ -141,7 +138,7 @@ public class StubConstraint {
/**
* Set the message that will be set on built constraints.
- *
+ *
* @param message
* @return this, per fluent/chained idiom
*/
@@ -152,7 +149,7 @@ public class StubConstraint {
/**
* Set the payload that will be set on built constraints.
- *
+ *
* @param payload
* @return this, per fluent/chained idiom
*/
@@ -165,7 +162,7 @@ public class StubConstraint {
/**
* Get a ConstraintConfig stub configurer for the specified type, with
* default or no custom attributes.
- *
+ *
* @param <A>
* @param type
* @return ConstraintConfig<A>
@@ -182,7 +179,7 @@ public class StubConstraint {
/**
* Get a builder for refining built constraints.
- *
+ *
* @return StubConstraint.Builder instance
*/
public static StubConstraint.Builder build() {
@@ -191,7 +188,7 @@ public class StubConstraint {
/**
* Build a default constraint annotation of type
- *
+ *
* @param <A>
* @param type
* @return
@@ -202,7 +199,7 @@ public class StubConstraint {
/**
* Build a multivalued annotation.
- *
+ *
* @param <A>
* @param <M>
* @param type
@@ -239,17 +236,14 @@ public class StubConstraint {
validateConstraintType(constraintType);
}
- return AnnotationFactory.INSTANCE.create(new StubConfigurer<M>(type) {
+ return AnnotationBuilder.of(type).train(new Trainer<M>(type) {
- /**
- * {@inheritDoc}
- */
@Override
- protected void configure(M stub) {
+ protected void train(M stub) {
when(getAttribute(VALUE.getAttributeName(), type, stub))
.thenReturn(value);
}
- });
+ }).build();
}
private static <A extends Annotation> void validateConstraintType(
@@ -264,7 +258,7 @@ public class StubConstraint {
* Reimplement the retrieval of attribute values using an externally
* specified type; incomplete stubbed annotations cannot answer
* {@link Annotation#annotationType()}.
- *
+ *
* @param attributeName
* @param type
* @param instance
Modified: bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/constraints/dynamic/NullValueValidationTest.java
URL: http://svn.apache.org/viewvc/bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/constraints/dynamic/NullValueValidationTest.java?rev=1554975&r1=1554974&r2=1554975&view=diff
==============================================================================
--- bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/constraints/dynamic/NullValueValidationTest.java (original)
+++ bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/constraints/dynamic/NullValueValidationTest.java Fri Jan 3 00:04:23 2014
@@ -16,8 +16,11 @@
*/
package org.apache.bval.constraints.dynamic;
-import static org.junit.Assert.*;
-import static org.apache.bval.constraints.dynamic.NullValue.Rule.*;
+import static org.apache.bval.constraints.dynamic.NullValue.Rule.ALLOW;
+import static org.apache.bval.constraints.dynamic.NullValue.Rule.DENY;
+import static org.apache.bval.constraints.dynamic.NullValue.Rule.REQUIRE;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import java.util.Locale;
@@ -30,15 +33,16 @@ import org.apache.bval.jsr303.ApacheVali
import org.apache.bval.jsr303.DefaultMessageInterpolator;
import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
import org.apache.bval.jsr303.dynamic.DynamicValidatorFactory;
-import org.apache.commons.proxy2.stub.AnnotationFactory;
-import org.apache.commons.proxy2.stub.StubConfigurer;
+import org.apache.commons.proxy2.stub.AnnotationBuilder;
+import org.apache.commons.proxy2.stub.AnnotationTrainer;
import org.junit.Before;
import org.junit.Test;
/**
* Test {@link NullValue} validation.
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2010-10-07 10:56:07 -0500 (Thu, 07 Oct 2010)
+ * $
*/
public class NullValueValidationTest {
@@ -195,16 +199,21 @@ public class NullValueValidationTest {
*
* // blank slate private Object hoo;
*
- * @NullValue.List({ @NullValue(value=REQUIRE, groups=X.class), @NullValue(value=DENY, groups=Y.class)}) private
- * Object groo;
+ * @NullValue.List({ @NullValue(value=REQUIRE, groups=X.class),
+ * @NullValue(value=DENY, groups=Y.class)}) private Object groo;
*/
@Test
public void testAppend() throws Exception {
- validatorContext.constrain(TestBean.class, "foo", nullValue(ALLOW)); // was REQUIRE
- validatorContext.constrain(TestBean.class, "bar", nullValue(DENY)); // was REQUIRE
- validatorContext.constrain(TestBean.class, "baz", nullValue(REQUIRE)); // was ALLOW
- validatorContext.constrain(TestBean.class, "boo", nullValue(REQUIRE)); // was DENY
- validatorContext.constrain(TestBean.class, "hoo", nullValue(REQUIRE)); // was unspecified
+ validatorContext.constrain(TestBean.class, "foo", nullValue(ALLOW)); // was
+ // REQUIRE
+ validatorContext.constrain(TestBean.class, "bar", nullValue(DENY)); // was
+ // REQUIRE
+ validatorContext.constrain(TestBean.class, "baz", nullValue(REQUIRE)); // was
+ // ALLOW
+ validatorContext.constrain(TestBean.class, "boo", nullValue(REQUIRE)); // was
+ // DENY
+ validatorContext.constrain(TestBean.class, "hoo", nullValue(REQUIRE)); // was
+ // unspecified
assertEquals(0, validator.validateProperty(testBean, "foo").size());
assertEquals(0, validator.validateValue(TestBean.class, "foo", "whatever").size());
@@ -219,11 +228,16 @@ public class NullValueValidationTest {
@Test
public void testMultilevelAppend() throws Exception {
- validatorContext.constrain(TestBeanHolder.class, "testBean.foo", nullValue(ALLOW)); // was REQUIRE
- validatorContext.constrain(TestBeanHolder.class, "testBean.bar", nullValue(DENY)); // was REQUIRE
- validatorContext.constrain(TestBeanHolder.class, "testBean.baz", nullValue(REQUIRE)); // was ALLOW
- validatorContext.constrain(TestBeanHolder.class, "testBean.boo", nullValue(REQUIRE)); // was DENY
- validatorContext.constrain(TestBeanHolder.class, "testBean.hoo", nullValue(REQUIRE)); // was unspecified
+ validatorContext.constrain(TestBeanHolder.class, "testBean.foo", nullValue(ALLOW)); // was
+ // REQUIRE
+ validatorContext.constrain(TestBeanHolder.class, "testBean.bar", nullValue(DENY)); // was
+ // REQUIRE
+ validatorContext.constrain(TestBeanHolder.class, "testBean.baz", nullValue(REQUIRE)); // was
+ // ALLOW
+ validatorContext.constrain(TestBeanHolder.class, "testBean.boo", nullValue(REQUIRE)); // was
+ // DENY
+ validatorContext.constrain(TestBeanHolder.class, "testBean.hoo", nullValue(REQUIRE)); // was
+ // unspecified
TestBeanHolder holder = new TestBeanHolder(testBean);
assertEquals(0, validator.validateProperty(holder, "testBean.foo").size());
@@ -239,9 +253,18 @@ public class NullValueValidationTest {
@Test
public void testAppendWithGroups() throws Exception {
- validatorContext.constrain(TestBean.class, "foo", nullValue(DENY, W.class)); // group W was unspecified but
- // default is REQUIRE
- validatorContext.constrain(TestBean.class, "groo", nullValue(REQUIRE, W.class)); // group W was unspecified
+ validatorContext.constrain(TestBean.class, "foo", nullValue(DENY, W.class)); // group
+ // W
+ // was
+ // unspecified
+ // but
+ // default
+ // is
+ // REQUIRE
+ validatorContext.constrain(TestBean.class, "groo", nullValue(REQUIRE, W.class)); // group
+ // W
+ // was
+ // unspecified
assertEquals(0, validator.validateProperty(testBean, "foo").size());
assertEquals(1, validator.validateProperty(testBean, "foo", W.class).size());
@@ -251,11 +274,17 @@ public class NullValueValidationTest {
@Test
public void testMultilevelAppendWithGroups() throws Exception {
- validatorContext.constrain(TestBeanHolder.class, "testBean.foo", nullValue(DENY, W.class)); // group W was
- // unspecified but
- // default is
+ validatorContext.constrain(TestBeanHolder.class, "testBean.foo", nullValue(DENY, W.class)); // group
+ // W
+ // was
+ // unspecified
+ // but
+ // default
+ // is
// REQUIRE
- validatorContext.constrain(TestBeanHolder.class, "testBean.groo", nullValue(REQUIRE, W.class)); // group W was
+ validatorContext.constrain(TestBeanHolder.class, "testBean.groo", nullValue(REQUIRE, W.class)); // group
+ // W
+ // was
// unspecified
TestBeanHolder holder = new TestBeanHolder(testBean);
@@ -272,13 +301,13 @@ public class NullValueValidationTest {
}
private NullValue nullValue(final NullValue.Rule rule, final Class<?>... groups) {
- return AnnotationFactory.INSTANCE.create(new StubConfigurer<NullValue>() {
+ return AnnotationBuilder.of(NullValue.class).train(new AnnotationTrainer<NullValue>() {
@Override
- protected void configure(NullValue stub) {
+ protected void train(NullValue stub) {
when(stub.value()).thenReturn(rule).when(stub.groups()).thenReturn(groups);
}
- });
+ }).build();
}
}
Modified: bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/constraints/dynamic/ValuesConstraintValidationTest.java
URL: http://svn.apache.org/viewvc/bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/constraints/dynamic/ValuesConstraintValidationTest.java?rev=1554975&r1=1554974&r2=1554975&view=diff
==============================================================================
--- bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/constraints/dynamic/ValuesConstraintValidationTest.java (original)
+++ bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/constraints/dynamic/ValuesConstraintValidationTest.java Fri Jan 3 00:04:23 2014
@@ -42,16 +42,17 @@ import org.apache.bval.jsr303.dynamic.Co
import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
import org.apache.bval.jsr303.dynamic.DynamicValidatorFactory;
import org.apache.bval.jsr303.dynamic.StubConstraint;
-import org.apache.commons.proxy2.stub.AnnotationFactory;
-import org.apache.commons.proxy2.stub.StubConfigurer;
+import org.apache.commons.proxy2.stub.AnnotationBuilder;
+import org.apache.commons.proxy2.stub.AnnotationTrainer;
import org.junit.Before;
import org.junit.Test;
/**
- * Test the {@link Values} and {@link Values.Labeled} constraints, as well as their provided {@link ConstraintValidator}
- * s and {@link ConstraintAppender}s.
+ * Test the {@link Values} and {@link Values.Labeled} constraints, as well as
+ * their provided {@link ConstraintValidator} s and {@link ConstraintAppender}s.
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2011-06-02 12:52:02 -0500 (Thu, 02 Jun 2011)
+ * $
*/
public class ValuesConstraintValidationTest {
public static class TestBean {
@@ -135,11 +136,9 @@ public class ValuesConstraintValidationT
short s;
@Values({ "0", "1", "2" })
int i;
- @Values.Labeled({//@formatter:off
- @Item(label = "zero", value = "0"),
- @Item(label = "one", value = "1"),
- @Item(label = "two", value = "2")
- })//@formatter:on
+ @Values.Labeled({// @formatter:off
+ @Item(label = "zero", value = "0"), @Item(label = "one", value = "1"), @Item(label = "two", value = "2") })
+ // @formatter:on
long l;
@Values(value = { "Infinity", "-Infinity", "NaN" }, rule = Rule.EXCLUDE)
float f;
@@ -179,11 +178,9 @@ public class ValuesConstraintValidationT
Short s;
@Values({ "0", "1", "2" })
Integer i;
- @Values.Labeled({//@formatter:off
- @Item(label = "zero", value = "0"),
- @Item(label = "one", value = "1"),
- @Item(label = "two", value = "2")
- })//@formatter:on
+ @Values.Labeled({// @formatter:off
+ @Item(label = "zero", value = "0"), @Item(label = "one", value = "1"), @Item(label = "two", value = "2") })
+ // @formatter:on
Long l;
@Values(value = { "Infinity", "-Infinity", "NaN" }, rule = Rule.EXCLUDE)
Float f;
@@ -248,7 +245,6 @@ public class ValuesConstraintValidationT
private Validator validator;
private DynamicValidatorContext validatorContext;
- private final AnnotationFactory annotationFactory = new AnnotationFactory();
private TestBean testBean;
private StringBean stringBean;
private PrimitiveBean primitiveBean;
@@ -536,39 +532,39 @@ public class ValuesConstraintValidationT
assertEquals(0, validator.validate(testBean).size());
validatorContext.constrain(TestBean.class, "fooBarOrBaz",
- annotationFactory.create(new StubConfigurer<Values>() {
+ AnnotationBuilder.of(Values.class).train(new AnnotationTrainer<Values>() {
@Override
- protected void configure(Values stub) {
+ protected void train(Values stub) {
when(stub.value()).thenReturn("foo").when(stub.rule()).thenReturn(Rule.EXCLUDE)
.when(stub.strategy()).thenReturn(Strategy.MERGE);
}
- }));
+ }).build());
assertEquals(0, validator.validate(testBean).size());
testBean.fooBarOrBaz = "foo";
assertEquals(1, validator.validate(testBean).size());
validatorContext.constrain(TestBean.class, "fooBarOrBaz",
- annotationFactory.create(new StubConfigurer<Values>() {
+ AnnotationBuilder.of(Values.class).train(new AnnotationTrainer<Values>() {
@Override
- protected void configure(Values stub) {
+ protected void train(Values stub) {
when(stub.value()).thenReturn("blah").when(stub.strategy()).thenReturn(Strategy.MERGE);
}
- }));
+ }).build());
assertEquals(1, validator.validate(testBean).size());
testBean.fooBarOrBaz = "blah";
assertEquals(0, validator.validate(testBean).size());
validatorContext.constrain(TestBean.class, "fooBarOrBaz",
- annotationFactory.create(new StubConfigurer<Values>() {
+ AnnotationBuilder.of(Values.class).train(new AnnotationTrainer<Values>() {
@Override
- protected void configure(Values stub) {
+ protected void train(Values stub) {
when(stub.value()).thenReturn("foo").when(stub.strategy()).thenReturn(Strategy.MERGE);
}
- }));
+ }).build());
assertEquals(0, validator.validate(testBean).size());
testBean.fooBarOrBaz = "foo";
@@ -586,29 +582,30 @@ public class ValuesConstraintValidationT
testBean.fooBarOrBaz = "foo";
assertEquals(0, validator.validateProperty(testBean, "fooBarOrBaz").size());
StubConstraint.Builder builder = StubConstraint.build();
- validatorContext.constrain(TestBean.class, "fooBarOrBaz", builder.new CustomConfig<Values>() {
+ validatorContext.constrain(TestBean.class, "fooBarOrBaz", builder.new CustomTrainer<Values>() {
@Override
- protected void customConfigure(Values stub) {
+ protected void customTrain(Values stub) {
when(stub.value()).thenReturn("foo", "bar", "baz");
}
}.build());
assertEquals(0, validator.validateProperty(testBean, "fooBarOrBaz").size());
- validatorContext.constrain(TestBean.class, "fooBarOrBaz", builder.new CustomConfig<Values>() {
+ validatorContext.constrain(TestBean.class, "fooBarOrBaz", builder.new CustomTrainer<Values>() {
@Override
- protected void customConfigure(Values stub) {
+ protected void customTrain(Values stub) {
when(stub.value()).thenReturn(/* nothing */);
}
}.build());
assertEquals(1, validator.validateProperty(testBean, "fooBarOrBaz").size());
- // verify that constraint merging did not eliminate the empty values entirely when re-applying:
- validatorContext.constrain(TestBean.class, "fooBarOrBaz", builder.new CustomConfig<Values>() {
+ // verify that constraint merging did not eliminate the empty values
+ // entirely when re-applying:
+ validatorContext.constrain(TestBean.class, "fooBarOrBaz", builder.new CustomTrainer<Values>() {
@Override
- protected void customConfigure(Values stub) {
+ protected void customTrain(Values stub) {
when(stub.value()).thenReturn(/* nothing */);
}
}.build());
@@ -620,42 +617,42 @@ public class ValuesConstraintValidationT
testBean.annotationOrConstructor = ElementType.ANNOTATION_TYPE;
assertEquals(0, validator.validate(testBean).size());
- validatorContext.constrain(TestBean.class, "annotationOrConstructor",
- annotationFactory.create(new StubConfigurer<Values.Labeled>() {
+ validatorContext.constrain(TestBean.class, "annotationOrConstructor", AnnotationBuilder
+ .of(Values.Labeled.class).train(new AnnotationTrainer<Values.Labeled>() {
@Override
- protected void configure(Values.Labeled stub) {
- when(stub.value()).thenReturn(item(ElementType.CONSTRUCTOR, "new")).when(stub.rule())
- .thenReturn(Rule.EXCLUDE).when(stub.strategy()).thenReturn(Strategy.MERGE);
+ protected void train(Labeled stub) {
+ when(stub.value()).thenBuildArray().addElement(item(ElementType.CONSTRUCTOR, "new")).build();
+ when(stub.rule()).thenReturn(Rule.EXCLUDE).when(stub.strategy()).thenReturn(Strategy.MERGE);
}
- }));
+ }).build());
assertEquals(0, validator.validate(testBean).size());
testBean.annotationOrConstructor = ElementType.CONSTRUCTOR;
assertEquals(1, validator.validate(testBean).size());
- validatorContext.constrain(TestBean.class, "annotationOrConstructor",
- annotationFactory.create(new StubConfigurer<Values.Labeled>() {
+ validatorContext.constrain(TestBean.class, "annotationOrConstructor", AnnotationBuilder
+ .of(Values.Labeled.class).train(new AnnotationTrainer<Values.Labeled>() {
@Override
- protected void configure(Values.Labeled stub) {
- when(stub.value()).thenReturn(item(ElementType.FIELD, ".")).when(stub.strategy())
- .thenReturn(Strategy.MERGE);
+ protected void train(Labeled stub) {
+ when(stub.value()).thenBuildArray().addElement(item(ElementType.FIELD, ".")).build();
+ when(stub.strategy()).thenReturn(Strategy.MERGE);
}
- }));
+ }).build());
assertEquals(1, validator.validate(testBean).size());
testBean.annotationOrConstructor = ElementType.FIELD;
assertEquals(0, validator.validate(testBean).size());
- validatorContext.constrain(TestBean.class, "annotationOrConstructor",
- annotationFactory.create(new StubConfigurer<Values.Labeled>() {
+ validatorContext.constrain(TestBean.class, "annotationOrConstructor", AnnotationBuilder
+ .of(Values.Labeled.class).train(new AnnotationTrainer<Values.Labeled>() {
@Override
- protected void configure(Values.Labeled stub) {
- when(stub.value()).thenReturn(item(ElementType.CONSTRUCTOR, "new")).when(stub.strategy())
- .thenReturn(Strategy.MERGE);
+ protected void train(Labeled stub) {
+ when(stub.value()).thenBuildArray().addElement(item(ElementType.CONSTRUCTOR, "new")).build();
+ when(stub.strategy()).thenReturn(Strategy.MERGE);
}
- }));
+ }).build());
assertEquals(0, validator.validate(testBean).size());
testBean.annotationOrConstructor = ElementType.CONSTRUCTOR;
@@ -669,24 +666,26 @@ public class ValuesConstraintValidationT
@Test
public void testValuesConstraintAccumulationGrouping() {
validatorContext.constrain(TestBean.class, "fooBarOrBaz",
- annotationFactory.create(new StubConfigurer<Values>() {
+ AnnotationBuilder.of(Values.class).train(new AnnotationTrainer<Values>() {
@Override
- protected void configure(Values stub) {
+ protected void train(Values stub) {
when(stub.groups()).thenReturn(X.class).when(stub.rule()).thenReturn(Rule.EXCLUDE)
.when(stub.value()).thenReturn("anythingButThis").when(stub.message())
.thenReturn("anything but 'anythingButThis' in group X");
}
- }));
+ }).build());
+
validatorContext.constrain(TestBean.class, "fooBarOrBaz",
- annotationFactory.create(new StubConfigurer<Values>() {
+ AnnotationBuilder.of(Values.class).train(new AnnotationTrainer<Values>() {
@Override
- protected void configure(Values stub) {
+ protected void train(Values stub) {
when(stub.groups()).thenReturn(Y.class).when(stub.value()).thenReturn("onlyThis")
.when(stub.message()).thenReturn("only 'onlyThis' in group Y");
}
- }));
+ }).build());
+
testBean.fooBarOrBaz = "foo";
assertEquals(0, validator.validate(testBean).size());
assertEquals(0, validator.validate(testBean, X.class).size());
@@ -706,13 +705,13 @@ public class ValuesConstraintValidationT
assertEquals(0, validator.validate(testBean, X.class, Y.class).size());
validatorContext.constrain(TestBean.class, "fooBarOrBaz",
- annotationFactory.create(new StubConfigurer<Values>() {
+ AnnotationBuilder.of(Values.class).train(new AnnotationTrainer<Values>() {
@Override
- protected void configure(Values stub) {
+ protected void train(Values stub) {
when(stub.groups()).thenReturn(Y.class).when(stub.value()).thenReturn("foo", "bar", "baz");
}
- }));
+ }).build());
testBean.fooBarOrBaz = "foo";
assertEquals(0, validator.validate(testBean).size());
@@ -742,15 +741,15 @@ public class ValuesConstraintValidationT
assertEquals(2, validator.getConstraintsForClass(TestBean.class).getConstraintsForProperty("fooBarOrBaz")
.getConstraintDescriptors().size());
validatorContext.constrain(TestBean.class, "fooBarOrBaz",
- annotationFactory.create(new StubConfigurer<Values>() {
+ AnnotationBuilder.of(Values.class).train(new AnnotationTrainer<Values>() {
@Override
- protected void configure(Values stub) {
+ protected void train(Values stub) {
when(stub.groups()).thenReturn(Y.class).when(stub.rule()).thenReturn(Rule.EXCLUDE)
.when(stub.strategy()).thenReturn(Strategy.MERGE).when(stub.value())
.thenReturn("foo", "bar", "baz");
}
- }));
+ }).build());
assertEquals(2, validator.getConstraintsForClass(TestBean.class).getConstraintsForProperty("fooBarOrBaz")
.getConstraintDescriptors().size());
@@ -758,26 +757,28 @@ public class ValuesConstraintValidationT
@Test
public void testLabeledValuesConstraintAccumulationGrouping() {
- validatorContext.constrain(TestBean.class, "annotationOrConstructor",
- annotationFactory.create(new StubConfigurer<Values.Labeled>() {
+ validatorContext.constrain(TestBean.class, "annotationOrConstructor", AnnotationBuilder
+ .of(Values.Labeled.class).train(new AnnotationTrainer<Values.Labeled>() {
@Override
- protected void configure(Labeled stub) {
+ protected void train(Labeled stub) {
when(stub.groups()).thenReturn(X.class).when(stub.rule()).thenReturn(Rule.EXCLUDE)
- .when(stub.value()).thenReturn(item(ElementType.FIELD, ".")).when(stub.message())
- .thenReturn("anything but ('.'/FIELD) in group X");
+ .when(stub.value()).thenBuildArray().addElement(item(ElementType.FIELD, ".")).build()
+ .when(stub.message()).thenReturn("anything but ('.'/FIELD) in group X");
}
- }));
- validatorContext.constrain(TestBean.class, "annotationOrConstructor",
- annotationFactory.create(new StubConfigurer<Values.Labeled>() {
+ }).build());
+
+ validatorContext.constrain(TestBean.class, "annotationOrConstructor", AnnotationBuilder
+ .of(Values.Labeled.class).train(new AnnotationTrainer<Values.Labeled>() {
@Override
- protected void configure(Labeled stub) {
- when(stub.groups()).thenReturn(Y.class).when(stub.value())
- .thenReturn(item(ElementType.METHOD, "()")).when(stub.message())
- .thenReturn("only ('()'/METHOD) in group Y");
+ protected void train(Labeled stub) {
+ when(stub.groups()).thenReturn(Y.class).when(stub.value()).thenBuildArray()
+ .addElement(item(ElementType.METHOD, "()")).build();
+ when(stub.message()).thenReturn("only ('()'/METHOD) in group Y");
}
- }));
+ }).build());
+
testBean.annotationOrConstructor = ElementType.ANNOTATION_TYPE;
assertEquals(0, validator.validate(testBean).size());
assertEquals(0, validator.validate(testBean, X.class).size());
@@ -796,15 +797,16 @@ public class ValuesConstraintValidationT
assertEquals(0, validator.validate(testBean, Y.class).size());
assertEquals(0, validator.validate(testBean, X.class, Y.class).size());
- validatorContext.constrain(TestBean.class, "annotationOrConstructor",
- annotationFactory.create(new StubConfigurer<Values.Labeled>() {
+ validatorContext.constrain(TestBean.class, "annotationOrConstructor", AnnotationBuilder
+ .of(Values.Labeled.class).train(new AnnotationTrainer<Values.Labeled>() {
@Override
- protected void configure(Labeled stub) {
- when(stub.groups()).thenReturn(Y.class).when(stub.value())
- .thenReturn(item(ElementType.ANNOTATION_TYPE, "@"), item(ElementType.CONSTRUCTOR, "new"));
+ protected void train(Labeled stub) {
+ when(stub.groups()).thenReturn(Y.class).when(stub.value()).thenBuildArray()
+ .addElement(item(ElementType.ANNOTATION_TYPE, "@"))
+ .addElement(item(ElementType.CONSTRUCTOR, "new")).build();
}
- }));
+ }).build());
testBean.annotationOrConstructor = ElementType.ANNOTATION_TYPE;
assertEquals(0, validator.validate(testBean).size());
@@ -828,16 +830,17 @@ public class ValuesConstraintValidationT
assertEquals(2,
validator.getConstraintsForClass(TestBean.class).getConstraintsForProperty("annotationOrConstructor")
.getConstraintDescriptors().size());
- validatorContext.constrain(TestBean.class, "annotationOrConstructor",
- annotationFactory.create(new StubConfigurer<Values.Labeled>() {
+ validatorContext.constrain(TestBean.class, "annotationOrConstructor", AnnotationBuilder
+ .of(Values.Labeled.class).train(new AnnotationTrainer<Values.Labeled>() {
@Override
- protected void configure(Labeled stub) {
+ protected void train(Labeled stub) {
when(stub.groups()).thenReturn(Y.class).when(stub.rule()).thenReturn(Rule.EXCLUDE)
- .when(stub.strategy()).thenReturn(Strategy.MERGE).when(stub.value())
- .thenReturn(item(ElementType.ANNOTATION_TYPE, "@"), item(ElementType.CONSTRUCTOR, "new"));
+ .when(stub.strategy()).thenReturn(Strategy.MERGE).when(stub.value()).thenBuildArray()
+ .addElement(item(ElementType.ANNOTATION_TYPE, "@"))
+ .addElement(item(ElementType.CONSTRUCTOR, "new")).build();
}
- }));
+ }).build());
assertEquals(2,
validator.getConstraintsForClass(TestBean.class).getConstraintsForProperty("annotationOrConstructor")
@@ -903,14 +906,13 @@ public class ValuesConstraintValidationT
public interface Z extends X, Y {
}
- private Values.Labeled.Item item(final ElementType elementType, final String label) {
- return annotationFactory.create(new StubConfigurer<Values.Labeled.Item>() {
+ private AnnotationTrainer<Values.Labeled.Item> item(final ElementType elementType, final String label) {
+ return new AnnotationTrainer<Values.Labeled.Item>() {
@Override
- protected void configure(Item stub) {
+ protected void train(Item stub) {
when(stub.label()).thenReturn(label).when(stub.value()).thenReturn(elementType.name());
}
- });
-
+ };
}
}
Modified: bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicBeanDescriptorTest.java
URL: http://svn.apache.org/viewvc/bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicBeanDescriptorTest.java?rev=1554975&r1=1554974&r2=1554975&view=diff
==============================================================================
--- bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicBeanDescriptorTest.java (original)
+++ bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicBeanDescriptorTest.java Fri Jan 3 00:04:23 2014
@@ -30,13 +30,14 @@ import org.apache.bval.jsr303.BeanDescri
import org.apache.bval.jsr303.DefaultMessageInterpolator;
import org.apache.bval.jsr303.example.First;
import org.apache.bval.jsr303.util.TestUtils;
-import org.apache.commons.proxy2.stub.AnnotationFactory;
-import org.apache.commons.proxy2.stub.StubConfigurer;
+import org.apache.commons.proxy2.stub.AnnotationBuilder;
+import org.apache.commons.proxy2.stub.AnnotationTrainer;
/**
*
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2011-02-21 12:14:45 -0600 (Mon, 21 Feb 2011)
+ * $
*/
public class DynamicBeanDescriptorTest extends BeanDescriptorTest {
@@ -74,29 +75,30 @@ public class DynamicBeanDescriptorTest e
NotNull.class);
validatorContext.constrain(Person.class, "name",
- AnnotationFactory.INSTANCE.create(new StubConfigurer<Pattern>() {
+ AnnotationBuilder.of(Pattern.class).train(new AnnotationTrainer<Pattern>() {
/**
* {@inheritDoc}
*/
@Override
- protected void configure(Pattern stub) {
+ protected void train(Pattern stub) {
when(stub.regexp()).thenReturn("[A-Za-z].*").when(stub.groups()).thenReturn(First.class);
}
- }));
+ }).build());
TestUtils.assertConstraintTypesFound(
validator.getConstraintsForClass(Woman.class).getConstraintsForProperty("name").findConstraints(),
NotNull.class, Pattern.class);
- validatorContext.constrain(Person.class, "name", AnnotationFactory.INSTANCE.create(new StubConfigurer<Size>() {
- /**
- * {@inheritDoc}
- */
- @Override
- protected void configure(Size stub) {
- when(stub.min()).thenReturn(1);
- }
- }));
+ validatorContext.constrain(Person.class, "name",
+ AnnotationBuilder.of(Size.class).train(new AnnotationTrainer<Size>() {
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void train(Size stub) {
+ when(stub.min()).thenReturn(1);
+ }
+ }).build());
TestUtils.assertConstraintTypesFound(
validator.getConstraintsForClass(Woman.class).getConstraintsForProperty("name").findConstraints(),
Modified: bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicCollectionValidationTest.java
URL: http://svn.apache.org/viewvc/bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicCollectionValidationTest.java?rev=1554975&r1=1554974&r2=1554975&view=diff
==============================================================================
--- bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicCollectionValidationTest.java (original)
+++ bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicCollectionValidationTest.java Fri Jan 3 00:04:23 2014
@@ -30,8 +30,6 @@ import org.apache.bval.constraints.Autho
import org.apache.bval.jsr303.ApacheValidationProvider;
import org.apache.bval.jsr303.ApacheValidatorConfiguration;
import org.apache.bval.jsr303.DefaultMessageInterpolator;
-import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
-import org.apache.bval.jsr303.dynamic.DynamicValidatorFactory;
import org.apache.bval.jsr303.example.Address;
import org.apache.bval.jsr303.example.Author;
import org.apache.bval.jsr303.example.Book;
@@ -39,18 +37,17 @@ import org.apache.bval.jsr303.example.Co
import org.apache.bval.jsr303.example.Library;
import org.apache.bval.jsr303.groups.CollectionValidationTest;
import org.apache.bval.jsr303.util.TestUtils;
-import org.apache.commons.proxy2.stub.AnnotationConfigurer;
-import org.apache.commons.proxy2.stub.AnnotationFactory;
-import org.apache.commons.proxy2.stub.StubConfigurer;
+import org.apache.commons.proxy2.stub.AnnotationBuilder;
+import org.apache.commons.proxy2.stub.AnnotationTrainer;
/**
*
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2011-02-01 16:52:48 -0600 (Tue, 01 Feb 2011)
+ * $
*/
public class DynamicCollectionValidationTest extends CollectionValidationTest {
- private final AnnotationFactory annotationFactory = new AnnotationFactory();
private DynamicValidatorContext validatorContext;
/**
@@ -122,8 +119,8 @@ public class DynamicCollectionValidation
violations = validator.validate(lib);
assertTrue(violations.isEmpty());
- validatorContext.constrain(Library.class, "taggedBooks[].author", annotationFactory
- .create(AuthorAddressKnown.class));
+ validatorContext.constrain(Library.class, "taggedBooks[].author",
+ AnnotationBuilder.buildDefault(AuthorAddressKnown.class));
violations = validator.validate(lib);
assertEquals(2, violations.size());
@@ -137,22 +134,22 @@ public class DynamicCollectionValidation
// mix different constraint levels, plus wildcard key at one level,
// explicit index at another:
- validatorContext.constrain(Book.class, "author.addresses[0].addressline1", annotationFactory
- .create(new StubConfigurer<Pattern>() {
+ validatorContext.constrain(Book.class, "author.addresses[0].addressline1", AnnotationBuilder.of(Pattern.class)
+ .train(new AnnotationTrainer<Pattern>() {
/**
* {@inheritDoc}
*/
@Override
- protected void configure(Pattern stub) {
+ protected void train(Pattern stub) {
when(stub.regexp()).thenReturn("[0..9]+.*");
}
- }));
+ }).build());
violations = validator.validate(lib);
assertEquals(3, violations.size());
assertNotNull(TestUtils.getViolation(violations, "taggedBooks[science].author.addresses[0].addressline1"));
}
-
+
public void testDynamicMultilevelGenericIterable() {
Library lib = new Library();
lib.setLibraryName("Leibnitz Bibliothek");
@@ -206,22 +203,24 @@ public class DynamicCollectionValidation
lib.getTaggedBooks().put("politics", book2);
lib.getTaggedBooks().put("self-help", book3);
- validatorContext.constrain(Library.class, "taggedBooks[].author.addresses[].city", annotationFactory.create(new AnnotationConfigurer<Pattern>() {
-
- @Override
- protected void configure(Pattern stub) {
- when(stub.regexp()).thenReturn("[A-Z].*");
- }
- }));
-
- validatorContext.constrain(Library.class, "taggedBooks[self-help].author.addresses[].city", annotationFactory.create(new AnnotationConfigurer<Min>() {
-
- @Override
- protected void configure(Min stub) {
- when(stub.value()).thenReturn(1L);
- }
- }));
-
+ validatorContext.constrain(Library.class, "taggedBooks[].author.addresses[].city",
+ AnnotationBuilder.of(Pattern.class).train(new AnnotationTrainer<Pattern>() {
+
+ @Override
+ protected void train(Pattern stub) {
+ when(stub.regexp()).thenReturn("[A-Z].*");
+ }
+ }).build());
+
+ validatorContext.constrain(Library.class, "taggedBooks[self-help].author.addresses[].city", AnnotationBuilder
+ .of(Min.class).train(new AnnotationTrainer<Min>() {
+
+ @Override
+ protected void train(Min stub) {
+ when(stub.value()).thenReturn(1L);
+ }
+ }).build());
+
Set<ConstraintViolation<Library>> violations;
violations = validator.validate(lib);
Modified: bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicJsr303Test.java
URL: http://svn.apache.org/viewvc/bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicJsr303Test.java?rev=1554975&r1=1554974&r2=1554975&view=diff
==============================================================================
--- bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicJsr303Test.java (original)
+++ bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicJsr303Test.java Fri Jan 3 00:04:23 2014
@@ -26,15 +26,14 @@ import org.apache.bval.jsr303.ApacheVali
import org.apache.bval.jsr303.ApacheValidatorConfiguration;
import org.apache.bval.jsr303.DefaultMessageInterpolator;
import org.apache.bval.jsr303.Jsr303Test;
-import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
-import org.apache.bval.jsr303.dynamic.DynamicValidatorFactory;
import org.apache.bval.jsr303.example.IllustratedBook;
-import org.apache.commons.proxy2.stub.AnnotationFactory;
+import org.apache.commons.proxy2.stub.AnnotationBuilder;
/**
- *
- *
- * @version $Rev$ $Date$
+ *
+ *
+ * @version $Rev$ $Date: 2010-10-05 14:16:16 -0500 (Tue, 05 Oct 2010)
+ * $
*/
public class DynamicJsr303Test extends Jsr303Test {
@@ -46,9 +45,12 @@ public class DynamicJsr303Test extends J
@Override
public void setUp() throws Exception {
DynamicValidatorFactory factory =
- Validation.byProvider(ApacheValidationProvider.class).configure().addProperty(
- ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME,
- DynamicValidatorFactory.class.getName()).buildValidatorFactory().unwrap(DynamicValidatorFactory.class);
+ Validation
+ .byProvider(ApacheValidationProvider.class)
+ .configure()
+ .addProperty(ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME,
+ DynamicValidatorFactory.class.getName()).buildValidatorFactory()
+ .unwrap(DynamicValidatorFactory.class);
((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
validatorContext = factory.usingContext();
super.setUp();
@@ -63,7 +65,7 @@ public class DynamicJsr303Test extends J
}
public void testDynamicCascade() {
- validatorContext.constrain(IllustratedBook.class, "illustrator", AnnotationFactory.INSTANCE.create(Valid.class));
+ validatorContext.constrain(IllustratedBook.class, "illustrator", AnnotationBuilder.buildDefault(Valid.class));
assertEquals(0, validator.validateValue(IllustratedBook.class, "illustrator.firstName", "Edgar").size());
}
Modified: bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagementTest.java
URL: http://svn.apache.org/viewvc/bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagementTest.java?rev=1554975&r1=1554974&r2=1554975&view=diff
==============================================================================
--- bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagementTest.java (original)
+++ bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagementTest.java Fri Jan 3 00:04:23 2014
@@ -30,7 +30,7 @@ import org.apache.bval.jsr303.example.Bo
import org.apache.bval.model.FeaturesCapable;
import org.apache.bval.model.MetaBean;
import org.apache.bval.model.MetaProperty;
-import org.apache.commons.proxy2.stub.AnnotationFactory;
+import org.apache.commons.proxy2.stub.AnnotationBuilder;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -38,10 +38,11 @@ import org.junit.Test;
/**
* Test the {@link DynamicValidatorContext}'s meta-graph management.
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2011-08-19 17:52:44 -0500 (Fri, 19 Aug 2011)
+ * $
*/
public class DynamicMetaGraphManagementTest {
- private static final NotNull NOT_NULL = AnnotationFactory.INSTANCE.create(NotNull.class);
+ private static final NotNull NOT_NULL = AnnotationBuilder.buildDefault(NotNull.class);
private DynamicValidatorContext dynamicValidatorContext;
Modified: bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicValidationTest.java
URL: http://svn.apache.org/viewvc/bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicValidationTest.java?rev=1554975&r1=1554974&r2=1554975&view=diff
==============================================================================
--- bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicValidationTest.java (original)
+++ bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/DynamicValidationTest.java Fri Jan 3 00:04:23 2014
@@ -37,8 +37,6 @@ import org.apache.bval.jsr303.ApacheVali
import org.apache.bval.jsr303.ApacheValidatorConfiguration;
import org.apache.bval.jsr303.DefaultMessageInterpolator;
import org.apache.bval.jsr303.ValidationTest;
-import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
-import org.apache.bval.jsr303.dynamic.DynamicValidatorFactory;
import org.apache.bval.jsr303.example.Address;
import org.apache.bval.jsr303.example.Author;
import org.apache.bval.jsr303.example.Book;
@@ -46,17 +44,17 @@ import org.apache.bval.jsr303.example.Co
import org.apache.bval.jsr303.example.First;
import org.apache.bval.jsr303.example.ZipCodeCityCarrier;
import org.apache.bval.jsr303.util.TestUtils;
-import org.apache.commons.proxy2.stub.AnnotationFactory;
-import org.apache.commons.proxy2.stub.StubConfigurer;
+import org.apache.commons.proxy2.stub.AnnotationBuilder;
+import org.apache.commons.proxy2.stub.AnnotationTrainer;
/**
* Test dynamic bean validation.
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2011-06-22 16:06:16 -0500 (Wed, 22 Jun 2011)
+ * $
*/
public class DynamicValidationTest extends ValidationTest {
- private final AnnotationFactory annotationFactory = new AnnotationFactory();
private DynamicValidatorContext validatorContext;
/**
@@ -94,15 +92,14 @@ public class DynamicValidationTest exten
Set<ConstraintViolation<Book>> errors = validator.validate(book, Book.All.class);
assertTrue(errors.isEmpty());
- validatorContext.constrain(Book.class, "title", annotationFactory.create(new StubConfigurer<Pattern>() {
- /**
- * {@inheritDoc}
- */
- @Override
- protected void configure(Pattern stub) {
- when(stub.regexp()).thenReturn("[A-Za-z]*").when(stub.groups()).thenReturn(First.class);
- }
- }));
+ validatorContext.constrain(Book.class, "title",
+ AnnotationBuilder.of(Pattern.class).train(new AnnotationTrainer<Pattern>() {
+
+ @Override
+ protected void train(Pattern stub) {
+ when(stub.regexp()).thenReturn("[A-Za-z]*").when(stub.groups()).thenReturn(First.class);
+ }
+ }).build());
errors = validator.validate(book, Book.All.class);
assertTrue(errors.isEmpty());
@@ -136,15 +133,13 @@ public class DynamicValidationTest exten
assertTrue(errors.isEmpty());
validatorContext.constrain(Author.class, "addresses[].addressline2",
- annotationFactory.create(new StubConfigurer<Pattern>() {
- /**
- * {@inheritDoc}
- */
+ AnnotationBuilder.of(Pattern.class).train(new AnnotationTrainer<Pattern>() {
+
@Override
- protected void configure(Pattern stub) {
+ protected void train(Pattern stub) {
when(stub.regexp()).thenReturn("[0..9]+.*");
}
- }));
+ }).build());
errors = validator.validate(author);
assertTrue(errors.isEmpty());
@@ -154,7 +149,8 @@ public class DynamicValidationTest exten
errors = validator.validate(author);
assertEquals(1, errors.size());
- validatorContext.constrain(Author.class, "addresses[0].addressline2", annotationFactory.create(NotNull.class));
+ validatorContext.constrain(Author.class, "addresses[0].addressline2",
+ AnnotationBuilder.buildDefault(NotNull.class));
errors = validator.validate(author);
assertEquals(2, errors.size());
@@ -171,10 +167,10 @@ public class DynamicValidationTest exten
assertTrue(errors.isEmpty());
StubConstraint.Builder builder = StubConstraint.build().withGroups(First.class);
- validatorContext.constrain(Book.class, "title", builder.new CustomConfig<Pattern>() {
+ validatorContext.constrain(Book.class, "title", builder.new CustomTrainer<Pattern>() {
@Override
- protected void customConfigure(Pattern stub) {
+ protected void customTrain(Pattern stub) {
when(stub.regexp()).thenReturn("[A-Za-z]*");
}
}.build());
@@ -187,11 +183,11 @@ public class DynamicValidationTest exten
assertEquals(1, errors.size());
ConstraintViolation<Book> vio = errors.iterator().next();
assertEquals(Pattern.class, vio.getConstraintDescriptor().getAnnotation().annotationType());
-
- validatorContext.constrain(Book.class, "title", builder.new CustomConfig<Pattern>() {
+
+ validatorContext.constrain(Book.class, "title", builder.new CustomTrainer<Pattern>() {
@Override
- protected void customConfigure(Pattern stub) {
+ protected void customTrain(Pattern stub) {
when(stub.regexp()).thenReturn("[A-Za-z]*");
}
}.build());
@@ -205,7 +201,7 @@ public class DynamicValidationTest exten
public void testDynamicMetadataBean() {
BeanDescriptor authorDescriptor = validator.getConstraintsForClass(Author.class);
assertEquals(0, authorDescriptor.getConstraintDescriptors().size());
- validatorContext.constrain(Author.class, AnnotationFactory.INSTANCE.create(AuthorAddressKnown.class));
+ validatorContext.constrain(Author.class, AnnotationBuilder.buildDefault(AuthorAddressKnown.class));
authorDescriptor = validator.getConstraintsForClass(Author.class);
assertEquals(1, authorDescriptor.getConstraintDescriptors().size());
}
@@ -222,15 +218,15 @@ public class DynamicValidationTest exten
}
validatorContext.constrain(Author.class, "addresses[].addressline2",
- annotationFactory.create(new StubConfigurer<Pattern>() {
+ AnnotationBuilder.of(Pattern.class).train(new AnnotationTrainer<Pattern>() {
/**
* {@inheritDoc}
*/
@Override
- protected void configure(Pattern stub) {
+ protected void train(Pattern stub) {
when(stub.regexp()).thenReturn("[0..9]+.*");
}
- }));
+ }).build());
for (ConstraintDescriptor<?> desc : propertyDescriptor.getConstraintDescriptors()) {
assertFalse(Pattern.class.equals(desc.getAnnotation().annotationType()));
@@ -268,7 +264,8 @@ public class DynamicValidationTest exten
assertTrue(validator.validate(carrierHolder).isEmpty());
assertTrue(validator.validate(carrierHolder.getCarrier()).isEmpty());
- validatorContext.constrain(ZipCodeCityCarrier.class, annotationFactory.create(ZipCodeCityCoherence.class));
+ validatorContext
+ .constrain(ZipCodeCityCarrier.class, AnnotationBuilder.buildDefault(ZipCodeCityCoherence.class));
Set<ConstraintViolation<ZipCodeCityCarrierHolder>> holderErrors = validator.validate(carrierHolder);
assertEquals(2, holderErrors.size());
assertNotNull(TestUtils.getViolation(holderErrors, "carrier"));
@@ -298,7 +295,7 @@ public class DynamicValidationTest exten
public static class ZipCodeCityCarrierHolder {
@Valid
- private ZipCodeCityCarrier carrier;
+ private final ZipCodeCityCarrier carrier;
public ZipCodeCityCarrierHolder(ZipCodeCityCarrier carrier) {
super();
Modified: bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/NestedValidatorTest.java
URL: http://svn.apache.org/viewvc/bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/NestedValidatorTest.java?rev=1554975&r1=1554974&r2=1554975&view=diff
==============================================================================
--- bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/NestedValidatorTest.java (original)
+++ bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/NestedValidatorTest.java Fri Jan 3 00:04:23 2014
@@ -124,8 +124,8 @@ public class NestedValidatorTest {
assertTrue(errors.isEmpty());
validatorContext.constrain(Author.class, "addresses[].addressline2",
- StubConstraint.build().withGroups(First.class).new CustomConfig<Pattern>() {
- protected void customConfigure(Pattern stub) {
+ StubConstraint.build().withGroups(First.class).new CustomTrainer<Pattern>() {
+ protected void customTrain(Pattern stub) {
when(stub.regexp()).thenReturn("[0..9]+.*");
}
}.build());
@@ -155,8 +155,8 @@ public class NestedValidatorTest {
@Test
public void testDescriptor() {
validatorContext.constrain(Author.class, "addresses[].addressline2",
- StubConstraint.build().withGroups(First.class).new CustomConfig<Pattern>() {
- protected void customConfigure(Pattern stub) {
+ StubConstraint.build().withGroups(First.class).new CustomTrainer<Pattern>() {
+ protected void customTrain(Pattern stub) {
when(stub.regexp()).thenReturn("[0..9]+.*");
}
}.build());
Modified: bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/StubConstraintTest.java
URL: http://svn.apache.org/viewvc/bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/StubConstraintTest.java?rev=1554975&r1=1554974&r2=1554975&view=diff
==============================================================================
--- bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/StubConstraintTest.java (original)
+++ bval/sandbox/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/StubConstraintTest.java Fri Jan 3 00:04:23 2014
@@ -33,13 +33,14 @@ import javax.validation.constraints.Null
import javax.validation.constraints.Size;
import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.proxy2.stub.AnnotationFactory;
+import org.apache.commons.proxy2.stub.AnnotationBuilder;
import org.junit.Test;
/**
* Test/example of {@link StubConstraint} use.
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2010-10-08 11:00:59 -0500 (Fri, 08 Oct 2010)
+ * $
*/
public class StubConstraintTest {
@@ -74,9 +75,9 @@ public class StubConstraintTest {
@Test
public void testCustomConfig() throws Exception {
- Size size = StubConstraint.build().new CustomConfig<Size>() {
+ Size size = StubConstraint.build().new CustomTrainer<Size>() {
@Override
- protected void customConfigure(Size stub) {
+ protected void customTrain(Size stub) {
when(stub.min()).thenReturn(5).when(stub.max()).thenReturn(50);
}
}.build();
@@ -93,9 +94,9 @@ public class StubConstraintTest {
public void testCommonAttributesWithCustomConfig() throws Exception {
Size size =
StubConstraint.build().withGroups(Large.class, Small.class).withMessage("size between 5 and 50")
- .withPayload(CustomPayload.class).new CustomConfig<Size>() {
+ .withPayload(CustomPayload.class).new CustomTrainer<Size>() {
@Override
- protected void customConfigure(Size stub) {
+ protected void customTrain(Size stub) {
when(stub.min()).thenReturn(5).when(stub.max()).thenReturn(50);
}
}.build();
@@ -116,16 +117,17 @@ public class StubConstraintTest {
public void testMultiple() throws Exception {
Size.List sizes =
StubConstraint.buildMultiple(Size.List.class,
- StubConstraint.build().withGroups(Small.class).withMessage("1-5").new CustomConfig<Size>() {
+ StubConstraint.build().withGroups(Small.class).withMessage("1-5").new CustomTrainer<Size>() {
@Override
- protected void customConfigure(Size stub) {
+ protected void customTrain(Size stub) {
when(stub.min()).thenReturn(1).when(stub.max()).thenReturn(5);
}
- }.build(), StubConstraint.build().withGroups(Large.class).withMessage("1-50").new CustomConfig<Size>() {
+ }.build(),
+ StubConstraint.build().withGroups(Large.class).withMessage("1-50").new CustomTrainer<Size>() {
@Override
- protected void customConfigure(Size stub) {
+ protected void customTrain(Size stub) {
when(stub.min()).thenReturn(1).when(stub.max()).thenReturn(50);
}
}.build());
@@ -148,7 +150,7 @@ public class StubConstraintTest {
@Test
public void testEmptyMultiple() throws Exception {
Null.List nullList = StubConstraint.<Null, Null.List> buildMultiple(Null.List.class);
- assertTrue(Arrays.equals(new Null[] { }, nullList.value()));
+ assertTrue(Arrays.equals(new Null[] {}, nullList.value()));
}
@Test(expected = ValidationException.class)
@@ -158,14 +160,14 @@ public class StubConstraintTest {
@Test(expected = ValidationException.class)
public void testMultipleWithInvalidSingleType() throws Exception {
- StubConstraint.buildMultiple(Retention.class, AnnotationFactory.INSTANCE.create(Documented.class));
+ StubConstraint.buildMultiple(Retention.class, AnnotationBuilder.buildDefault(Documented.class));
}
@Test(expected = ValidationException.class)
public void testEmptyMultipleWithInvalidSingleType() throws Exception {
StubConstraint.<NotNull, Null.List> buildMultiple(Null.List.class);
}
-
+
@Test(expected = ValidationException.class)
public void testMismatchedSingleAndMultiple() throws Exception {
StubConstraint.buildMultiple(Null.List.class, StubConstraint.build(NotNull.class));