bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r930301 - in /incubator/bval/sandbox/guice-integration/src: main/java/org/apache/bval/extentions/guice/ test/java/org/apache/bval/extentions/guice/
Date Fri, 02 Apr 2010 15:47:11 GMT
Author: simonetripodi
Date: Fri Apr  2 15:47:11 2010
New Revision: 930301

URL: http://svn.apache.org/viewvc?rev=930301&view=rev
Log:
added AOP validation + test case

Added:
    incubator/bval/sandbox/guice-integration/src/test/java/org/apache/bval/extentions/guice/DummyCountryDao.java
  (with props)
Modified:
    incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidationModule.java
    incubator/bval/sandbox/guice-integration/src/test/java/org/apache/bval/extentions/guice/GuiceAwareValidationTestCase.java

Modified: incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidationModule.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidationModule.java?rev=930301&r1=930300&r2=930301&view=diff
==============================================================================
--- incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidationModule.java
(original)
+++ incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidationModule.java
Fri Apr  2 15:47:11 2010
@@ -24,12 +24,14 @@ import javax.validation.ValidatorFactory
 import javax.validation.spi.ConfigurationState;
 import javax.validation.spi.ValidationProvider;
 
+import org.aopalliance.intercept.MethodInterceptor;
 import org.apache.bval.jsr303.ApacheValidationProvider;
 import org.apache.bval.jsr303.DefaultMessageInterpolator;
 import org.apache.bval.jsr303.resolver.DefaultTraversableResolver;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.Scopes;
+import com.google.inject.matcher.Matchers;
 
 /**
  * The Google-Guice module for Apache Bean Validation.
@@ -43,6 +45,7 @@ public final class ValidationModule exte
      */
     @Override
     protected void configure() {
+        // apache bval bootstrap
         this.bind(MessageInterpolator.class).to(DefaultMessageInterpolator.class).in(Scopes.SINGLETON);
         this.bind(TraversableResolver.class).to(DefaultTraversableResolver.class).in(Scopes.SINGLETON);
         this.bind(ConstraintValidatorFactory.class).to(GuiceAwareConstraintValidatorFactory.class);
@@ -50,6 +53,11 @@ public final class ValidationModule exte
         this.bind(ConfigurationState.class).toProvider(ConfigurationStateProvider.class);
         this.bind(ValidatorFactory.class).toProvider(ValidatorFactoryProvider.class);
         this.bind(Validator.class).toProvider(ValidatorProvider.class);
+
+        // AOP stuff
+        MethodInterceptor validateMethodInterceptor = new ValidateMethodInterceptor();
+        this.binder().requestInjection(validateMethodInterceptor);
+        this.bindInterceptor(Matchers.any(), Matchers.annotatedWith(Validate.class), validateMethodInterceptor);
     }
 
 }

Added: incubator/bval/sandbox/guice-integration/src/test/java/org/apache/bval/extentions/guice/DummyCountryDao.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/guice-integration/src/test/java/org/apache/bval/extentions/guice/DummyCountryDao.java?rev=930301&view=auto
==============================================================================
--- incubator/bval/sandbox/guice-integration/src/test/java/org/apache/bval/extentions/guice/DummyCountryDao.java
(added)
+++ incubator/bval/sandbox/guice-integration/src/test/java/org/apache/bval/extentions/guice/DummyCountryDao.java
Fri Apr  2 15:47:11 2010
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bval.extentions.guice;
+
+/**
+ * 
+ *
+ * @version $Id$
+ */
+public class DummyCountryDao {
+
+    @Validate
+    public void insertCountry(Country country) {
+        // do nothing
+    }
+
+}

Propchange: incubator/bval/sandbox/guice-integration/src/test/java/org/apache/bval/extentions/guice/DummyCountryDao.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/sandbox/guice-integration/src/test/java/org/apache/bval/extentions/guice/DummyCountryDao.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/sandbox/guice-integration/src/test/java/org/apache/bval/extentions/guice/DummyCountryDao.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/bval/sandbox/guice-integration/src/test/java/org/apache/bval/extentions/guice/GuiceAwareValidationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/guice-integration/src/test/java/org/apache/bval/extentions/guice/GuiceAwareValidationTestCase.java?rev=930301&r1=930300&r2=930301&view=diff
==============================================================================
--- incubator/bval/sandbox/guice-integration/src/test/java/org/apache/bval/extentions/guice/GuiceAwareValidationTestCase.java
(original)
+++ incubator/bval/sandbox/guice-integration/src/test/java/org/apache/bval/extentions/guice/GuiceAwareValidationTestCase.java
Fri Apr  2 15:47:11 2010
@@ -46,4 +46,21 @@ public final class GuiceAwareValidationT
         assertTrue(violations.isEmpty());
     }
 
+    public void testAOPInjectedValidation() {
+        Country country = new Country();
+        country.setName("Italy");
+        country.setIso2Code("ita");
+        country.setIso3Code("ita");
+
+        Injector injector = Guice.createInjector(new ValidationModule());
+        DummyCountryDao dummyCountryDao = injector.getInstance(DummyCountryDao.class);
+
+        try {
+            dummyCountryDao.insertCountry(country);
+            fail("org.apache.bval.extentions.guice.ValidationException expected");
+        } catch (Throwable t) {
+            // do nothing
+        }
+    }
+
 }



Mime
View raw message