Skip to content

Commit

Permalink
WBRI-351
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@3469 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Aug 12, 2009
1 parent b600a8b commit 8627122
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 0 deletions.
Expand Up @@ -78,6 +78,9 @@ public void inject(T instance, CreationalContext<T> ctx)

public void postConstruct(T instance)
{
if (postConstruct == null)
return;

try
{
postConstruct.invoke(instance);
Expand All @@ -90,6 +93,9 @@ public void postConstruct(T instance)

public void preDestroy(T instance)
{
if (preDestroy == null)
return;

try
{
preDestroy.invoke(instance);
Expand Down
@@ -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);
}
}

}
@@ -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;
}
@@ -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
{

}
@@ -0,0 +1,5 @@
package org.jboss.webbeans.test.unit.noncontextual;

public class WebBean
{
}
1 change: 1 addition & 0 deletions tests/unit-tests.xml
Expand Up @@ -52,6 +52,7 @@
<package name="org.jboss.webbeans.test.unit.lookup.circular" />
<package name="org.jboss.webbeans.test.unit.lookup.wbri279" />
<package name="org.jboss.webbeans.test.unit.manager" />
<package name="org.jboss.webbeans.test.unit.noncontextual" />
<package name="org.jboss.webbeans.test.unit.security" />
</packages>
</test>
Expand Down

0 comments on commit 8627122

Please sign in to comment.