diff --git a/integration-tests/kafka-json-schema-apicurio2/src/main/java/io/quarkus/it/kafka/jsonschema/JsonSchemaKafkaCreator.java b/integration-tests/kafka-json-schema-apicurio2/src/main/java/io/quarkus/it/kafka/jsonschema/JsonSchemaKafkaCreator.java index 9d6842b765f77..20b3933c8a3ef 100644 --- a/integration-tests/kafka-json-schema-apicurio2/src/main/java/io/quarkus/it/kafka/jsonschema/JsonSchemaKafkaCreator.java +++ b/integration-tests/kafka-json-schema-apicurio2/src/main/java/io/quarkus/it/kafka/jsonschema/JsonSchemaKafkaCreator.java @@ -1,13 +1,9 @@ package io.quarkus.it.kafka.jsonschema; -import java.util.Collections; -import java.util.Properties; -import java.util.UUID; - +import io.apicurio.registry.serde.SerdeConfig; import io.apicurio.registry.serde.jsonschema.JsonSchemaKafkaDeserializer; import io.apicurio.registry.serde.jsonschema.JsonSchemaKafkaSerializer; import jakarta.enterprise.context.ApplicationScoped; - import org.apache.kafka.clients.consumer.ConsumerConfig; import org.apache.kafka.clients.consumer.KafkaConsumer; import org.apache.kafka.clients.producer.KafkaProducer; @@ -16,7 +12,9 @@ import org.apache.kafka.common.serialization.IntegerSerializer; import org.eclipse.microprofile.config.inject.ConfigProperty; -import io.apicurio.registry.serde.SerdeConfig; +import java.util.Collections; +import java.util.Properties; +import java.util.UUID; /** * Create Json Schema Kafka Consumers and Producers @@ -51,13 +49,13 @@ public KafkaProducer createApicurioProducer(String clientId) { } public static KafkaConsumer createApicurioConsumer(String bootstrap, String apicurio, - String groupdIdConfig, String subscribtionName) { + String groupdIdConfig, String subscribtionName) { Properties p = getApicurioConsumerProperties(bootstrap, apicurio, groupdIdConfig); return createConsumer(p, subscribtionName); } public static KafkaProducer createApicurioProducer(String bootstrap, String apicurio, - String clientId) { + String clientId) { Properties p = getApicurioProducerProperties(bootstrap, apicurio, clientId); return createProducer(p); } @@ -101,7 +99,6 @@ private static Properties getApicurioProducerProperties(String bootstrap, String props.put(ProducerConfig.ACKS_CONFIG, "all"); props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSchemaKafkaSerializer.class.getName()); props.put(SerdeConfig.REGISTRY_URL, apicurio); - props.put(SerdeConfig.AUTO_REGISTER_ARTIFACT, true); return props; } diff --git a/integration-tests/kafka-json-schema-apicurio2/src/test/java/kafka/KafkaJsonSchemaIT.java b/integration-tests/kafka-json-schema-apicurio2/src/test/java/io/quarkus/it/kafka/KafkaJsonSchemaIT.java similarity index 96% rename from integration-tests/kafka-json-schema-apicurio2/src/test/java/kafka/KafkaJsonSchemaIT.java rename to integration-tests/kafka-json-schema-apicurio2/src/test/java/io/quarkus/it/kafka/KafkaJsonSchemaIT.java index f9817025a81a2..3e51516254338 100644 --- a/integration-tests/kafka-json-schema-apicurio2/src/test/java/kafka/KafkaJsonSchemaIT.java +++ b/integration-tests/kafka-json-schema-apicurio2/src/test/java/io/quarkus/it/kafka/KafkaJsonSchemaIT.java @@ -1,6 +1,4 @@ -package kafka; - -import org.junit.jupiter.api.BeforeAll; +package io.quarkus.it.kafka; import io.apicurio.registry.rest.client.RegistryClientFactory; import io.apicurio.rest.client.VertxHttpClientProvider; @@ -8,6 +6,7 @@ import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusIntegrationTest; import io.vertx.core.Vertx; +import org.junit.jupiter.api.BeforeAll; @QuarkusIntegrationTest @QuarkusTestResource(value = KafkaResource.class, restrictToAnnotatedClass = true) diff --git a/integration-tests/kafka-json-schema-apicurio2/src/test/java/kafka/KafkaJsonSchemaTest.java b/integration-tests/kafka-json-schema-apicurio2/src/test/java/io/quarkus/it/kafka/KafkaJsonSchemaTest.java similarity index 92% rename from integration-tests/kafka-json-schema-apicurio2/src/test/java/kafka/KafkaJsonSchemaTest.java rename to integration-tests/kafka-json-schema-apicurio2/src/test/java/io/quarkus/it/kafka/KafkaJsonSchemaTest.java index 5820527d07e28..4bcfe8c6982b2 100644 --- a/integration-tests/kafka-json-schema-apicurio2/src/test/java/kafka/KafkaJsonSchemaTest.java +++ b/integration-tests/kafka-json-schema-apicurio2/src/test/java/io/quarkus/it/kafka/KafkaJsonSchemaTest.java @@ -1,9 +1,8 @@ -package kafka; - -import jakarta.inject.Inject; +package io.quarkus.it.kafka; import io.quarkus.it.kafka.jsonschema.JsonSchemaKafkaCreator; import io.quarkus.test.junit.QuarkusTest; +import jakarta.inject.Inject; @QuarkusTest public class KafkaJsonSchemaTest extends KafkaJsonSchemaTestBase { diff --git a/integration-tests/kafka-json-schema-apicurio2/src/test/java/kafka/KafkaJsonSchemaTestBase.java b/integration-tests/kafka-json-schema-apicurio2/src/test/java/io/quarkus/it/kafka/KafkaJsonSchemaTestBase.java similarity index 66% rename from integration-tests/kafka-json-schema-apicurio2/src/test/java/kafka/KafkaJsonSchemaTestBase.java rename to integration-tests/kafka-json-schema-apicurio2/src/test/java/io/quarkus/it/kafka/KafkaJsonSchemaTestBase.java index 54df35eed83b0..71444631ba03e 100644 --- a/integration-tests/kafka-json-schema-apicurio2/src/test/java/kafka/KafkaJsonSchemaTestBase.java +++ b/integration-tests/kafka-json-schema-apicurio2/src/test/java/io/quarkus/it/kafka/KafkaJsonSchemaTestBase.java @@ -1,7 +1,10 @@ -package kafka; - -import java.time.Duration; +package io.quarkus.it.kafka; +import io.apicurio.registry.rest.client.RegistryClientFactory; +import io.apicurio.registry.types.ArtifactType; +import io.quarkus.it.kafka.jsonschema.JsonSchemaKafkaCreator; +import io.quarkus.it.kafka.jsonschema.Pet; +import io.restassured.RestAssured; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.clients.consumer.KafkaConsumer; import org.apache.kafka.clients.producer.KafkaProducer; @@ -9,13 +12,12 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import io.quarkus.it.kafka.jsonschema.JsonSchemaKafkaCreator; -import io.quarkus.it.kafka.jsonschema.Pet; -import io.restassured.RestAssured; +import java.io.InputStream; +import java.time.Duration; public abstract class KafkaJsonSchemaTestBase { - static final String APICURIO_PATH = "/jsonschema/apicurio"; + static final String APICURIO_PATH = "/json-schema/apicurio"; abstract JsonSchemaKafkaCreator creator(); @@ -26,16 +28,28 @@ public void testUrls() { @Test public void testApicurioJsonSchemaProducer() { + String subscriptionName = "test-json-schema-apicurio-producer"; + + //Since autoregister is not supported for json schema, we must register the schema beforehand. + InputStream jsonSchema = getClass().getResourceAsStream("/io/quarkus/it/kafka/json-schema.json"); + RegistryClientFactory.create(creator().getApicurioRegistryUrl()).createArtifact(null, subscriptionName + "-value", ArtifactType.JSON, jsonSchema); + KafkaConsumer consumer = creator().createApicurioConsumer( "test-json-schema-apicurio", - "test-json-schema-apicurio-producer"); + subscriptionName); testJsonSchemaProducer(consumer, APICURIO_PATH); } @Test public void testApicurioJsonSchemaConsumer() { + String topic = "test-json-schema-apicurio-consumer"; + + //Since autoregister is not supported for json schema, we must register the schema beforehand. + InputStream jsonSchema = getClass().getResourceAsStream("/io/quarkus/it/kafka/json-schema.json"); + RegistryClientFactory.create(creator().getApicurioRegistryUrl()).createArtifact(null, topic + "-value", ArtifactType.JSON, jsonSchema); + KafkaProducer producer = creator().createApicurioProducer("test-json-schema-apicurio-test"); - testJsonSchemaConsumer(producer, APICURIO_PATH, "test-json-schema-apicurio-consumer"); + testJsonSchemaConsumer(producer, APICURIO_PATH, topic); } protected void testJsonSchemaProducer(KafkaConsumer consumer, String path) { diff --git a/integration-tests/kafka-json-schema-apicurio2/src/test/java/kafka/KafkaResource.java b/integration-tests/kafka-json-schema-apicurio2/src/test/java/io/quarkus/it/kafka/KafkaResource.java similarity index 97% rename from integration-tests/kafka-json-schema-apicurio2/src/test/java/kafka/KafkaResource.java rename to integration-tests/kafka-json-schema-apicurio2/src/test/java/io/quarkus/it/kafka/KafkaResource.java index eb5186c92c5cb..3ea4a51d86b6b 100644 --- a/integration-tests/kafka-json-schema-apicurio2/src/test/java/kafka/KafkaResource.java +++ b/integration-tests/kafka-json-schema-apicurio2/src/test/java/io/quarkus/it/kafka/KafkaResource.java @@ -1,12 +1,12 @@ -package kafka; - -import java.util.Collections; -import java.util.Map; +package io.quarkus.it.kafka; import io.quarkus.it.kafka.jsonschema.JsonSchemaKafkaCreator; import io.quarkus.test.common.DevServicesContext; import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; +import java.util.Collections; +import java.util.Map; + public class KafkaResource implements QuarkusTestResourceLifecycleManager, DevServicesContext.ContextAware { JsonSchemaKafkaCreator creator; diff --git a/integration-tests/kafka-json-schema-apicurio2/src/test/resources/io/quarkus/it/kafka/json-schema.json b/integration-tests/kafka-json-schema-apicurio2/src/test/resources/io/quarkus/it/kafka/json-schema.json new file mode 100644 index 0000000000000..18a1c5f482bd6 --- /dev/null +++ b/integration-tests/kafka-json-schema-apicurio2/src/test/resources/io/quarkus/it/kafka/json-schema.json @@ -0,0 +1,16 @@ +{ + "$id": "https://example.com/person.schema.json", + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Pet", + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The pet's name." + }, + "color": { + "type": "string", + "description": "The pet's color." + } + } +} \ No newline at end of file