Skip to content

Commit

Permalink
Merge pull request #428 from KyleAure/fix-qualifier-tests
Browse files Browse the repository at this point in the history
Remove override via application.xml test
  • Loading branch information
KyleAure authored Feb 14, 2024
2 parents 4ae8fb1 + 2005dac commit b84edec
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package ee.jakarta.tck.concurrent.common.qualifiers;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import jakarta.enterprise.util.AnnotationLiteral;
import jakarta.inject.Qualifier;

/**
* A qualifier that is used to identify concurrent resources for injection.
* This qualifier is sometimes overwritten via config.
*/
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE })
public @interface OverwrittenQualifier4 {

class Literal extends AnnotationLiteral<OverwrittenQualifier4> implements OverwrittenQualifier4 {
private static final long serialVersionUID = 1L;

private static Literal inst = new Literal();

public static Literal get() {
return inst;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void testAnnoDefinedManagedScheduledExecutorSvcQualifers() {
}

@Assertion(id = "GIT:404", strategy = "Tests injection of managed thread factory defined in an annotation with qualifier(s).")
public void testAnnoDefinedManagedThreadFactoryQualifers() {
public void testAnnoDefinedManagedThreadFactoryQualifersFull() {
runTest(baseURL, testname);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import ee.jakarta.tck.concurrent.common.qualifiers.CustomQualifier1;
import ee.jakarta.tck.concurrent.common.qualifiers.CustomQualifier2;
import ee.jakarta.tck.concurrent.common.qualifiers.InvalidQualifier3;
import ee.jakarta.tck.concurrent.common.qualifiers.OverwrittenQualifier4;
import ee.jakarta.tck.concurrent.framework.TestServlet;
import jakarta.annotation.Resource;
import jakarta.ejb.EJB;
Expand Down Expand Up @@ -76,7 +77,7 @@
@ManagedThreadFactoryDefinition(
name = "java:app/concurrent/ThreadFactoryE",
context = "java:app/concurrent/ContextE",
qualifiers = InvalidQualifier3.class, // overridden via deployment descriptor
qualifiers = OverwrittenQualifier4.class, // overwritten via web.xml
priority = 6
)
@WebServlet("/AnnotationServlet")
Expand Down Expand Up @@ -229,11 +230,32 @@ public void testAnnoDefinedManagedScheduledExecutorSvcQualifers() throws Throwab

@Resource(lookup = "java:app/concurrent/ThreadFactoryE")
private ManagedThreadFactory resourceMTFE;

// Qualifier on @ManagedThreadFactoryDefinition is only overridden in web mode
public void testAnnoDefinedManagedThreadFactoryQualifersFull() throws Throwable {

ManagedThreadFactory lookupDefMTF = InitialContext.doLookup("java:comp/DefaultManagedThreadFactory");
ManagedThreadFactory lookupMTFE = InitialContext.doLookup("java:app/concurrent/ThreadFactoryE");

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."),
() -> assertNotNull(resourceMTFE,
"Annotation defined managedThreadFactory with qualifiers could not be found via @Resource."),
() -> assertEquals(lookupMTFE.newThread(NOOP_RUNNABLE).getPriority(), resourceMTFE.newThread(NOOP_RUNNABLE).getPriority(),
"The managedThreadFactory from resource injection and lookup did not have the same priority."),
() -> assertTrue(CDI.current().select(ManagedThreadFactory.class, OverwrittenQualifier4.Literal.get()).isResolvable(),
"A managedThreadFactory was not satisfied with a required qualifier that was not overwritten by a deployment descriptor.")
);
}

public void testAnnoDefinedManagedThreadFactoryQualifers() throws Throwable {
// Qualifier on @ManagedThreadFactoryDefinition is overridden in web mode
public void testAnnoDefinedManagedThreadFactoryQualifersWeb() throws Throwable {

ManagedThreadFactory lookupDefMTF = InitialContext.doLookup("java:comp/DefaultManagedThreadFactory");
ManagedThreadFactory lookupMTFE = InitialContext.doLookup("java:app/concurrent/ThreadFactoryD");
ManagedThreadFactory lookupMTFE = InitialContext.doLookup("java:app/concurrent/ThreadFactoryE");

assertAll("Thread Factory Tests",
() -> assertNotNull(injectedDefMTF,
Expand All @@ -244,8 +266,8 @@ public void testAnnoDefinedManagedThreadFactoryQualifers() throws Throwable {
"Annotation defined managedThreadFactory with no qualifiers could not be found via @Resource."),
() -> assertEquals(lookupMTFE.newThread(NOOP_RUNNABLE).getPriority(), resourceMTFE.newThread(NOOP_RUNNABLE).getPriority(),
"The managedThreadFactory from resource injection and lookup did not have the same priority."),
() -> assertTrue(CDI.current().select(ManagedThreadFactory.class, InvalidQualifier3.Literal.get()).isUnsatisfied(),
"A managedThreadFactory was satisfied with a required qualifier that should have been overriden by the deployment descriptor.")
() -> assertTrue(CDI.current().select(ManagedThreadFactory.class, OverwrittenQualifier4.Literal.get()).isUnsatisfied(),
"A managedThreadFactory was satisfied with a required qualifier that should have been overwritten by the deployment descriptor.")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void testAnnoDefinedManagedScheduledExecutorSvcQualifers() {
}

@Assertion(id = "GIT:404", strategy = "Tests injection of managed thread factory defined in an annotation with qualifier(s).")
public void testAnnoDefinedManagedThreadFactoryQualifers() {
public void testAnnoDefinedManagedThreadFactoryQualifersWeb() {
runTest(baseURL, testname);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,4 @@
<ejb>AnnotationTests_ejb.jar</ejb>
</module>

<managed-thread-factory>
<name>java:app/concurrent/ThreadFactoryE</name>
<qualifier></qualifier> <!-- Overrides qualifiers defined in ManagedThreadFactoryDefinition -->
</managed-thread-factory>

</application>

0 comments on commit b84edec

Please sign in to comment.