Skip to content

Commit

Permalink
WELD-556
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Aug 19, 2010
1 parent 52cb451 commit 9176403
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 4 deletions.
@@ -0,0 +1,34 @@
package org.jboss.weld.tests.enterprise.lifecycle;

import java.io.Serializable;

import javax.decorator.Decorator;
import javax.decorator.Delegate;
import javax.inject.Inject;

@Decorator
public abstract class AlarmedChickenHutch implements ChickenHutch, Serializable
{

private static boolean ping;

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

public static boolean isPing()
{
return ping;
}

@Inject @Delegate
private ChickenHutch chickenHutch;

public void ping()
{
ping = true;
chickenHutch.ping();
}

}
@@ -0,0 +1,11 @@
package org.jboss.weld.tests.enterprise.lifecycle;

import javax.ejb.Local;

@Local
public interface ChickenHutch
{

public void ping();

}
@@ -0,0 +1,16 @@
package org.jboss.weld.tests.enterprise.lifecycle;

import javax.enterprise.inject.Produces;

public class ChickenHutchFactory
{

// Redirect via a producer method so dependents are automatically destroyed
@Produces @MassProduced
public ChickenHutch makeChickenHutch(ChickenHutch chickenHutch)
{
chickenHutch.ping();
return chickenHutch;
}

}
Expand Up @@ -17,16 +17,16 @@
package org.jboss.weld.tests.enterprise.lifecycle;

import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.spi.Bean;
import javax.inject.Inject;

import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.BeanArchive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.weld.Container;
import org.jboss.weld.context.ContextLifecycle;
import org.jboss.weld.context.RequestContext;
Expand Down Expand Up @@ -62,10 +62,10 @@ public static Archive<?> deploy()
{
return ShrinkWrap.create(EnterpriseArchive.class, "test.ear")
.addModule(
ShrinkWrap.create(JavaArchive.class, "test.jar")
ShrinkWrap.create(BeanArchive.class, "test.jar")
.decorate(AlarmedChickenHutch.class)
.addPackage(EnterpriseBeanLifecycleTest.class.getPackage())
.addClass(Utils.class)
.addManifestResource(EmptyAsset.INSTANCE, "beans.xml")
);
}

Expand Down Expand Up @@ -124,5 +124,19 @@ public void testDestroyDoesntTryToRemoveSLSB()
BeanLocal instance = bean.create(creationalContext);
bean.destroy(instance, creationalContext);
}

@Inject @MassProduced Instance<ChickenHutch> chickenHutchInstance;

@Test
// WELD-556
public void testDecoratedSFSBsAreRemoved()
{
StandardChickenHutch.reset();
AlarmedChickenHutch.reset();
chickenHutchInstance.get();
assert StandardChickenHutch.isPing();
assert AlarmedChickenHutch.isPing();
assert StandardChickenHutch.isPredestroy();
}

}
@@ -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.enterprise.lifecycle;

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.Retention;
import java.lang.annotation.Target;

import javax.inject.Qualifier;

@Retention(RUNTIME)
@Target({TYPE, METHOD, FIELD, PARAMETER})
@Qualifier
@interface MassProduced
{

}
@@ -0,0 +1,47 @@
package org.jboss.weld.tests.enterprise.lifecycle;

import javax.annotation.PreDestroy;
import javax.ejb.Stateful;

@Stateful
public class StandardChickenHutch implements ChickenHutch
{

private static boolean preDestroy;

private static boolean ping;

public static boolean isPing()
{
return ping;
}

public static void reset()
{
preDestroy = false;
ping = false;
}

public static boolean isPredestroy()
{
return preDestroy;
}

public void ping()
{
ping = true;
}

@PreDestroy
public void preDestroy()
{
if (ping)
{
preDestroy = true;
}
else
{
preDestroy = false;
}
}
}

0 comments on commit 9176403

Please sign in to comment.