From 578b397d36222c02e8436a3bd46e8bcd5a0baef3 Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Tue, 2 Apr 2013 11:42:33 +0200 Subject: [PATCH] BVTCK-54 Using qualifiers for injected Strings in order to avoid clashes with String producer methods from other extensions --- .../cdi/executable/AnotherBookingService.java | 2 +- .../integration/cdi/executable/LongName.java | 36 +++++++++++++++++++ .../cdi/executable/NameProducer.java | 1 + .../cdi/executable/UserService.java | 2 +- .../types/AnotherCalendarService.java | 2 +- .../types/AnotherDeliveryService.java | 2 +- .../cdi/executable/types/LongName.java | 36 +++++++++++++++++++ .../types/OnlineCalendarService.java | 2 +- .../executable/types/ParameterProducer.java | 1 + .../types/YetAnotherCalendarService.java | 2 +- 10 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/LongName.java create mode 100644 tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/LongName.java diff --git a/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/AnotherBookingService.java b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/AnotherBookingService.java index 8293997f..5e4149b7 100644 --- a/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/AnotherBookingService.java +++ b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/AnotherBookingService.java @@ -35,7 +35,7 @@ public interface IgnoredValidationGroup { @Inject @ValidAnotherBookingService @Null(groups = IgnoredValidationGroup.class) - public AnotherBookingService(@Size(min = 5) @Null(groups = IgnoredValidationGroup.class) String name) { + public AnotherBookingService(@LongName @Size(min = 5) @Null(groups = IgnoredValidationGroup.class) String name) { AnotherBookingService.name = name; invocationCount++; } diff --git a/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/LongName.java b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/LongName.java new file mode 100644 index 00000000..8f26ca1c --- /dev/null +++ b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/LongName.java @@ -0,0 +1,36 @@ +/* +* JBoss, Home of Professional Open Source +* Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual contributors +* by the @authors tag. See the copyright.txt in the distribution for a +* full listing of individual contributors. +* +* Licensed 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.hibernate.beanvalidation.tck.tests.integration.cdi.executable; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import javax.inject.Qualifier; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * @author Gunnar Morling + */ +@Qualifier +@Retention(RUNTIME) +@Target({ TYPE, METHOD, FIELD, PARAMETER }) +public @interface LongName { +} diff --git a/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/NameProducer.java b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/NameProducer.java index 1995eb6a..73a90cae 100644 --- a/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/NameProducer.java +++ b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/NameProducer.java @@ -30,6 +30,7 @@ public class NameProducer { @Produces @Dependent + @LongName public String getName() { return name; } diff --git a/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/UserService.java b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/UserService.java index 04586183..83fd4766 100644 --- a/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/UserService.java +++ b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/UserService.java @@ -26,6 +26,6 @@ public class UserService { @Inject @CrossParameterConstraint - public UserService(@Size(min = 5) String name) { + public UserService(@LongName @Size(min = 5) String name) { } } diff --git a/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/AnotherCalendarService.java b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/AnotherCalendarService.java index 15d67e68..ceecb18b 100644 --- a/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/AnotherCalendarService.java +++ b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/AnotherCalendarService.java @@ -28,6 +28,6 @@ public class AnotherCalendarService { @Inject @ValidateOnExecution(type = ExecutableType.NON_GETTER_METHODS) - public AnotherCalendarService(@Size(min = 5) String name) { + public AnotherCalendarService(@LongName @Size(min = 5) String name) { } } diff --git a/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/AnotherDeliveryService.java b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/AnotherDeliveryService.java index 75acea5a..ee1f36ad 100644 --- a/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/AnotherDeliveryService.java +++ b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/AnotherDeliveryService.java @@ -27,6 +27,6 @@ public class AnotherDeliveryService { @Inject @ValidateOnExecution - public AnotherDeliveryService(@Size(min = 5) String id) { + public AnotherDeliveryService(@LongName @Size(min = 5) String id) { } } diff --git a/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/LongName.java b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/LongName.java new file mode 100644 index 00000000..4a38f30c --- /dev/null +++ b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/LongName.java @@ -0,0 +1,36 @@ +/* +* JBoss, Home of Professional Open Source +* Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual contributors +* by the @authors tag. See the copyright.txt in the distribution for a +* full listing of individual contributors. +* +* Licensed 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.hibernate.beanvalidation.tck.tests.integration.cdi.executable.types; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import javax.inject.Qualifier; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * @author Gunnar Morling + */ +@Qualifier +@Retention(RUNTIME) +@Target({ TYPE, METHOD, FIELD, PARAMETER }) +public @interface LongName { +} diff --git a/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/OnlineCalendarService.java b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/OnlineCalendarService.java index 61576310..3fdbcb25 100644 --- a/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/OnlineCalendarService.java +++ b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/OnlineCalendarService.java @@ -28,6 +28,6 @@ public class OnlineCalendarService { @Inject @ValidateOnExecution(type = ExecutableType.CONSTRUCTORS) - public OnlineCalendarService(@Size(min = 5) String name) { + public OnlineCalendarService(@LongName @Size(min = 5) String name) { } } diff --git a/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/ParameterProducer.java b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/ParameterProducer.java index 58f5565a..142553f0 100644 --- a/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/ParameterProducer.java +++ b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/ParameterProducer.java @@ -24,6 +24,7 @@ public class ParameterProducer { @Produces + @LongName public String getName() { return "Bob"; } diff --git a/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/YetAnotherCalendarService.java b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/YetAnotherCalendarService.java index 76817f29..c9c2733a 100644 --- a/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/YetAnotherCalendarService.java +++ b/tests/src/main/java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/types/YetAnotherCalendarService.java @@ -28,6 +28,6 @@ public class YetAnotherCalendarService { @Inject @ValidateOnExecution(type = ExecutableType.ALL) - public YetAnotherCalendarService(@Size(min = 5) String name) { + public YetAnotherCalendarService(@LongName @Size(min = 5) String name) { } }