You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2014/12/23 13:21:22 UTC
svn commit: r1647564 - in /openwebbeans/trunk/webbeans-impl/src:
main/java/org/apache/webbeans/component/ManagedBean.java
test/java/org/apache/webbeans/test/portable/BeanInjectionTest.java
Author: rmannibucau
Date: Tue Dec 23 12:21:21 2014
New Revision: 1647564
URL: http://svn.apache.org/r1647564
Log:
ensuring injected Bean<T> is the expected one and not a pervious one
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/BeanInjectionTest.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java?rev=1647564&r1=1647563&r2=1647564&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java Tue Dec 23 12:21:21 2014
@@ -18,6 +18,7 @@
*/
package org.apache.webbeans.component;
+import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Bean;
@@ -60,6 +61,7 @@ public class ManagedBean<T> extends Inje
}
CreationalContextImpl<T> creationalContextImpl = (CreationalContextImpl<T>)creationalContext;
Bean<T> oldBean = creationalContextImpl.putBean(this);
+ Contextual<T> oldContextual = creationalContextImpl.putContextual(this); // otherwise BeanMetaData is broken
try
{
return super.create(creationalContext);
@@ -67,6 +69,7 @@ public class ManagedBean<T> extends Inje
finally
{
creationalContextImpl.putBean(oldBean);
+ creationalContextImpl.putContextual(oldContextual);
}
}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/BeanInjectionTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/BeanInjectionTest.java?rev=1647564&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/BeanInjectionTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/BeanInjectionTest.java Tue Dec 23 12:21:21 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.portable;
+
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.junit.Test;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.inject.Inject;
+
+import static org.junit.Assert.assertEquals;
+
+public class BeanInjectionTest extends AbstractUnitTest
+{
+ @Test
+ public void run()
+ {
+ startContainer(Foo.class, Bar.class);
+ assertEquals(Foo.class, getInstance(Bar.class).getFoo().getBean().getBeanClass());
+ }
+
+ public static class Foo
+ {
+ @Inject
+ private Bean<Foo> bean;
+
+ public Bean<Foo> getBean() {
+ return bean;
+ }
+ }
+
+ public static class Bar
+ {
+ @Inject
+ private Foo foo;
+
+ public Foo getFoo() {
+ return foo;
+ }
+ }
+}