Step 3 - Understand the JUnit test implementation
We need to ...
... use the two-factor authentication to access the
AuthorsMicroservice... use a REST a client to send the requests to the
AuthorsMicroservice and Keycloak... verify
AuthorsMicroservice 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_GetAuthorsclass implemments the test.AuthorJsonbAdapterclass implemets theJSON-Badapter to convertAuthorobjects toJSONformat.KeycloakAuthRequestFilterimplementsClientRequestFilterto 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 MicroserviceRequest the
bearer tokenfrom the Keycloak server. The request is implemented in the privategetTokenoperation of theTest_GetAuthorsclassUse the
KeycloakAuthRequestFilterinterface implementation for aClientRequestFilter.KeycloakAuthRequestFilterdoes help to automatically build the needed parameter frombearer-tokon responseof theKeycloakserver. We need now to invoke theAuthorsMicroservice with a REST Client which contains the bearer token we got fromKeycloak.Invoke the Authors Microservice from the private
getAuthorAuthorizedoperation of theTest_GetAuthorsclass.Using a
WebTargetto build a REST client to send the request to the Authors MicroserviceCreate from JSON response of the
Authors MicroserviceanAuthorJava object, using the JSON-B adapter classAuthorJsonbAdapter.
Verify the
AuthorsMicroservice response in the JUnit test
Last updated
Was this helpful?