Skip to content

Commit 4264be7

Browse files
authored
Merge pull request #78 from OpenLiberty/qa
Merge qa to master: Fixing conversion issue (#76)
2 parents e58e9da + 46b040f commit 4264be7

File tree

1 file changed

+56
-11
lines changed

1 file changed

+56
-11
lines changed

README.adoc

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019, 2020 IBM Corporation and others.
1+
// Copyright (c) 2019, 2021 IBM Corporation and others.
22
// Licensed under Creative Commons Attribution-NoDerivatives
33
// 4.0 International (CC BY-ND 4.0)
44
// https://creativecommons.org/licenses/by-nd/4.0/
@@ -17,7 +17,7 @@
1717
:page-seo-title: Testing a MicroProfile or Jakarta EE application using MicroShed Testing with an Open Liberty docker container
1818
:page-seo-description: A tutorial on how to develop tests for a MicroProfile microservice or a Jakarta EE application by using Open Liberty development mode provided by the Liberty Maven plugin.
1919
:guide-author: Open Liberty
20-
:page-tags: ['MicroProfile', 'Java EE', 'Jakarta EE', 'Testing', 'Docker']
20+
:page-tags: ['MicroProfile', 'Jakarta EE', 'Docker']
2121
:page-related-guides: ['rest-intro', 'docker', 'rest-client-java']
2222
:page-permalink: /guides/{projectid}
2323
:repo-description: Visit the https://openliberty.io/guides/{projectid}.html[website] for the rendered version of the guide.
@@ -71,10 +71,23 @@ include::finish/src/test/java/io/openliberty/guides/testing/PersonServiceIT.java
7171

7272
To try out the application, go to the `finish` directory and run the following Maven
7373
goal to build the application and run the integration tests on an Open Liberty server in a container:
74+
75+
// static guide instructions:
76+
ifndef::cloud-hosted[]
7477
[role='command']
7578
```
7679
mvn verify
7780
```
81+
endif::[]
82+
83+
// cloud-hosted guide instructions:
84+
ifdef::cloud-hosted[]
85+
```
86+
cd /home/project/guide-microshed-testing/finish
87+
mvn verify
88+
```
89+
{: codeblock}
90+
endif::[]
7891

7992
This command might take some time to run the first time because the dependencies and the Docker image for Open Liberty must download. If you
8093
run the same command again, it will be faster.
@@ -87,6 +100,14 @@ an already running Open Liberty server. Run the following Maven goal to start Op
87100
mvn liberty:dev
88101
```
89102

103+
After you see the following message, your application server in dev mode is ready:
104+
105+
[role="no_copy"]
106+
----
107+
************************************************************************
108+
* Liberty is running in dev mode.
109+
----
110+
90111
After the Open Liberty server starts and you see the `Press the Enter key to run tests on demand.` message, you can press the
91112
`enter/return` key to run the integration tests. After the tests finish, you can press the `enter/return` key to run the tests again, or you
92113
can make code changes to the application or tests. Development mode automatically
@@ -97,10 +118,22 @@ where you ran the server, or by typing `q` and then pressing the `enter/return`
97118

98119
== Bootstrapping your application for testing
99120

121+
// static guide instructions:
122+
ifndef::cloud-hosted[]
100123
Navigate to the `start` directory to begin.
124+
endif::[]
125+
126+
// cloud-hosted guide instructions:
127+
ifdef::cloud-hosted[]
128+
To begin, run the following command to navigate to the **start** directory:
129+
```
130+
cd /home/project/guide-microprofile-metrics/start
131+
```
132+
{: codeblock}
133+
endif::[]
101134

102135
[role=command]
103-
include::{common-includes}/devmode-start.adoc[]
136+
include::{common-includes}/devmode-lmp33-start.adoc[]
104137

105138
Wait for the `Press the Enter key to run tests on demand.` message, and then press the `enter/return` key to run the tests. You see that one test runs:
106139

@@ -160,35 +193,47 @@ include::hotspots/src/test/java/io/openliberty/guides/testing/PersonServiceIT.2.
160193
161194
The [hotspot=withAppContextRoot file=1]`withAppContextRoot(String)` method indicates the base path of the application. The app context root is the portion of the URL after the hostname and port. In this case, the application is deployed at the `\http://localhost:9080/guide-microshed-testing` URL, so the app context root is [hotspot=withAppContextRoot file=1]`/guide-microshed-testing`.
162195
163-
The [hotspot=withReadinessPath file=1]`withReadinessPath(String)` method indicates what path is polled by HTTP to determine application readiness. MicroShed Testing automatically starts the ApplicationContainer application and waits for it to be ready before the tests start running. In this case, you are using the default application readiness check at the http://localhost:9080/health/ready[http://localhost:9080/health/ready^] URL, which is enabled by the [hotspot=mpHealth file=2]`MicroProfile Health` feature in our server.xml configuration file. When the readiness URL returns `HTTP 200`, the application is considered ready and the tests begin running.
164-
165196
server.xml
166197
[source, xml, linenums, role='code_column']
167198
----
168199
include::finish/src/main/liberty/config/server.xml[]
169200
----
170201
171-
Save your changes to the `PersonServiceIT` class and press the `enter/return` key in your console window to rerun the tests. You still see only one test running, but the output is different. Notice that MicroShed Testing is using a `hollow` configuration mode. This configuration mode means that MicroShed Testing is reusing an existing application runtime for the test, not starting up a new application instance each time you initiate a test run.
202+
The [hotspot=withReadinessPath file=1]`withReadinessPath(String)` method indicates what path is polled by HTTP to determine application readiness.
203+
MicroShed Testing automatically starts the ApplicationContainer application and waits for it to be ready before the tests start running.
204+
In this case, you are using the default application readiness check at the http://localhost:9080/health/ready[http://localhost:9080/health/ready^] URL, which is enabled by the [hotspot=mpHealth file=2]`MicroProfile Health` feature in our server.xml configuration file. When the readiness URL returns `HTTP 200`, the application is considered ready and the tests begin running.
205+
206+
Save your changes to the `PersonServiceIT` class and press the `enter/return` key in your console window to rerun the tests.
207+
You still see only one test running, but the output is different.
208+
Notice that MicroShed Testing is using a `hollow` configuration mode.
209+
This configuration mode means that MicroShed Testing is reusing an existing application runtime for the test,
210+
not starting up a new application instance each time you initiate a test run.
172211
173212
== Talking to your application with a REST client
174213
175-
With MicroShed Testing, applications are exercised in a black box fashion. Black box means the tests cannot access the application internals. Instead, the application is exercised from the outside, usually with HTTP requests. To simplify the HTTP interactions, inject a REST client into the tests.
214+
With MicroShed Testing, applications are exercised in a black box fashion. Black box means the tests cannot access the application internals.
215+
Instead, the application is exercised from the outside, usually with HTTP requests. To simplify the HTTP interactions, inject a REST client into the tests.
176216
177217
[role="code_command hotspot file=0", subs="quotes"]
178218
----
179219
#Update the `PersonServiceIT` class.#
180220
`src/test/java/io/openliberty/guides/testing/PersonServiceIT.java`
181221
----
182222
[role="edit_command_text"]
183-
Import the [hotspot=importInject file=0]`org.microshed.testing.jaxrs.RESTClient` annotation, create a [hotspot=personSvc file=0]`PersonService` REST client, and annotate the REST client with [hotspot=inject file=0]`@RESTClient`.
223+
Import the [hotspot=importInject file=0]`org.microshed.testing.jaxrs.RESTClient` annotation,
224+
create a [hotspot=personSvc file=0]`PersonService` REST client, and annotate the REST client with [hotspot=inject file=0]`@RESTClient`.
184225
185226
PersonServiceIT.java
186227
[source, java, linenums, role='code_column hide_tags=copyright,importAssertNotNull,importSharedContainerConfig,sharedContainerConfig,testCreatePerson']
187228
----
188229
include::hotspots/src/test/java/io/openliberty/guides/testing/PersonServiceIT.2.java[]
189230
----
190231
191-
In this example, the [hotspot=personSvc file=0]`PersonService` injected type is the same [hotspot file=1]`io.openliberty.guides.testing.PersonService` class that is used in your application. However, the _instance_ that gets injected is a REST client proxy. So, if you call `personSvc.createPerson("Bob", 42)`, the REST client makes an HTTP POST request to the application that is running at http://localhost:9080/guide-microshed-testing/people[http://localhost:9080/guide-microshed-testing/people^], which triggers the corresponding Java method in the application.
232+
In this example, the [hotspot=personSvc file=0]`PersonService` injected type is the same
233+
[hotspot file=1]`io.openliberty.guides.testing.PersonService` class that is used in your application.
234+
However, the _instance_ that gets injected is a REST client proxy.
235+
So, if you call `personSvc.createPerson("Bob", 42)`, the REST client makes an HTTP POST request to the application
236+
that is running at `\http://localhost:9080/guide-microshed-testing/people`, which triggers the corresponding Java method in the application.
192237
193238
PersonService.java
194239
[source, java, linenums, role='code_column hide_tags=copyright']
@@ -219,8 +264,8 @@ Save the changes. Then, press the `enter/return` key in your console window to r
219264
220265
[role="no_copy"]
221266
----
222-
INFO org.microshed.testing.jaxrs.RestClientBuilder - Building rest client for class io.openliberty.guides.testing.PersonService with base path: http://localhost:9080/guide-microshed-testing/ and providers: [class org.microshed.testing.jaxrs.JsonBProvider]
223-
INFO org.microshed.testing.jaxrs.JsonBProvider - Response from server: 1809686877352335426
267+
[INFO] Building rest client for class io.openliberty.guides.testing.PersonService with base path: http://localhost:9080/guide-microshed-testing/ and providers: [class org.microshed.testing.jaxrs.JsonBProvider]
268+
[INFO] Response from server: 1809686877352335426
224269
----
225270
226271
Next, add more tests.

0 commit comments

Comments
 (0)