Author: jharting
Date: 2010-06-24 07:51:42 -0400 (Thu, 24 Jun 2010)
New Revision: 6577
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/Aircraft.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/AircraftDecorator.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/InjectionTargetExtension.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/InjectionTargetTest.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/InjectionTargetWrapper.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/Secured.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/SecurityInterceptor.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/Spitfire.java
core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/injectionTarget/
core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/injectionTarget/beans.xml
core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/injectionTarget/javax.enterprise.inject.spi.Extension
Log:
Added tests for WELD-557
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/Aircraft.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/Aircraft.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/Aircraft.java 2010-06-24
11:51:42 UTC (rev 6577)
@@ -0,0 +1,22 @@
+/*
+ * 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.extensions.injectionTarget;
+
+interface Aircraft
+{
+ boolean isFlying();
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/AircraftDecorator.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/AircraftDecorator.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/AircraftDecorator.java 2010-06-24
11:51:42 UTC (rev 6577)
@@ -0,0 +1,34 @@
+/*
+ * 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.extensions.injectionTarget;
+
+import javax.decorator.Decorator;
+import javax.decorator.Delegate;
+import javax.inject.Inject;
+
+@Decorator
+class AircraftDecorator implements Aircraft
+{
+ @Inject @Delegate
+ private Aircraft delegate;
+
+ public boolean isFlying()
+ {
+ return ! delegate.isFlying();
+ }
+
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/InjectionTargetExtension.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/InjectionTargetExtension.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/InjectionTargetExtension.java 2010-06-24
11:51:42 UTC (rev 6577)
@@ -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.extensions.injectionTarget;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.InjectionTarget;
+import javax.enterprise.inject.spi.ProcessInjectionTarget;
+
+public class InjectionTargetExtension implements Extension
+{
+ public void foo(@Observes ProcessInjectionTarget<Spitfire> event)
+ {
+ InjectionTarget<Spitfire> it = event.getInjectionTarget();
+ event.setInjectionTarget(decorate(it));
+ }
+
+ private <T> InjectionTarget<T> decorate(InjectionTarget<T>
delegate)
+ {
+ return new InjectionTargetWrapper<T>(delegate);
+ }
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/InjectionTargetTest.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/InjectionTargetTest.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/InjectionTargetTest.java 2010-06-24
11:51:42 UTC (rev 6577)
@@ -0,0 +1,71 @@
+/*
+ * 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.extensions.injectionTarget;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.IntegrationTest;
+import org.jboss.testharness.impl.packaging.Packaging;
+import org.jboss.testharness.impl.packaging.PackagingType;
+import org.jboss.testharness.impl.packaging.jsr299.BeansXml;
+import org.jboss.testharness.impl.packaging.jsr299.Extension;
+import org.jboss.weld.test.AbstractWeldTest;
+import org.testng.annotations.Test;
+
+@Artifact
+@IntegrationTest
+(a)BeansXml("beans.xml")
+(a)Packaging(PackagingType.EAR)
+(a)Extension("javax.enterprise.inject.spi.Extension")
+public class InjectionTargetTest extends AbstractWeldTest
+{
+ @Test(description="WELD-557")
+ public void testActualInstanceAndNotProxyPassedToInject()
+ {
+ InjectionTargetWrapper.clear();
+ Spitfire aircraft = getReference(Spitfire.class);
+ aircraft.isFlying();
+ assert aircraft.isTheSameInstance(InjectionTargetWrapper.injectInstance);
+ }
+
+ @Test(description="WELD-557")
+ public void testActualInstanceAndNotProxyPassedToPostConstruct()
+ {
+ InjectionTargetWrapper.clear();
+ Spitfire aircraft = getReference(Spitfire.class);
+ aircraft.isFlying();
+ assert aircraft.isTheSameInstance(InjectionTargetWrapper.postConstructInstance);
+ }
+
+ @Test(description="WELD-557")
+ public void testActualInstanceAndNotProxyPassedToPreDestroy()
+ {
+ // prepare instance
+ InjectionTargetWrapper.clear();
+ Bean<Spitfire> bean = getBean(Spitfire.class);
+ CreationalContext<Spitfire> ctx =
getCurrentManager().createCreationalContext(bean);
+ Spitfire aircraft = (Spitfire) getCurrentManager().getReference(bean,
Spitfire.class, ctx);
+ // invoke business method
+ aircraft.isFlying();
+ // destroy instance
+ bean.destroy(aircraft, ctx);
+
+ assert aircraft.isTheSameInstance(InjectionTargetWrapper.preDestroyInstance);
+ }
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/InjectionTargetWrapper.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/InjectionTargetWrapper.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/InjectionTargetWrapper.java 2010-06-24
11:51:42 UTC (rev 6577)
@@ -0,0 +1,76 @@
+/*
+ * 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.extensions.injectionTarget;
+
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InjectionTarget;
+
+class InjectionTargetWrapper<T> implements InjectionTarget<T>
+{
+ private InjectionTarget<T> delegate;
+ public static Object injectInstance;
+ public static Object postConstructInstance;
+ public static Object preDestroyInstance;
+
+ public static void clear()
+ {
+ injectInstance = null;
+ postConstructInstance = null;
+ preDestroyInstance = null;
+ }
+
+ public InjectionTargetWrapper(InjectionTarget<T> delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ public void inject(T instance, CreationalContext<T> ctx)
+ {
+ injectInstance = instance;
+ delegate.inject(instance, ctx);
+ }
+
+ public void postConstruct(T instance)
+ {
+ postConstructInstance = instance;
+ delegate.postConstruct(instance);
+ }
+
+ public void preDestroy(T instance)
+ {
+ preDestroyInstance = instance;
+ delegate.preDestroy(instance);
+ }
+
+ public void dispose(T instance)
+ {
+ delegate.dispose(instance);
+ }
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return delegate.getInjectionPoints();
+ }
+
+ public T produce(CreationalContext<T> ctx)
+ {
+ return delegate.produce(ctx);
+ }
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/Secured.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/Secured.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/Secured.java 2010-06-24
11:51:42 UTC (rev 6577)
@@ -0,0 +1,33 @@
+/*
+ * 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.extensions.injectionTarget;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import javax.interceptor.InterceptorBinding;
+
+@InterceptorBinding
+@Retention(RUNTIME)
+(a)Target({ElementType.TYPE, ElementType.METHOD})
+@Documented
+@interface Secured
+{
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/SecurityInterceptor.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/SecurityInterceptor.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/SecurityInterceptor.java 2010-06-24
11:51:42 UTC (rev 6577)
@@ -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.extensions.injectionTarget;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+
+@Interceptor
+@Secured
+class SecurityInterceptor
+{
+ @AroundInvoke
+ public Object intercept(InvocationContext ctx) throws Exception
+ {
+ return ! (Boolean) ctx.proceed();
+ }
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/Spitfire.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/Spitfire.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/Spitfire.java 2010-06-24
11:51:42 UTC (rev 6577)
@@ -0,0 +1,43 @@
+/*
+ * 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.extensions.injectionTarget;
+
+import javax.enterprise.context.RequestScoped;
+
+@RequestScoped
+class Spitfire implements Aircraft
+{
+ @Secured
+ public boolean interceptedMethod()
+ {
+ return false;
+ }
+
+ public boolean isFlying()
+ {
+ return false;
+ }
+
+ /*
+ * Cannot use equals() since behavior of all Object class methods
+ * except for toString() is not defined on the client proxy
+ */
+ public boolean isTheSameInstance(Object object)
+ {
+ return this == object;
+ }
+}
Added:
core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/injectionTarget/beans.xml
===================================================================
---
core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/injectionTarget/beans.xml
(rev 0)
+++
core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/injectionTarget/beans.xml 2010-06-24
11:51:42 UTC (rev 6577)
@@ -0,0 +1,8 @@
+<beans>
+ <interceptors>
+
<class>org.jboss.weld.tests.extensions.injectionTarget.SecurityInterceptor</class>
+ </interceptors>
+ <decorators>
+
<class>org.jboss.weld.tests.extensions.injectionTarget.AircraftDecorator</class>
+ </decorators>
+</beans>
Added:
core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/injectionTarget/javax.enterprise.inject.spi.Extension
===================================================================
---
core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/injectionTarget/javax.enterprise.inject.spi.Extension
(rev 0)
+++
core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/injectionTarget/javax.enterprise.inject.spi.Extension 2010-06-24
11:51:42 UTC (rev 6577)
@@ -0,0 +1 @@
+org.jboss.weld.tests.extensions.injectionTarget.InjectionTargetExtension