diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml new file mode 100644 index 000000000..6f031e301 --- /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: + - '**' + 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: | + mvn 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: | + mvn 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/integration-tests/common/pom.xml b/integration-tests/common/pom.xml new file mode 100644 index 000000000..3d033d144 --- /dev/null +++ b/integration-tests/common/pom.xml @@ -0,0 +1,69 @@ + + + 4.0.0 + + org.jboss.arquillian + integration-tests + 1.9.0.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..e60f750d7 --- /dev/null +++ b/integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/TestEnvironment.java @@ -0,0 +1,77 @@ +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..76d177423 --- /dev/null +++ b/integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/app/EchoResource.java @@ -0,0 +1,18 @@ +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..c6d69b3e2 --- /dev/null +++ b/integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/app/Greeter.java @@ -0,0 +1,14 @@ +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..c2d671c40 --- /dev/null +++ b/integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/app/RestActivator.java @@ -0,0 +1,12 @@ +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..353bb0db7 --- /dev/null +++ b/integration-tests/common/src/main/resources/manual-mode-arquillian.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/integration-tests/junit4-tests/pom.xml b/integration-tests/junit4-tests/pom.xml new file mode 100644 index 000000000..bbe897957 --- /dev/null +++ b/integration-tests/junit4-tests/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + + org.jboss.arquillian + integration-tests + 1.9.0.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..5424043fd --- /dev/null +++ b/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java @@ -0,0 +1,43 @@ +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..16e2be232 --- /dev/null +++ b/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/manual/ManualModeTest.java @@ -0,0 +1,73 @@ +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..f6f32961b --- /dev/null +++ b/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/AbstractArquillianResourceTest.java @@ -0,0 +1,83 @@ +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..457324599 --- /dev/null +++ b/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/ClientArquillianResourceTest.java @@ -0,0 +1,10 @@ +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..ec17d53df --- /dev/null +++ b/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/InContainerArquillianResourceTest.java @@ -0,0 +1,48 @@ +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..475e5df66 --- /dev/null +++ b/integration-tests/junit5-tests/pom.xml @@ -0,0 +1,61 @@ + + + 4.0.0 + + org.jboss.arquillian + integration-tests + 1.9.0.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..704bc7198 --- /dev/null +++ b/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java @@ -0,0 +1,43 @@ +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..3d2ae17b3 --- /dev/null +++ b/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/manual/ManualModeTest.java @@ -0,0 +1,79 @@ +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..4270cc3ad --- /dev/null +++ b/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/AbstractArquillianResourceTest.java @@ -0,0 +1,86 @@ +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..457324599 --- /dev/null +++ b/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/ClientArquillianResourceTest.java @@ -0,0 +1,10 @@ +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..bab609853 --- /dev/null +++ b/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/InContainerArquillianResourceTest.java @@ -0,0 +1,51 @@ +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..55800c902 --- /dev/null +++ b/integration-tests/pom.xml @@ -0,0 +1,274 @@ + + + 4.0.0 + + org.jboss + jboss-parent + 46 + + + + org.jboss.arquillian + integration-tests + 1.9.0.Final-SNAPSHOT + pom + Arquillian Core: Implementation Integration Tests + Tests for implementations of Arquillian Core + + + common + junit4-tests + junit5-tests + testng-tests + + + + true + false + ${maven.test.skip} + + + 10.0.0 + ${project.version} + 1.8.1.Final + + + + + + + jakarta.platform + jakarta.jakartaee-bom + ${version.jakarta.ee} + import + pom + + + org.jboss.arquillian + arquillian-bom + ${version.org.jboss.arquillian} + 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..8876c1703 --- /dev/null +++ b/integration-tests/testng-tests/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + + org.jboss.arquillian + integration-tests + 1.9.0.Final-SNAPSHOT + ../pom.xml + + + testng-tests + Arquillian Core: TestNG Integration Tests + + + 7.5 + + + + + + + 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..7d63f21b1 --- /dev/null +++ b/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java @@ -0,0 +1,41 @@ +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..d09ef3ad9 --- /dev/null +++ b/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/manual/ManualModeTest.java @@ -0,0 +1,71 @@ +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..cda736617 --- /dev/null +++ b/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/AbstractArquillianResourceTest.java @@ -0,0 +1,64 @@ +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..457324599 --- /dev/null +++ b/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/ClientArquillianResourceTest.java @@ -0,0 +1,10 @@ +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..cfde0a0f9 --- /dev/null +++ b/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/resource/injection/InContainerArquillianResourceTest.java @@ -0,0 +1,34 @@ +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/pom.xml b/pom.xml index 46cf48d03..b2f796936 100644 --- a/pom.xml +++ b/pom.xml @@ -146,6 +146,12 @@ + + integration-tests + + integration-tests + + release diff --git a/testenrichers/cdi/pom.xml b/testenrichers/cdi/pom.xml index 107f02825..119574058 100644 --- a/testenrichers/cdi/pom.xml +++ b/testenrichers/cdi/pom.xml @@ -15,8 +15,8 @@ org.jboss.arquillian.testenricher arquillian-testenricher-cdi - Arquillian TestEnricher CDI - CDI TestEnricher for the Arquillian Project + Arquillian TestEnricher org.jboss.arquillian.integration.test.junit.common.CDI + org.jboss.arquillian.integration.test.junit.common.CDI TestEnricher for the Arquillian Project