This is an automated email from the ASF dual-hosted git repository. jungm pushed a commit to branch BVAL-222 in repository https://gitbox.apache.org/repos/asf/bval.git
commit 7ebd079bd3d419e3439de0a13c46b7a2dbbf2614 Author: Markus Jung <[email protected]> AuthorDate: Tue Jan 28 12:54:02 2025 +0100 BVAL222 - Add unit test --- bval-jsr/pom.xml | 19 ++++++ .../java/org/apache/bval/cdi/BValExtension.java | 2 +- .../cdi/CdiConstraintOnlyOnParentClassTest.java | 75 ++++++++++++++++++++++ bval-tck/pom.xml | 12 ++-- pom.xml | 4 ++ 5 files changed, 104 insertions(+), 8 deletions(-) diff --git a/bval-jsr/pom.xml b/bval-jsr/pom.xml index 36dce35..1e37d26 100644 --- a/bval-jsr/pom.xml +++ b/bval-jsr/pom.xml @@ -218,6 +218,25 @@ </exclusion> </exclusions> </dependency> + + <dependency> + <groupId>org.jboss.arquillian.junit</groupId> + <artifactId>arquillian-junit-container</artifactId> + <scope>test</scope> + <version>${version.arquillian}</version> + </dependency> + <dependency> + <groupId>org.apache.openwebbeans.arquillian</groupId> + <artifactId>owb-arquillian-standalone</artifactId> + <version>${version.owb}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.openwebbeans</groupId> + <artifactId>openwebbeans-impl</artifactId> + <version>${version.owb}</version> + <scope>test</scope> + </dependency> </dependencies> <build> diff --git a/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java b/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java index 9943ca4..ae02f47 100644 --- a/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java +++ b/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java @@ -66,7 +66,7 @@ import org.apache.bval.util.Validate; public class BValExtension implements Extension { private static final Logger LOGGER = Logger.getLogger(BValExtension.class.getName()); - private static final AnnotatedTypeFilter DEFAULT_ANNOTATED_TYPE_FILTER = + public static final AnnotatedTypeFilter DEFAULT_ANNOTATED_TYPE_FILTER = annotatedType -> !annotatedType.getJavaClass().getName().startsWith("org.apache.bval."); private static AnnotatedTypeFilter annotatedTypeFilter = DEFAULT_ANNOTATED_TYPE_FILTER; diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/cdi/CdiConstraintOnlyOnParentClassTest.java b/bval-jsr/src/test/java/org/apache/bval/jsr/cdi/CdiConstraintOnlyOnParentClassTest.java new file mode 100644 index 0000000..1713a6e --- /dev/null +++ b/bval-jsr/src/test/java/org/apache/bval/jsr/cdi/CdiConstraintOnlyOnParentClassTest.java @@ -0,0 +1,75 @@ +/* + * 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.jsr.cdi; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.validation.ConstraintViolationException; +import jakarta.validation.constraints.NotNull; +import org.apache.bval.cdi.BValExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Assert; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.rules.ExternalResource; +import org.junit.runner.RunWith; + +@RunWith(Arquillian.class) +public class CdiConstraintOnlyOnParentClassTest { + @ClassRule + public static ExternalResource allowMyServiceImplType = new ExternalResource() { + @Override + protected void before() throws Throwable { + BValExtension.setAnnotatedTypeFilter(at -> at.getJavaClass() == GreetingServiceImpl.class); + } + + @Override + protected void after() { + BValExtension.setAnnotatedTypeFilter(BValExtension.DEFAULT_ANNOTATED_TYPE_FILTER); + } + }; + + @Inject + private GreetingService service; + + @Deployment + public static JavaArchive createDeployment() { + return ShrinkWrap.create(JavaArchive.class) + .addClasses(GreetingService.class, GreetingServiceImpl.class); + } + + @Test + public void validationFail() { + Assert.assertThrows(ConstraintViolationException.class, () -> service.greet(null)); + } + + public interface GreetingService { + void greet(@NotNull String name); + } + + @ApplicationScoped + public static class GreetingServiceImpl implements GreetingService { + @Override + public void greet(String name) { + } + } +} diff --git a/bval-tck/pom.xml b/bval-tck/pom.xml index 8f921f3..84bf413 100644 --- a/bval-tck/pom.xml +++ b/bval-tck/pom.xml @@ -32,8 +32,6 @@ under the License. <properties> <tck.version>3.1.1</tck.version> - <owb.version>4.0.2</owb.version> - <arquillian.version>1.8.1.Final</arquillian.version> <validation.provider>org.apache.bval.jsr.ApacheValidationProvider</validation.provider> </properties> @@ -109,18 +107,18 @@ under the License. <dependency> <groupId>org.jboss.arquillian.container</groupId> <artifactId>arquillian-container-test-spi</artifactId> - <version>${arquillian.version}</version> + <version>${version.arquillian}</version> </dependency> <dependency> <groupId>org.apache.openwebbeans.arquillian</groupId> <artifactId>owb-arquillian-standalone</artifactId> - <version>${owb.version}</version> + <version>${version.owb}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.openwebbeans</groupId> <artifactId>openwebbeans-impl</artifactId> - <version>${owb.version}</version> + <version>${version.owb}</version> <scope>test</scope> </dependency> <dependency> @@ -136,13 +134,13 @@ under the License. <dependency> <groupId>org.jboss.arquillian.testng</groupId> <artifactId>arquillian-testng-container</artifactId> - <version>${arquillian.version}</version> + <version>${version.arquillian}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.jboss.arquillian.protocol</groupId> <artifactId>arquillian-protocol-servlet-jakarta</artifactId> - <version>${arquillian.version}</version> + <version>${version.arquillian}</version> <scope>test</scope> </dependency> diff --git a/pom.xml b/pom.xml index 87b3dca..c376f85 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,11 @@ <built.by>${user.name}</built.by> <version.plugin.javadoc>3.11.1</version.plugin.javadoc> + + <!-- Testing dependencies --> <version.tomcat>11.0.1</version.tomcat> <!-- used for EL API + EL impl in tests --> + <version.owb>4.0.2</version.owb> + <version.arquillian>1.8.0.Final</version.arquillian> </properties> <inceptionYear>2010</inceptionYear>
