Search in sources :

Example 1 with HttpException

use of io.micronaut.http.exceptions.HttpException in project quick by bakdata.

the class KafkaTopicServiceTest method shouldThrowExceptionForNonExistingGateway.

@Test
void shouldThrowExceptionForNonExistingGateway() {
    final String topicName = UUID.randomUUID().toString();
    this.successfulMock();
    // error thrown when checking if gateway exists
    final Throwable error = new NotFoundException(String.format("Could not find resource %s", GATEWAY_SCHEMA.getGateway()));
    when(this.gatewayService.getGateway(GATEWAY_SCHEMA.getGateway())).thenReturn(Single.error(error));
    // resource doesn't exist, traefik cannot route it; This should not be called since we check existence before
    final HttpException clientException = new HttpClientResponseException("Not found", HttpResponse.notFound());
    when(this.gatewayClient.getWriteSchema(anyString(), anyString())).thenReturn(Single.error(clientException));
    final TopicCreationData requestData = new TopicCreationData(TopicWriteType.MUTABLE, GATEWAY_SCHEMA, null, null);
    final Completable completable = this.topicService.createTopic(topicName, QuickTopicType.DOUBLE, QuickTopicType.SCHEMA, requestData);
    final Throwable actual = completable.blockingGet();
    assertThat(actual).isNotNull().isInstanceOf(QuickException.class).hasMessageStartingWith("Could not find resource test");
    verify(this.gatewayClient, never()).getWriteSchema(anyString(), anyString());
}
Also used : TopicCreationData(com.bakdata.quick.common.api.model.manager.creation.TopicCreationData) Completable(io.reactivex.Completable) QuickException(com.bakdata.quick.common.exception.QuickException) HttpClientResponseException(io.micronaut.http.client.exceptions.HttpClientResponseException) NotFoundException(com.bakdata.quick.common.exception.NotFoundException) HttpException(io.micronaut.http.exceptions.HttpException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

TopicCreationData (com.bakdata.quick.common.api.model.manager.creation.TopicCreationData)1 NotFoundException (com.bakdata.quick.common.exception.NotFoundException)1 QuickException (com.bakdata.quick.common.exception.QuickException)1 HttpClientResponseException (io.micronaut.http.client.exceptions.HttpClientResponseException)1 HttpException (io.micronaut.http.exceptions.HttpException)1 Completable (io.reactivex.Completable)1 Test (org.junit.jupiter.api.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1