Search in sources :

Example 6 with SubjectNameStrategy

use of io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy in project kafka-rest by confluentinc.

the class SchemaManagerImplTest method getSchema_avro_schemaVersion_subjectNameStrategy.

@Test
public void getSchema_avro_schemaVersion_subjectNameStrategy() throws Exception {
    ParsedSchema schema = new AvroSchema("{\"type\": \"int\"}");
    SubjectNameStrategy strategy = new MySubjectNameStrategy();
    String subject = strategy.subjectName(TOPIC_NAME, /* isKey= */
    true, /* schema= */
    null);
    int schemaId = schemaRegistryClient.register(subject, schema);
    int schemaVersion = schemaRegistryClient.getVersion(subject, schema);
    RegisteredSchema actual = schemaManager.getSchema(TOPIC_NAME, /* format= */
    Optional.empty(), /* subject= */
    Optional.empty(), /* subjectNameStrategy= */
    Optional.of(strategy), /* schemaId= */
    Optional.empty(), /* schemaVersion= */
    Optional.of(schemaVersion), /* rawSchema= */
    Optional.empty(), /* isKey= */
    true);
    assertEquals(RegisteredSchema.create(subject, schemaId, schemaVersion, schema), actual);
}
Also used : RegisteredSchema(io.confluent.kafkarest.entities.RegisteredSchema) AvroSchema(io.confluent.kafka.schemaregistry.avro.AvroSchema) SubjectNameStrategy(io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) Test(org.junit.jupiter.api.Test)

Example 7 with SubjectNameStrategy

use of io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy in project kafka-rest by confluentinc.

the class SchemaManagerImplTest method getSchema_avro_rawSchema_subjectNameStrategy.

@Test
public void getSchema_avro_rawSchema_subjectNameStrategy() throws Exception {
    SubjectNameStrategy strategy = new MySubjectNameStrategy();
    String subject = strategy.subjectName(TOPIC_NAME, /* isKey= */
    true, /* schema= */
    null);
    RegisteredSchema actual = schemaManager.getSchema(TOPIC_NAME, /* format= */
    Optional.of(EmbeddedFormat.AVRO), /* subject= */
    Optional.empty(), /* subjectNameStrategy= */
    Optional.of(strategy), /* schemaId= */
    Optional.empty(), /* schemaVersion= */
    Optional.empty(), /* rawSchema= */
    Optional.of("{\"type\": \"int\"}"), /* isKey= */
    true);
    ParsedSchema schema = schemaRegistryClient.getSchemaById(actual.getSchemaId());
    int schemaId = schemaRegistryClient.getId(subject, schema);
    int schemaVersion = schemaRegistryClient.getVersion(subject, schema);
    assertEquals(RegisteredSchema.create(subject, schemaId, schemaVersion, schema), actual);
}
Also used : RegisteredSchema(io.confluent.kafkarest.entities.RegisteredSchema) SubjectNameStrategy(io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) Test(org.junit.jupiter.api.Test)

Aggregations

SubjectNameStrategy (io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy)7 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)6 Test (org.junit.jupiter.api.Test)6 RegisteredSchema (io.confluent.kafkarest.entities.RegisteredSchema)5 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)4 BadRequestException (io.confluent.kafkarest.exceptions.BadRequestException)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 SchemaProvider (io.confluent.kafka.schemaregistry.SchemaProvider)1 SchemaMetadata (io.confluent.kafka.schemaregistry.client.SchemaMetadata)1 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)1 Schema (io.confluent.kafka.schemaregistry.client.rest.entities.Schema)1 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)1 Errors (io.confluent.kafkarest.Errors)1 EmbeddedFormat (io.confluent.kafkarest.entities.EmbeddedFormat)1 IOException (java.io.IOException)1 Collections.emptyList (java.util.Collections.emptyList)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1 SchemaParseException (org.apache.avro.SchemaParseException)1