Skip to content

Commit

Permalink
Merge pull request jakartaee#416 from KyleAure/404-qualifier-anno-tests
Browse files Browse the repository at this point in the history
Add qualifier injection tests for Annotation defined resources
  • Loading branch information
KyleAure authored Jan 29, 2024
2 parents d6b56c8 + 5455dd3 commit beeb79a
Show file tree
Hide file tree
Showing 14 changed files with 851 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

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

/**
Expand All @@ -29,4 +30,15 @@
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE })
public @interface CustomQualifier1 {

class Literal extends AnnotationLiteral<CustomQualifier1> implements CustomQualifier1 {
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 @@ -20,6 +20,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

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

/**
Expand All @@ -29,4 +30,15 @@
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE })
public @interface CustomQualifier2 {

class Literal extends AnnotationLiteral<CustomQualifier2> implements CustomQualifier2 {
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 @@ -20,6 +20,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

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

/**
Expand All @@ -30,4 +31,15 @@
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE })
public @interface InvalidQualifier3 {

class Literal extends AnnotationLiteral<InvalidQualifier3> implements InvalidQualifier3 {
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
@@ -0,0 +1,105 @@
/*
* 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.spec.Platform.anno;

import java.net.URL;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;

import ee.jakarta.tck.concurrent.common.context.providers.IntContextProvider;
import ee.jakarta.tck.concurrent.common.context.providers.StringContextProvider;
import ee.jakarta.tck.concurrent.framework.TestClient;
import ee.jakarta.tck.concurrent.framework.junit.anno.Assertion;
import ee.jakarta.tck.concurrent.framework.junit.anno.Challenge;
import ee.jakarta.tck.concurrent.framework.junit.anno.Full;
import ee.jakarta.tck.concurrent.framework.junit.anno.TestName;
import ee.jakarta.tck.concurrent.framework.junit.anno.Common.PACKAGE;
import jakarta.enterprise.concurrent.spi.ThreadContextProvider;

/**
* Covers ContextServiceDefinition, ManagedExecutorDefinition, ManagedScheduledExecutorDefinition, and
* ManagedThreadFactoryDefinition annotations and their interaction with Deployment Descriptors.
*/
@Full
@RunAsClient // Requires client testing due to annotation configuration
public class AnnotationFullTests extends TestClient {

@ArquillianResource(AnnotationServlet.class)
private URL baseURL;

@Deployment(name = "AnnotationTests")
public static EnterpriseArchive createDeployment() {

WebArchive war = ShrinkWrap.create(WebArchive.class, "AnnotationTests_web.war")
.addClasses(AnnotationServlet.class);

JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "AnnotationTests_ejb.jar")
.addClasses(AnnotationTestBean.class, AnnotationTestBeanInterface.class)
.addPackages(false,
PACKAGE.CONTEXT.getPackageName(),
PACKAGE.CONTEXT_PROVIDERS.getPackageName(),
PACKAGE.QUALIFIERS.getPackageName())
.addAsServiceProvider(ThreadContextProvider.class.getName(), IntContextProvider.class.getName(),
StringContextProvider.class.getName());

EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "AnnotationTests.ear")
.addAsManifestResource(AnnotationFullTests.class.getPackage(), "application.xml",
"application.xml")
.addAsModules(war, jar);

return ear;
}

@TestName
private String testname;

@Override
protected String getServletPath() {
return "AnnotationServlet";
}

@Assertion(id = "GIT:404", strategy = "Tests injection of concurrent resources defined in a annotation with qualifier(s).")
public void testAnnotationDefinesQualifiers() {
runTest(baseURL, testname);
}

@Assertion(id = "GIT:404", strategy = "Tests context-service defined in a annotation.")
public void testAnnotationDefinesContextService() {
runTest(baseURL, testname);
}

@Assertion(id = "GIT:404", strategy = "Tests managed-executor defined in a annotation.")
public void testAnnotationDefinesManagedExecutor() {
runTest(baseURL, testname);
}

@Assertion(id = "GIT:404", strategy = "Tests managed-scheduled-executor defined in a annotation.")
public void testAnnotationDefinesManagedScheduledExecutor() {
runTest(baseURL, testname);
}

@Challenge(link = "https://github.com/jakartaee/concurrency/issues/226", version = "3.0.0")
@Assertion(id = "GIT:404", strategy = "Tests managed-thread-factory defined in a annotation.")
public void testAnnotationDefinesManagedThreadFactory() {
runTest(baseURL, testname);
}
}
Loading

0 comments on commit beeb79a

Please sign in to comment.