Search in sources :

Example 1 with SchemaData

use of com.bakdata.quick.common.api.model.gateway.SchemaData in project quick by bakdata.

the class ControllerUpdateSchemaTest method returnsErrorForWrongBody.

@Test
void returnsErrorForWrongBody() {
    final HttpRequest<?> httpRequest = HttpRequest.create(HttpMethod.POST, "/control/schema").body(new SchemaData("test"));
    assertThatExceptionOfType(HttpClientResponseException.class).isThrownBy(() -> this.httpClient.retrieve(httpRequest).blockingFirst()).isInstanceOfSatisfying(HttpClientResponseException.class, ex -> assertThat(extractErrorMessage(ex)).isPresent().get().hasFieldOrPropertyWithValue("type", "errors/clientError").hasFieldOrPropertyWithValue("title", "Bad Request").extracting(ErrorMessage::getDetail, InstanceOfAssertFactories.STRING).startsWith("Could not parse GraphQL schema:"));
}
Also used : SchemaData(com.bakdata.quick.common.api.model.gateway.SchemaData) ErrorMessage(com.bakdata.quick.common.api.model.ErrorMessage) Test(org.junit.jupiter.api.Test) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest)

Example 2 with SchemaData

use of com.bakdata.quick.common.api.model.gateway.SchemaData in project quick by bakdata.

the class GatewayController method getWriteSchema.

/**
 * Returns schema for a type.
 *
 * <p>
 * The schema does not represent the GraphQL view but the write (as in Kafka) view.
 */
@Get("/schema/{type}")
public SchemaData getWriteSchema(final String type) {
    final GraphQLObjectType graphQLType = this.graphQLContext.getGraphQLSchema().getObjectType(StringUtils.capitalize(type));
    if (graphQLType == null) {
        throw new BadArgumentException(String.format("Type %s does not exist", type));
    }
    final String schema = TypePrinter.printTypeSchema(graphQLType);
    return new SchemaData(schema);
}
Also used : BadArgumentException(com.bakdata.quick.common.exception.BadArgumentException) SchemaData(com.bakdata.quick.common.api.model.gateway.SchemaData) GraphQLObjectType(graphql.schema.GraphQLObjectType) Get(io.micronaut.http.annotation.Get)

Example 3 with SchemaData

use of com.bakdata.quick.common.api.model.gateway.SchemaData in project quick by bakdata.

the class KafkaTopicServiceTest method shouldSetRetentionTime.

@Test
void shouldSetRetentionTime() {
    final String topicName = UUID.randomUUID().toString();
    this.successfulMock();
    when(this.gatewayService.getGateway(GATEWAY_SCHEMA.getGateway())).thenReturn(Single.just(new GatewayDescription("test", 1, "latest")));
    when(this.gatewayClient.getWriteSchema(anyString(), anyString())).thenReturn(Single.just(new SchemaData(SCHEMA)));
    final Duration retentionTime = Duration.ofMinutes(30);
    final TopicCreationData requestData = new TopicCreationData(TopicWriteType.MUTABLE, GATEWAY_SCHEMA, null, retentionTime);
    final Completable completable = this.topicService.createTopic(topicName, QuickTopicType.DOUBLE, QuickTopicType.DOUBLE, requestData);
    assertThat(completable.blockingGet()).isNull();
    final MirrorCreationData mirrorCreationData = new MirrorCreationData(topicName, topicName, 1, null, retentionTime);
    verify(this.mirrorService).createMirror(mirrorCreationData);
}
Also used : TopicCreationData(com.bakdata.quick.common.api.model.manager.creation.TopicCreationData) Completable(io.reactivex.Completable) SchemaData(com.bakdata.quick.common.api.model.gateway.SchemaData) GatewayDescription(com.bakdata.quick.common.api.model.manager.GatewayDescription) Duration(java.time.Duration) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MirrorCreationData(com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData) Test(org.junit.jupiter.api.Test)

Example 4 with SchemaData

use of com.bakdata.quick.common.api.model.gateway.SchemaData in project quick by bakdata.

the class KafkaTopicServiceTest method shouldNotCreateTopicIfSubjectExists.

@Test
@Disabled("Compatibility test not supported in SR mock yet")
void shouldNotCreateTopicIfSubjectExists() throws RestClientException, IOException {
    final String topicName = UUID.randomUUID().toString();
    this.successfulMock();
    this.schemaRegistry.registerValueSchema(topicName, this.graphQLToAvroConverter.convertToSchema(SCHEMA));
    when(this.gatewayService.getGateway(GATEWAY_SCHEMA.getGateway())).thenReturn(Single.just(new GatewayDescription("test", 1, "latest")));
    when(this.gatewayClient.getWriteSchema(anyString(), anyString())).thenReturn(Single.just(new SchemaData(SCHEMA)));
    final TopicCreationData requestData = new TopicCreationData(TopicWriteType.MUTABLE, GATEWAY_SCHEMA, null, null);
    final Throwable throwable = this.topicService.createTopic(topicName, QuickTopicType.DOUBLE, QuickTopicType.SCHEMA, requestData).blockingGet();
    assertThat(throwable).isNotNull().isExactlyInstanceOf(BadArgumentException.class).extracting(Throwable::getMessage).asString().endsWith("already exists");
    assertThat(kafkaCluster.exists(topicName)).isFalse();
    assertThat(this.topicRegistryClient.topicDataExists(topicName).blockingGet()).isFalse();
    assertThat(this.schemaRegistry.getSchemaRegistryClient().getAllSubjects()).isEmpty();
}
Also used : BadArgumentException(com.bakdata.quick.common.exception.BadArgumentException) TopicCreationData(com.bakdata.quick.common.api.model.manager.creation.TopicCreationData) SchemaData(com.bakdata.quick.common.api.model.gateway.SchemaData) GatewayDescription(com.bakdata.quick.common.api.model.manager.GatewayDescription) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 5 with SchemaData

use of com.bakdata.quick.common.api.model.gateway.SchemaData in project quick by bakdata.

the class GatewayControllerTest method shouldGetGatewayAvroSchema.

@Test
void shouldGetGatewayAvroSchema() throws IOException {
    final Path workingDirectory = Path.of("src", "test", "resources", "schema", "avro");
    final String avroSchema = new Schema.Parser().parse(Files.readString(workingDirectory.resolve("test.avsc"))).toString();
    final SchemaData schemaData = new SchemaData(avroSchema);
    final GatewayDescription gatewayDescription = new GatewayDescription(GATEWAY_NAME, 1, null);
    when(this.gatewayService.getGateway(GATEWAY_NAME)).thenReturn(Single.just(gatewayDescription));
    when(this.gatewayService.getGatewayWriteSchema(GATEWAY_NAME, "Test", SchemaFormat.AVRO)).thenReturn(Single.just(schemaData));
    final String uri = UriBuilder.of(BASE_PATH + "/schema/{type}/avro").expand(Map.of("name", GATEWAY_NAME, "type", "Test")).toString();
    assertEquals("/gateway/test-gateway/schema/Test/avro", uri);
    final SchemaData retrievedAvroSchema = this.client.toBlocking().retrieve(GET(uri), SchemaData.class);
    assertThat(retrievedAvroSchema).isEqualTo(schemaData);
}
Also used : Path(java.nio.file.Path) SchemaData(com.bakdata.quick.common.api.model.gateway.SchemaData) GatewayDescription(com.bakdata.quick.common.api.model.manager.GatewayDescription) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest) Test(org.junit.jupiter.api.Test)

Aggregations

SchemaData (com.bakdata.quick.common.api.model.gateway.SchemaData)13 Test (org.junit.jupiter.api.Test)10 GatewayDescription (com.bakdata.quick.common.api.model.manager.GatewayDescription)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 Completable (io.reactivex.Completable)6 MicronautTest (io.micronaut.test.extensions.junit5.annotation.MicronautTest)5 TopicCreationData (com.bakdata.quick.common.api.model.manager.creation.TopicCreationData)4 BadArgumentException (com.bakdata.quick.common.exception.BadArgumentException)3 GatewaySchema (com.bakdata.quick.common.api.model.manager.GatewaySchema)2 GatewayClient (com.bakdata.quick.common.api.client.GatewayClient)1 ErrorMessage (com.bakdata.quick.common.api.model.ErrorMessage)1 TopicData (com.bakdata.quick.common.api.model.TopicData)1 GatewayCreationData (com.bakdata.quick.common.api.model.manager.creation.GatewayCreationData)1 MirrorCreationData (com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData)1 GatewayResourceLoader (com.bakdata.quick.manager.gateway.resource.GatewayResourceLoader)1 GraphQLToAvroConverter (com.bakdata.quick.manager.graphql.GraphQLToAvroConverter)1 KubernetesResources (com.bakdata.quick.manager.k8s.KubernetesResources)1 KubernetesTest (com.bakdata.quick.manager.k8s.KubernetesTest)1 MiddlewareList (com.bakdata.quick.manager.k8s.middleware.MiddlewareList)1 Nullable (edu.umd.cs.findbugs.annotations.Nullable)1