use of com.redhat.service.smartevents.infra.auth.AbstractOidcClient in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class WebhookActionInvokerTest method testBearerToken.
@Test
void testBearerToken() throws InterruptedException {
wireMockServer.stubFor(post(urlEqualTo(TEST_WEBHOOK_PATH)).willReturn(aResponse().withStatus(200)));
CountDownLatch latch = new CountDownLatch(1);
addUpdateRequestListener(TEST_WEBHOOK_PATH, RequestMethod.POST, latch);
String testSinkEndpoint = webhookSinkUrl + TEST_WEBHOOK_PATH;
AbstractOidcClient abstractOidcClient = mock(AbstractOidcClient.class);
when(abstractOidcClient.getToken()).thenReturn("token");
WebhookActionInvoker invoker = new WebhookActionInvoker(testSinkEndpoint, WebClient.create(vertx), abstractOidcClient);
invoker.onEvent(TEST_EVENT, TEST_HEADERS);
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
RequestPatternBuilder requestPatternBuilder = postRequestedFor(urlEqualTo(TEST_WEBHOOK_PATH)).withRequestBody(equalToJson(TEST_EVENT, true, true)).withHeader("Content-Type", equalTo("application/json")).withHeader("Authorization", equalTo("Bearer token"));
for (Map.Entry<String, String> testHeader : TEST_HEADERS.entrySet()) {
requestPatternBuilder = requestPatternBuilder.withHeader("x-" + testHeader.getKey(), equalTo(testHeader.getValue()));
}
wireMockServer.verify(requestPatternBuilder);
}
Aggregations