Skip to content

Commit

Permalink
WELD-318
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Jan 13, 2010
1 parent 33441f0 commit e77eb6f
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 1 deletion.
@@ -0,0 +1,11 @@
package org.jboss.weld.tests.extensions;

public class Capercaillie
{

public Capercaillie(String name)
{
// TODO Auto-generated constructor stub
}

}
Expand Up @@ -89,5 +89,16 @@ public void testContainerEventsOnlySentToExtensionBeans()
assert !otherObserver.isAllAfterDeploymentValidation();

}

@Test
public void testInjectionTargetWrapped()
{
getCurrentManager().getInstanceByType(Capercaillie.class);
assert Woodland.isPostConstructCalled();
assert WoodlandExtension.isInjectCalled();
assert WoodlandExtension.isPostConstructCalled();
assert WoodlandExtension.isPreDestroyCalled();
assert WoodlandExtension.isProduceCalled();
}

}
30 changes: 30 additions & 0 deletions tests/src/test/java/org/jboss/weld/tests/extensions/Woodland.java
@@ -0,0 +1,30 @@
package org.jboss.weld.tests.extensions;

import javax.annotation.PostConstruct;
import javax.enterprise.inject.Produces;

public class Woodland
{

private static boolean postConstructCalled;

@Produces
private Capercaillie capercaillie = new Capercaillie("bob");

@PostConstruct
public void postConstruct()
{
postConstructCalled = true;
}

public static boolean isPostConstructCalled()
{
return postConstructCalled;
}

public static void reset()
{
postConstructCalled = false;
}

}
@@ -0,0 +1,99 @@
package org.jboss.weld.tests.extensions;

import java.util.Set;

import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.BeforeShutdown;
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;
import javax.enterprise.inject.spi.ProcessInjectionTarget;

public class WoodlandExtension implements Extension
{

private static boolean injectCalled;
private static boolean postConstructCalled;
private static boolean preDestroyCalled;
private static boolean produceCalled;

public void cleanup(@Observes BeforeShutdown shutdown)
{
reset();
Woodland.reset();
}

public void enhanceWoodland(final @Observes ProcessInjectionTarget<Woodland> processWoodland)
{
final InjectionTarget<Woodland> it = processWoodland.getInjectionTarget();
processWoodland.setInjectionTarget(new InjectionTarget<Woodland>()
{

public void inject(Woodland instance, CreationalContext<Woodland> ctx)
{
injectCalled = true;
it.inject(instance, ctx);
}

public void postConstruct(Woodland instance)
{
postConstructCalled = true;
it.postConstruct(instance);
}

public void preDestroy(Woodland instance)
{
preDestroyCalled = true;
it.preDestroy(instance);
}

public void dispose(Woodland instance)
{
// No-op for class bean

}

public Set<InjectionPoint> getInjectionPoints()
{
return it.getInjectionPoints();
}

public Woodland produce(CreationalContext<Woodland> ctx)
{
produceCalled = true;
return it.produce(ctx);
}

});
}

public static void reset()
{
injectCalled = false;
postConstructCalled = false;
preDestroyCalled = false;
preDestroyCalled = false;
}

public static boolean isInjectCalled()
{
return injectCalled;
}

public static boolean isPostConstructCalled()
{
return postConstructCalled;
}

public static boolean isPreDestroyCalled()
{
return preDestroyCalled;
}

public static boolean isProduceCalled()
{
return produceCalled;
}

}
@@ -1,2 +1,3 @@
org.jboss.weld.tests.extensions.SimpleExtension
org.jboss.weld.tests.extensions.ExtensionObserver
org.jboss.weld.tests.extensions.ExtensionObserver
org.jboss.weld.tests.extensions.WoodlandExtension

0 comments on commit e77eb6f

Please sign in to comment.