Search in sources :

Example 1 with SchemaResult

use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult in project ksql by confluentinc.

the class SchemaRegistryTopicSchemaSupplierTest method shouldReturnSchemaFromGetKeySchemaIfFound.

@Test
public void shouldReturnSchemaFromGetKeySchemaIfFound() {
    // When:
    final SchemaResult result = supplier.getKeySchema(Optional.of(TOPIC_NAME), Optional.empty(), expectedFormat, SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES));
    // Then:
    assertThat(result.schemaAndId, is(not(Optional.empty())));
    assertThat(result.schemaAndId.get().id, is(SCHEMA_ID));
    assertThat(result.schemaAndId.get().columns, is(ImmutableList.of(column1)));
}
Also used : SchemaResult(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult) Test(org.junit.Test)

Example 2 with SchemaResult

use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult in project ksql by confluentinc.

the class SchemaRegistryTopicSchemaSupplierTest method shouldReturnErrorFromGetValueSchemaIfSchemaIsNotInExpectedFormat.

@Test
public void shouldReturnErrorFromGetValueSchemaIfSchemaIsNotInExpectedFormat() {
    // Given:
    when(parsedSchema.schemaType()).thenReturn(ProtobufSchema.TYPE);
    // When:
    final SchemaResult result = supplier.getValueSchema(Optional.of(TOPIC_NAME), Optional.empty(), expectedFormat, SerdeFeatures.of());
    // Then:
    assertThat(result.schemaAndId, is(Optional.empty()));
    assertThat(result.failureReason, is(not(Optional.empty())));
    assertThat(result.failureReason.get().getMessage(), is("Value schema is not in the expected format. " + "You may want to set VALUE_FORMAT to 'PROTOBUF'." + System.lineSeparator() + "topic: " + TOPIC_NAME + System.lineSeparator() + "expected format: AVRO" + System.lineSeparator() + "actual format from Schema Registry: PROTOBUF"));
}
Also used : SchemaResult(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult) Test(org.junit.Test)

Example 3 with SchemaResult

use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult in project ksql by confluentinc.

the class SchemaRegistryTopicSchemaSupplierTest method shouldReturnErrorFromGetKeySchemaIfNotFound.

@Test
public void shouldReturnErrorFromGetKeySchemaIfNotFound() throws Exception {
    // Given:
    when(srClient.getLatestSchemaMetadata(any())).thenThrow(notFoundException());
    // When:
    final SchemaResult result = supplier.getKeySchema(Optional.of(TOPIC_NAME), Optional.empty(), expectedFormat, SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES));
    // Then:
    assertThat(result.schemaAndId, is(Optional.empty()));
    assertThat(result.failureReason, is(not(Optional.empty())));
    verifyFailureMessageForKey(result, Optional.empty());
}
Also used : SchemaResult(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult) Test(org.junit.Test)

Example 4 with SchemaResult

use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult in project ksql by confluentinc.

the class SchemaRegistryTopicSchemaSupplierTest method shouldReturnErrorFromGetKeySchemaIfSchemaIsNotInExpectedFormat.

@Test
public void shouldReturnErrorFromGetKeySchemaIfSchemaIsNotInExpectedFormat() {
    // Given:
    when(parsedSchema.schemaType()).thenReturn(ProtobufSchema.TYPE);
    // When:
    final SchemaResult result = supplier.getKeySchema(Optional.of(TOPIC_NAME), Optional.empty(), expectedFormat, SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES));
    // Then:
    assertThat(result.schemaAndId, is(Optional.empty()));
    assertThat(result.failureReason, is(not(Optional.empty())));
    assertThat(result.failureReason.get().getMessage(), is("Key schema is not in the expected format. " + "You may want to set KEY_FORMAT to 'PROTOBUF'." + System.lineSeparator() + "topic: " + TOPIC_NAME + System.lineSeparator() + "expected format: AVRO" + System.lineSeparator() + "actual format from Schema Registry: PROTOBUF"));
}
Also used : SchemaResult(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult) Test(org.junit.Test)

Example 5 with SchemaResult

use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult in project ksql by confluentinc.

the class SchemaRegistryTopicSchemaSupplierTest method shouldReturnErrorFromGetKeyIfForbidden.

@Test
public void shouldReturnErrorFromGetKeyIfForbidden() throws Exception {
    // Given:
    when(srClient.getSchemaBySubjectAndId(any(), anyInt())).thenThrow(forbiddenException());
    // When:
    final SchemaResult result = supplier.getKeySchema(Optional.of(TOPIC_NAME), Optional.of(42), expectedFormat, SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES));
    // Then:
    assertThat(result.schemaAndId, is(Optional.empty()));
    assertThat(result.failureReason, is(not(Optional.empty())));
    verifyFailureMessageForKey(result, Optional.of(42));
}
Also used : SchemaResult(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult) Test(org.junit.Test)

Aggregations

SchemaResult (io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult)16 Test (org.junit.Test)16 ImmutableList (com.google.common.collect.ImmutableList)1 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)1 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)1 SchemaMetadata (io.confluent.kafka.schemaregistry.client.SchemaMetadata)1 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)1 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)1 ProtobufSchema (io.confluent.kafka.schemaregistry.protobuf.ProtobufSchema)1 SimpleColumn (io.confluent.ksql.schema.ksql.SimpleColumn)1 Format (io.confluent.ksql.serde.Format)1 FormatInfo (io.confluent.ksql.serde.FormatInfo)1 SchemaTranslator (io.confluent.ksql.serde.SchemaTranslator)1 SerdeFeature (io.confluent.ksql.serde.SerdeFeature)1 SerdeFeatures (io.confluent.ksql.serde.SerdeFeatures)1 KsqlException (io.confluent.ksql.util.KsqlException)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Optional (java.util.Optional)1 HttpStatus (org.apache.http.HttpStatus)1