Step 3 - Understand the JUnit test implementation
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 theJSON-B
adapter to convertAuthor
objects toJSON
format.KeycloakAuthRequestFilter
implementsClientRequestFilter
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 privategetToken
operation of theTest_GetAuthors
classUse the
KeycloakAuthRequestFilter
interface implementation for aClientRequestFilter
.KeycloakAuthRequestFilter
does help to automatically build the needed parameter frombearer-tokon response
of theKeycloak
server. We need now to invoke theAuthors
Microservice with a REST Client which contains the bearer token we got fromKeycloak
.Invoke the Authors Microservice from the private
getAuthorAuthorized
operation of theTest_GetAuthors
class.Using a
WebTarget
to build a REST client to send the request to the Authors MicroserviceCreate from JSON response of the
Authors Microservice
anAuthor
Java object, using the JSON-B adapter classAuthorJsonbAdapter
.
Verify the
Authors
Microservice response in the JUnit test
Last updated