Class SchemaRegistryMockExtension

  • All Implemented Interfaces:
    org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.Extension

    public class SchemaRegistryMockExtension
    extends com.bakdata.schemaregistrymock.SchemaRegistryMock
    implements org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback

    The schema registry mock implements a few basic HTTP endpoints that are used by the Avro serdes.

    In particular,
    • you can register a schema
    • retrieve a schema by id.
    • list and get schema versions of a subject

    If you use the TestTopology of the fluent Kafka Streams test, you don't have to interact with this class at all.

    Without the test framework, you can use the mock as follows:

    
     class SchemaRegistryMockTest {
         @RegisterExtension
         final SchemaRegistryMockExtension schemaRegistry = new SchemaRegistryMockExtension();
    
         @Test
         void shouldRegisterKeySchema() throws IOException, RestClientException {
             final Schema keySchema = this.createSchema("key_schema");
             final int id = this.schemaRegistry.registerKeySchema("test-topic", keySchema);
    
             final Schema retrievedSchema = this.schemaRegistry.getSchemaRegistryClient().getById(id);
             assertThat(retrievedSchema).isEqualTo(keySchema);
         }
     }
    To retrieve the url of the schema registry for a Kafka Streams config, please use SchemaRegistryMock.getUrl()
    • Constructor Summary

      Constructors 
      Constructor Description
      SchemaRegistryMockExtension()
      Create a new SchemaRegistryMockExtension with default SchemaProviders.
      SchemaRegistryMockExtension​(java.util.List<io.confluent.kafka.schemaregistry.SchemaProvider> schemaProviders)
      Create a new SchemaRegistryMockExtension from SchemaProviders.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void afterEach​(org.junit.jupiter.api.extension.ExtensionContext context)  
      void beforeEach​(org.junit.jupiter.api.extension.ExtensionContext context)  
      • Methods inherited from class com.bakdata.schemaregistrymock.SchemaRegistryMock

        deleteKeySchema, deleteValueSchema, getSchemaRegistryClient, getSchemaRegistryClient, getUrl, registerKeySchema, registerKeySchema, registerValueSchema, registerValueSchema, start, stop
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SchemaRegistryMockExtension

        public SchemaRegistryMockExtension()
        Create a new SchemaRegistryMockExtension with default SchemaProviders.
        See Also:
        SchemaRegistryMockExtension(List)
      • SchemaRegistryMockExtension

        public SchemaRegistryMockExtension​(java.util.List<io.confluent.kafka.schemaregistry.SchemaProvider> schemaProviders)
        Create a new SchemaRegistryMockExtension from SchemaProviders.
        Parameters:
        schemaProviders - List of SchemaProvider. If null, AvroSchemaProvider will be used.
    • Method Detail

      • afterEach

        public void afterEach​(org.junit.jupiter.api.extension.ExtensionContext context)
        Specified by:
        afterEach in interface org.junit.jupiter.api.extension.AfterEachCallback
      • beforeEach

        public void beforeEach​(org.junit.jupiter.api.extension.ExtensionContext context)
        Specified by:
        beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback