Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@3469 1c488680-804c-0410-94cd-c6b725194a0e
- Loading branch information
Showing
6 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
tests/src/test/java/org/jboss/webbeans/test/unit/noncontextual/ExampleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.jboss.webbeans.test.unit.noncontextual; | ||
|
||
import javax.enterprise.context.spi.CreationalContext; | ||
import javax.enterprise.inject.spi.AnnotatedType; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
import javax.enterprise.inject.spi.InjectionTarget; | ||
|
||
import org.jboss.testharness.impl.packaging.Artifact; | ||
import org.jboss.webbeans.test.AbstractWebBeansTest; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
@Artifact | ||
public class ExampleTest extends AbstractWebBeansTest | ||
{ | ||
@Test | ||
public void testNonContextual() throws Exception | ||
{ | ||
NonContextual<External> nonContextual = new NonContextual<External>(getCurrentManager(), External.class); | ||
|
||
External external = new External(); | ||
Assert.assertNull(external.bean); | ||
nonContextual.postConstruct(external); | ||
Assert.assertNotNull(external.bean); | ||
nonContextual.preDestroy(external); | ||
// preDestroy doesn't cause any dis-injection | ||
Assert.assertNotNull(external.bean); | ||
} | ||
|
||
public class NonContextual<T> { | ||
|
||
final InjectionTarget<T> it; | ||
final BeanManager manager; | ||
|
||
public NonContextual(BeanManager manager, Class<T> clazz) { | ||
this.manager = manager; | ||
AnnotatedType<T> type = manager.createAnnotatedType(clazz); | ||
this.it = manager.createInjectionTarget(type); | ||
} | ||
|
||
public CreationalContext<T> postConstruct(T instance) { | ||
CreationalContext<T> cc = manager.createCreationalContext(null); | ||
it.inject(instance, cc); | ||
it.postConstruct(instance); | ||
return cc; | ||
} | ||
|
||
public void preDestroy(T instance) { | ||
it.preDestroy(instance); | ||
} | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
tests/src/test/java/org/jboss/webbeans/test/unit/noncontextual/External.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2006, Red Hat Middleware LLC, and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.webbeans.test.unit.noncontextual; | ||
|
||
import javax.enterprise.inject.Current; | ||
|
||
/** | ||
* | ||
* @author <a href="kabir.khan@jboss.com">Kabir Khan</a> | ||
* @version $Revision: 1.1 $ | ||
*/ | ||
public class External | ||
{ | ||
|
||
public External() | ||
{ | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
@Current WebBean bean; | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/src/test/java/org/jboss/webbeans/test/unit/noncontextual/Random.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.jboss.webbeans.test.unit.noncontextual; | ||
|
||
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.enterprise.inject.BindingType; | ||
|
||
@Target( { TYPE, METHOD, PARAMETER, FIELD }) | ||
@Retention(RUNTIME) | ||
@Documented | ||
@BindingType | ||
public @interface Random | ||
{ | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
tests/src/test/java/org/jboss/webbeans/test/unit/noncontextual/WebBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.jboss.webbeans.test.unit.noncontextual; | ||
|
||
public class WebBean | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters