You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
:page-seo-title: Testing a MicroProfile or Jakarta EE application using MicroShed Testing with an Open Liberty docker container
18
18
: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.
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:
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`.
162
195
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.
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.
172
211
173
212
== Talking to your application with a REST client
174
213
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.
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`.
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.
@@ -219,8 +264,8 @@ Save the changes. Then, press the `enter/return` key in your console window to r
219
264
220
265
[role="no_copy"]
221
266
----
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]
0 commit comments