Author: struberg
Date: Sun Jun 15 19:33:59 2014
New Revision: 1602754
URL: http://svn.apache.org/r1602754
Log:
OWB-971 disposal and produces not allowed in interceptors and decorators
hacked together with arne
Added:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/BrokenDisposalTest.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/DecoratorWithDisposes.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/InterceptorWithDisposes.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/NonProducerBeanWithDisposes.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/BrokenProducesTest.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerField.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerMethod.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerField.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerMethod.java
Removed:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/disposal/broken/
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractProducerBeanBuilder.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/DecoratorBeanBuilder.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java?rev=1602754&r1=1602753&r2=1602754&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
Sun Jun 15 19:33:59 2014
@@ -23,7 +23,7 @@ import java.lang.reflect.Method;
import javax.enterprise.context.spi.CreationalContext;
import org.apache.webbeans.component.creation.MethodProducerFactory;
-import org.apache.webbeans.exception.WebBeansConfigurationException;
+
/**
* Concrete implementation of the {@link AbstractOwbBean}.
@@ -39,8 +39,6 @@ public class ProducerMethodBean<T> exten
/** Creator method of the parent component */
protected Method creatorMethod;
- /** Disposal method */
- protected Method disposalMethod;
/**
* Creates a new instance.
@@ -67,11 +65,6 @@ public class ProducerMethodBean<T> exten
}
- public Method getDisposalMethod()
- {
- return disposalMethod;
- }
-
/**
* Sets the method.
*
@@ -82,22 +75,6 @@ public class ProducerMethodBean<T> exten
this.creatorMethod = creatorMethod;
}
- /**
- * Sets the disposal method.
- *
- * @param disposalMethod disposal method of this producer method component
- */
- public void setDisposalMethod(Method disposalMethod)
- {
- if (this.disposalMethod != null)
- {
- throw new WebBeansConfigurationException("There are multiple
disposal method for producer method " +
- "component with name : " + getName() + " with
implementation class " +
- getBeanClass().getName() + " with disposal method name : "
+
- disposalMethod.getName());
- }
- this.disposalMethod = disposalMethod;
- }
@Override
public String getId()
Added:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java?rev=1602754&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
(added)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
Sun Jun 15 19:33:59 2014
@@ -0,0 +1,97 @@
+/*
+ * 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.webbeans.component.creation;
+
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.AnnotatedType;
+import java.util.Set;
+
+import org.apache.webbeans.component.ProducerMethodBean;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.util.GenericsUtil;
+
+/**
+ * Base class for all bean builders
+ */
+public abstract class AbstractBeanBuilder<T>
+{
+
+ /**
+ * Make sure there is no disposer method without a corresponding producer
method.
+ * @param annotatedMethods of the given bean class
+ * @param producerBeans or an empty Set
+ */
+ protected void validateNoDisposerWithoutProducer(Set<AnnotatedMethod<?
super T>> annotatedMethods, Set<ProducerMethodBean<?>> producerBeans)
+ {
+ for (final AnnotatedMethod<?> annotatedMethod : annotatedMethods)
+ {
+ for (final AnnotatedParameter<?> param :
annotatedMethod.getParameters())
+ {
+ if (param.isAnnotationPresent(Disposes.class))
+ {
+ boolean found = false;
+ for (final ProducerMethodBean<?> producer : producerBeans)
+ {
+ if (GenericsUtil.satisfiesDependency(false,
producer.getCreatorMethod().getGenericReturnType(), param.getBaseType()))
+ {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ {
+ throw new WebBeansConfigurationException("@Disposes
without @Produces " + annotatedMethod.getJavaMember());
+ }
+ break;
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Certain beans like CDI Interceptors and Decorators
+ * are not allowed to define producer methods.
+ */
+ protected void validateNoProducerMethod(AnnotatedType<T> annotatedType)
+ {
+ Set<AnnotatedMethod<? super T>> annotatedMethods =
annotatedType.getMethods();
+ for (final AnnotatedMethod<?> annotatedMethod : annotatedMethods)
+ {
+ if (annotatedMethod.isAnnotationPresent(Produces.class))
+ {
+ throw new WebBeansConfigurationException("This class must not
have a @Produces method" + annotatedMethod.getJavaMember());
+ }
+ }
+
+ Set<AnnotatedField<? super T>> annotatedFields =
annotatedType.getFields();
+ for (final AnnotatedField<? super T> annotatedField : annotatedFields)
+ {
+ if (annotatedField.isAnnotationPresent(Produces.class))
+ {
+ throw new WebBeansConfigurationException("This class must not
have a @Produces field" + annotatedField.getJavaMember());
+ }
+ }
+ }
+
+}
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractProducerBeanBuilder.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractProducerBeanBuilder.java?rev=1602754&r1=1602753&r2=1602754&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractProducerBeanBuilder.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractProducerBeanBuilder.java
Sun Jun 15 19:33:59 2014
@@ -20,6 +20,7 @@ package org.apache.webbeans.component.cr
import javax.enterprise.inject.spi.AnnotatedMember;
import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.DefinitionException;
import org.apache.webbeans.component.AbstractProducerBean;
import org.apache.webbeans.component.BeanAttributesImpl;
@@ -53,6 +54,14 @@ public abstract class AbstractProducerBe
return
parent.getWebBeansContext().getAnnotatedElementFactory().getAnnotatedType(superclass);
}
+ /**
+ * Check if the producer rules are met.
+ */
+ public void validate() throws DefinitionException
+ {
+
+ }
+
protected abstract <X> P createBean(InjectionTargetBean<X> parent,
Class<T> beanClass);
protected P createBean(Class<T> beanClass)
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java?rev=1602754&r1=1602753&r2=1602754&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java
Sun Jun 15 19:33:59 2014
@@ -24,6 +24,7 @@ import javax.enterprise.inject.spi.Inter
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
+import java.util.Collections;
import java.util.Map;
import java.util.Set;
@@ -51,6 +52,12 @@ public class CdiInterceptorBeanBuilder<T
checkInterceptorConditions();
defineInterceptorMethods();
defineInterceptorBindings();
+
+ // make sure that CDI interceptors do not have any Producer methods
+ validateNoProducerMethod(annotatedType);
+
+ // make sure that CDI interceptors do not have a Disposes method
+ validateNoDisposerWithoutProducer(annotatedType.getMethods(),
Collections.EMPTY_SET);
}
@Override
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/DecoratorBeanBuilder.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/DecoratorBeanBuilder.java?rev=1602754&r1=1602753&r2=1602754&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/DecoratorBeanBuilder.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/DecoratorBeanBuilder.java
Sun Jun 15 19:33:59 2014
@@ -36,6 +36,7 @@ import java.lang.reflect.AnnotatedElemen
import java.lang.reflect.Constructor;
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -57,7 +58,7 @@ import org.apache.webbeans.util.Generics
/**
* Bean builder for {@link org.apache.webbeans.component.InterceptorBean}s.
*/
-public class DecoratorBeanBuilder<T>
+public class DecoratorBeanBuilder<T> extends AbstractBeanBuilder
{
private static Logger logger =
WebBeansLoggerFacade.getLogger(DecoratorBeanBuilder.class);
@@ -145,6 +146,13 @@ public class DecoratorBeanBuilder<T>
}
}
}
+
+ // make sure that CDI Decorators do not have any Producer methods
+ validateNoProducerMethod(annotatedType);
+
+ // make sure that CDI Decorator do not have a Disposes method
+ validateNoDisposerWithoutProducer(annotatedType.getMethods(),
Collections.EMPTY_SET);
+
}
public void defineDecoratorRules()
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java?rev=1602754&r1=1602753&r2=1602754&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
Sun Jun 15 19:33:59 2014
@@ -52,7 +52,7 @@ import org.apache.webbeans.util.ClassUti
/**
* Bean builder for {@link org.apache.webbeans.component.InterceptorBean}s.
*/
-public abstract class InterceptorBeanBuilder<T, B extends InterceptorBean<T>>
+public abstract class InterceptorBeanBuilder<T, B extends InterceptorBean<T>>
extends AbstractBeanBuilder
{
protected final WebBeansContext webBeansContext;
protected final AnnotatedType<T> annotatedType;
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java?rev=1602754&r1=1602753&r2=1602754&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java
Sun Jun 15 19:33:59 2014
@@ -42,9 +42,6 @@ import org.apache.webbeans.util.Annotati
import org.apache.webbeans.util.Asserts;
/**
- * Abstract implementation of {@link AbstractBeanBuilder}.
- *
- * @version $Rev$ $Date$
*
* @param <T> bean class type
*/
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java?rev=1602754&r1=1602753&r2=1602754&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java
Sun Jun 15 19:33:59 2014
@@ -44,10 +44,6 @@ import org.apache.webbeans.util.ClassUti
import org.apache.webbeans.util.WebBeansUtil;
/**
- * Abstract implementation of {@link AbstractBeanBuilder}.
- *
- * @version $Rev$ $Date$
- *
* @param <T> bean class type
*/
public class ProducerFieldBeansBuilder<T, I extends InjectionTargetBean<T>>
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java?rev=1602754&r1=1602753&r2=1602754&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java
Sun Jun 15 19:33:59 2014
@@ -25,7 +25,6 @@ import org.apache.webbeans.config.WebBea
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.util.AnnotationUtil;
import org.apache.webbeans.util.Asserts;
-import org.apache.webbeans.util.GenericsUtil;
import org.apache.webbeans.util.WebBeansUtil;
import javax.enterprise.event.Observes;
@@ -33,20 +32,15 @@ import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.Specializes;
import javax.enterprise.inject.spi.AnnotatedMethod;
-import javax.enterprise.inject.spi.AnnotatedParameter;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.inject.Inject;
import java.util.HashSet;
import java.util.Set;
/**
- * Abstract implementation of {@link AbstractBeanBuilder}.
- *
- * @version $Rev$ $Date$
- *
* @param <T> bean class type
*/
-public class ProducerMethodBeansBuilder<T, I extends InjectionTargetBean<T>>
+public class ProducerMethodBeansBuilder<T, I extends InjectionTargetBean<T>>
extends AbstractBeanBuilder
{
protected final WebBeansContext webBeansContext;
@@ -100,7 +94,6 @@ public class ProducerMethodBeansBuilder<
{
producerMethodBeanCreator.configureProducerSpecialization(producerMethodBean,
(AnnotatedMethod<T>) annotatedMethod);
}
- MethodProducerFactory<?> producerFactory = new
MethodProducerFactory(annotatedMethod, bean, webBeansContext);
producerMethodBean.setCreatorMethod(annotatedMethod.getJavaMember());
webBeansContext.getWebBeansUtil().setBeanEnableFlagForProducerBean(bean,
@@ -114,30 +107,8 @@ public class ProducerMethodBeansBuilder<
}
// valid all @Disposes have a @Produces
- for (final AnnotatedMethod<? super T> annotatedMethod :
annotatedMethods)
- {
- for (final AnnotatedParameter<?> param :
annotatedMethod.getParameters())
- {
- if (param.isAnnotationPresent(Disposes.class))
- {
- boolean found = false;
- for (final ProducerMethodBean<?> producer : producerBeans)
- {
- if (GenericsUtil.satisfiesDependency(false,
producer.getCreatorMethod().getGenericReturnType(), param.getBaseType()))
- {
- found = true;
- break;
- }
- }
- if (!found)
- {
- throw new WebBeansConfigurationException("@Disposes
without @Produces " + annotatedMethod.getJavaMember());
- }
- break;
- }
- }
- }
-
+ validateNoDisposerWithoutProducer(annotatedMethods, producerBeans);
+
return producerBeans;
}
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java?rev=1602754&r1=1602753&r2=1602754&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java
Sun Jun 15 19:33:59 2014
@@ -85,11 +85,6 @@ public class ProducerMethodProducer<T, P
}
}
- public void specializeBy(Bean<P> bean)
- {
- owner = bean;
- }
-
@Override
protected T produce(Map<Interceptor<?>, ?> interceptors,
CreationalContextImpl<T> creationalContext)
{
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/BrokenDisposalTest.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/BrokenDisposalTest.java?rev=1602754&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/BrokenDisposalTest.java
(added)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/BrokenDisposalTest.java
Sun Jun 15 19:33:59 2014
@@ -0,0 +1,49 @@
+/*
+ * 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.webbeans.test.disposes.beans.broken;
+
+import javax.enterprise.inject.spi.DefinitionException;
+
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.junit.Test;
+
+/**
+ * Test a few situations where disposal methods are not allowed
+ */
+public class BrokenDisposalTest extends AbstractUnitTest
+{
+ @Test(expected = DefinitionException.class)
+ public void testDisposalWithoutProducerMethod() throws Exception
+ {
+ startContainer(NonProducerBeanWithDisposes.class);
+ }
+
+ @Test(expected = DefinitionException.class)
+ public void testDisposalOnDecorator() throws Exception
+ {
+ addDecorator(DecoratorWithDisposes.class);
+ startContainer();
+ }
+
+ @Test(expected = DefinitionException.class)
+ public void testDisposalOnInterceptor() throws Exception
+ {
+ addInterceptor(InterceptorWithDisposes.class);
+ startContainer();
+ }
+}
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/DecoratorWithDisposes.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/DecoratorWithDisposes.java?rev=1602754&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/DecoratorWithDisposes.java
(added)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/DecoratorWithDisposes.java
Sun Jun 15 19:33:59 2014
@@ -0,0 +1,69 @@
+/*
+ * 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.webbeans.test.disposes.beans.broken;
+
+import javax.decorator.Decorator;
+import javax.decorator.Delegate;
+import javax.enterprise.inject.Disposes;
+import javax.inject.Inject;
+
+import org.apache.webbeans.test.decorators.multiple.IOutputProvider;
+
+/**
+ * This class is a standard CDI bean but has a method annotated with
+ * @Disposes which is illegal.
+ */
+@Decorator
+public class DecoratorWithDisposes implements IOutputProvider
+{
+ @Inject
+ @Delegate
+ private IOutputProvider delegate;
+
+
+ public void disposerMethodOnDecorator_isBroken(@Disposes String val)
+ {
+
+ }
+
+ @Override
+ public String getOutput()
+ {
+ return null;
+ }
+
+ @Override
+ public String trace()
+ {
+ return null;
+ }
+
+ @Override
+ public String otherMethod()
+ {
+ return null;
+ }
+
+ @Override
+ public String getDelayedOutput() throws InterruptedException
+ {
+ return null;
+ }
+
+}
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/InterceptorWithDisposes.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/InterceptorWithDisposes.java?rev=1602754&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/InterceptorWithDisposes.java
(added)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/InterceptorWithDisposes.java
Sun Jun 15 19:33:59 2014
@@ -0,0 +1,49 @@
+/*
+ * 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.webbeans.test.disposes.beans.broken;
+
+
+import javax.enterprise.inject.Disposes;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+
+import java.io.Serializable;
+
+import
org.apache.webbeans.test.component.intercept.webbeans.bindings.Transactional;
+
+/**
+ * This class is a standard CDI bean but has a method annotated with
+ * @Disposes which is illegal.
+ */
+@Transactional
+@Interceptor
+public class InterceptorWithDisposes implements Serializable
+{
+ @AroundInvoke
+ public Object caller(InvocationContext context) throws Exception
+ {
+ return context.proceed();
+ }
+
+ public void disposerMethodWithoutProducer_isBroken(@Disposes String val)
+ {
+
+ }
+}
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/NonProducerBeanWithDisposes.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/NonProducerBeanWithDisposes.java?rev=1602754&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/NonProducerBeanWithDisposes.java
(added)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/NonProducerBeanWithDisposes.java
Sun Jun 15 19:33:59 2014
@@ -0,0 +1,33 @@
+/*
+ * 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.webbeans.test.disposes.beans.broken;
+
+import javax.enterprise.inject.Disposes;
+
+/**
+ * This class is a standard CDI bean but has a method annotated with
+ * @Disposes which is illegal.
+ */
+public class NonProducerBeanWithDisposes
+{
+ public void disposerMethodWithoutProducer_isBroken(@Disposes String val)
+ {
+
+ }
+}
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/BrokenProducesTest.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/BrokenProducesTest.java?rev=1602754&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/BrokenProducesTest.java
(added)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/BrokenProducesTest.java
Sun Jun 15 19:33:59 2014
@@ -0,0 +1,57 @@
+/*
+ * 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.webbeans.test.producer.broken;
+
+import javax.enterprise.inject.spi.DefinitionException;
+
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.junit.Test;
+
+/**
+ * Test a few situations where producer methods are not allowed
+ */
+public class BrokenProducesTest extends AbstractUnitTest
+{
+
+ @Test(expected = DefinitionException.class)
+ public void testProducerMethodInDecorator() throws Exception
+ {
+ addDecorator(DecoratorWithProducerMethod.class);
+ startContainer();
+ }
+
+ @Test(expected = DefinitionException.class)
+ public void testProducerMethodInInterceptor() throws Exception
+ {
+ addInterceptor(InterceptorWithProducerMethod.class);
+ startContainer();
+ }
+ @Test(expected = DefinitionException.class)
+ public void testProducerFieldInDecorator() throws Exception
+ {
+ addDecorator(DecoratorWithProducerField.class);
+ startContainer();
+ }
+
+ @Test(expected = DefinitionException.class)
+ public void testProducerFieldInInterceptor() throws Exception
+ {
+ addInterceptor(InterceptorWithProducerField.class);
+ startContainer();
+ }
+}
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerField.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerField.java?rev=1602754&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerField.java
(added)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerField.java
Sun Jun 15 19:33:59 2014
@@ -0,0 +1,67 @@
+/*
+ * 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.webbeans.test.producer.broken;
+
+import javax.decorator.Decorator;
+import javax.decorator.Delegate;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+
+import org.apache.webbeans.test.decorators.multiple.IOutputProvider;
+
+/**
+ * This class is a standard CDI bean but has a method annotated with
+ * @Disposes which is illegal.
+ */
+@Decorator
+public class DecoratorWithProducerField implements IOutputProvider
+{
+ @Inject
+ @Delegate
+ private IOutputProvider delegate;
+
+ @Produces
+ public String kaboom = "kaboom";
+
+
+ @Override
+ public String getOutput()
+ {
+ return null;
+ }
+
+ @Override
+ public String trace()
+ {
+ return null;
+ }
+
+ @Override
+ public String otherMethod()
+ {
+ return null;
+ }
+
+ @Override
+ public String getDelayedOutput() throws InterruptedException
+ {
+ return null;
+ }
+
+}
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerMethod.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerMethod.java?rev=1602754&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerMethod.java
(added)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerMethod.java
Sun Jun 15 19:33:59 2014
@@ -0,0 +1,70 @@
+/*
+ * 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.webbeans.test.producer.broken;
+
+import javax.decorator.Decorator;
+import javax.decorator.Delegate;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+
+import org.apache.webbeans.test.decorators.multiple.IOutputProvider;
+
+/**
+ * This class is a standard CDI bean but has a method annotated with
+ * @Disposes which is illegal.
+ */
+@Decorator
+public class DecoratorWithProducerMethod implements IOutputProvider
+{
+ @Inject
+ @Delegate
+ private IOutputProvider delegate;
+
+
+ @Produces
+ public String producerMethodOnDecorator_isBroken()
+ {
+ return "kaboom";
+ }
+
+ @Override
+ public String getOutput()
+ {
+ return null;
+ }
+
+ @Override
+ public String trace()
+ {
+ return null;
+ }
+
+ @Override
+ public String otherMethod()
+ {
+ return null;
+ }
+
+ @Override
+ public String getDelayedOutput() throws InterruptedException
+ {
+ return null;
+ }
+
+}
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerField.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerField.java?rev=1602754&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerField.java
(added)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerField.java
Sun Jun 15 19:33:59 2014
@@ -0,0 +1,47 @@
+/*
+ * 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.webbeans.test.producer.broken;
+
+
+import javax.enterprise.inject.Produces;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+import java.io.Serializable;
+
+import
org.apache.webbeans.test.component.intercept.webbeans.bindings.Transactional;
+
+/**
+ * This class is a standard CDI bean but has a method annotated with
+ * @Disposes which is illegal.
+ */
+@Transactional
+@Interceptor
+public class InterceptorWithProducerField implements Serializable
+{
+ @Produces
+ public String kaboom = "kaboom";
+
+ @AroundInvoke
+ public Object caller(InvocationContext context) throws Exception
+ {
+ return context.proceed();
+ }
+
+}
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerMethod.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerMethod.java?rev=1602754&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerMethod.java
(added)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerMethod.java
Sun Jun 15 19:33:59 2014
@@ -0,0 +1,50 @@
+/*
+ * 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.webbeans.test.producer.broken;
+
+
+import javax.enterprise.inject.Produces;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+import java.io.Serializable;
+
+import
org.apache.webbeans.test.component.intercept.webbeans.bindings.Transactional;
+
+/**
+ * This class is a standard CDI bean but has a method annotated with
+ * @Disposes which is illegal.
+ */
+@Transactional
+@Interceptor
+public class InterceptorWithProducerMethod implements Serializable
+{
+ @AroundInvoke
+ public Object caller(InvocationContext context) throws Exception
+ {
+ return context.proceed();
+ }
+
+ @Produces
+ public String producerMethodOnDecorator_isBroken()
+ {
+ return "kaboom";
+ }
+
+}