Return-Path: Delivered-To: apmail-incubator-bval-commits-archive@minotaur.apache.org Received: (qmail 90585 invoked from network); 2 Apr 2010 15:47:33 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 2 Apr 2010 15:47:33 -0000 Received: (qmail 65489 invoked by uid 500); 2 Apr 2010 15:47:33 -0000 Delivered-To: apmail-incubator-bval-commits-archive@incubator.apache.org Received: (qmail 65461 invoked by uid 500); 2 Apr 2010 15:47:33 -0000 Mailing-List: contact bval-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: bval-dev@incubator.apache.org Delivered-To: mailing list bval-commits@incubator.apache.org Received: (qmail 65454 invoked by uid 99); 2 Apr 2010 15:47:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Apr 2010 15:47:33 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Apr 2010 15:47:31 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id AC09D23888FE; Fri, 2 Apr 2010 15:47:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: bval-commits@incubator.apache.org From: simonetripodi@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100402154711.AC09D23888FE@eris.apache.org> 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 + } + } + }