# Step 3 - Understand the JUnit test implementation

We need to ...

1. ... use the two-factor authentication to access the `Authors` Microservice
2. ... use a REST a client to send the requests to the `Authors` Microservice and Keycloak
3. ... verify `Authors` Microservice response in the JUnit test

The simplified classdiagram shows an overview of classes of our project for the `Authors` Microservice and the `JUnit` test.

* `Test_GetAuthors` class implemments the test.
* `AuthorJsonbAdapter` class implemets the `JSON-B` adapter to convert `Author` objects to `JSON` format.
* `KeycloakAuthRequestFilter` implements [`ClientRequestFilter`](https://docs.oracle.com/javaee/7/api/javax/ws/rs/client/ClientRequestFilter.html) to simplify the creation of the REST client to access the Authors Microservice.

![](https://2281508817-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-MBeCtL-jysFPva8K%2Fsync%2Fccb9ab579d7a722d90436b939cb4de963cffb92b.png?generation=1593439006117309\&alt=media)

The JUnit test is implemented to do following tasks:

1. Use the two-factor authentication to access the `Authors Microservice`
   1. Request the `bearer token` from the Keycloak server. The request is implemented in the private `getToken` operation of the `Test_GetAuthors` class
   2. Use the `KeycloakAuthRequestFilter` interface implementation for a  `ClientRequestFilter`. `KeycloakAuthRequestFilter` does help to automatically build the needed parameter from `bearer-tokon response` of the `Keycloak` server. We need now to invoke the `Authors`Microservice with a *REST Client* which contains the *bearer token* we got from `Keycloak`.&#x20;
   3. Invoke the Authors Microservice from the private `getAuthorAuthorized` operation of the `Test_GetAuthors` class.
      1. Using a `WebTarget` to build a REST client to send the request to the Authors Microservice
      2. Create from JSON response of the `Authors Microservice` an `Author` Java object, using the JSON-B adapter class `AuthorJsonbAdapter`.
2. Verify the `Authors` Microservice response in the JUnit test
