-
Notifications
You must be signed in to change notification settings - Fork 47
add TCK tests for auto-closeable beans (@AutoClose)
#709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
impl/src/main/java/org/jboss/cdi/tck/tests/autoclose/bean/AutoCloseBeanTest.java
This file contains hidden or 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,68 @@ | ||
| /* | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * Apache Software License 2.0 which is available at: | ||
| * https://www.apache.org/licenses/LICENSE-2.0. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.jboss.cdi.tck.tests.autoclose.bean; | ||
|
|
||
| import static org.jboss.cdi.tck.cdi.Sections.AUTO_CLOSING; | ||
| import static org.jboss.cdi.tck.cdi.Sections.BEAN; | ||
| import static org.testng.Assert.assertFalse; | ||
| import static org.testng.Assert.assertTrue; | ||
|
|
||
| import jakarta.enterprise.context.spi.CreationalContext; | ||
| import jakarta.enterprise.inject.spi.Bean; | ||
|
|
||
| import org.jboss.arquillian.container.test.api.Deployment; | ||
| import org.jboss.cdi.tck.AbstractTest; | ||
| import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; | ||
| import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
| import org.jboss.test.audit.annotations.SpecAssertion; | ||
| import org.jboss.test.audit.annotations.SpecVersion; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| @SpecVersion(spec = "cdi", version = "5.0") | ||
| public class AutoCloseBeanTest extends AbstractTest { | ||
| @Deployment | ||
| public static WebArchive createTestArchive() { | ||
| return new WebArchiveBuilder() | ||
| .withTestClassPackage(AutoCloseBeanTest.class) | ||
| .build(); | ||
| } | ||
|
|
||
| @Test | ||
| @SpecAssertion(section = AUTO_CLOSING, id = "aa") | ||
| @SpecAssertion(section = AUTO_CLOSING, id = "b") | ||
| public void testAutoClose() { | ||
| Bean<WithAutoCloseBean> bean = getUniqueBean(WithAutoCloseBean.class); | ||
| CreationalContext<WithAutoCloseBean> cc = getCurrentBeanContainer().createCreationalContext(bean); | ||
| WithAutoCloseBean instance = bean.create(cc); | ||
| assertFalse(instance.closed); | ||
| bean.destroy(instance, cc); | ||
| assertTrue(instance.destroyed); | ||
| assertTrue(instance.closed); | ||
| } | ||
|
|
||
| @Test | ||
| @SpecAssertion(section = AUTO_CLOSING, id = "aa") | ||
| @SpecAssertion(section = AUTO_CLOSING, id = "b") | ||
| public void testNoAutoClose() { | ||
| Bean<WithoutAutoCloseBean> bean = getUniqueBean(WithoutAutoCloseBean.class); | ||
| CreationalContext<WithoutAutoCloseBean> cc = getCurrentBeanContainer().createCreationalContext(bean); | ||
| WithoutAutoCloseBean instance = bean.create(cc); | ||
| bean.destroy(instance, cc); | ||
| assertTrue(instance.destroyed); | ||
| } | ||
|
|
||
| @Test | ||
| @SpecAssertion(section = BEAN, id = "bg") | ||
| public void testMetadata() { | ||
| assertTrue(getUniqueBean(WithAutoCloseBean.class).isAutoClose()); | ||
| assertTrue(getUniqueBean(WithoutAutoCloseBean.class).isAutoClose()); | ||
| assertFalse(getUniqueBean(NormalBean.class).isAutoClose()); | ||
| } | ||
| } | ||
16 changes: 16 additions & 0 deletions
16
impl/src/main/java/org/jboss/cdi/tck/tests/autoclose/bean/NormalBean.java
This file contains hidden or 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,16 @@ | ||
| /* | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * Apache Software License 2.0 which is available at: | ||
| * https://www.apache.org/licenses/LICENSE-2.0. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.jboss.cdi.tck.tests.autoclose.bean; | ||
|
|
||
| import jakarta.enterprise.context.Dependent; | ||
|
|
||
| @Dependent | ||
| public class NormalBean { | ||
| } |
31 changes: 31 additions & 0 deletions
31
impl/src/main/java/org/jboss/cdi/tck/tests/autoclose/bean/WithAutoCloseBean.java
This file contains hidden or 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,31 @@ | ||
| /* | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * Apache Software License 2.0 which is available at: | ||
| * https://www.apache.org/licenses/LICENSE-2.0. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.jboss.cdi.tck.tests.autoclose.bean; | ||
|
|
||
| import jakarta.annotation.PreDestroy; | ||
| import jakarta.enterprise.context.AutoClose; | ||
| import jakarta.enterprise.context.Dependent; | ||
|
|
||
| @Dependent | ||
| @AutoClose | ||
| public class WithAutoCloseBean implements AutoCloseable { | ||
| public boolean destroyed = false; | ||
| public boolean closed = false; | ||
|
|
||
| @PreDestroy | ||
| public void destroy() { | ||
| destroyed = true; | ||
| } | ||
|
|
||
| @Override | ||
| public void close() throws Exception { | ||
| closed = true; | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
impl/src/main/java/org/jboss/cdi/tck/tests/autoclose/bean/WithoutAutoCloseBean.java
This file contains hidden or 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,25 @@ | ||
| /* | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * Apache Software License 2.0 which is available at: | ||
| * https://www.apache.org/licenses/LICENSE-2.0. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.jboss.cdi.tck.tests.autoclose.bean; | ||
|
|
||
| import jakarta.annotation.PreDestroy; | ||
| import jakarta.enterprise.context.AutoClose; | ||
| import jakarta.enterprise.context.Dependent; | ||
|
|
||
| @Dependent | ||
| @AutoClose | ||
| public class WithoutAutoCloseBean { | ||
| public boolean destroyed = false; | ||
|
|
||
| @PreDestroy | ||
| public void destroy() { | ||
| destroyed = true; | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
...ain/java/org/jboss/cdi/tck/tests/autoclose/bean/dependent/AutoCloseDependentBeanTest.java
This file contains hidden or 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,46 @@ | ||
| /* | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * Apache Software License 2.0 which is available at: | ||
| * https://www.apache.org/licenses/LICENSE-2.0. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.jboss.cdi.tck.tests.autoclose.bean.dependent; | ||
|
|
||
| import static org.jboss.cdi.tck.cdi.Sections.AUTO_CLOSING; | ||
| import static org.testng.Assert.assertFalse; | ||
| import static org.testng.Assert.assertTrue; | ||
|
|
||
| import jakarta.enterprise.inject.Instance; | ||
|
|
||
| import org.jboss.arquillian.container.test.api.Deployment; | ||
| import org.jboss.cdi.tck.AbstractTest; | ||
| import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; | ||
| import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
| import org.jboss.test.audit.annotations.SpecAssertion; | ||
| import org.jboss.test.audit.annotations.SpecVersion; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| @SpecVersion(spec = "cdi", version = "5.0") | ||
| public class AutoCloseDependentBeanTest extends AbstractTest { | ||
| @Deployment | ||
| public static WebArchive createTestArchive() { | ||
| return new WebArchiveBuilder() | ||
| .withTestClassPackage(AutoCloseDependentBeanTest.class) | ||
| .build(); | ||
| } | ||
|
|
||
| @Test | ||
| @SpecAssertion(section = AUTO_CLOSING, id = "aa") | ||
| @SpecAssertion(section = AUTO_CLOSING, id = "b") | ||
| public void test() { | ||
| Instance<Object> instance = getCurrentBeanContainer().createInstance(); | ||
| ConsumerBean bean = instance.select(ConsumerBean.class).get(); | ||
|
|
||
| assertFalse(DependentBean.closed); | ||
| instance.destroy(bean); | ||
| assertTrue(DependentBean.closed); | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
impl/src/main/java/org/jboss/cdi/tck/tests/autoclose/bean/dependent/ConsumerBean.java
This file contains hidden or 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,19 @@ | ||
| /* | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * Apache Software License 2.0 which is available at: | ||
| * https://www.apache.org/licenses/LICENSE-2.0. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.jboss.cdi.tck.tests.autoclose.bean.dependent; | ||
|
|
||
| import jakarta.enterprise.context.Dependent; | ||
| import jakarta.inject.Inject; | ||
|
|
||
| @Dependent | ||
| public class ConsumerBean { | ||
| @Inject | ||
| DependentBean bean; | ||
| } |
24 changes: 24 additions & 0 deletions
24
impl/src/main/java/org/jboss/cdi/tck/tests/autoclose/bean/dependent/DependentBean.java
This file contains hidden or 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,24 @@ | ||
| /* | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * Apache Software License 2.0 which is available at: | ||
| * https://www.apache.org/licenses/LICENSE-2.0. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.jboss.cdi.tck.tests.autoclose.bean.dependent; | ||
|
|
||
| import jakarta.enterprise.context.AutoClose; | ||
| import jakarta.enterprise.context.Dependent; | ||
|
|
||
| @Dependent | ||
| @AutoClose | ||
| public class DependentBean implements AutoCloseable { | ||
| public static boolean closed = false; | ||
|
|
||
| @Override | ||
| public void close() throws Exception { | ||
| closed = true; | ||
| } | ||
| } |
70 changes: 70 additions & 0 deletions
70
...ain/java/org/jboss/cdi/tck/tests/autoclose/producer/field/AutoCloseProducerFieldTest.java
This file contains hidden or 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,70 @@ | ||
| /* | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * Apache Software License 2.0 which is available at: | ||
| * https://www.apache.org/licenses/LICENSE-2.0. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.jboss.cdi.tck.tests.autoclose.producer.field; | ||
|
|
||
| import static org.jboss.cdi.tck.cdi.Sections.AUTO_CLOSING; | ||
| import static org.jboss.cdi.tck.cdi.Sections.BEAN; | ||
| import static org.testng.Assert.assertFalse; | ||
| import static org.testng.Assert.assertTrue; | ||
|
|
||
| import jakarta.enterprise.context.spi.CreationalContext; | ||
| import jakarta.enterprise.inject.spi.Bean; | ||
|
|
||
| import org.jboss.arquillian.container.test.api.Deployment; | ||
| import org.jboss.cdi.tck.AbstractTest; | ||
| import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; | ||
| import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
| import org.jboss.test.audit.annotations.SpecAssertion; | ||
| import org.jboss.test.audit.annotations.SpecVersion; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| @SpecVersion(spec = "cdi", version = "5.0") | ||
| public class AutoCloseProducerFieldTest extends AbstractTest { | ||
| @Deployment | ||
| public static WebArchive createTestArchive() { | ||
| return new WebArchiveBuilder() | ||
| .withTestClassPackage(AutoCloseProducerFieldTest.class) | ||
| .build(); | ||
| } | ||
|
|
||
| @Test | ||
| @SpecAssertion(section = AUTO_CLOSING, id = "ac") | ||
| @SpecAssertion(section = AUTO_CLOSING, id = "b") | ||
| public void testWithAutoClose() { | ||
| Bean<WithAutoClose> bean = getUniqueBean(WithAutoClose.class); | ||
| CreationalContext<WithAutoClose> cc = getCurrentBeanContainer().createCreationalContext(bean); | ||
| WithAutoClose instance = bean.create(cc); | ||
| assertFalse(Producers.withAutoCloseDisposed); | ||
| assertFalse(instance.closed); | ||
| bean.destroy(instance, cc); | ||
| assertTrue(Producers.withAutoCloseDisposed); | ||
| assertTrue(instance.closed); | ||
| } | ||
|
|
||
| @Test | ||
| @SpecAssertion(section = AUTO_CLOSING, id = "ac") | ||
| @SpecAssertion(section = AUTO_CLOSING, id = "b") | ||
| public void testWithoutAutoClose() { | ||
| Bean<WithoutAutoClose> bean = getUniqueBean(WithoutAutoClose.class); | ||
| CreationalContext<WithoutAutoClose> cc = getCurrentBeanContainer().createCreationalContext(bean); | ||
| WithoutAutoClose instance = bean.create(cc); | ||
| assertFalse(Producers.withoutAutoCloseDisposed); | ||
| bean.destroy(instance, cc); | ||
| assertTrue(Producers.withoutAutoCloseDisposed); | ||
| } | ||
|
|
||
| @Test | ||
| @SpecAssertion(section = BEAN, id = "bg") | ||
| public void testMetadata() { | ||
| assertTrue(getUniqueBean(WithAutoClose.class).isAutoClose()); | ||
| assertTrue(getUniqueBean(WithoutAutoClose.class).isAutoClose()); | ||
| assertFalse(getUniqueBean(Normal.class).isAutoClose()); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
impl/src/main/java/org/jboss/cdi/tck/tests/autoclose/producer/field/Normal.java
This file contains hidden or 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,13 @@ | ||
| /* | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * Apache Software License 2.0 which is available at: | ||
| * https://www.apache.org/licenses/LICENSE-2.0. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.jboss.cdi.tck.tests.autoclose.producer.field; | ||
|
|
||
| public class Normal { | ||
| } |
44 changes: 44 additions & 0 deletions
44
impl/src/main/java/org/jboss/cdi/tck/tests/autoclose/producer/field/Producers.java
This file contains hidden or 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,44 @@ | ||
| /* | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * Apache Software License 2.0 which is available at: | ||
| * https://www.apache.org/licenses/LICENSE-2.0. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.jboss.cdi.tck.tests.autoclose.producer.field; | ||
|
|
||
| import jakarta.enterprise.context.ApplicationScoped; | ||
| import jakarta.enterprise.context.AutoClose; | ||
| import jakarta.enterprise.context.Dependent; | ||
| import jakarta.enterprise.inject.Disposes; | ||
| import jakarta.enterprise.inject.Produces; | ||
|
|
||
| @ApplicationScoped | ||
| public class Producers { | ||
| static boolean withAutoCloseDisposed = false; | ||
| static boolean withoutAutoCloseDisposed = false; | ||
|
|
||
| @Produces | ||
| @Dependent | ||
| @AutoClose | ||
| WithAutoClose withAutoClose = new WithAutoClose(); | ||
|
|
||
| @Produces | ||
| @Dependent | ||
| @AutoClose | ||
| WithoutAutoClose withoutAutoClose = new WithoutAutoClose(); | ||
|
|
||
| @Produces | ||
| @Dependent | ||
| Normal normal = new Normal(); | ||
|
|
||
| public void disposeWithAutoClose(@Disposes WithAutoClose withAutoClose) { | ||
| withAutoCloseDisposed = true; | ||
| } | ||
|
|
||
| public void disposeWithoutAutoClose(@Disposes WithoutAutoClose withAutoClose) { | ||
| withoutAutoCloseDisposed = true; | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
impl/src/main/java/org/jboss/cdi/tck/tests/autoclose/producer/field/WithAutoClose.java
This file contains hidden or 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,19 @@ | ||
| /* | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * Apache Software License 2.0 which is available at: | ||
| * https://www.apache.org/licenses/LICENSE-2.0. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.jboss.cdi.tck.tests.autoclose.producer.field; | ||
|
|
||
| public class WithAutoClose implements AutoCloseable { | ||
| public boolean closed = false; | ||
|
|
||
| @Override | ||
| public void close() throws Exception { | ||
| closed = true; | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
impl/src/main/java/org/jboss/cdi/tck/tests/autoclose/producer/field/WithoutAutoClose.java
This file contains hidden or 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,13 @@ | ||
| /* | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * Apache Software License 2.0 which is available at: | ||
| * https://www.apache.org/licenses/LICENSE-2.0. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.jboss.cdi.tck.tests.autoclose.producer.field; | ||
|
|
||
| public class WithoutAutoClose { | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.