Skip to content

Commit

Permalink
Support dev mode (#136)
Browse files Browse the repository at this point in the history
* support dev mode

* support dev mode

* support dev mode

* support dev mode

* support dev mode

* support dev mode

* Update README.adoc

Co-authored-by: David Mueller <[email protected]>

* Update README.adoc

Co-authored-by: David Mueller <[email protected]>

* Update README.adoc

Co-authored-by: David Mueller <[email protected]>

* Update README.adoc

Co-authored-by: David Mueller <[email protected]>

* Update README.adoc

Co-authored-by: David Mueller <[email protected]>

* Update README.adoc

* Update README.adoc

* Update README.adoc

Co-authored-by: David Mueller <[email protected]>

* Update README.adoc

Co-authored-by: David Mueller <[email protected]>

---------

Co-authored-by: David Mueller <[email protected]>
  • Loading branch information
gkwan-ibm and dmuelle authored Nov 14, 2023
1 parent 9a46e02 commit 914686f
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 19 deletions.
75 changes: 73 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,45 @@ You will develop Arquillian tests that use JUnit as the runner and build your te

You will work with an `inventory` microservice, which stores information about various systems. The `inventory` service communicates with the `system` service on a particular host to retrieve its system properties and store them. You will develop functional and integration tests for the microservices. You will also learn about the Maven and Liberty configurations so that you can run your tests on Open Liberty with the Arquillian Liberty Managed container.

// Getting Started
[role="command"]
include::{common-includes}/gitclone.adoc[]

=== Try what you'll build

To try out the application, navigate to the `finish` directory and run the following commands:

[role="command"]
----
mvn clean package
mvn liberty:create liberty:install-feature
mvn liberty:configure-arquillian
mvn failsafe:integration-test
----

Look for the following output:

[source, role="no_copy"]
----
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running it.io.openliberty.guides.system.SystemArquillianIT
...
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.133 s - in it.io.openliberty.guides.system.SystemArquillianIT
[INFO] Running it.io.openliberty.guides.inventory.InventoryArquillianIT
...
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.297 s - in it.io.openliberty.guides.
...
[INFO] Results:
[INFO]
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...
----

== Developing Arquillian tests

Expand All @@ -50,6 +86,9 @@ endif::[]

You'll develop tests that use Arquillian and JUnit to verify the `inventory` microservice as an endpoint and the functions of the `InventoryResource` class. The code for the microservices is in the `src/main/java/io/openliberty/guides` directory.

[role='command']
include::{common-includes}/devmode-lmp33-start.adoc[]

[role="code_command", subs="quotes"]
----
#Create the `InventoryArquillianIT` test class.#
Expand Down Expand Up @@ -114,7 +153,10 @@ The [hotspot=arquillian-liberty-managed-junit]`arquillian-liberty-managed-junit`

The [hotspot=maven-failsafe-plugin]`maven-failsafe-plugin` artifact runs your Arquillian integration tests by using JUnit.

Lastly, specify the [hotspot=liberty-maven-plugin]`liberty-maven-plugin` configuration that defines your Open Liberty runtime configuration. When the application runs in an Arquillian Liberty managed container, the name of the war file is used as the context root of the application. You can pass context root information to the application and customize the container by using the [hotspot=arquillianProperties]`arquillianProperties` configuration. To learn more about the `arquillianProperties` configuration, see the https://github.com/OpenLiberty/liberty-arquillian/blob/main/liberty-managed/README.md#configuration[Arquillian Liberty Managed documentation^].
Lastly, specify the [hotspot=liberty-maven-plugin]`liberty-maven-plugin` configuration that defines your Open Liberty runtime configuration. When the application runs in an Arquillian Liberty managed container, the name of the `.war` file is used as the context root of the application. You can pass context root information to the application and customize the container by using the [hotspot=arquillianProperties]`arquillianProperties` configuration. To allow connections to Liberty running in dev mode, set [hotspot=allowConnectingToRunningServer]`allowConnectingToRunningServer` to `true`.


To learn more about the `arquillianProperties` configuration, see the https://github.com/OpenLiberty/liberty-arquillian/blob/main/liberty-managed/README.md#configuration[Arquillian Liberty Managed documentation^].


=== Configuring Liberty's `server.xml` configuration file
Expand All @@ -137,10 +179,39 @@ endif::[]

The [hotspot=localConnector]`localConnector` feature is required by the Arquillian Liberty Managed container to connect to and communicate with the Open Liberty runtime. The [hotspot=Servlet]`servlet` feature is required during the deployment of the Arquillian tests in which servlets are created to perform the in-container testing.

Open another command-line session and run the `configure-arquillian` goal from the `start` directory to integrate Arquillian and the Arquillian Liberty managed and remote containers with your existing project.

[role="command"]
```
mvn liberty:configure-arquillian
```

Because you started Open Liberty in dev mode, all the changes were automatically picked up. You can run the tests by pressing the `enter/return` key from the command-line session where you started dev mode. Look for the following output:

[source, role="no_copy"]
----
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running it.io.openliberty.guides.system.SystemArquillianIT
...
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.133 s - in it.io.openliberty.guides.system.SystemArquillianIT
[INFO] Running it.io.openliberty.guides.inventory.InventoryArquillianIT
...
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.297 s - in it.io.openliberty.guides.
...
[INFO] Results:
[INFO]
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
...
----


== Running the tests

It's now time to build and run your Arquillian tests. Navigate to the `start` directory. First, run the Maven command to package the application. Then, run the `liberty-maven-plugin` goals to create the Liberty instance, install the features, and deploy the application to the instance. The `configure-arquillian` goal configures your Arquillian container. You can learn more about this goal in the https://github.com/OpenLiberty/ci.maven/blob/main/docs/configure-arquillian.md[configure-arquillian goal documentation^].
It's now time to build and run your Arquillian tests outside of dev mode. Exit dev mode by pressing `CTRL+C` in the command-line session where you ran Liberty in the previous section.

Run the Maven command to package the application. Then, run the Liberty Maven Plugin goals to create the Liberty instance, install the features, and deploy the application to the instance. The `configure-arquillian` goal configures your Arquillian container. You can learn more about this goal in the https://github.com/OpenLiberty/ci.maven/blob/main/docs/configure-arquillian.md[configure-arquillian goal documentation^].

ifndef::cloud-hosted[]
[role="command"]
Expand Down
19 changes: 11 additions & 8 deletions finish/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.6.0.Final</version>
<version>1.7.1.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -64,13 +64,13 @@
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>6.2.3.Final</version>
<version>6.2.5.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-json-binding-provider</artifactId>
<version>6.2.3.Final</version>
<version>6.2.5.Final</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -94,7 +94,7 @@
<dependency>
<groupId>io.openliberty.arquillian</groupId>
<artifactId>arquillian-liberty-managed-jakarta-junit</artifactId>
<version>2.1.2</version>
<version>2.1.3</version>
<type>pom</type>
<scope>test</scope>
</dependency>
Expand All @@ -114,7 +114,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
<version>3.4.0</version>
<configuration>
<packagingExcludes>pom.xml</packagingExcludes>
</configuration>
Expand All @@ -123,7 +123,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0</version>
<version>3.1.2</version>
<configuration>
<systemPropertyVariables>
<arquillian.war.name>${arquillian.war.name}.war</arquillian.war.name>
Expand All @@ -135,14 +135,17 @@
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.8.2</version>
<version>3.9</version>
<configuration>
<!-- tag::arquillianProperties[] -->
<arquillianProperties>
<javaVmArguments>
-Dsystem.context.root=/${arquillian.war.name}
</javaVmArguments>
</arquillianProperties>
<!-- tag::allowConnectingToRunningServer[] -->
<allowConnectingToRunningServer>true</allowConnectingToRunningServer>
<!-- end::allowConnectingToRunningServer[] -->
</arquillianProperties>
<!-- end::arquillianProperties[] -->
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class SystemClient {
private final String PROTOCOL = "http";

@Inject
@ConfigProperty(name = "system.context.root", defaultValue = "")
@ConfigProperty(name = "system.context.root", defaultValue = "/")
String SYSTEM_CONTEXT_ROOT;

@Inject
Expand Down
15 changes: 8 additions & 7 deletions start/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.6.0.Final</version>
<version>1.7.1.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -64,13 +64,13 @@
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>6.2.3.Final</version>
<version>6.2.5.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-json-binding-provider</artifactId>
<version>6.2.3.Final</version>
<version>6.2.5.Final</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -94,7 +94,7 @@
<dependency>
<groupId>io.openliberty.arquillian</groupId>
<artifactId>arquillian-liberty-managed-jakarta-junit</artifactId>
<version>2.1.2</version>
<version>2.1.3</version>
<type>pom</type>
<scope>test</scope>
</dependency>
Expand All @@ -114,7 +114,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
<version>3.4.0</version>
<configuration>
<packagingExcludes>pom.xml</packagingExcludes>
</configuration>
Expand All @@ -123,7 +123,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0</version>
<version>3.1.2</version>
<configuration>
<systemPropertyVariables>
<arquillian.war.name>${arquillian.war.name}.war</arquillian.war.name>
Expand All @@ -135,13 +135,14 @@
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.8.2</version>
<version>3.9</version>
<configuration>
<!-- tag::arquillianProperties[] -->
<arquillianProperties>
<javaVmArguments>
-Dsystem.context.root=/${arquillian.war.name}
</javaVmArguments>
<allowConnectingToRunningServer>true</allowConnectingToRunningServer>
</arquillianProperties>
<!-- end::arquillianProperties[] -->
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class SystemClient {
private final String PROTOCOL = "http";

@Inject
@ConfigProperty(name = "system.context.root", defaultValue = "")
@ConfigProperty(name = "system.context.root", defaultValue = "/")
String SYSTEM_CONTEXT_ROOT;

@Inject
Expand Down

0 comments on commit 914686f

Please sign in to comment.