Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WELD-1894 - test disposer method called once.
- Loading branch information
Showing
6 changed files
with
332 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
...an/src/test/java/org/jboss/weld/tests/disposer/weld1894/DisposesMethodCalledOnceTest.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,87 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2015, 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.disposer.weld1894; | ||
|
||
import javax.enterprise.inject.spi.BeanManager; | ||
import javax.inject.Inject; | ||
|
||
import junit.framework.Assert; | ||
import org.jboss.arquillian.container.test.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.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* @author Tomas Remes | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class DisposesMethodCalledOnceTest { | ||
|
||
@Inject | ||
BeanManager beanManager; | ||
|
||
@Deployment | ||
public static Archive<?> getDeployment() { | ||
return ShrinkWrap.create(BeanArchive.class).addPackage(DisposesMethodCalledOnceTest.class.getPackage()); | ||
} | ||
|
||
@Test | ||
public void testDisposerCalledOnce1() { | ||
ProducerBean.reset(); | ||
beanManager.fireEvent("Hello"); | ||
Assert.assertEquals("Disposer method called multiple times!", 1, ProducerBean.firstDisposerCalled.get()); | ||
} | ||
|
||
@Test | ||
public void testDisposerCalledOnce2() { | ||
ProducerBean.reset(); | ||
beanManager.fireEvent("Hello"); | ||
Assert.assertEquals("Disposer method called multiple times!", 1, ProducerBean.secondDisposerCalled.get()); | ||
} | ||
|
||
@Test | ||
public void testDisposerCalledOnce3() { | ||
ProducerBean.reset(); | ||
beanManager.fireEvent("Hello"); | ||
Assert.assertEquals("Disposer method called multiple times!", 1, ProducerBean.thirdDisposerCalled.get()); | ||
} | ||
|
||
@Test | ||
public void testDisposerCalledOnce4() { | ||
ProducerBean.reset(); | ||
beanManager.fireEvent("Hello"); | ||
Assert.assertEquals("Disposer method called multiple times!", 1, ProducerBean.forthDisposerCalled.get()); | ||
} | ||
|
||
@Test | ||
public void testDisposerCalledOnce5() { | ||
ProducerBean.reset(); | ||
beanManager.fireEvent("Hello"); | ||
Assert.assertEquals("Disposer method called multiple times!", 1, ProducerBean.fifthDisposerCalled.get()); | ||
} | ||
|
||
@Test | ||
public void testDisposerCalledOnce6() { | ||
ProducerBean.reset(); | ||
beanManager.fireEvent("Hello"); | ||
Assert.assertEquals("Disposer method called multiple times!", 1, ProducerBean.sixthDisposerCalled.get()); | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
tests-arquillian/src/test/java/org/jboss/weld/tests/disposer/weld1894/DummyQualifier.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,45 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2015, 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.disposer.weld1894; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
import javax.enterprise.util.AnnotationLiteral; | ||
import javax.inject.Qualifier; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Qualifier | ||
public @interface DummyQualifier { | ||
|
||
String value(); | ||
|
||
@SuppressWarnings("all") | ||
public static class Literal extends AnnotationLiteral<DummyQualifier> implements DummyQualifier { | ||
|
||
private final String value; | ||
|
||
public Literal(String value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public String value() { | ||
return value; | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
tests-arquillian/src/test/java/org/jboss/weld/tests/disposer/weld1894/FirstBean.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,27 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2015, 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.disposer.weld1894; | ||
|
||
import javax.enterprise.context.Dependent; | ||
|
||
@Dependent | ||
public class FirstBean { | ||
|
||
public void ping() { | ||
|
||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
tests-arquillian/src/test/java/org/jboss/weld/tests/disposer/weld1894/ProducerBean.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,104 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2015, 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.disposer.weld1894; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import javax.enterprise.inject.Disposes; | ||
import javax.enterprise.inject.Produces; | ||
import javax.enterprise.inject.TransientReference; | ||
|
||
public class ProducerBean { | ||
|
||
public static AtomicInteger firstDisposerCalled = new AtomicInteger(); | ||
public static AtomicInteger secondDisposerCalled = new AtomicInteger(); | ||
public static AtomicInteger thirdDisposerCalled = new AtomicInteger(); | ||
public static AtomicInteger forthDisposerCalled = new AtomicInteger(); | ||
public static AtomicInteger fifthDisposerCalled = new AtomicInteger(); | ||
public static AtomicInteger sixthDisposerCalled = new AtomicInteger(); | ||
|
||
@Produces | ||
@DummyQualifier("A") | ||
public FirstBean produceA() { | ||
return new FirstBean(); | ||
} | ||
|
||
@Produces | ||
@DummyQualifier("B") | ||
public FirstBean produceB() { | ||
return new FirstBean(); | ||
} | ||
|
||
@Produces | ||
@DummyQualifier("C") | ||
public FirstBean produceC(@DummyQualifier("D") SecondBean secondBean) { | ||
secondBean.ping(); | ||
return new FirstBean(); | ||
} | ||
|
||
@Produces | ||
@DummyQualifier("E") | ||
public FirstBean produceE(@TransientReference @DummyQualifier("F") SecondBean secondBean) { | ||
secondBean.ping(); | ||
return new FirstBean(); | ||
} | ||
|
||
@Produces | ||
@DummyQualifier("D") | ||
public SecondBean produceD() { | ||
return new SecondBean(); | ||
} | ||
|
||
@Produces | ||
@DummyQualifier("F") | ||
public SecondBean produceF() { | ||
return new SecondBean(); | ||
} | ||
|
||
public void disposeA(@Disposes @DummyQualifier("A") FirstBean bean) { | ||
firstDisposerCalled.incrementAndGet(); | ||
} | ||
|
||
public void disposeB(@Disposes @DummyQualifier("B") FirstBean bean) { | ||
secondDisposerCalled.incrementAndGet(); | ||
} | ||
|
||
public void disposeC(@Disposes @DummyQualifier("C") FirstBean bean) { | ||
thirdDisposerCalled.incrementAndGet(); | ||
} | ||
|
||
public void disposeE(@Disposes @DummyQualifier("E") FirstBean bean) { | ||
sixthDisposerCalled.incrementAndGet(); | ||
} | ||
|
||
public void disposeD(@Disposes @DummyQualifier("D") SecondBean bean) { | ||
forthDisposerCalled.incrementAndGet(); | ||
} | ||
|
||
public void disposeF(@Disposes @DummyQualifier("F") SecondBean bean) { | ||
fifthDisposerCalled.incrementAndGet(); | ||
} | ||
|
||
public static void reset() { | ||
firstDisposerCalled = new AtomicInteger(); | ||
secondDisposerCalled = new AtomicInteger(); | ||
thirdDisposerCalled = new AtomicInteger(); | ||
forthDisposerCalled = new AtomicInteger(); | ||
fifthDisposerCalled = new AtomicInteger(); | ||
sixthDisposerCalled = new AtomicInteger(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
tests-arquillian/src/test/java/org/jboss/weld/tests/disposer/weld1894/SecondBean.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,27 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2015, 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.disposer.weld1894; | ||
|
||
import javax.enterprise.context.Dependent; | ||
|
||
@Dependent | ||
public class SecondBean { | ||
|
||
public void ping() { | ||
|
||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
tests-arquillian/src/test/java/org/jboss/weld/tests/disposer/weld1894/TestObserver.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,42 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2015, 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.disposer.weld1894; | ||
|
||
import javax.enterprise.event.Observes; | ||
import javax.enterprise.inject.Instance; | ||
import javax.inject.Inject; | ||
|
||
public class TestObserver { | ||
|
||
@Inject | ||
@DummyQualifier("B") | ||
Instance<FirstBean> beanB; | ||
|
||
@Inject | ||
@DummyQualifier("C") | ||
FirstBean beanC; | ||
|
||
@Inject | ||
@DummyQualifier("E") | ||
FirstBean beanE; | ||
|
||
public void observes(@Observes String message, @DummyQualifier("A") FirstBean dependentBean) { | ||
beanB.destroy(beanB.get()); | ||
beanE.ping(); | ||
beanC.ping(); | ||
} | ||
} |