Skip to content

Commit

Permalink
Fix apicurio json schema tests structure
Browse files Browse the repository at this point in the history
  • Loading branch information
carlesarnal committed Dec 13, 2023
1 parent a5cb2fb commit ca741ac
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -51,13 +49,13 @@ public KafkaProducer<Integer, Pet> createApicurioProducer(String clientId) {
}

public static KafkaConsumer<Integer, Pet> 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<Integer, Pet> createApicurioProducer(String bootstrap, String apicurio,
String clientId) {
String clientId) {
Properties p = getApicurioProducerProperties(bootstrap, apicurio, clientId);
return createProducer(p);
}
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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;
import io.quarkus.it.kafka.jsonschema.JsonSchemaKafkaCreator;
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
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;
import org.apache.kafka.clients.producer.ProducerRecord;
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();

Expand All @@ -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<Integer, Pet> 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<Integer, Pet> 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<Integer, Pet> consumer, String path) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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."
}
}
}

0 comments on commit ca741ac

Please sign in to comment.