From fbd394b3e6cb95d411c0f1cad6a83c6de05d2365 Mon Sep 17 00:00:00 2001 From: "James R. Perkins" Date: Mon, 8 Jul 2024 08:37:17 -0700 Subject: [PATCH] [580] Add a manual mode test and do not use the Arquillian core parent POM for tests. --- docs/introduction.adoc | 2 +- docs/test-enrichers.adoc | 28 +++---- integration-tests/common/pom.xml | 24 +++++- .../test/common/TestEnvironment.java | 83 +++++++++++++++++++ .../test/common/app/EchoResource.java | 18 ++++ .../test/common/app/RestActivator.java | 12 +++ .../main/resources/manual-mode-arquillian.xml | 10 +++ integration-tests/junit4-tests/pom.xml | 14 +++- .../CdiInjectionTest.java} | 4 +- .../test/manual/ManualModeTest.java | 73 ++++++++++++++++ integration-tests/junit5-tests/pom.xml | 1 + .../CdiInjectionTest.java} | 4 +- .../test/manual/ManualModeTest.java | 79 ++++++++++++++++++ integration-tests/pom.xml | 52 +++++++++--- integration-tests/testng-tests/pom.xml | 3 +- .../CdiInjectionTest.java} | 4 +- .../test/manual/ManualModeTest.java | 71 ++++++++++++++++ testenrichers/cdi/pom.xml | 4 +- 18 files changed, 448 insertions(+), 38 deletions(-) create mode 100644 integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/TestEnvironment.java create mode 100644 integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/app/EchoResource.java create mode 100644 integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/app/RestActivator.java create mode 100644 integration-tests/common/src/main/resources/manual-mode-arquillian.xml rename integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/{junit/CdiInjectionTestCase.java => cdi/CdiInjectionTest.java} (93%) create mode 100644 integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/manual/ManualModeTest.java rename integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/{junit5/CdiInjectionTestCase.java => cdi/CdiInjectionTest.java} (93%) create mode 100644 integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/manual/ManualModeTest.java rename integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/{testng/CdiInjectionTestCase.java => cdi/CdiInjectionTest.java} (91%) create mode 100644 integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/manual/ManualModeTest.java diff --git a/docs/introduction.adoc b/docs/introduction.adoc index 6174f912f..9a5af0801 100644 --- a/docs/introduction.adoc +++ b/docs/introduction.adoc @@ -145,7 +145,7 @@ _Do you really need to run the test in a real container when a Java SE CDI environment would do?_ It's true, some tests can work without a full container. For instance, -you can run certain tests in a Java SE CDI environment with Arquillian. +you can run certain tests in a Java SE org.jboss.arquillian.integration.test.junit.common.CDI environment with Arquillian. Let's call these "standalone" tests, whereas tests which do require a full container are called "integration" tests. Every standalone test can also be run as an integration test, but not the other way around. While diff --git a/docs/test-enrichers.adoc b/docs/test-enrichers.adoc index 6952e02b3..c423ac1cd 100644 --- a/docs/test-enrichers.adoc +++ b/docs/test-enrichers.adoc @@ -15,8 +15,8 @@ endif::[] * <> * <> ** <> -** <> -** <> +** <> +** <> * <> When you use a unit testing framework like JUnit or TestNG, your test @@ -28,7 +28,7 @@ this environment in the test falls on the developer's shoulders. With Arquillian, you no longer have to worry about setting up the execution environment because that is all handled for you. The test will -either be running in a container or a local CDI environment. But you +either be running in a container or a local org.jboss.arquillian.integration.test.junit.common.CDI environment. But you still need some way to hook your test into this environment. A key part of in-container integration testing is getting access to the @@ -90,17 +90,17 @@ the box: * `@Resource` - Java EE resource injections * `@EJB` - EJB session bean reference injections * `@Inject`, `@Resource`, `@EJB`, `@PersistenceContext` and -`@PersistenceUnit` - CDI-supported injections +`@PersistenceUnit` - org.jboss.arquillian.integration.test.junit.common.CDI-supported injections The first two enrichers use JNDI to lookup the instance to inject. The -CDI injections are handled by treating the test class as a bean capable -of receiving standard CDI injections (non-contextual injection). Since -CDI requires containers to satisfy all Java EE injection points on a CDI +org.jboss.arquillian.integration.test.junit.common.CDI injections are handled by treating the test class as a bean capable +of receiving standard org.jboss.arquillian.integration.test.junit.common.CDI injections (non-contextual injection). Since +org.jboss.arquillian.integration.test.junit.common.CDI requires containers to satisfy all Java EE injection points on a org.jboss.arquillian.integration.test.junit.common.CDI bean, the `@Resource`, `@EJB`, `@PersistenceContext` and -`@PersistenceUnit` injections are supported transitively by the CDI -enricher. In fact, because of CDI's tight integration with the +`@PersistenceUnit` injections are supported transitively by the org.jboss.arquillian.integration.test.junit.common.CDI +enricher. In fact, because of org.jboss.arquillian.integration.test.junit.common.CDI's tight integration with the container, `@EJB` injections in the test class are satisfied according -to specification when the CDI enricher is available. +to specification when the org.jboss.arquillian.integration.test.junit.common.CDI enricher is available. [[resource-injection]] ====== Resource Injection @@ -111,7 +111,7 @@ defined in the Section 2.3 of the Common Annotations for the Java Platform specification). [[ejb-injection]] -====== EJB Injection (without CDI support) +====== EJB Injection (without org.jboss.arquillian.integration.test.junit.common.CDI support) The `@EJB` annotation performs a JNDI lookup for the EJB session bean reference using the following equation in the specified order: @@ -139,9 +139,9 @@ common naming convention of EJB beans. In the future the lookup will rely on the standard JNDI naming conventions established in Java EE 6. [[cdi-injection]] -====== CDI Injection +====== org.jboss.arquillian.integration.test.junit.common.CDI Injection -In order for CDI injections to work, the test archive defined with +In order for org.jboss.arquillian.integration.test.junit.common.CDI injections to work, the test archive defined with ShrinkWrap must be in a bean archive. That means adding beans.xml to the META-INF directory. Here's a `@Deployment` method that shows one way to add a beans.xml to the archive: @@ -155,7 +155,7 @@ public static JavaArchive createTestArchive() { .addAsManifestResource(EmptyAsset.INSTANCE, Paths.create("beans.xml")) ---- -In an application that takes full advantage of CDI, you can likely get +In an application that takes full advantage of org.jboss.arquillian.integration.test.junit.common.CDI, you can likely get by only using injections defined with the `@Inject` annotation. Regardless, the other two types of injection come in handy from time-to-time. diff --git a/integration-tests/common/pom.xml b/integration-tests/common/pom.xml index 1a60ed9aa..c7a9aa400 100644 --- a/integration-tests/common/pom.xml +++ b/integration-tests/common/pom.xml @@ -14,7 +14,22 @@ Arquillian Core: Common integration tests - + + 5.10.3 + + + + + + org.junit + junit-bom + ${version.org.junit} + pom + import + + + + jakarta.annotation @@ -40,6 +55,13 @@ 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..a5bdc71fe --- /dev/null +++ b/integration-tests/common/src/main/java/org/jboss/arquillian/integration/test/common/TestEnvironment.java @@ -0,0 +1,83 @@ +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; + private static final String HOST; + private static final int PORT; + public static final String REST_PATH = "/rest"; + + static { + PROTOCOL = System.getProperty("arq.protocol", "http"); + HOST = System.getProperty("arq.host", "localhost"); + PORT = Integer.parseInt(System.getProperty("arq.port", "8080")); + } + + 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 localhost} 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/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 index a438e1ffd..fcb62ae92 100644 --- a/integration-tests/junit4-tests/pom.xml +++ b/integration-tests/junit4-tests/pom.xml @@ -7,6 +7,7 @@ org.jboss.arquillian integration-tests 1.8.2.Final-SNAPSHOT + ../pom.xml junit4-tests @@ -37,7 +38,18 @@ - + + + + org.apache.maven.plugins + maven-compiler-plugin + + 11 + 11 + + + + diff --git a/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/junit/CdiInjectionTestCase.java b/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java similarity index 93% rename from integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/junit/CdiInjectionTestCase.java rename to integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java index 2afa4d4aa..5424043fd 100644 --- a/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/junit/CdiInjectionTestCase.java +++ b/integration-tests/junit4-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java @@ -1,4 +1,4 @@ -package org.jboss.arquillian.integration.test.junit; +package org.jboss.arquillian.integration.test.cdi; import java.net.URI; @@ -20,7 +20,7 @@ */ @RunWith(Arquillian.class) @ApplicationScoped -public class CdiInjectionTestCase { +public class CdiInjectionTest { @Deployment public static WebArchive createDeployment() { 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/junit5-tests/pom.xml b/integration-tests/junit5-tests/pom.xml index 606f93ef0..c28ca6d7d 100644 --- a/integration-tests/junit5-tests/pom.xml +++ b/integration-tests/junit5-tests/pom.xml @@ -7,6 +7,7 @@ org.jboss.arquillian integration-tests 1.8.2.Final-SNAPSHOT + ../pom.xml junit5-tests diff --git a/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/junit5/CdiInjectionTestCase.java b/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java similarity index 93% rename from integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/junit5/CdiInjectionTestCase.java rename to integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java index faf6f65ad..704bc7198 100644 --- a/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/junit5/CdiInjectionTestCase.java +++ b/integration-tests/junit5-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java @@ -1,4 +1,4 @@ -package org.jboss.arquillian.integration.test.junit5; +package org.jboss.arquillian.integration.test.cdi; import java.net.URI; @@ -20,7 +20,7 @@ */ @ExtendWith(ArquillianExtension.class) @ApplicationScoped -public class CdiInjectionTestCase { +public class CdiInjectionTest { @Deployment public static WebArchive createDeployment() { 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/pom.xml b/integration-tests/pom.xml index 3206f7f7d..161b434ca 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -4,13 +4,15 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.jboss.arquillian - arquillian-parent - 1.8.2.Final-SNAPSHOT - ../pom.xml + org.jboss + jboss-parent + 46 + + org.jboss.arquillian integration-tests + 1.8.2.Final-SNAPSHOT pom Arquillian Core: Implementation Integration Tests Tests for implementations of Arquillian Core @@ -23,7 +25,9 @@ + true false + ${skipTests} 10.0.0 @@ -71,7 +75,39 @@ 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 + + + + @@ -90,8 +126,7 @@ wildfly - ${skipTests} - true + ${skipTests} 5.1.0.Beta3 @@ -101,15 +136,10 @@ - - - - maven-surefire-plugin - ${skipTests} ${jboss.home} diff --git a/integration-tests/testng-tests/pom.xml b/integration-tests/testng-tests/pom.xml index 3c402d7de..09b6ec61c 100644 --- a/integration-tests/testng-tests/pom.xml +++ b/integration-tests/testng-tests/pom.xml @@ -7,6 +7,7 @@ org.jboss.arquillian integration-tests 1.8.2.Final-SNAPSHOT + ../pom.xml testng-tests @@ -37,8 +38,6 @@ - - wildfly diff --git a/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/testng/CdiInjectionTestCase.java b/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java similarity index 91% rename from integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/testng/CdiInjectionTestCase.java rename to integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java index a92605952..7d63f21b1 100644 --- a/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/testng/CdiInjectionTestCase.java +++ b/integration-tests/testng-tests/src/test/java/org/jboss/arquillian/integration/test/cdi/CdiInjectionTest.java @@ -1,4 +1,4 @@ -package org.jboss.arquillian.integration.test.testng; +package org.jboss.arquillian.integration.test.cdi; import java.net.URI; @@ -18,7 +18,7 @@ * @author James R. Perkins */ @ApplicationScoped -public class CdiInjectionTestCase extends Arquillian { +public class CdiInjectionTest extends Arquillian { @Deployment public static WebArchive createDeployment() { 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..7e0e9976e --- /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(200, response.statusCode()); + Assert.assertEquals(response.body(), msg); + } +} diff --git a/testenrichers/cdi/pom.xml b/testenrichers/cdi/pom.xml index bf82ab185..eb18f426f 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