Step 3 - Understand the JUnit test implementation
Last updated
Was this helpful?
Last updated
Was this helpful?
We need to ...
... use the two-factor authentication to access the Authors
Microservice
... use a REST a client to send the requests to the Authors
Microservice and Keycloak
... 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 to simplify the creation of the REST client to access the Authors Microservice.
The JUnit test is implemented to do following tasks:
Use the two-factor authentication to access the Authors Microservice
Request the bearer token
from the Keycloak server. The request is implemented in the private getToken
operation of the Test_GetAuthors
class
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
.
Invoke the Authors Microservice from the private getAuthorAuthorized
operation of the Test_GetAuthors
class.
Using a WebTarget
to build a REST client to send the request to the Authors Microservice
Create from JSON response of the Authors Microservice
an Author
Java object, using the JSON-B adapter class AuthorJsonbAdapter
.
Verify the Authors
Microservice response in the JUnit test