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 creational context implementations #463

Merged
merged 3 commits into from
May 25, 2023
Merged
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
Expand Up @@ -20,14 +20,12 @@

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.context.SessionScoped;
import jakarta.enterprise.context.spi.Contextual;
import jakarta.enterprise.context.spi.CreationalContext;

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.shrinkwrap.api.spec.WebArchive;
import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.test.audit.annotations.SpecVersion;
Expand All @@ -51,10 +49,10 @@ public void testGetMayNotCreateNewInstanceUnlessCreationalContextGiven() {
assert getCurrentManager().getContext(ApplicationScoped.class).get(myApplicationBean) == null;

// Now try same operation with a CreationalContext
CreationalContext<MyRequestBean> myCreationalContext = new MockCreationalContext<MyRequestBean>();
CreationalContext<MyRequestBean> myCreationalContext = getCurrentManager().createCreationalContext(myRequestBean);
assert getCurrentManager().getContext(RequestScoped.class).get(myRequestBean, myCreationalContext) != null;

CreationalContext<MyApplicationBean> myOtherCreationalContext = new MockCreationalContext<MyApplicationBean>();
CreationalContext<MyApplicationBean> myOtherCreationalContext = getCurrentManager().createCreationalContext(myApplicationBean);
assert getCurrentManager().getContext(ApplicationScoped.class).get(myApplicationBean, myOtherCreationalContext) != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
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.shrinkwrap.api.spec.WebArchive;
import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.test.audit.annotations.SpecVersion;
Expand Down Expand Up @@ -187,8 +186,8 @@ public void testContextGetWithCreationalContextReturnsNewInstance() {
assert foxBeans.size() == 1;
Bean<Fox> foxBean = foxBeans.iterator().next();
Context context = getCurrentManager().getContext(Dependent.class);
assert context.get(foxBean, new MockCreationalContext<Fox>()) != null;
assert context.get(foxBean, new MockCreationalContext<Fox>()) instanceof Fox;
assert context.get(foxBean, getCurrentManager().createCreationalContext(foxBean)) != null;
assert context.get(foxBean, getCurrentManager().createCreationalContext(foxBean)) instanceof Fox;
}

@Test
Expand Down Expand Up @@ -272,7 +271,7 @@ public void testContextIsActiveDuringBeanCreation() {
// Dependent context is now always active
public void testContextIsActiveDuringInjection() {
Bean<FoxRun> foxRunBean = getBeans(FoxRun.class).iterator().next();
FoxRun foxRun = foxRunBean.create(new MockCreationalContext<FoxRun>());
FoxRun foxRun = foxRunBean.create(getCurrentManager().createCreationalContext(foxRunBean));
assert foxRun.fox != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
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.shrinkwrap.api.spec.WebArchive;
import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.test.audit.annotations.SpecVersion;
Expand All @@ -30,7 +29,7 @@ public void testGetMayNotCreateNewInstanceUnlessCreationalContextGiven() {
assert getCurrentManager().getContext(SessionScoped.class).get(mySessionBean) == null;

// Now try same operation with a CreationalContext
CreationalContext<MySessionBean> myCreationalContext = new MockCreationalContext<MySessionBean>();
CreationalContext<MySessionBean> myCreationalContext = getCurrentManager().createCreationalContext(mySessionBean);
assert getCurrentManager().getContext(SessionScoped.class).get(mySessionBean, myCreationalContext) != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
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.shrinkwrap.api.BeanDiscoveryMode;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.impl.BeansXml;
Expand Down Expand Up @@ -77,7 +76,7 @@ public void testGetWithCreationalContextReturnsNewInstance() {
MyContextual bean = AfterBeanDiscoveryObserver.getBean();
bean.setShouldReturnNullInstances(false);

CreationalContext<MySessionBean> creationalContext = new MockCreationalContext<MySessionBean>();
CreationalContext<MySessionBean> creationalContext = getCurrentManager().createCreationalContext(bean);
MySessionBean newBean = getCurrentManager().getContext(SessionScoped.class).get(bean, creationalContext);
assert newBean != null;
assert bean.isCreateCalled();
Expand All @@ -91,7 +90,7 @@ public void testGetMayNotReturnNullUnlessContextualCreateReturnsNull() {
MyContextual bean = AfterBeanDiscoveryObserver.getBean();
bean.setShouldReturnNullInstances(true);

CreationalContext<MySessionBean> creationalContext = new MockCreationalContext<MySessionBean>();
CreationalContext<MySessionBean> creationalContext = getCurrentManager().createCreationalContext(bean);
assert getCurrentManager().getContext(SessionScoped.class).get(bean, creationalContext) == null;
assert bean.isCreateCalled();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ public void testCreateReturnsSameBeanPushed() {
@Test
@SpecAssertions({ @SpecAssertion(section = MANAGED_BEAN_LIFECYCLE, id = "aa") })
public void testBeanCreateInjectsDependenciesAndInvokesInitializerToInstantiateInstance() {
MockCreationalContext.reset();
final CreationalContext<FishPond> creationalContext = new MockCreationalContext<FishPond>();
final Contextual<FishPond> bean = getBeans(FishPond.class).iterator().next();
final CreationalContext<FishPond> creationalContext = getCurrentManager().createCreationalContext(bean);
FishPond fishPond = bean.create(creationalContext);
assert fishPond != null;
assert fishPond.goldfish != null;
Expand Down
13 changes: 13 additions & 0 deletions impl/src/main/resources/tck-tests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,25 @@
<exclude name=".*"/>
</methods>
</class>

<!-- https://github.com/jakartaee/cdi-tck/issues/440 -->
<class name="org.jboss.cdi.tck.tests.full.extensions.lifecycle.processBeanAttributes.specialization.VetoTest">
<methods>
<exclude name=".*"/>
</methods>
</class>

<!-- https://github.com/jakartaee/cdi-tck/issues/453 -->
<class name="org.jboss.cdi.tck.tests.implementation.simple.lifecycle.SimpleBeanLifecycleTest">
<methods>
<exclude name="testCreateReturnsSameBeanPushed"/>
</methods>
</class>
<class name="org.jboss.cdi.tck.tests.context.DestroyForSameCreationalContextTest">
<methods>
<exclude name="testDestroyForSameCreationalContextOnly"/>
</methods>
</class>
</classes>

</test>
Expand Down
Loading