incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1080681 - /incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagementTest.java
Date Fri, 11 Mar 2011 17:21:44 GMT
Author: mbenson
Date: Fri Mar 11 17:21:44 2011
New Revision: 1080681

URL: http://svn.apache.org/viewvc?rev=1080681&view=rev
Log:
test caching behavior (tests fail)

Modified:
    incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagementTest.java

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagementTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagementTest.java?rev=1080681&r1=1080680&r2=1080681&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagementTest.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/test/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagementTest.java
Fri Mar 11 17:21:44 2011
@@ -21,12 +21,15 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertThat;
 
 import javax.validation.Validation;
+import javax.validation.constraints.NotNull;
 
 import org.apache.bval.jsr303.ApacheValidationProvider;
 import org.apache.bval.jsr303.ApacheValidatorConfiguration;
 import org.apache.bval.jsr303.example.Book;
 import org.apache.bval.model.MetaBean;
 import org.apache.bval.model.MetaProperty;
+import org.apache.commons.proxy2.stub.AnnotationFactory;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -36,6 +39,7 @@ import org.junit.Test;
  * @version $Rev$ $Date$
  */
 public class DynamicMetaGraphManagementTest {
+    private static final NotNull NOT_NULL = AnnotationFactory.INSTANCE.create(NotNull.class);
 
     private DynamicValidatorContext dynamicValidatorContext;
 
@@ -79,4 +83,230 @@ public class DynamicMetaGraphManagementT
             is(MetaProperty.class));
     }
 
+    @Test
+    public void testCachedMetaBean() throws Exception {
+        Buffer<MetaBean> buffer = new Buffer<MetaBean>() {
+            @Override
+            MetaBean read() {
+                return dynamicValidatorContext.readOnly().getMetaBean(Book.class);
+            }
+        };
+        // original:
+        buffer.next().next().same();
+
+        // new feature:
+        Thread.sleep(1);
+        dynamicValidatorContext.writable().getMetaBean(Book.class).putFeature("foo", true);
+
+        buffer.next().notSame();
+        buffer.next().same();
+
+        // same feature:
+        Thread.sleep(1);
+        dynamicValidatorContext.writable().getMetaBean(Book.class).putFeature("foo", true);
+
+        buffer.next().same();
+
+        // new constraint:
+        Thread.sleep(1);
+        dynamicValidatorContext.constrain(Book.class, NOT_NULL);
+
+        buffer.next().notSame();
+        buffer.next().same();
+
+        // same constraint:
+        Thread.sleep(1);
+        dynamicValidatorContext.constrain(Book.class, NOT_NULL);
+
+        buffer.next().same();
+    }
+
+    @Test
+    public void testCachedMetaProperty() throws Exception {
+        Buffer<MetaProperty> buffer = new Buffer<MetaProperty>() {
+            @Override
+            MetaProperty read() {
+                return dynamicValidatorContext.readOnly().getMeta(Book.class, "author");
+            }
+        };
+        // original:
+        buffer.next().next().same();
+
+        // new feature:
+        Thread.sleep(1);
+        dynamicValidatorContext.writable().getMeta(Book.class, "author").putFeature("foo",
true);
+
+        buffer.next().notSame();
+        buffer.next().same();
+
+        // same feature:
+        Thread.sleep(1);
+        dynamicValidatorContext.writable().getMeta(Book.class, "author").putFeature("foo",
true);
+
+        buffer.next().same();
+
+        // new constraint:
+        Thread.sleep(1);
+        dynamicValidatorContext.constrain(Book.class, "author", NOT_NULL);
+
+        buffer.next().notSame();
+        buffer.next().same();
+
+        // same constraint:
+        Thread.sleep(1);
+        dynamicValidatorContext.constrain(Book.class, "author", NOT_NULL);
+
+        buffer.next().same();
+    }
+
+    @Test
+    public void testCachedIndexedNestedMetaBean() throws Exception {
+        Buffer<MetaBean> buffer = new Buffer<MetaBean>() {
+            @Override
+            MetaBean read() {
+                return dynamicValidatorContext.readOnly().getMeta(Book.class, "author.addresses[0]");
+            }
+        };
+        // original:
+        buffer.next().next().same();
+
+        // new feature:
+        Thread.sleep(1);
+        dynamicValidatorContext.writable().getMeta(Book.class, "author.addresses[0]").putFeature("foo",
true);
+
+        buffer.next().notSame();
+        buffer.next().same();
+
+        // same feature:
+        Thread.sleep(1);
+        dynamicValidatorContext.writable().getMeta(Book.class, "author.addresses[0]").putFeature("foo",
true);
+
+        buffer.next().same();
+
+        // new feature, any index:
+        Thread.sleep(1);
+        dynamicValidatorContext.writable().getMeta(Book.class, "author.addresses[]").putFeature("bar",
false);
+
+        buffer.next().notSame();
+        buffer.next().same();
+
+        // same feature, any index:
+        Thread.sleep(1);
+        dynamicValidatorContext.writable().getMeta(Book.class, "author.addresses[]").putFeature("bar",
false);
+
+        buffer.next().same();
+
+        // new constraint:
+        Thread.sleep(1);
+        dynamicValidatorContext.constrain(Book.class, "author.addresses[0]", NOT_NULL);
+
+        buffer.next().notSame();
+        buffer.next().same();
+
+        // same constraint:
+        Thread.sleep(1);
+        dynamicValidatorContext.constrain(Book.class, "author.addresses[0]", NOT_NULL);
+
+        buffer.next().same();
+
+        // new constraint, any index:
+        Thread.sleep(1);
+        dynamicValidatorContext.constrain(Book.class, "author.addresses[]", NOT_NULL);
+
+        buffer.next().notSame();
+        buffer.next().same();
+
+        // same constraint, any index:
+        Thread.sleep(1);
+        dynamicValidatorContext.constrain(Book.class, "author.addresses[]", NOT_NULL);
+
+        buffer.next().same();
+    }
+
+    @Test
+    public void testCachedIndexedNestedMetaProperty() throws Exception {
+        Buffer<MetaProperty> buffer = new Buffer<MetaProperty>() {
+
+            @Override
+            MetaProperty read() {
+                return dynamicValidatorContext.readOnly().getMeta(Book.class, "author.addresses[0].city");
+            }
+
+        };
+        // original:
+        buffer.next().next().same();
+
+        // new feature:
+        Thread.sleep(1);
+        dynamicValidatorContext.writable().getMeta(Book.class, "author.addresses[0].city").putFeature("foo",
true);
+
+        buffer.next().notSame();
+        buffer.next().same();
+
+        // same feature:
+        Thread.sleep(1);
+        dynamicValidatorContext.writable().getMeta(Book.class, "author.addresses[0].city").putFeature("foo",
true);
+
+        buffer.next().same();
+
+        // new feature, any index:
+        Thread.sleep(1);
+        dynamicValidatorContext.writable().getMeta(Book.class, "author.addresses[].city").putFeature("bar",
false);
+
+        buffer.next().notSame();
+        buffer.next().same();
+
+        // same feature, any index:
+        Thread.sleep(1);
+        dynamicValidatorContext.writable().getMeta(Book.class, "author.addresses[].city").putFeature("bar",
false);
+
+        buffer.next().same();
+
+        // new constraint:
+        Thread.sleep(1);
+        dynamicValidatorContext.constrain(Book.class, "author.addresses[0].city", NOT_NULL);
+
+        buffer.next().notSame();
+        buffer.next().same();
+
+        // same constraint:
+        Thread.sleep(1);
+        dynamicValidatorContext.constrain(Book.class, "author.addresses[0].city", NOT_NULL);
+
+        buffer.next().same();
+
+        // new constraint, any index:
+        Thread.sleep(1);
+        dynamicValidatorContext.constrain(Book.class, "author.addresses[].city", NOT_NULL);
+
+        buffer.next().notSame();
+        buffer.next().same();
+
+        // same constraint, any index:
+        Thread.sleep(1);
+        dynamicValidatorContext.constrain(Book.class, "author.addresses[].city", NOT_NULL);
+
+        buffer.next().same();
+    }
+
+    abstract static class Buffer<T> {
+        T previous;
+        T current;
+
+        abstract T read();
+
+        synchronized Buffer<T> next() {
+            previous = current;
+            current = read();
+            return this;
+        }
+
+        void same() {
+            Assert.assertSame(previous, current);
+        }
+
+        void notSame() {
+            Assert.assertNotSame(previous, current);
+        }
+    }
 }



Mime
View raw message