use of io.confluent.ksql.serde.connect.ConnectKsqlSchemaTranslator in project ksql by confluentinc.
the class DefaultSchemaInjectorFunctionalTest method shouldInferSchema.
private void shouldInferSchema(final org.apache.avro.Schema avroSchema, final Schema expectedKqlSchema) {
// Given:
final Schema expectedSchema = new ConnectKsqlSchemaTranslator(SchemaTranslationPolicies.of(this.translationPolicy)).toKsqlSchema(expectedKqlSchema);
try {
if (testType == TestType.WITHOUT_SCHEMA_ID) {
when(srClient.getLatestSchemaMetadata(any())).thenReturn(new SchemaMetadata(1, 1, avroSchema.toString()));
}
when(srClient.getSchemaBySubjectAndId(any(), anyInt())).thenReturn(this.avroSchema);
when(this.avroSchema.schemaType()).thenReturn("AVRO");
when(this.avroSchema.rawSchema()).thenReturn(avroSchema);
constructCSASSource(expectedSchema);
} catch (final Exception e) {
throw new AssertionError(e);
}
final PreparedStatement<Statement> prepared = KsqlParserTestUtil.buildSingleAst(this.statement, metaStore, true);
// When:
final KsqlConfig ksqlConfig = new KsqlConfig(ImmutableMap.of());
final ConfiguredStatement<?> inferred = schemaInjector.inject(ConfiguredStatement.of(prepared, SessionConfig.of(ksqlConfig, ImmutableMap.of())));
// Then:
if (testType == TestType.CSAS_WITH_SCHEMA_ID) {
validateCsasInference((ConfiguredStatement<CreateStreamAsSelect>) inferred, this.avroSchema);
} else {
final Statement withSchema = KsqlParserTestUtil.buildSingleAst(inferred.getStatementText(), metaStore, true).getStatement();
final Schema actual = getSchemaForDdlStatement((CreateSource) withSchema);
assertThat(FORMATTER.format(actual), equalTo(FORMATTER.format(expectedSchema)));
assertThat(actual, equalTo(expectedSchema));
}
}
Aggregations