From b3cd5e6144059bd65c2e4168e79c6be8e081d7c3 Mon Sep 17 00:00:00 2001 From: Jozef Hartinger Date: Fri, 18 May 2012 12:48:47 +0200 Subject: [PATCH] WELD-1088 Resource definition which specifies an EL name should be definition error Conflicts: impl/src/main/java/org/jboss/weld/bean/builtin/ee/EEResourceProducerField.java impl/src/main/java/org/jboss/weld/logging/messages/BeanMessage.java impl/src/main/resources/org/jboss/weld/messages/bean_en.properties jboss-tck-runner/1.1/src/test/resources/tck-tests.xml --- .../builtin/ee/EEResourceProducerField.java | 12 +++-- .../weld/logging/messages/BeanMessage.java | 7 ++- .../jboss/weld/messages/bean_en.properties | 6 ++- .../simple/resource/broken/name/Another.java | 36 +++++++++++++++ .../name/ResourceDefinitionWithNameTest.java | 45 +++++++++++++++++++ .../broken/name/ResourceProducer.java | 32 +++++++++++++ 6 files changed, 132 insertions(+), 6 deletions(-) create mode 100644 tests-arquillian/src/test/java/org/jboss/weld/tests/cditck11/simple/resource/broken/name/Another.java create mode 100644 tests-arquillian/src/test/java/org/jboss/weld/tests/cditck11/simple/resource/broken/name/ResourceDefinitionWithNameTest.java create mode 100644 tests-arquillian/src/test/java/org/jboss/weld/tests/cditck11/simple/resource/broken/name/ResourceProducer.java diff --git a/impl/src/main/java/org/jboss/weld/bean/builtin/ee/EEResourceProducerField.java b/impl/src/main/java/org/jboss/weld/bean/builtin/ee/EEResourceProducerField.java index 0f504b905e2..564da852683 100644 --- a/impl/src/main/java/org/jboss/weld/bean/builtin/ee/EEResourceProducerField.java +++ b/impl/src/main/java/org/jboss/weld/bean/builtin/ee/EEResourceProducerField.java @@ -16,6 +16,11 @@ */ package org.jboss.weld.bean.builtin.ee; +import static org.jboss.weld.logging.messages.BeanMessage.BEAN_NOT_EE_RESOURCE_PRODUCER; +import static org.jboss.weld.logging.messages.BeanMessage.INVALID_RESOURCE_PRODUCER_FIELD; +import static org.jboss.weld.logging.messages.BeanMessage.NAMED_RESOURCE_PRODUCER_FIELD; +import static org.jboss.weld.logging.messages.BeanMessage.NON_DEPENDENT_RESOURCE_PRODUCER_FIELD; + import java.io.Serializable; import javax.enterprise.context.Dependent; @@ -44,10 +49,6 @@ import org.jboss.weld.util.reflection.Reflections; import org.jboss.weld.ws.WSApiAbstraction; -import static org.jboss.weld.logging.messages.BeanMessage.BEAN_NOT_EE_RESOURCE_PRODUCER; -import static org.jboss.weld.logging.messages.BeanMessage.INVALID_RESOURCE_PRODUCER_FIELD; -import static org.jboss.weld.logging.messages.BeanMessage.NON_DEPENDENT_RESOURCE_PRODUCER_FIELD; - /** * @author pmuir */ @@ -120,6 +121,9 @@ protected void checkEEResource() { if (!getScope().equals(Dependent.class)) { throw new DefinitionException(NON_DEPENDENT_RESOURCE_PRODUCER_FIELD, this); } + if (getName() != null) { + throw new DefinitionException(NAMED_RESOURCE_PRODUCER_FIELD, this); + } EJBApiAbstraction ejbApiAbstraction = beanManager.getServices().get(EJBApiAbstraction.class); PersistenceApiAbstraction persistenceApiAbstraction = beanManager.getServices().get(PersistenceApiAbstraction.class); WSApiAbstraction wsApiAbstraction = beanManager.getServices().get(WSApiAbstraction.class); diff --git a/impl/src/main/java/org/jboss/weld/logging/messages/BeanMessage.java b/impl/src/main/java/org/jboss/weld/logging/messages/BeanMessage.java index e2d548815aa..13e13e56f7a 100644 --- a/impl/src/main/java/org/jboss/weld/logging/messages/BeanMessage.java +++ b/impl/src/main/java/org/jboss/weld/logging/messages/BeanMessage.java @@ -144,6 +144,11 @@ public enum BeanMessage { @MessageId("001508")INJECTION_TARGET_CANNOT_BE_CREATED_FOR_INTERFACE, @MessageId("001509")BEAN_NOT_PASIVATION_CAPABLE_IN_SERIALIZATION, @MessageId("001510")PROXY_HANDLER_SERIALIZED_FOR_NON_SERIALIZABLE_BEAN, - @MessageId("001511")SPECIALIZING_BEAN_MISSING_SPECIALIZED_TYPE; + @MessageId("001511")SPECIALIZING_BEAN_MISSING_SPECIALIZED_TYPE, + @MessageId("001512")INVALID_INJECTION_POINT_TYPE, + @MessageId("001513")INVALID_ANNOTATED_CALLABLE, + @MessageId("001514")INVALID_ANNOTATED_MEMBER, + @MessageId("001515")UNABLE_TO_LOAD_MEMBER, + @MessageId("001516")NAMED_RESOURCE_PRODUCER_FIELD; } diff --git a/impl/src/main/resources/org/jboss/weld/messages/bean_en.properties b/impl/src/main/resources/org/jboss/weld/messages/bean_en.properties index 5aa3ccb3743..1a8f90a780b 100644 --- a/impl/src/main/resources/org/jboss/weld/messages/bean_en.properties +++ b/impl/src/main/resources/org/jboss/weld/messages/bean_en.properties @@ -107,4 +107,8 @@ FAILED_TO_SET_THREAD_LOCAL_ON_PROXY=Failed to set ThreadLocal for serialization CREATED_NEW_CLIENT_PROXY_TYPE=Created new client proxy of type {0} for bean {1} with ID {2} LOOKED_UP_CLIENT_PROXY=Located client proxy of type {0} for bean {1} INJECTION_TARGET_CANNOT_BE_CREATED_FOR_INTERFACE=Cannot create an InjectionTarget from {0} as it is an interface -SPECIALIZING_BEAN_MISSING_SPECIALIZED_TYPE=Specializing bean {0} does not have bean type {1} of specialized bean {2} \ No newline at end of file +INVALID_INJECTION_POINT_TYPE={0} cannot be constructed for {1} +INVALID_ANNOTATED_CALLABLE=An implementation of AnnotatedCallable must implement either AnnotatedConstructor or AnnotatedMethod, {0} +INVALID_ANNOTATED_MEMBER=An implementation of AnnotatedMember must implement either AnnotatedConstructor, AnnotatedMethod or AnnotatedField, {0} +UNABLE_TO_LOAD_MEMBER=Unable to load annotated member {0} +NAMED_RESOURCE_PRODUCER_FIELD=Resource producer field [{0}] must not have an EL name diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/cditck11/simple/resource/broken/name/Another.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/cditck11/simple/resource/broken/name/Another.java new file mode 100644 index 00000000000..9a47662d61e --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/cditck11/simple/resource/broken/name/Another.java @@ -0,0 +1,36 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2010, Red Hat, Inc., 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.jboss.weld.tests.cditck11.simple.resource.broken.name; + +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; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RUNTIME) +@Documented +@Qualifier +public @interface Another { +} \ No newline at end of file diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/cditck11/simple/resource/broken/name/ResourceDefinitionWithNameTest.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/cditck11/simple/resource/broken/name/ResourceDefinitionWithNameTest.java new file mode 100644 index 00000000000..8a53976fd28 --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/cditck11/simple/resource/broken/name/ResourceDefinitionWithNameTest.java @@ -0,0 +1,45 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2010, Red Hat, Inc., 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.jboss.weld.tests.cditck11.simple.resource.broken.name; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.ShouldThrowException; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.BeanArchive; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * @author Martin Kouba + */ +@RunWith(Arquillian.class) +public class ResourceDefinitionWithNameTest { + + @ShouldThrowException(Exception.class) + @Deployment + public static Archive createTestArchive() { + return ShrinkWrap.create(BeanArchive.class).addPackage(ResourceDefinitionWithNameTest.class.getPackage()); + } + + @Test + public void testDeployment() { + } + +} \ No newline at end of file diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/cditck11/simple/resource/broken/name/ResourceProducer.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/cditck11/simple/resource/broken/name/ResourceProducer.java new file mode 100644 index 00000000000..c30b6dab2ce --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/cditck11/simple/resource/broken/name/ResourceProducer.java @@ -0,0 +1,32 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2010, Red Hat, Inc., 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.jboss.weld.tests.cditck11.simple.resource.broken.name; + +import javax.annotation.Resource; +import javax.enterprise.inject.Produces; +import javax.enterprise.inject.spi.BeanManager; +import javax.inject.Named; + +public class ResourceProducer { + + @SuppressWarnings("unused") + @Named + @Another + @Produces + @Resource(mappedName = "java:comp/BeanManager") + private BeanManager manager; +} \ No newline at end of file