Skip to content

Commit

Permalink
Add test for app defined default producer
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAure committed Jan 31, 2024
1 parent 7b387bf commit 2289d05
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class DeploymentDescriptorFullTests extends TestClient {
public static EnterpriseArchive createDeployment() {

WebArchive war = ShrinkWrap.create(WebArchive.class, "DeploymentDescriptorTests_web.war")
.addClasses(DeploymentDescriptorServlet.class);
.addClasses(DeploymentDescriptorServlet.class, ManagedThreadFactoryProducer.class);

JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "DeploymentDescriptorTests_ejb.jar")
.addClasses(DeploymentDescriptorTestBean.class, DeploymentDescriptorTestBeanInterface.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,17 @@ public void testDeploymentDescriptorDefinedManagedThreadFactoryQualifers() throw

assertAll("Thread Factory Tests",
() -> assertNotNull(injectedDefMTF,
"Default managedThreadFactory was not registered with default qualifier."),
() -> assertEquals(lookupDefMTF.newThread(NOOP_RUNNABLE).getPriority(), injectedDefMTF.newThread(NOOP_RUNNABLE).getPriority(),
"Default managedThreadFactory from injection and lookup did not have the same priority."),
"A managedThreadFactory was not registered with the default qualifier when the application included a producer."),
() -> assertEquals(5, lookupDefMTF.newThread(NOOP_RUNNABLE).getPriority(),
"Default managedThreadFactory from lookup did not have the default priority."),
() -> assertEquals(7, injectedDefMTF.newThread(NOOP_RUNNABLE).getPriority(),
"Default managedThreadFactory from injection did not have the expected priority."),
() -> assertNotNull(resourceMTFD,
"Deployment Descriptor defined managedThreadFactory with no qualifiers could not be found via @Resource."),
() -> assertEquals(lookupMTFD.newThread(NOOP_RUNNABLE).getPriority(), resourceMTFD.newThread(NOOP_RUNNABLE).getPriority(),
"The managedThreadFactory from resource injection and lookup did not have the same priority."),
() -> assertTrue(CDI.current().select(ManagedThreadFactory.class, CustomQualifier1.Literal.get()).isUnsatisfied(),
"A managedThreadFactory was satisfied with a required qualifier that should have been overriden by the deployment descriptor.")
"A managedThreadFactory was satisfied with a required qualifier that was not configured on the deployment descriptor.")
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ee.jakarta.tck.concurrent.spec.Platform.dd;

import javax.naming.InitialContext;

import jakarta.enterprise.concurrent.ManagedThreadFactory;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;

@ApplicationScoped
public class ManagedThreadFactoryProducer {

@Produces
public ManagedThreadFactory getDefaultManagedThreadFactory() throws Exception {
return InitialContext.doLookup("java:app/concurrent/ThreadFactoryDefault");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,11 @@
<qualifier></qualifier>
<priority>6</priority>
</managed-thread-factory>

<managed-thread-factory>
<name>java:app/concurrent/ThreadFactoryDefault</name>
<context-service-ref>java:comp/DefaultContextService</context-service-ref>
<priority>7</priority>
</managed-thread-factory>

</application>
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,11 @@
<qualifier></qualifier>
<priority>6</priority>
</managed-thread-factory>

<managed-thread-factory>
<name>java:app/concurrent/ThreadFactoryDefault</name>
<context-service-ref>java:comp/DefaultContextService</context-service-ref>
<priority>7</priority>
</managed-thread-factory>

</web-app>

0 comments on commit 2289d05

Please sign in to comment.