-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[580] Add a manual mode test and do not use the Arquillian core paren…
…t POM for tests.
- Loading branch information
Showing
18 changed files
with
448 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...ts/common/src/main/java/org/jboss/arquillian/integration/test/common/TestEnvironment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.jboss.arquillian.integration.test.common; | ||
|
||
import java.net.URI; | ||
|
||
/** | ||
* The test environment setup. | ||
* | ||
* @author <a href="mailto:[email protected]">James R. Perkins</a> | ||
*/ | ||
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()); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...s/common/src/main/java/org/jboss/arquillian/integration/test/common/app/EchoResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <a href="mailto:[email protected]">James R. Perkins</a> | ||
*/ | ||
@Path("echo") | ||
@RequestScoped | ||
public class EchoResource { | ||
|
||
@POST | ||
public String echo(final String msg) { | ||
return msg; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
.../common/src/main/java/org/jboss/arquillian/integration/test/common/app/RestActivator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <a href="mailto:[email protected]">James R. Perkins</a> | ||
*/ | ||
@ApplicationPath(TestEnvironment.REST_PATH) | ||
public class RestActivator extends Application { | ||
} |
10 changes: 10 additions & 0 deletions
10
integration-tests/common/src/main/resources/manual-mode-arquillian.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright The WildFly Authors | ||
~ SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd"> | ||
<container qualifier="default" default="true" mode="manual"/> | ||
</arquillian> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...nit4-tests/src/test/java/org/jboss/arquillian/integration/test/manual/ManualModeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <a href="mailto:[email protected]">James R. Perkins</a> | ||
*/ | ||
@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<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); | ||
Assert.assertEquals(200, response.statusCode()); | ||
Assert.assertEquals(msg, response.body()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.