Skip to content
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

avoid custom CreationalContext and Contextual implementations in the TCK #452

Merged
merged 8 commits into from
Sep 21, 2023
Prev Previous commit
Next Next commit
replace usages of MockCreationalContext with the CreationalContexts SPI
  • Loading branch information
Ladicek committed Sep 21, 2023
commit fe84312e4ed8f24b2cfbc643b959b9449d078784
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
import static org.jboss.cdi.tck.cdi.Sections.CONTEXT;

import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.context.SessionScoped;
import jakarta.enterprise.context.spi.Context;
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.cdi.tck.util.MockCreationalContext;
import org.jboss.cdi.tck.spi.CreationalContexts;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.test.audit.annotations.SpecVersion;
Expand All @@ -51,19 +49,18 @@ public static WebArchive createTestArchive() {
@Test
@SpecAssertion(section = CONTEXT, id = "r")
public void testDestroyForSameCreationalContextOnly() {
// Check that the mock cc is called (via cc.release()) when we request a context destroyed
// Check that the cc is called (via cc.release()) when we request a context destroyed
// Note that this is an indirect effect
Context requestContext = getCurrentManager().getContext(RequestScoped.class);

Bean<AnotherRequestBean> requestBean = getBeans(AnotherRequestBean.class).iterator().next();

MockCreationalContext.reset();
CreationalContext<AnotherRequestBean> creationalContext = new MockCreationalContext<AnotherRequestBean>();
CreationalContexts.Inspectable<AnotherRequestBean> creationalContext = createInspectableCreationalContext(requestBean);
AnotherRequestBean instance = requestContext.get(requestBean, creationalContext);
instance.ping();

destroyContext(requestContext);
assert MockCreationalContext.isReleaseCalled();
assert creationalContext.isReleaseCalled();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static WebArchive createTestArchive() {
@Test(groups = CDI_FULL)
@SpecAssertion(section = CONTEXT, id = "r")
public void testDestroyForSameCreationalContextOnly() {
// Check that the mock cc is called (via cc.release()) when we request a context destroyed
// Check that the cc is called (via cc.release()) when we request a context destroyed
// Note that this is an indirect effect
Context sessionContext = getCurrentManager().getContext(SessionScoped.class);
Context requestContext = getCurrentManager().getContext(RequestScoped.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

import jakarta.enterprise.context.SessionScoped;
import jakarta.enterprise.context.spi.Context;
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.TestGroups;
import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder;
import org.jboss.cdi.tck.util.MockCreationalContext;
import org.jboss.cdi.tck.spi.CreationalContexts;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.test.audit.annotations.SpecVersion;
Expand All @@ -34,19 +33,18 @@ public static WebArchive createTestArchive() {
@Test(groups = TestGroups.CDI_FULL)
@SpecAssertion(section = CONTEXT, id = "r")
public void testDestroyForSameCreationalContextOnly() {
// Check that the mock cc is called (via cc.release()) when we request a context destroyed
// Check that the cc is called (via cc.release()) when we request a context destroyed
// Note that this is an indirect effect
Context sessionContext = getCurrentManager().getContext(SessionScoped.class);

Bean<AnotherSessionBean> sessionBean = getBeans(AnotherSessionBean.class).iterator().next();

MockCreationalContext.reset();
CreationalContext<AnotherSessionBean> creationalContext = new MockCreationalContext<AnotherSessionBean>();
CreationalContexts.Inspectable<AnotherSessionBean> creationalContext = createInspectableCreationalContext(sessionBean);
AnotherSessionBean instance = sessionContext.get(sessionBean, creationalContext);
instance.ping();

destroyContext(sessionContext);
assert MockCreationalContext.isReleaseCalled();
assert creationalContext.isReleaseCalled();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import static org.jboss.cdi.tck.cdi.Sections.MANAGED_BEAN_LIFECYCLE;
import static org.jboss.cdi.tck.cdi.Sections.MEMBER_LEVEL_INHERITANCE;
import static org.jboss.cdi.tck.cdi.Sections.METHOD_CONSTRUCTOR_PARAMETER_QUALIFIERS;
import static org.jboss.cdi.tck.cdi.Sections.PASSIVATION_CAPABLE_DEPENDENCY;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
Expand All @@ -50,8 +49,8 @@
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.cdi.tck.AbstractTest;
import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder;
import org.jboss.cdi.tck.spi.CreationalContexts;
import org.jboss.cdi.tck.util.DependentInstance;
import org.jboss.cdi.tck.util.MockCreationalContext;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.test.audit.annotations.SpecAssertions;
Expand Down Expand Up @@ -87,12 +86,11 @@ public void testQualifierTypeAnnotatedConstructor() {
@Test
@SpecAssertions({ @SpecAssertion(section = CREATIONAL_CONTEXT, id = "d"), @SpecAssertion(section = CREATIONAL_CONTEXT, id = "g") })
public void testCreateReturnsSameBeanPushed() {
final CreationalContext<ShoeFactory> creationalContext = new MockCreationalContext<ShoeFactory>();
final Contextual<ShoeFactory> bean = getBeans(ShoeFactory.class).iterator().next();
MockCreationalContext.reset();
final CreationalContexts.Inspectable<ShoeFactory> creationalContext = createInspectableCreationalContext(bean);
ShoeFactory instance = getCurrentManager().getContext(Dependent.class).get(bean, creationalContext);
if (MockCreationalContext.isPushCalled()) {
assert instance == MockCreationalContext.getLastBeanPushed();
if (creationalContext.isPushCalled()) {
assert instance == creationalContext.getLastBeanPushed();
}
}

Expand Down