-
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
Open
Ladicek
wants to merge
5
commits into
jakartaee:main
Choose a base branch
from
Ladicek:auto-close
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9747598
modernize ActionSequence a little
Ladicek 0962388
add TCK tests for auto-closeable beans (@AutoClose)
Ladicek dc637e5
add TCK tests for CDI Full SPI changes related to auto-closeable beans
Ladicek fb7345e
add test that the call to AutoCloseable.close() during destruction is…
Ladicek e444d99
add test that auto-closeable dependent objects are closed when the co…
Ladicek 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
67 changes: 67 additions & 0 deletions
67
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,67 @@ | ||
| /* | ||
| * 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()); | ||
| } | ||
| } | ||
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; | ||
| } | ||
| } |
69 changes: 69 additions & 0 deletions
69
...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,69 @@ | ||
| /* | ||
| * 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()); | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
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,40 @@ | ||
| /* | ||
| * 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(); | ||
|
|
||
| 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.