diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5f749be47..3d07d6ed1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ name: Java CI with Maven on: push: branches: - - '*' + - main pull_request: branches: - '*' @@ -70,3 +70,19 @@ jobs: cache: maven - name: Build with Maven run: mvn --batch-mode --no-transfer-progress clean verify + + arquillian-build-jdk21: + name: Integration - JDK 21 + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Build with Maven + uses: actions/checkout@v4 + - name: Setup JDK 21 + uses: actions/setup-java@v4 + with: + java-version: 21 + distribution: temurin + cache: maven + - name: Build with Maven + run: mvn --batch-mode --no-transfer-progress clean verify diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml new file mode 100644 index 000000000..22cce9087 --- /dev/null +++ b/.github/workflows/integration-tests.yml @@ -0,0 +1,84 @@ +# This workflow will build a Java project with Maven +# For more information see: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions + +name: Arquillian Integration Tests + +on: + push: + branches: + - main + pull_request: + branches: + - '**' + schedule: + - cron: '0 0 * * *' # Every day at 00:00 UTC + +# Only run the latest job +concurrency: + group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' + cancel-in-progress: true + +jobs: + wildfly-integration: + name: 'WildFly Integration Tests' + runs-on: ${{ matrix.os }} + timeout-minutes: 90 + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest ] + java: ['11', '17', '21'] + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK ${{ matrix.java }} + uses: actions/setup-java@v4 + with: + java-version: ${{ matrix.java }} + distribution: 'temurin' + cache: 'maven' + - name: Build with Maven Java ${{ matrix.java }} - ${{ matrix.os }} + run: | + ./mvnw -V clean install -U -B -fae '-Pwildfly' '-T1' '-Pintegration-tests' + - uses: actions/upload-artifact@v4 + if: failure() + with: + name: surefire-reports-${{ matrix.os }}-${{ matrix.java }} + path: '**/surefire-reports/*' + - uses: actions/upload-artifact@v4 + if: failure() + with: + name: server-logs-${{ matrix.os }}-${{ matrix.java }} + path: '**/server.log' + + payara-integration: + name: 'Payara Integration Tests' + runs-on: ${{ matrix.os }} + timeout-minutes: 90 + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest ] + java: ['11', '17', '21'] + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK ${{ matrix.java }} + uses: actions/setup-java@v4 + with: + java-version: ${{ matrix.java }} + distribution: 'temurin' + cache: 'maven' + - name: Build with Maven Java ${{ matrix.java }} - ${{ matrix.os }} + run: | + ./mvnw -V clean install -U -B -fae '-Ppayara' '-T1' '-Pintegration-tests' + - uses: actions/upload-artifact@v4 + if: failure() + with: + name: surefire-reports-${{ matrix.os }}-${{ matrix.java }} + path: '**/surefire-reports/*' + - uses: actions/upload-artifact@v4 + if: failure() + with: + name: server-logs-${{ matrix.os }}-${{ matrix.java }} + path: '**/server.log' diff --git a/.github/workflows/maven-jboss-snapshot-publish.yml b/.github/workflows/maven-jboss-snapshot-publish.yml index 87ae0ca76..2f0b8595c 100644 --- a/.github/workflows/maven-jboss-snapshot-publish.yml +++ b/.github/workflows/maven-jboss-snapshot-publish.yml @@ -40,5 +40,5 @@ jobs: run: mvn -B package --file pom.xml - name: Publish to JBoss Nexus Maven Snapshot Repo - run: mvn -s .github/settings.xml deploy -Prelease + run: mvn -s .github/settings.xml deploy -Prelease -DskipItTests=true diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index ffdc10e59..e09662410 100644 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1,2 +1,2 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.8/apache-maven-3.9.8-bin.zip wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar diff --git a/bom/pom.xml b/bom/pom.xml index e91f76dea..df13daca4 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -7,15 +7,15 @@ org.jboss.arquillian arquillian-bom - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT pom Arquillian BOM http://arquillian.org - Arquillian Bill Of Material + Arquillian Bill Of Materials jira - http://jira.jboss.com/jira/browse/ARQ + https://issues.redhat.com/browse/ARQ @@ -42,18 +42,10 @@ - - 1.2.6 - 2.0.0 - 3.3.0 - jboss-releases-repository - https://repository.jboss.org/nexus/service/local/staging/deploy/maven2/ - + https://repository.jboss.org/nexus/service/local/staging/deploy/maven2/ jboss-snapshots-repository - https://repository.jboss.org/nexus/content/repositories/snapshots/ - - + https://repository.jboss.org/nexus/content/repositories/snapshots/ @@ -218,33 +210,6 @@ ${project.version} - - - org.jboss.shrinkwrap - shrinkwrap-bom - ${version.shrinkwrap_core} - pom - import - - - - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-bom - ${version.shrinkwrap_resolver} - pom - import - - - - - org.jboss.shrinkwrap.descriptors - shrinkwrap-descriptors-bom - ${version.shrinkwrap_descriptors} - pom - import - - diff --git a/build/pom.xml b/build/pom.xml index 2636c33a3..b31e96f2b 100644 --- a/build/pom.xml +++ b/build/pom.xml @@ -6,7 +6,7 @@ org.jboss.arquillian arquillian-parent - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../pom.xml @@ -25,8 +25,8 @@ 1 4.13.2 - 1.10.1 - 5.10.2 + 1.10.3 + 5.10.3 4.10.0 7.5 3.24.2 diff --git a/config/api/pom.xml b/config/api/pom.xml index 99dd9fc84..a3deac5b1 100644 --- a/config/api/pom.xml +++ b/config/api/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/config/impl-base/pom.xml b/config/impl-base/pom.xml index 8438b9cf6..b507a47db 100644 --- a/config/impl-base/pom.xml +++ b/config/impl-base/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/config/pom.xml b/config/pom.xml index ff98c497b..13b8eb9ba 100644 --- a/config/pom.xml +++ b/config/pom.xml @@ -6,7 +6,7 @@ org.jboss.arquillian arquillian-parent - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT diff --git a/config/spi/pom.xml b/config/spi/pom.xml index 7c98996a0..03f022cf6 100644 --- a/config/spi/pom.xml +++ b/config/spi/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/container/impl-base/pom.xml b/container/impl-base/pom.xml index 07bf603a6..f93d28b32 100644 --- a/container/impl-base/pom.xml +++ b/container/impl-base/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/container/pom.xml b/container/pom.xml index c778413f9..162b0471c 100644 --- a/container/pom.xml +++ b/container/pom.xml @@ -6,7 +6,7 @@ org.jboss.arquillian arquillian-parent - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT diff --git a/container/spi/pom.xml b/container/spi/pom.xml index 72cb1409d..2b2fac9a4 100644 --- a/container/spi/pom.xml +++ b/container/spi/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/container/test-api/pom.xml b/container/test-api/pom.xml index 6f821cb99..094e00c70 100644 --- a/container/test-api/pom.xml +++ b/container/test-api/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/container/test-api/src/main/java/org/jboss/arquillian/container/test/api/Deployment.java b/container/test-api/src/main/java/org/jboss/arquillian/container/test/api/Deployment.java index 14ff19021..041bd9591 100644 --- a/container/test-api/src/main/java/org/jboss/arquillian/container/test/api/Deployment.java +++ b/container/test-api/src/main/java/org/jboss/arquillian/container/test/api/Deployment.java @@ -78,6 +78,9 @@ /** * Defines if this deployment should be wrapped up based on the protocol so the testcase can be executed incontainer. + *

+ * Setting this to {@code false} for a deployment used in {@link RunAsClient} tests allows you to avoid needing to + * package client-side test resources in the deployment. */ boolean testable() default true; } diff --git a/container/test-api/src/main/java/org/jboss/arquillian/container/test/api/OperateOnDeployment.java b/container/test-api/src/main/java/org/jboss/arquillian/container/test/api/OperateOnDeployment.java index 8d9f2196e..24c4818e6 100644 --- a/container/test-api/src/main/java/org/jboss/arquillian/container/test/api/OperateOnDeployment.java +++ b/container/test-api/src/main/java/org/jboss/arquillian/container/test/api/OperateOnDeployment.java @@ -46,10 +46,10 @@ * .addClass(MyServletY.class); * } * - * @Test @OperatesOnDeployment("X") + * @Test @OperateOnDeployment("X") * public void shouldExecuteInX() { ... } * - * @Test @OperatesOnDeployment("Y") + * @Test @OperateOnDeployment("Y") * public void shouldExecuteInY() { ... } * *

@@ -70,10 +70,10 @@ * .addClass(MyServletY.class); * } * - * @Test @OperatesOnDeployment("X") + * @Test @OperateOnDeployment("X") * public void shouldExecuteInX() { ... } * - * @Test @OperatesOnDeployment("Y") @RunAsClient + * @Test @OperateOnDeployment("Y") @RunAsClient * public void shouldExecuteInY(@ArquillianResource @OperateOnDeployment("X") URL deploymentXURLContext) { ... } * * diff --git a/container/test-impl-base/pom.xml b/container/test-impl-base/pom.xml index 24efbb04d..165b373ba 100644 --- a/container/test-impl-base/pom.xml +++ b/container/test-impl-base/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/ContainerTestExtension.java b/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/ContainerTestExtension.java index b45dcb03f..e41477953 100644 --- a/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/ContainerTestExtension.java +++ b/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/ContainerTestExtension.java @@ -90,6 +90,7 @@ public void register(ExtensionBuilder builder) { builder.observer(ContainerEventController.class) .observer(ContainerRestarter.class) .observer(DeploymentGenerator.class) + .observer(AnnotationDeploymentScenarioGenerator.class) .observer(ArchiveDeploymentToolingExporter.class) .observer(ProtocolRegistryCreator.class) .observer(ClientContainerControllerCreator.class) diff --git a/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/client/ContainerEventController.java b/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/client/ContainerEventController.java index 2e2fcab0c..8d655c795 100644 --- a/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/client/ContainerEventController.java +++ b/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/client/ContainerEventController.java @@ -132,7 +132,7 @@ private void createContext(EventContext context) { } /* - * Internal Helpers needed to extract @OperatesOnDeployment from TestMethod. + * Internal Helpers needed to extract @OperateOnDeployment from TestMethod. * * TODO: This should not rely on direct Reflection, but rather access the metadata through some * common metadata layer. diff --git a/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/client/deployment/AnnotationDeploymentScenarioGenerator.java b/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/client/deployment/AnnotationDeploymentScenarioGenerator.java index 42365ed0d..4a6c57797 100644 --- a/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/client/deployment/AnnotationDeploymentScenarioGenerator.java +++ b/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/client/deployment/AnnotationDeploymentScenarioGenerator.java @@ -18,7 +18,9 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.lang.reflect.Parameter; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import org.jboss.arquillian.container.spi.client.deployment.DeploymentScenario; import org.jboss.arquillian.container.test.api.Deployment; @@ -27,7 +29,13 @@ import org.jboss.arquillian.container.test.api.ShouldThrowException; import org.jboss.arquillian.container.test.api.TargetsContainer; import org.jboss.arquillian.container.test.spi.client.deployment.DeploymentScenarioGenerator; +import org.jboss.arquillian.core.api.Instance; +import org.jboss.arquillian.core.api.annotation.Inject; +import org.jboss.arquillian.core.spi.ServiceLoader; +import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.arquillian.test.spi.TestClass; +import org.jboss.arquillian.test.spi.TestEnricher; +import org.jboss.arquillian.test.spi.execution.ExecUtils; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.descriptor.api.Descriptor; @@ -39,9 +47,10 @@ * @version $Revision: $ */ public class AnnotationDeploymentScenarioGenerator extends AbstractDeploymentScenarioGenerator implements DeploymentScenarioGenerator { + @Inject + private Instance serviceLoader; protected List generateDeploymentContent(TestClass testClass) { - List deployments = new ArrayList(); Method[] deploymentMethods = testClass.getMethods(Deployment.class); @@ -71,26 +80,48 @@ private void validate(Method deploymentMethod) { + ". " + deploymentMethod); } - if (deploymentMethod.getParameterTypes().length != 0) { - throw new IllegalArgumentException("Method annotated with " - + Deployment.class.getName() - + " can not accept parameters. " - + deploymentMethod); + // This will throw IllegalArgumentException if check fails + hasZeroOrOnlyArquillianResourceArgs(deploymentMethod); + } + + private void hasZeroOrOnlyArquillianResourceArgs(Method deploymentMethod) throws IllegalArgumentException{ + boolean isOk = deploymentMethod.getParameterTypes().length == 0; + if (!isOk) { + ArrayList badArgs = new ArrayList<>(); + for (Parameter param : deploymentMethod.getParameters()) { + if (param.getAnnotation(ArquillianResource.class) == null) { + badArgs.add(param.getName()); + } + } + if (!badArgs.isEmpty()) { + throw new IllegalArgumentException("Method annotated with " + + Deployment.class.getName() + + " can not accept parameters that are not annotated with " + + ArquillianResource.class.getName() + + ". " + + deploymentMethod + + " has invalid parameters: " + + badArgs); + } } } /** - * @param deploymentMethod - * @return + * Call the deployment method and generate the deployment content and return a {@link DeploymentConfiguration} + * populated with the content and any relevant deployment method annotation information + * @param deploymentMethod - {@link Deployment} annotated method + * @return configured {@link DeploymentConfiguration} */ private DeploymentConfiguration generateDeploymentContent(Method deploymentMethod) { Deployment deploymentAnnotation = deploymentMethod.getAnnotation(Deployment.class); DeploymentConfiguration.DeploymentContentBuilder deploymentContentBuilder = null; if (Archive.class.isAssignableFrom(deploymentMethod.getReturnType())) { - deploymentContentBuilder = new DeploymentConfiguration.DeploymentContentBuilder(invoke(Archive.class, deploymentMethod)); + Archive archive = invoke(Archive.class, deploymentMethod); + deploymentContentBuilder = new DeploymentConfiguration.DeploymentContentBuilder(archive); } else if (Descriptor.class.isAssignableFrom(deploymentMethod.getReturnType())) { - deploymentContentBuilder = new DeploymentConfiguration.DeploymentContentBuilder(invoke(Descriptor.class, deploymentMethod)); + Descriptor descriptor = invoke(Descriptor.class, deploymentMethod); + deploymentContentBuilder = new DeploymentConfiguration.DeploymentContentBuilder(descriptor); } if (deploymentMethod.isAnnotationPresent(OverProtocol.class)) { @@ -118,12 +149,19 @@ private DeploymentConfiguration generateDeploymentContent(Method deploymentMetho /** - * @param deploymentMethod - * @return + * Invoke the deployment method to generate the test archive or descriptor + * @param type - the expected return type + * @param deploymentMethod - class deployment method + * @return the generated archive or descriptor */ private T invoke(Class type, Method deploymentMethod) { try { - return type.cast(deploymentMethod.invoke(null)); + Object[] args = null; + if(deploymentMethod.getParameterCount() > 0) { + Collection enrichers = serviceLoader.get().all(TestEnricher.class); + args = ExecUtils.enrichArguments(deploymentMethod, enrichers); + } + return type.cast(deploymentMethod.invoke(null, args)); } catch (Exception e) { throw new RuntimeException("Could not invoke deployment method: " + deploymentMethod, e); } diff --git a/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/execution/LocalTestExecuter.java b/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/execution/LocalTestExecuter.java index d7eae1ece..967688284 100644 --- a/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/execution/LocalTestExecuter.java +++ b/container/test-impl-base/src/main/java/org/jboss/arquillian/container/test/impl/execution/LocalTestExecuter.java @@ -16,8 +16,6 @@ */ package org.jboss.arquillian.container.test.impl.execution; -import java.lang.reflect.Method; -import java.util.Collection; import org.jboss.arquillian.container.test.impl.execution.event.LocalExecutionEvent; import org.jboss.arquillian.core.api.Injector; import org.jboss.arquillian.core.api.Instance; @@ -28,6 +26,7 @@ import org.jboss.arquillian.test.spi.TestEnricher; import org.jboss.arquillian.test.spi.TestResult; import org.jboss.arquillian.test.spi.annotation.TestScoped; +import org.jboss.arquillian.test.spi.execution.ExecUtils; /** * A Handler for executing the Test Method.
@@ -53,10 +52,10 @@ public class LocalTestExecuter { public void execute(@Observes LocalExecutionEvent event) throws Exception { TestResult result = TestResult.passed(); try { - event.getExecutor().invoke( - enrichArguments( - event.getExecutor().getMethod(), - serviceLoader.get().all(TestEnricher.class))); + Object[] args = ExecUtils.enrichArguments( + event.getExecutor().getMethod(), + serviceLoader.get().all(TestEnricher.class)); + event.getExecutor().invoke(args); } catch (Throwable e) { result = TestResult.failed(e); } finally { @@ -65,36 +64,4 @@ public void execute(@Observes LocalExecutionEvent event) throws Exception { testResult.set(result); } - /** - * Enrich the method arguments of a method call.
- * The Object[] index will match the method parameterType[] index. - * - * @return the argument values - */ - private Object[] enrichArguments(Method method, Collection enrichers) { - Object[] values = new Object[method.getParameterTypes().length]; - if (method.getParameterTypes().length == 0) { - return values; - } - for (TestEnricher enricher : enrichers) { - mergeValues(values, enricher.resolve(method)); - } - return values; - } - - private void mergeValues(Object[] values, Object[] resolvedValues) { - if (resolvedValues == null || resolvedValues.length == 0) { - return; - } - if (values.length != resolvedValues.length) { - throw new IllegalStateException("TestEnricher resolved wrong argument count, expected " + - values.length + " returned " + resolvedValues.length); - } - for (int i = 0; i < resolvedValues.length; i++) { - Object resvoledValue = resolvedValues[i]; - if (resvoledValue != null && values[i] == null) { - values[i] = resvoledValue; - } - } - } } diff --git a/container/test-impl-base/src/test/java/org/jboss/arquillian/container/test/impl/client/deployment/DeploymentGeneratorTestCase.java b/container/test-impl-base/src/test/java/org/jboss/arquillian/container/test/impl/client/deployment/DeploymentGeneratorTestCase.java index 11fcfcf37..279eb0881 100644 --- a/container/test-impl-base/src/test/java/org/jboss/arquillian/container/test/impl/client/deployment/DeploymentGeneratorTestCase.java +++ b/container/test-impl-base/src/test/java/org/jboss/arquillian/container/test/impl/client/deployment/DeploymentGeneratorTestCase.java @@ -17,6 +17,8 @@ */ package org.jboss.arquillian.container.test.impl.client.deployment; +import java.lang.annotation.Annotation; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -56,7 +58,11 @@ import org.jboss.arquillian.core.api.annotation.Inject; import org.jboss.arquillian.core.api.annotation.Observer; import org.jboss.arquillian.core.spi.ServiceLoader; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.arquillian.test.impl.enricher.resource.ArquillianResourceTestEnricher; import org.jboss.arquillian.test.spi.TestClass; +import org.jboss.arquillian.test.spi.TestEnricher; +import org.jboss.arquillian.test.spi.enricher.resource.ResourceProvider; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; @@ -109,7 +115,7 @@ public void prepare() { Injector injector = injectorInst.get(); final List deploymentScenarioGenerators = new ArrayList(); - deploymentScenarioGenerators.add(new AnnotationDeploymentScenarioGenerator()); + deploymentScenarioGenerators.add(injector.inject(new AnnotationDeploymentScenarioGenerator())); when(serviceLoader.all(DeploymentScenarioGenerator.class)) .thenReturn(deploymentScenarioGenerators); when(serviceLoader.onlyOne(eq(DeployableContainer.class))).thenReturn(deployableContainer); @@ -121,6 +127,13 @@ public void prepare() { .thenReturn(create(AuxiliaryArchiveProcessor.class, injector.inject(new TestAuxiliaryArchiveProcessor()))); when(serviceLoader.all(eq(ApplicationArchiveProcessor.class))) .thenReturn(create(ApplicationArchiveProcessor.class, injector.inject(new TestApplicationArchiveAppender()))); + when(serviceLoader.all(TestEnricher.class)) + .thenReturn(create(TestEnricher.class, injector.inject(new ArquillianResourceTestEnricher()))); + final List resourceProviders = new ArrayList<>(); + resourceProviders.add(new TestStringResourceProvider()); + resourceProviders.add(new TestBigDecimalResourceProvider()); + when(serviceLoader.all(ResourceProvider.class)) + .thenReturn(resourceProviders); containerRegistry = new LocalContainerRegistry(injector); protocolRegistry = new ProtocolRegistry(); @@ -257,6 +270,37 @@ public void shouldAllowMultipleSameNamedArchiveDeploymentWithDifferentTargets() verifyScenario("X", "Y"); } + /** + * https://github.com/arquillian/arquillian-core/issues/602 + */ + @Test + public void shouldAllowDeployMethodWithArqResource() { + addContainer(CONTAINER_NAME_1).getContainerConfiguration().setMode("suite"); + addProtocol(PROTOCOL_NAME_1, true); + + fire(createEvent(DeploymentWithArqResoureArg.class)); + verifyScenario("DeploymentWithArqResoureArg"); + } + @Test + public void shouldAllowDeployMethodWithMultipleArqResource() { + addContainer(CONTAINER_NAME_1).getContainerConfiguration().setMode("suite"); + addProtocol(PROTOCOL_NAME_1, true); + + fire(createEvent(DeploymentWithArqResoureArgsDifferentProviders.class)); + verifyScenario("DeploymentWithArqResoureArgsDifferentProviders"); + } + + + @Test(expected = IllegalArgumentException.class) + public void shouldFailDeployMethodWithNonArqResource() { + addContainer(CONTAINER_NAME_1).getContainerConfiguration().setMode("suite"); + addProtocol(PROTOCOL_NAME_1, true); + + fire(createEvent(DeploymentWithBadArg.class)); + // Should not get here + Assert.fail("Should have failed with IllegalArgumentException"); + } + @Test // ARQ-971 @SuppressWarnings("unchecked") public void shouldFilterNullAuxiliaryArchiveAppenderResulsts() throws Exception { @@ -527,6 +571,32 @@ public static JavaArchive deploy() { return ShrinkWrap.create(JavaArchive.class); } } + private static class DeploymentWithArqResoureArg { + @Deployment(name = "DeploymentWithArqResoureArg", managed = false, testable = false) + @TargetsContainer(CONTAINER_NAME_1) + public static JavaArchive deploy(@ArquillianResource String resource) { + Assert.assertEquals("deploy-method-resource", resource); + return ShrinkWrap.create(JavaArchive.class); + } + } + private static class DeploymentWithArqResoureArgsDifferentProviders { + @Deployment(name = "DeploymentWithArqResoureArgsDifferentProviders", managed = false, testable = false) + @TargetsContainer(CONTAINER_NAME_1) + public static JavaArchive deploy(@ArquillianResource String resource, @ArquillianResource BigDecimal pi) { + Assert.assertEquals("deploy-method-resource", resource); + Assert.assertEquals("3.14159265358979323846", pi.toPlainString()); + return ShrinkWrap.create(JavaArchive.class); + } + } + private static class DeploymentWithBadArg { + @Deployment(name = "DeploymentWithBadArg", managed = false, testable = false) + @TargetsContainer(CONTAINER_NAME_1) + public static JavaArchive deploy(String resource) { + // Should not be called + Assert.fail("DeploymentWithBadArg.deploy(String) should not be called"); + return ShrinkWrap.create(JavaArchive.class); + } + } private static class CallMap { private Set> calls = new HashSet>(); @@ -600,4 +670,27 @@ public ProtocolConfiguration getConfig() { return config; } } + + private static class TestStringResourceProvider implements ResourceProvider { + @Override + public boolean canProvide(Class type) { + return String.class.isAssignableFrom(type); + } + + @Override + public Object lookup(ArquillianResource resource, Annotation... qualifiers) { + return "deploy-method-resource"; + } + } + private static class TestBigDecimalResourceProvider implements ResourceProvider { + @Override + public boolean canProvide(Class type) { + return BigDecimal.class.isAssignableFrom(type); + } + + @Override + public Object lookup(ArquillianResource resource, Annotation... qualifiers) { + return new BigDecimal("3.14159265358979323846"); + } + } } diff --git a/container/test-spi/pom.xml b/container/test-spi/pom.xml index 0f876fa5b..468293b21 100644 --- a/container/test-spi/pom.xml +++ b/container/test-spi/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/core/api/pom.xml b/core/api/pom.xml index 1efc18aaa..9792df6d1 100644 --- a/core/api/pom.xml +++ b/core/api/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/core/impl-base/pom.xml b/core/impl-base/pom.xml index 7c40d767b..5ff78df93 100644 --- a/core/impl-base/pom.xml +++ b/core/impl-base/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 5f960c8e8..c0e052820 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -6,7 +6,7 @@ org.jboss.arquillian arquillian-parent - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT diff --git a/core/spi/pom.xml b/core/spi/pom.xml index bd6e5d6f4..e2fa80c56 100644 --- a/core/spi/pom.xml +++ b/core/spi/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/core/spi/src/main/java/org/jboss/arquillian/core/spi/LoadableExtension.java b/core/spi/src/main/java/org/jboss/arquillian/core/spi/LoadableExtension.java index c43715082..5c91989f2 100644 --- a/core/spi/src/main/java/org/jboss/arquillian/core/spi/LoadableExtension.java +++ b/core/spi/src/main/java/org/jboss/arquillian/core/spi/LoadableExtension.java @@ -22,7 +22,7 @@ /** * LoadableExtension. *

- * Loadable extensions are loaded on the local side of Arquillan. For extensions, components, observers etc to run on + * Loadable extensions are loaded on the local side of Arquillian. For extensions, components, observers etc to run on * the remote side, use {@code RemoteLoadableExtension} instead, and provide it via an * {@code AuxilliaryArchiveAppender}. * @@ -58,6 +58,9 @@ ExtensionBuilder override(Class service, Class oldServiceImp * Register an observer for events. This observer will be injected according to any * {@link org.jboss.arquillian.core.api.annotation.Inject} annotated * {@link org.jboss.arquillian.core.api.Instance} fields. + * Note: the handler does not have to have any use of {@link org.jboss.arquillian.core.api.annotation.Observer} + * and this can be used to simply register a class that has needs to be instantiated and injected. + * @param handler A class with observer methods and/or Instance fields */ ExtensionBuilder observer(Class handler); diff --git a/integration-tests/common/pom.xml b/integration-tests/common/pom.xml new file mode 100644 index 000000000..849e15e6f --- /dev/null +++ b/integration-tests/common/pom.xml @@ -0,0 +1,88 @@ + + + + + 4.0.0 + + org.jboss.arquillian + integration-tests + 1.9.1.Final-SNAPSHOT + ../pom.xml + + + common-tests + Arquillian Core: Common integration tests + + + + 5.10.3 + + + + + + org.junit + junit-bom + ${version.org.junit} + pom + import + + + + + + + jakarta.annotation + jakarta.annotation-api + + + jakarta.enterprise + jakarta.enterprise.cdi-api + + + jakarta.inject + jakarta.inject-api + + + jakarta.ws.rs + jakarta.ws.rs-api + + + org.jboss.arquillian.container + arquillian-container-test-api + + + org.jboss.arquillian.test + arquillian-test-api + + + + + org.junit.jupiter + junit-jupiter + test + + + + + + diff --git a/integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/TestEnvironment.java b/integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/TestEnvironment.java new file mode 100644 index 000000000..aeb1485f1 --- /dev/null +++ b/integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/TestEnvironment.java @@ -0,0 +1,96 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.common; + +import java.net.URI; + +/** + * The test environment setup. + * + * @author James R. Perkins + */ +public class TestEnvironment { + + private static final String PROTOCOL = System.getProperty("arq.protocol", "http"); + private static final String HOST = System.getProperty("arq.host", "127.0.0.1"); + private static final int PORT = Integer.parseInt(System.getProperty("arq.port", "8080")); + public static final String REST_PATH = "/rest"; + + private TestEnvironment() { + } + + /** + * Returns the defined protocol to use for HTTP connections. The default is {@code http} and can be overridden + * with the {@code arq.protocol} system property. + * + * @return the HTTP protocol + */ + public static String protocol() { + return PROTOCOL; + } + + /** + * Returns the defined host to use for HTTP connections. The default is {@code 127.0.0.1} and can be overridden + * with the {@code arq.host} system property. + * + * @return the HTTP host + */ + public static String host() { + return HOST; + } + + /** + * Returns the defined port to use for HTTP connections. The default is {@code 8080} and can be overridden + * with the {@code arq.port} system property. + * + * @return the HTTP port + */ + public static int port() { + return PORT; + } + + /** + * Creates a URI with the given paths appended to the {@linkplain #protocol() protocol}, {@linkplain #host() host} + * and {@linkplain #port() port}. + * + * @param paths the paths to append + * + * @return a new URI for an HTTP connection + */ + public static URI uri(final String... paths) { + final StringBuilder uri = new StringBuilder() + .append(protocol()) + .append("://") + .append(host()) + .append(':') + .append(port()); + for (String path : paths) { + if (!path.isEmpty()) { + if (path.charAt(0) == '/') { + uri.append(path); + } else { + uri.append('/').append(path); + } + } + } + return URI.create(uri.toString()); + } + +} diff --git a/integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/app/EchoResource.java b/integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/app/EchoResource.java new file mode 100644 index 000000000..51090cb4d --- /dev/null +++ b/integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/app/EchoResource.java @@ -0,0 +1,37 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.common.app; + +import jakarta.enterprise.context.RequestScoped; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; + +/** + * @author James R. Perkins + */ +@Path("echo") +@RequestScoped +public class EchoResource { + + @POST + public String echo(final String msg) { + return msg; + } +} diff --git a/integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/app/Greeter.java b/integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/app/Greeter.java new file mode 100644 index 000000000..23051ca92 --- /dev/null +++ b/integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/app/Greeter.java @@ -0,0 +1,33 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.common.app; + +import jakarta.enterprise.context.ApplicationScoped; + +/** + * @author James R. Perkins + */ +@ApplicationScoped +public class Greeter { + + public String greet(String name) { + return "Hello " + name + "!"; + } +} diff --git a/integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/app/RestActivator.java b/integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/app/RestActivator.java new file mode 100644 index 000000000..d40050d35 --- /dev/null +++ b/integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/app/RestActivator.java @@ -0,0 +1,31 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.common.app; + +import jakarta.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; +import org.jboss.arquillian.integration.test.common.TestEnvironment; + +/** + * @author James R. Perkins + */ +@ApplicationPath(TestEnvironment.REST_PATH) +public class RestActivator extends Application { +} diff --git a/integration-tests/common/src/main/resources/manual-mode-arquillian.xml b/integration-tests/common/src/main/resources/manual-mode-arquillian.xml new file mode 100644 index 000000000..efdaaaa41 --- /dev/null +++ b/integration-tests/common/src/main/resources/manual-mode-arquillian.xml @@ -0,0 +1,24 @@ + + + + + + diff --git a/integration-tests/junit4-tests/pom.xml b/integration-tests/junit4-tests/pom.xml new file mode 100644 index 000000000..3ac93d209 --- /dev/null +++ b/integration-tests/junit4-tests/pom.xml @@ -0,0 +1,70 @@ + + + + + 4.0.0 + + org.jboss.arquillian + integration-tests + 1.9.1.Final-SNAPSHOT + ../pom.xml + + + junit4-tests + Arquillian Core: JUnit 4 Integration Tests + + + 4.13.2 + + + + + + + junit + junit + test + ${version.org.junit} + + + org.jboss.arquillian + common-tests + test + + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + + + + wildfly + + + false + + + + + diff --git a/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java b/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java new file mode 100644 index 000000000..eae767304 --- /dev/null +++ b/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java @@ -0,0 +1,62 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.cdi; + +import java.net.URI; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.integration.test.common.app.Greeter; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * @author James R. Perkins + */ +@RunWith(Arquillian.class) +@ApplicationScoped +public class CdiInjectionTest { + + @Deployment + public static WebArchive createDeployment() { + return ShrinkWrap.create(WebArchive.class) + .addClass(Greeter.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @ArquillianResource + private URI uri; + + @Inject + Greeter greeter; + + @Test + public void validateGreeting() { + Assert.assertNotNull("Greeter should not be null", greeter); + Assert.assertEquals("Hello JUnit5!", greeter.greet("JUnit5")); + } +} diff --git a/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/manual/ManualModeTest.java b/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/manual/ManualModeTest.java new file mode 100644 index 000000000..9ffeabf83 --- /dev/null +++ b/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/manual/ManualModeTest.java @@ -0,0 +1,92 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.manual; + +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; + +import org.jboss.arquillian.container.test.api.ContainerController; +import org.jboss.arquillian.container.test.api.Deployer; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.integration.test.common.TestEnvironment; +import org.jboss.arquillian.integration.test.common.app.EchoResource; +import org.jboss.arquillian.integration.test.common.app.RestActivator; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * @author James R. Perkins + */ +@RunWith(Arquillian.class) +@RunAsClient +public class ManualModeTest { + private static final String CONTAINER_NAME = "default"; + private static final String DEPLOYMENT_NAME = "manual-mode"; + + @Deployment(name = DEPLOYMENT_NAME, managed = false) + public static WebArchive createDeployment() { + return ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME + ".war") + .addClasses(RestActivator.class, EchoResource.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @ArquillianResource + private static ContainerController controller; + + @ArquillianResource + private static Deployer deployer; + + @Test + public void startConnectAndStop() throws Exception { + Assert.assertNotNull(controller); + Assert.assertFalse("This is a manual mode test and the server should not have been started.", controller.isStarted(CONTAINER_NAME)); + // Check that we can start the server and the server is running + controller.start(CONTAINER_NAME); + Assert.assertTrue("The server should have been started", controller.isStarted(CONTAINER_NAME)); + + // Deploy the application and make a REST request + deployer.deploy(DEPLOYMENT_NAME); + assertAppDeployed(); + + // Undeploy the application and stop the server + deployer.undeploy(DEPLOYMENT_NAME); + controller.stop(CONTAINER_NAME); + } + + private void assertAppDeployed() throws Exception { + final String msg = "Test message"; + final HttpClient client = HttpClient.newHttpClient(); + final HttpRequest request = HttpRequest.newBuilder() + .uri(TestEnvironment.uri(DEPLOYMENT_NAME, TestEnvironment.REST_PATH, "echo")) + .POST(HttpRequest.BodyPublishers.ofString(msg)) + .build(); + final HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + Assert.assertEquals(200, response.statusCode()); + Assert.assertEquals(msg, response.body()); + } +} diff --git a/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/AbstractArquillianResourceTest.java b/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/AbstractArquillianResourceTest.java new file mode 100644 index 000000000..8cf1b7587 --- /dev/null +++ b/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/AbstractArquillianResourceTest.java @@ -0,0 +1,102 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.resource.injection; + +import java.net.URI; +import java.net.URL; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.integration.test.common.TestEnvironment; +import org.jboss.arquillian.integration.test.common.app.Greeter; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * @author James R. Perkins + */ +@RunWith(Arquillian.class) +abstract class AbstractArquillianResourceTest { + static final String DEPLOYMENT_NAME = "injection"; + + @ArquillianResource + protected URL url; + + @ArquillianResource + protected URI uri; + + @Deployment + public static WebArchive createDeployment() { + return ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME + ".war") + .addClasses(Greeter.class, AbstractArquillianResourceTest.class, TestEnvironment.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Test + public void checkUrl() { + Assert.assertNotNull("The URL should have been injected", url); + Assert.assertEquals(TestEnvironment.protocol(), url.getProtocol()); + checkHost(url.getHost()); + Assert.assertEquals(TestEnvironment.port(), url.getPort()); + Assert.assertEquals("/" + DEPLOYMENT_NAME + "/", url.getPath()); + } + + @Test + public void checkParameterUrl(@ArquillianResource final URL url) { + Assert.assertNotNull("The URL should have been injected", url); + Assert.assertEquals(TestEnvironment.protocol(), url.getProtocol()); + checkHost(url.getHost()); + Assert.assertEquals(TestEnvironment.port(), url.getPort()); + Assert.assertEquals("/" + DEPLOYMENT_NAME + "/", url.getPath()); + } + + @Test + public void checkUri() { + Assert.assertNotNull("The URI should have been injected", uri); + checkHost(uri.getHost()); + Assert.assertEquals(TestEnvironment.port(), uri.getPort()); + Assert.assertEquals("/" + DEPLOYMENT_NAME + "/", uri.getPath()); + } + + @Test + public void checkParameterUri(@ArquillianResource final URI uri) { + Assert.assertNotNull("The URI should have been injected", uri); + checkHost(uri.getHost()); + Assert.assertEquals(TestEnvironment.port(), uri.getPort()); + Assert.assertEquals("/" + DEPLOYMENT_NAME + "/", uri.getPath()); + } + + protected void checkHost(final String host) { + // localhost and 127.0.0.1 should be treated as the same + final String expectedHost = TestEnvironment.host(); + if ("127.0.0.1".equals(expectedHost)) { + Assert.assertEquals(expectedHost, host.replace("localhost", "127.0.0.1")); + } else if ("localhost".equals(expectedHost)) { + Assert.assertEquals(expectedHost, host.replace("127.0.0.1", "localhost")); + } else { + Assert.assertEquals(expectedHost, host); + } + } +} diff --git a/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/ClientArquillianResourceTest.java b/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/ClientArquillianResourceTest.java new file mode 100644 index 000000000..90a75fa22 --- /dev/null +++ b/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/ClientArquillianResourceTest.java @@ -0,0 +1,29 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.resource.injection; + +import org.jboss.arquillian.container.test.api.RunAsClient; + +/** + * @author James R. Perkins + */ +@RunAsClient +public class ClientArquillianResourceTest extends AbstractArquillianResourceTest { +} diff --git a/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/InContainerArquillianResourceTest.java b/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/InContainerArquillianResourceTest.java new file mode 100644 index 000000000..b54838f80 --- /dev/null +++ b/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/InContainerArquillianResourceTest.java @@ -0,0 +1,67 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.resource.injection; + +import javax.naming.Context; +import javax.naming.InitialContext; + +import org.jboss.arquillian.test.api.ArquillianResource; +import org.junit.Assert; +import org.junit.Test; + +/** + * @author James R. Perkins + */ +public class InContainerArquillianResourceTest extends AbstractArquillianResourceTest { + + @ArquillianResource + protected Context context; + + @ArquillianResource + protected InitialContext initialContext; + + @Test + public void checkContext() throws Exception { + Assert.assertNotNull("The Context should have been injected", context); + final Object bm = context.lookup("java:comp/BeanManager"); + Assert.assertNotNull(bm); + } + + @Test + public void checkContextParameter(@ArquillianResource final Context context) throws Exception { + Assert.assertNotNull("The Context should have been injected", context); + final Object bm = context.lookup("java:comp/BeanManager"); + Assert.assertNotNull(bm); + } + + @Test + public void checkInitialContext() throws Exception { + Assert.assertNotNull("The InitialContext should have been injected", initialContext); + final Object bm = initialContext.lookup("java:comp/BeanManager"); + Assert.assertNotNull(bm); + } + + @Test + public void checkInitialContextParameter(@ArquillianResource final InitialContext initialContext) throws Exception { + Assert.assertNotNull("The InitialContext should have been injected", initialContext); + final Object bm = initialContext.lookup("java:comp/BeanManager"); + Assert.assertNotNull(bm); + } +} diff --git a/integration-tests/junit5-tests/pom.xml b/integration-tests/junit5-tests/pom.xml new file mode 100644 index 000000000..55ebf2b2f --- /dev/null +++ b/integration-tests/junit5-tests/pom.xml @@ -0,0 +1,80 @@ + + + + + 4.0.0 + + org.jboss.arquillian + integration-tests + 1.9.1.Final-SNAPSHOT + ../pom.xml + + + junit5-tests + Arquillian Core: JUnit 5 Integration Tests + + + 5.10.3 + + + + + + org.junit + junit-bom + ${version.org.junit} + pom + import + + + + + + + + org.junit.jupiter + junit-jupiter + test + + + org.jboss.arquillian + common-tests + test + + + org.jboss.arquillian.junit5 + arquillian-junit5-container + test + + + + + + wildfly + + + false + + + + + diff --git a/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java b/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java new file mode 100644 index 000000000..5770015fc --- /dev/null +++ b/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java @@ -0,0 +1,62 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.cdi; + +import java.net.URI; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.integration.test.common.app.Greeter; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * @author James R. Perkins + */ +@ExtendWith(ArquillianExtension.class) +@ApplicationScoped +public class CdiInjectionTest { + + @Deployment + public static WebArchive createDeployment() { + return ShrinkWrap.create(WebArchive.class) + .addClass(Greeter.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @ArquillianResource + private URI uri; + + @Inject + Greeter greeter; + + @Test + public void validateGreeting() { + Assertions.assertNotNull(greeter, "Greeter should not be null"); + Assertions.assertEquals("Hello JUnit5!", greeter.greet("JUnit5")); + } +} diff --git a/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/manual/ManualModeTest.java b/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/manual/ManualModeTest.java new file mode 100644 index 000000000..83a59f0b8 --- /dev/null +++ b/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/manual/ManualModeTest.java @@ -0,0 +1,98 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.manual; + +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; + +import org.jboss.arquillian.container.test.api.ContainerController; +import org.jboss.arquillian.container.test.api.Deployer; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.integration.test.common.TestEnvironment; +import org.jboss.arquillian.integration.test.common.app.EchoResource; +import org.jboss.arquillian.integration.test.common.app.RestActivator; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * @author James R. Perkins + */ +@ExtendWith(ArquillianExtension.class) +@RunAsClient +public class ManualModeTest { + private static final String CONTAINER_NAME = "default"; + private static final String DEPLOYMENT_NAME = "manual-mode"; + + @ArquillianResource + private static ContainerController controller; + + @ArquillianResource + private static Deployer deployer; + + @Deployment(name = DEPLOYMENT_NAME, managed = false) + public static WebArchive createDeployment() { + return ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME + ".war") + .addClasses(RestActivator.class, EchoResource.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @BeforeEach + public void validate() { + Assertions.assertNotNull(controller); + Assertions.assertFalse(controller.isStarted(CONTAINER_NAME), "This is a manual mode test and the server should not have been started."); + } + + @AfterEach + public void cleanUp() { + if (controller.isStarted(CONTAINER_NAME)) { + deployer.undeploy(DEPLOYMENT_NAME); + controller.stop(CONTAINER_NAME); + } + } + + @Test + public void startConnectAndStop() throws Exception { + // Start the server, check it's been started and deploy the application + controller.start(CONTAINER_NAME); + Assertions.assertTrue(controller.isStarted(CONTAINER_NAME), "The server should be started."); + deployer.deploy(DEPLOYMENT_NAME); + + // Make an HTTP request to make sure the deployment is available + final String msg = "Test message"; + final HttpClient client = HttpClient.newHttpClient(); + final HttpRequest request = HttpRequest.newBuilder() + .uri(TestEnvironment.uri(DEPLOYMENT_NAME, TestEnvironment.REST_PATH, "echo")) + .POST(HttpRequest.BodyPublishers.ofString(msg)) + .build(); + final HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + Assertions.assertEquals(200, response.statusCode()); + Assertions.assertEquals(msg, response.body()); + } +} diff --git a/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/AbstractArquillianResourceTest.java b/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/AbstractArquillianResourceTest.java new file mode 100644 index 000000000..6162f2ede --- /dev/null +++ b/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/AbstractArquillianResourceTest.java @@ -0,0 +1,105 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.resource.injection; + +import java.net.URI; +import java.net.URL; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.integration.test.common.TestEnvironment; +import org.jboss.arquillian.integration.test.common.app.Greeter; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * @author James R. Perkins + */ +@ExtendWith(ArquillianExtension.class) +abstract class AbstractArquillianResourceTest { + static final String DEPLOYMENT_NAME = "injection"; + + @ArquillianResource + protected URL url; + + @ArquillianResource + protected URI uri; + + @Deployment + public static WebArchive createDeployment() { + return ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME + ".war") + .addClasses(Greeter.class, AbstractArquillianResourceTest.class, TestEnvironment.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Test + public void checkUrl() { + Assertions.assertNotNull(url, "The URL should have been injected"); + Assertions.assertEquals(TestEnvironment.protocol(), url.getProtocol()); + checkHost(url.getHost()); + Assertions.assertEquals(TestEnvironment.port(), url.getPort()); + Assertions.assertEquals("/" + DEPLOYMENT_NAME + "/", url.getPath()); + } + + @Test + @Disabled("https://github.com/arquillian/arquillian-core/issues/312") + public void checkParameterUrl(@ArquillianResource final URL url) { + Assertions.assertNotNull(url, "The URL should have been injected"); + Assertions.assertEquals(TestEnvironment.protocol(), url.getProtocol()); + checkHost(url.getHost()); + Assertions.assertEquals(TestEnvironment.port(), url.getPort()); + Assertions.assertEquals("/" + DEPLOYMENT_NAME + "/", url.getPath()); + } + + @Test + public void checkUri() { + Assertions.assertNotNull(uri, "The URI should have been injected"); + checkHost(uri.getHost()); + Assertions.assertEquals(TestEnvironment.port(), uri.getPort()); + Assertions.assertEquals("/" + DEPLOYMENT_NAME + "/", uri.getPath()); + } + + @Test + @Disabled("https://github.com/arquillian/arquillian-core/issues/312") + public void checkParameterUri(@ArquillianResource final URI uri) { + Assertions.assertNotNull(uri, "The URI should have been injected"); + checkHost(uri.getHost()); + Assertions.assertEquals(TestEnvironment.port(), uri.getPort()); + Assertions.assertEquals("/" + DEPLOYMENT_NAME + "/", uri.getPath()); + } + + protected void checkHost(final String host) { + // localhost and 127.0.0.1 should be treated as the same + final String expectedHost = TestEnvironment.host(); + if ("127.0.0.1".equals(expectedHost)) { + Assertions.assertEquals(expectedHost, host.replace("localhost", "127.0.0.1")); + } else if ("localhost".equals(expectedHost)) { + Assertions.assertEquals(expectedHost, host.replace("127.0.0.1", "localhost")); + } else { + Assertions.assertEquals(expectedHost, host); + } + } +} diff --git a/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/ClientArquillianResourceTest.java b/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/ClientArquillianResourceTest.java new file mode 100644 index 000000000..90a75fa22 --- /dev/null +++ b/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/ClientArquillianResourceTest.java @@ -0,0 +1,29 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.resource.injection; + +import org.jboss.arquillian.container.test.api.RunAsClient; + +/** + * @author James R. Perkins + */ +@RunAsClient +public class ClientArquillianResourceTest extends AbstractArquillianResourceTest { +} diff --git a/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/InContainerArquillianResourceTest.java b/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/InContainerArquillianResourceTest.java new file mode 100644 index 000000000..bab8ae897 --- /dev/null +++ b/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/InContainerArquillianResourceTest.java @@ -0,0 +1,70 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.resource.injection; + +import javax.naming.Context; +import javax.naming.InitialContext; + +import org.jboss.arquillian.test.api.ArquillianResource; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +/** + * @author James R. Perkins + */ +public class InContainerArquillianResourceTest extends AbstractArquillianResourceTest { + + @ArquillianResource + protected Context context; + + @ArquillianResource + protected InitialContext initialContext; + + @Test + public void checkContext() throws Exception { + Assertions.assertNotNull(context, "The Context should have been injected"); + final Object bm = context.lookup("java:comp/BeanManager"); + Assertions.assertNotNull(bm); + } + + @Test + @Disabled("https://github.com/arquillian/arquillian-core/issues/312") + public void checkContextParameter(@ArquillianResource final Context context) throws Exception { + Assertions.assertNotNull(context, "The Context should have been injected"); + final Object bm = context.lookup("java:comp/BeanManager"); + Assertions.assertNotNull(bm); + } + + @Test + public void checkInitialContext() throws Exception { + Assertions.assertNotNull(initialContext, "The InitialContext should have been injected"); + final Object bm = initialContext.lookup("java:comp/BeanManager"); + Assertions.assertNotNull(bm); + } + + @Test + @Disabled("https://github.com/arquillian/arquillian-core/issues/312") + public void checkInitialContextParameter(@ArquillianResource final InitialContext initialContext) throws Exception { + Assertions.assertNotNull(initialContext, "The InitialContext should have been injected"); + final Object bm = initialContext.lookup("java:comp/BeanManager"); + Assertions.assertNotNull(bm); + } +} diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml new file mode 100644 index 000000000..4346f1805 --- /dev/null +++ b/integration-tests/pom.xml @@ -0,0 +1,292 @@ + + + + + 4.0.0 + + org.jboss + jboss-parent + 46 + + + + org.jboss.arquillian + integration-tests + 1.9.1.Final-SNAPSHOT + pom + Arquillian Core: Implementation Integration Tests + Tests for implementations of Arquillian Core + + + common + junit4-tests + junit5-tests + testng-tests + + + + true + false + ${skipItTests} + + + 10.0.0 + 1.8.1.Final + + + + + + + jakarta.platform + jakarta.jakartaee-bom + ${version.jakarta.ee} + import + pom + + + org.jboss.arquillian + arquillian-bom + ${project.version} + import + pom + + + org.jboss.arquillian.jakarta + arquillian-jakarta-bom + ${version.org.jboss.arquillian.jakarta} + import + pom + + + org.jboss.arquillian + common-tests + ${project.version} + + + + + + + + + + maven-surefire-plugin + + + true + ${maven.test.redirectTestOutputToFile} + + + + cdi-tests + + test + + test + + ${skipTests} + + org.jboss.arquillian.integration.test.cdi.*Test + + + + + manual-mode-tests + + test + + test + + ${skipTests} + + org.jboss.arquillian.integration.test.manual.*Test + + + manual-mode-arquillian.xml + + + + + resource-injection-tests + + test + + test + + ${skipTests} + + org.jboss.arquillian.integration.test.resource.injection.*Test + + + + + + + + + + maven-deploy-plugin + + true + + + + + + + + + wildfly + + ${skipTests} + + + 5.1.0.Beta3 + 5.0.0.Final + + ${project.build.directory}${file.separator}wildfly + + + + + org.wildfly.arquillian + wildfly-arquillian-container-managed + ${version.org.wildfly.arquillian} + test + + + + + + + maven-surefire-plugin + + + ${jboss.home} + + + + + org.wildfly.plugins + wildfly-maven-plugin + ${version.wildfly-maven-plugin} + + ${skip.provision.server} + ${jboss.home} + ${jboss.home} + + + org.wildfly + wildfly-ee-galleon-pack + + + + + + org.wildfly.channels + wildfly-ee + + + + + ee-core-profile-server + + + true + + + + + provision-wildfly + + provision + + process-test-classes + + + + + + + + + payara + + ${skipTests} + + + 6.2024.6 + 3.0 + + ${project.build.directory}${file.separator}payara6 + + + + + fish.payara.arquillian + arquillian-payara-server-managed + ${version.fish.payara.arquillian} + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + unpack + process-test-classes + + unpack + + + + + fish.payara.distributions + payara + ${version.fish.payara} + zip + true + ${project.build.directory} + + + + + + + + maven-surefire-plugin + + + ${payara.home} + localhost + + + + + + + + + diff --git a/integration-tests/testng-tests/pom.xml b/integration-tests/testng-tests/pom.xml new file mode 100644 index 000000000..bcef2a955 --- /dev/null +++ b/integration-tests/testng-tests/pom.xml @@ -0,0 +1,70 @@ + + + + + 4.0.0 + + org.jboss.arquillian + integration-tests + 1.9.1.Final-SNAPSHOT + ../pom.xml + + + testng-tests + Arquillian Core: TestNG Integration Tests + + + 7.5.1 + + + + + + + org.testng + testng + ${version.org.testng} + test + + + org.jboss.arquillian + common-tests + test + + + org.jboss.arquillian.testng + arquillian-testng-container + test + + + + + + wildfly + + + false + + + + + diff --git a/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java b/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java new file mode 100644 index 000000000..62fd5e5d7 --- /dev/null +++ b/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java @@ -0,0 +1,60 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.cdi; + +import java.net.URI; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.integration.test.common.app.Greeter; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.arquillian.testng.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * @author James R. Perkins + */ +@ApplicationScoped +public class CdiInjectionTest extends Arquillian { + + @Deployment + public static WebArchive createDeployment() { + return ShrinkWrap.create(WebArchive.class) + .addClass(Greeter.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @ArquillianResource + private URI uri; + + @Inject + Greeter greeter; + + @Test + public void validateGreeting() { + Assert.assertNotNull(greeter, "Greeter should not be null"); + Assert.assertEquals(greeter.greet("JUnit5"), "Hello JUnit5!"); + } +} diff --git a/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/manual/ManualModeTest.java b/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/manual/ManualModeTest.java new file mode 100644 index 000000000..3f71fbd91 --- /dev/null +++ b/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/manual/ManualModeTest.java @@ -0,0 +1,90 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.manual; + +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; + +import org.jboss.arquillian.container.test.api.ContainerController; +import org.jboss.arquillian.container.test.api.Deployer; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.integration.test.common.TestEnvironment; +import org.jboss.arquillian.integration.test.common.app.EchoResource; +import org.jboss.arquillian.integration.test.common.app.RestActivator; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.arquillian.testng.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * @author James R. Perkins + */ +@RunAsClient +public class ManualModeTest extends Arquillian { + private static final String CONTAINER_NAME = "default"; + private static final String DEPLOYMENT_NAME = "manual-mode"; + + @Deployment(name = DEPLOYMENT_NAME, managed = false) + public static WebArchive createDeployment() { + return ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME + ".war") + .addClasses(RestActivator.class, EchoResource.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @ArquillianResource + private static ContainerController controller; + + @ArquillianResource + private static Deployer deployer; + + @Test + public void startConnectAndStop() throws Exception { + Assert.assertNotNull(controller); + Assert.assertFalse(controller.isStarted(CONTAINER_NAME), "This is a manual mode test and the server should not have been started."); + // Check that we can start the server and the server is running + controller.start(CONTAINER_NAME); + Assert.assertTrue(controller.isStarted(CONTAINER_NAME), "The server should have been started"); + + // Deploy the application and make a REST request + deployer.deploy(DEPLOYMENT_NAME); + assertAppDeployed(); + + // Undeploy the application and stop the server + deployer.undeploy(DEPLOYMENT_NAME); + controller.stop(CONTAINER_NAME); + } + + private void assertAppDeployed() throws Exception { + final String msg = "Test message"; + final HttpClient client = HttpClient.newHttpClient(); + final HttpRequest request = HttpRequest.newBuilder() + .uri(TestEnvironment.uri(DEPLOYMENT_NAME, TestEnvironment.REST_PATH, "echo")) + .POST(HttpRequest.BodyPublishers.ofString(msg)) + .build(); + final HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + Assert.assertEquals(response.statusCode(), 200); + Assert.assertEquals(msg, response.body()); + } +} diff --git a/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/AbstractArquillianResourceTest.java b/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/AbstractArquillianResourceTest.java new file mode 100644 index 000000000..8c8e9403e --- /dev/null +++ b/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/AbstractArquillianResourceTest.java @@ -0,0 +1,83 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.resource.injection; + +import java.net.URI; +import java.net.URL; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.integration.test.common.TestEnvironment; +import org.jboss.arquillian.integration.test.common.app.Greeter; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.arquillian.testng.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * @author James R. Perkins + */ +abstract class AbstractArquillianResourceTest extends Arquillian { + static final String DEPLOYMENT_NAME = "injection"; + + @ArquillianResource + protected URL url; + + @ArquillianResource + protected URI uri; + + @Deployment + public static WebArchive createDeployment() { + return ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME + ".war") + .addClasses(Greeter.class, AbstractArquillianResourceTest.class, TestEnvironment.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Test + public void checkUrl() { + Assert.assertNotNull(url, "The URL should have been injected"); + Assert.assertEquals(url.getProtocol(), TestEnvironment.protocol()); + checkHost(url.getHost()); + Assert.assertEquals(url.getPort(), TestEnvironment.port()); + Assert.assertEquals(url.getPath(), "/" + DEPLOYMENT_NAME + "/"); + } + + @Test + public void checkUri() { + Assert.assertNotNull(uri, "The URI should have been injected"); + checkHost(uri.getHost()); + Assert.assertEquals(uri.getPort(), TestEnvironment.port()); + Assert.assertEquals(uri.getPath(), "/" + DEPLOYMENT_NAME + "/"); + } + + protected void checkHost(final String host) { + // localhost and 127.0.0.1 should be treated as the same + final String expectedHost = TestEnvironment.host(); + if ("127.0.0.1".equals(expectedHost)) { + Assert.assertEquals(host.replace("localhost", "127.0.0.1"), expectedHost); + } else if ("localhost".equals(expectedHost)) { + Assert.assertEquals(host.replace("127.0.0.1", "localhost"), expectedHost); + } else { + Assert.assertEquals(host, expectedHost); + } + } +} diff --git a/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/ClientArquillianResourceTest.java b/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/ClientArquillianResourceTest.java new file mode 100644 index 000000000..90a75fa22 --- /dev/null +++ b/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/ClientArquillianResourceTest.java @@ -0,0 +1,29 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.resource.injection; + +import org.jboss.arquillian.container.test.api.RunAsClient; + +/** + * @author James R. Perkins + */ +@RunAsClient +public class ClientArquillianResourceTest extends AbstractArquillianResourceTest { +} diff --git a/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/InContainerArquillianResourceTest.java b/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/InContainerArquillianResourceTest.java new file mode 100644 index 000000000..dff00635d --- /dev/null +++ b/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/InContainerArquillianResourceTest.java @@ -0,0 +1,53 @@ +/* + * JBoss, Home of Professional Open Source. + * + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.arquillian.integration.test.resource.injection; + +import javax.naming.Context; +import javax.naming.InitialContext; + +import org.jboss.arquillian.test.api.ArquillianResource; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * @author James R. Perkins + */ +public class InContainerArquillianResourceTest extends AbstractArquillianResourceTest { + + @ArquillianResource + protected Context context; + + @ArquillianResource + protected InitialContext initialContext; + + @Test + public void checkContext() throws Exception { + Assert.assertNotNull(context, "The Context should have been injected"); + final Object bm = context.lookup("java:comp/BeanManager"); + Assert.assertNotNull(bm); + } + + @Test + public void checkInitialContext() throws Exception { + Assert.assertNotNull(initialContext, "The InitialContext should have been injected"); + final Object bm = initialContext.lookup("java:comp/BeanManager"); + Assert.assertNotNull(bm); + } +} diff --git a/junit/container/pom.xml b/junit/container/pom.xml index e159edbf2..3553c032a 100644 --- a/junit/container/pom.xml +++ b/junit/container/pom.xml @@ -6,7 +6,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/junit/core/pom.xml b/junit/core/pom.xml index 2a6c2b252..6301ecb02 100644 --- a/junit/core/pom.xml +++ b/junit/core/pom.xml @@ -6,7 +6,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/junit/pom.xml b/junit/pom.xml index 1c2f855c2..66642b278 100644 --- a/junit/pom.xml +++ b/junit/pom.xml @@ -6,7 +6,7 @@ org.jboss.arquillian arquillian-parent - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT diff --git a/junit/standalone/pom.xml b/junit/standalone/pom.xml index 1db5e47d7..7e218fdef 100644 --- a/junit/standalone/pom.xml +++ b/junit/standalone/pom.xml @@ -6,7 +6,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/junit/standalone/src/main/java/org/jboss/arquillian/junit/standalone/LocalTestMethodExecutor.java b/junit/standalone/src/main/java/org/jboss/arquillian/junit/standalone/LocalTestMethodExecutor.java index 1b838cee6..fcf3e9e6f 100644 --- a/junit/standalone/src/main/java/org/jboss/arquillian/junit/standalone/LocalTestMethodExecutor.java +++ b/junit/standalone/src/main/java/org/jboss/arquillian/junit/standalone/LocalTestMethodExecutor.java @@ -17,8 +17,6 @@ */ package org.jboss.arquillian.junit.standalone; -import java.lang.reflect.Method; -import java.util.Collection; import org.jboss.arquillian.core.api.Instance; import org.jboss.arquillian.core.api.InstanceProducer; import org.jboss.arquillian.core.api.annotation.Inject; @@ -28,6 +26,7 @@ import org.jboss.arquillian.test.spi.TestResult; import org.jboss.arquillian.test.spi.annotation.TestScoped; import org.jboss.arquillian.test.spi.event.suite.Test; +import org.jboss.arquillian.test.spi.execution.ExecUtils; /** * LocalTestMethodExecutor @@ -46,10 +45,10 @@ public class LocalTestMethodExecutor { public void execute(@Observes Test event) throws Exception { TestResult result = TestResult.passed(); try { - event.getTestMethodExecutor().invoke( - enrichArguments( - event.getTestMethod(), - serviceLoader.get().all(TestEnricher.class))); + Object[] args = ExecUtils.enrichArguments( + event.getTestMethodExecutor().getMethod(), + serviceLoader.get().all(TestEnricher.class)); + event.getTestMethodExecutor().invoke(args); } catch (Throwable e) { result = TestResult.failed(e); } finally { @@ -58,36 +57,4 @@ public void execute(@Observes Test event) throws Exception { testResult.set(result); } - /** - * Enrich the method arguments of a method call.
- * The Object[] index will match the method parameterType[] index. - * - * @return the argument values - */ - private Object[] enrichArguments(Method method, Collection enrichers) { - Object[] values = new Object[method.getParameterTypes().length]; - if (method.getParameterTypes().length == 0) { - return values; - } - for (TestEnricher enricher : enrichers) { - mergeValues(values, enricher.resolve(method)); - } - return values; - } - - private void mergeValues(Object[] values, Object[] resolvedValues) { - if (resolvedValues == null || resolvedValues.length == 0) { - return; - } - if (values.length != resolvedValues.length) { - throw new IllegalStateException("TestEnricher resolved wrong argument count, expected " + - values.length + " returned " + resolvedValues.length); - } - for (int i = 0; i < resolvedValues.length; i++) { - Object resvoledValue = resolvedValues[i]; - if (resvoledValue != null && values[i] == null) { - values[i] = resvoledValue; - } - } - } } diff --git a/junit5/container/pom.xml b/junit5/container/pom.xml index 132bfc41d..7775c0a9e 100644 --- a/junit5/container/pom.xml +++ b/junit5/container/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/junit5/core/pom.xml b/junit5/core/pom.xml index 83d3e89ff..27208b4a0 100644 --- a/junit5/core/pom.xml +++ b/junit5/core/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/junit5/pom.xml b/junit5/pom.xml index 59798d7cb..b196d4d5f 100644 --- a/junit5/pom.xml +++ b/junit5/pom.xml @@ -4,7 +4,7 @@ org.jboss.arquillian arquillian-parent - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT diff --git a/pom.xml b/pom.xml index 8619ba89b..5c1208784 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ org.jboss.arquillian arquillian-parent - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT pom Arquillian Aggregator http://arquillian.org @@ -146,8 +146,17 @@ + + integration-tests + + integration-tests + + release + + integration-tests + @@ -159,6 +168,7 @@ true clean install gpg-sign,jboss-release + -DskipItTests=true @{project.version} diff --git a/protocols/jmx/pom.xml b/protocols/jmx/pom.xml index 4a06ea0b0..2faa172ad 100644 --- a/protocols/jmx/pom.xml +++ b/protocols/jmx/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/protocols/pom.xml b/protocols/pom.xml index 7fd4e25ed..1097d3708 100644 --- a/protocols/pom.xml +++ b/protocols/pom.xml @@ -6,7 +6,7 @@ org.jboss.arquillian arquillian-parent - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT diff --git a/protocols/servlet/pom.xml b/protocols/servlet/pom.xml index 626d3b237..406c9774a 100644 --- a/protocols/servlet/pom.xml +++ b/protocols/servlet/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/test/api/pom.xml b/test/api/pom.xml index 437b594ba..bf811ec66 100644 --- a/test/api/pom.xml +++ b/test/api/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/test/impl-base/pom.xml b/test/impl-base/pom.xml index e93cb5998..a8c0aa7b5 100644 --- a/test/impl-base/pom.xml +++ b/test/impl-base/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/test/pom.xml b/test/pom.xml index 38cf86c30..2b4fcbf48 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -6,7 +6,7 @@ org.jboss.arquillian arquillian-parent - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT diff --git a/test/spi/pom.xml b/test/spi/pom.xml index bfb681ae6..4bd51745e 100644 --- a/test/spi/pom.xml +++ b/test/spi/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/test/spi/src/main/java/org/jboss/arquillian/test/spi/execution/ExecUtils.java b/test/spi/src/main/java/org/jboss/arquillian/test/spi/execution/ExecUtils.java new file mode 100644 index 000000000..8d0fe24b5 --- /dev/null +++ b/test/spi/src/main/java/org/jboss/arquillian/test/spi/execution/ExecUtils.java @@ -0,0 +1,67 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2024, Red Hat, Inc. and/or its affiliates, and individual + * contributors by the @authors tag. See the copyright.txt in the + * distribution for a full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.arquillian.test.spi.execution; + +import org.jboss.arquillian.test.spi.TestEnricher; + +import java.lang.reflect.Method; +import java.util.Collection; + +/** + * A utility class that provides methods for enriching method arguments. + */ +public class ExecUtils { + + /** + * Generate the enriched the method arguments of a method call.
+ * The Object[] index will match the method parameterType[] index. + * + * @return the enriched argument values to use + */ + public static Object[] enrichArguments(Method method, Collection enrichers) { + Object[] values = new Object[method.getParameterTypes().length]; + if (method.getParameterTypes().length == 0) { + return values; + } + for (TestEnricher enricher : enrichers) { + mergeValues(values, enricher.resolve(method)); + } + return values; + } + + /** + * Called for each {@link TestEnricher} to merge the resolved values into the values array. + * Since differeent TestEnrichers can resolve different arguments, we need to merge the values. + * @param values - the current values + * @param resolvedValues - the values from the last TestEnricher + */ + private static void mergeValues(Object[] values, Object[] resolvedValues) { + if (resolvedValues == null || resolvedValues.length == 0) { + return; + } + if (values.length != resolvedValues.length) { + throw new IllegalStateException("TestEnricher resolved wrong argument count, expected " + + values.length + " returned " + resolvedValues.length); + } + for (int i = 0; i < resolvedValues.length; i++) { + Object resvoledValue = resolvedValues[i]; + if (resvoledValue != null && values[i] == null) { + values[i] = resvoledValue; + } + } + } +} diff --git a/testenrichers/cdi/pom.xml b/testenrichers/cdi/pom.xml index bf82ab185..2c3972165 100644 --- a/testenrichers/cdi/pom.xml +++ b/testenrichers/cdi/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/testenrichers/ejb/pom.xml b/testenrichers/ejb/pom.xml index 6cfea7890..80d341614 100644 --- a/testenrichers/ejb/pom.xml +++ b/testenrichers/ejb/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/testenrichers/initialcontext/pom.xml b/testenrichers/initialcontext/pom.xml index 6f5fe5fbe..bbc2bc322 100644 --- a/testenrichers/initialcontext/pom.xml +++ b/testenrichers/initialcontext/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/testenrichers/pom.xml b/testenrichers/pom.xml index 44e2db482..a3e49003e 100644 --- a/testenrichers/pom.xml +++ b/testenrichers/pom.xml @@ -6,7 +6,7 @@ org.jboss.arquillian arquillian-parent - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT diff --git a/testenrichers/resource/pom.xml b/testenrichers/resource/pom.xml index d87516dbe..50b443828 100644 --- a/testenrichers/resource/pom.xml +++ b/testenrichers/resource/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/testng/container/pom.xml b/testng/container/pom.xml index a5776335e..aea27f41f 100644 --- a/testng/container/pom.xml +++ b/testng/container/pom.xml @@ -6,7 +6,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/testng/core/pom.xml b/testng/core/pom.xml index 1adbb3de2..62638751b 100644 --- a/testng/core/pom.xml +++ b/testng/core/pom.xml @@ -5,7 +5,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/testng/pom.xml b/testng/pom.xml index 96e80416d..ec90bf93a 100644 --- a/testng/pom.xml +++ b/testng/pom.xml @@ -6,7 +6,7 @@ org.jboss.arquillian arquillian-parent - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT diff --git a/testng/standalone/pom.xml b/testng/standalone/pom.xml index 31f7e9a09..c3bbc4b6e 100644 --- a/testng/standalone/pom.xml +++ b/testng/standalone/pom.xml @@ -6,7 +6,7 @@ org.jboss.arquillian arquillian-build - 1.8.2.Final-SNAPSHOT + 1.9.1.Final-SNAPSHOT ../../build/pom.xml diff --git a/testng/standalone/src/main/java/org/jboss/arquillian/testng/standalone/LocalTestMethodExecutor.java b/testng/standalone/src/main/java/org/jboss/arquillian/testng/standalone/LocalTestMethodExecutor.java index cde368615..ebcd27284 100644 --- a/testng/standalone/src/main/java/org/jboss/arquillian/testng/standalone/LocalTestMethodExecutor.java +++ b/testng/standalone/src/main/java/org/jboss/arquillian/testng/standalone/LocalTestMethodExecutor.java @@ -17,8 +17,6 @@ */ package org.jboss.arquillian.testng.standalone; -import java.lang.reflect.Method; -import java.util.Collection; import org.jboss.arquillian.core.api.Instance; import org.jboss.arquillian.core.api.InstanceProducer; import org.jboss.arquillian.core.api.annotation.Inject; @@ -28,6 +26,7 @@ import org.jboss.arquillian.test.spi.TestResult; import org.jboss.arquillian.test.spi.annotation.TestScoped; import org.jboss.arquillian.test.spi.event.suite.Test; +import org.jboss.arquillian.test.spi.execution.ExecUtils; /** * LocalTestMethodExecutor @@ -46,10 +45,10 @@ public class LocalTestMethodExecutor { public void execute(@Observes Test event) throws Exception { TestResult result = TestResult.passed(); try { - event.getTestMethodExecutor().invoke( - enrichArguments( - event.getTestMethod(), - serviceLoader.get().all(TestEnricher.class))); + Object[] args = ExecUtils.enrichArguments( + event.getTestMethodExecutor().getMethod(), + serviceLoader.get().all(TestEnricher.class)); + event.getTestMethodExecutor().invoke(args); } catch (Throwable e) { result = TestResult.failed(e); } finally { @@ -58,36 +57,4 @@ public void execute(@Observes Test event) throws Exception { testResult.set(result); } - /** - * Enrich the method arguments of a method call.
- * The Object[] index will match the method parameterType[] index. - * - * @return the argument values - */ - private Object[] enrichArguments(Method method, Collection enrichers) { - Object[] values = new Object[method.getParameterTypes().length]; - if (method.getParameterTypes().length == 0) { - return values; - } - for (TestEnricher enricher : enrichers) { - mergeValues(values, enricher.resolve(method)); - } - return values; - } - - private void mergeValues(Object[] values, Object[] resolvedValues) { - if (resolvedValues == null || resolvedValues.length == 0) { - return; - } - if (values.length != resolvedValues.length) { - throw new IllegalStateException("TestEnricher resolved wrong argument count, expected " + - values.length + " returned " + resolvedValues.length); - } - for (int i = 0; i < resolvedValues.length; i++) { - Object resvoledValue = resolvedValues[i]; - if (resvoledValue != null && values[i] == null) { - values[i] = resvoledValue; - } - } - } }