Search in sources :

Example 11 with RegisteredSchema

use of io.confluent.kafkarest.entities.RegisteredSchema in project kafka-rest by confluentinc.

the class SchemaManagerImplTest method getSchema_avro_latestSchema.

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

Example 12 with RegisteredSchema

use of io.confluent.kafkarest.entities.RegisteredSchema 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 13 with RegisteredSchema

use of io.confluent.kafkarest.entities.RegisteredSchema in project kafka-rest by confluentinc.

the class SchemaManagerImplTest method getSchema_avro_schemaVersion.

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

Example 14 with RegisteredSchema

use of io.confluent.kafkarest.entities.RegisteredSchema 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)

Example 15 with RegisteredSchema

use of io.confluent.kafkarest.entities.RegisteredSchema in project kafka-rest by confluentinc.

the class SchemaManagerImplTest method getSchema_avro_schemaVersion_subject.

@Test
public void getSchema_avro_schemaVersion_subject() throws Exception {
    String subject = "my-subject";
    ParsedSchema schema = new AvroSchema("{\"type\": \"int\"}");
    int schemaId = schemaRegistryClient.register(subject, schema);
    int schemaVersion = schemaRegistryClient.getVersion(subject, schema);
    RegisteredSchema actual = schemaManager.getSchema(TOPIC_NAME, /* format= */
    Optional.empty(), /* subject= */
    Optional.of(subject), /* subjectNameStrategy= */
    Optional.empty(), /* 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) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) Test(org.junit.jupiter.api.Test)

Aggregations

RegisteredSchema (io.confluent.kafkarest.entities.RegisteredSchema)18 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)16 Test (org.junit.jupiter.api.Test)15 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)10 SubjectNameStrategy (io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy)4 ByteString (com.google.protobuf.ByteString)2 BadRequestException (io.confluent.kafkarest.exceptions.BadRequestException)2 Instant (java.time.Instant)2 MappingIterator (com.fasterxml.jackson.databind.MappingIterator)1 NullNode (com.fasterxml.jackson.databind.node.NullNode)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 SchemaProvider (io.confluent.kafka.schemaregistry.SchemaProvider)1 Schema (io.confluent.kafka.schemaregistry.client.rest.entities.Schema)1 Errors (io.confluent.kafkarest.Errors)1 ProducerMetrics (io.confluent.kafkarest.ProducerMetrics)1 ProducerMetricsRegistry (io.confluent.kafkarest.ProducerMetricsRegistry)1 TestUtils.assertOKResponse (io.confluent.kafkarest.TestUtils.assertOKResponse)1 ProduceController (io.confluent.kafkarest.controllers.ProduceController)1 RecordSerializer (io.confluent.kafkarest.controllers.RecordSerializer)1 SchemaManager (io.confluent.kafkarest.controllers.SchemaManager)1