Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Comment thread
manovotn marked this conversation as resolved.
public void testMetadata() {
assertTrue(getUniqueBean(WithAutoCloseBean.class).isAutoClose());
assertTrue(getUniqueBean(WithoutAutoCloseBean.class).isAutoClose());
}
}
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;
}
}
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;
}
}
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);
}
}
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;
}
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;
}
}
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());
}
}
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;
}
}
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;
}
}
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 {
}
Loading