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:"));
}
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);
}
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);
}
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();
}
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);
}
Aggregations