From 607c270a174bc6a7f81984e488b32f3243df1f52 Mon Sep 17 00:00:00 2001 From: thcai Date: Tue, 27 Aug 2024 17:34:55 +0200 Subject: [PATCH] test6 --- .../integration/SchemaIntegrationTest.java | 83 ++++++++++++++----- 1 file changed, 64 insertions(+), 19 deletions(-) diff --git a/src/test/java/com/michelin/ns4kafka/integration/SchemaIntegrationTest.java b/src/test/java/com/michelin/ns4kafka/integration/SchemaIntegrationTest.java index 8cec829d..4ff005f0 100644 --- a/src/test/java/com/michelin/ns4kafka/integration/SchemaIntegrationTest.java +++ b/src/test/java/com/michelin/ns4kafka/integration/SchemaIntegrationTest.java @@ -768,6 +768,47 @@ void shouldRegisterSameSchemaTwice() { assertEquals("ns1-subject3-value", schemaAfterPostOnRegistry.subject()); } + @Test + void shouldRegisterSameSchemaTwice2() { + Schema schema = Schema.builder() + .metadata(Metadata.builder() + .name("ns1-subject3-value") + .build()) + .spec(Schema.SchemaSpec.builder() + .schema( + "{\"namespace\":\"com.michelin.kafka.producer.showcase.avro\",\"type\":\"record\"," + + "\"name\":\"PersonAvro\",\"fields\":[{\"name\":\"firstName\",\"type\":[\"null\",\"string\"]," + + "\"default\":null,\"doc\":\"First name of the person\"}," + + "{\"name\":\"lastName\",\"type\":[\"null\",\"string\"],\"default\":null," + + "\"doc\":\"Last name of the person\"},{\"name\":\"dateOfBirth\",\"type\":[\"null\"," + + "{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}],\"default\":null," + + "\"doc\":\"Date of birth of the person\"}]}") + .build()) + .build(); + + // Apply schema + var createResponse = ns4KafkaClient + .toBlocking() + .exchange(HttpRequest + .create(HttpMethod.POST, "/api/namespaces/ns1/schemas") + .bearerAuth(token) + .body(schema), Schema.class); + + assertEquals("created", createResponse.header("X-Ns4kafka-Result")); + + // Get all schemas + var getResponse = ns4KafkaClient + .toBlocking() + .exchange(HttpRequest + .create(HttpMethod.GET, "/api/namespaces/ns1/schemas") + .bearerAuth(token), Argument.listOf(SchemaList.class)); + + assertTrue(getResponse.getBody().isPresent()); + assertTrue(getResponse.getBody().get() + .stream() + .anyMatch(schemaList -> schemaList.getMetadata().getName().equals("ns1-subject3-value"))); + } + @Test void shouldDeleteSchema() { Schema schemaV1 = Schema.builder() @@ -777,9 +818,12 @@ void shouldDeleteSchema() { .spec(Schema.SchemaSpec.builder() .schema( "{\"namespace\":\"com.michelin.kafka.producer.showcase.avro\",\"type\":\"record\"," - + "\"name\":\"PersonAvro\",\"fields\":[" - + "{\"name\":\"field1\",\"type\":[\"null\",\"string\"]}," - + "{\"name\":\"field2\",\"type\":[\"null\",\"string\"]}]}") + + "\"name\":\"PersonAvro\",\"fields\":[{\"name\":\"firstName\",\"type\":[\"null\",\"string\"]," + + "\"default\":null,\"doc\":\"First name of the person\"}," + + "{\"name\":\"lastName\",\"type\":[\"null\",\"string\"],\"default\":null," + + "\"doc\":\"Last name of the person\"},{\"name\":\"dateOfBirth\",\"type\":[\"null\"," + + "{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}],\"default\":null," + + "\"doc\":\"Date of birth of the person\"}]}") .build()) .build(); @@ -798,9 +842,12 @@ void shouldDeleteSchema() { .spec(Schema.SchemaSpec.builder() .schema( "{\"namespace\":\"com.michelin.kafka.producer.showcase.avro\",\"type\":\"record\"," - + "\"name\":\"PersonAvro\",\"fields\":[" - + "{\"name\":\"field1\",\"type\":[\"null\",\"string\"]}," - + "{\"name\":\"field2\",\"type\":[\"null\",\"string\"]}]}") + + "\"name\":\"PersonAvro\",\"fields\":[{\"name\":\"firstName\",\"type\":[\"null\",\"string\"]," + + "\"default\":null,\"doc\":\"First name of the person\"}," + + "{\"name\":\"lastName\",\"type\":[\"null\",\"string\"],\"default\":null," + + "\"doc\":\"Last name of the person\"},{\"name\":\"dateOfBirth\",\"type\":[\"null\"," + + "{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}],\"default\":null," + + "\"doc\":\"Date of birth of the person\"}]}") .build()) .build(); @@ -819,10 +866,10 @@ void shouldDeleteSchema() { .spec(Schema.SchemaSpec.builder() .schema( "{\"namespace\":\"com.michelin.kafka.producer.showcase.avro\",\"type\":\"record\"," - + "\"name\":\"PersonAvro\",\"fields\":[" - + "{\"name\":\"field1\",\"type\":[\"null\",\"string\"]}," - + "{\"name\":\"field2\",\"type\":[\"null\",\"string\"]}," - + "{\"name\":\"field3\",\"type\":[\"null\",\"string\"]}]}") + + "\"name\":\"PersonAvro\",\"fields\":[{\"name\":\"firstName\",\"type\":[\"null\",\"string\"]," + + "\"default\":null,\"doc\":\"First name of the person\"}," + + "{\"name\":\"lastName\",\"type\":[\"null\",\"string\"],\"default\":null," + + "\"doc\":\"Last name of the person\"}]}") .build()) .build(); @@ -841,25 +888,23 @@ void shouldDeleteSchema() { .spec(Schema.SchemaSpec.builder() .schema( "{\"namespace\":\"com.michelin.kafka.producer.showcase.avro\",\"type\":\"record\"," - + "\"name\":\"PersonAvro\",\"fields\":[" - + "{\"name\":\"field1\",\"type\":[\"null\",\"string\"]}," - + "{\"name\":\"field2\",\"type\":[\"null\",\"string\"]}," - + "{\"name\":\"field3\",\"type\":[\"null\",\"string\"]}," - + "{\"name\":\"field4\",\"type\":[\"null\",\"string\"]}]}") + + "\"name\":\"PersonAvro\",\"fields\":[{\"name\":\"firstName\",\"type\":[\"null\",\"string\"]," + + "\"default\":null,\"doc\":\"First name of the person\"}," + + "{\"name\":\"lastName\",\"type\":[\"null\",\"string\"],\"default\":null," + + "\"doc\":\"Last name of the person\"},{\"name\":\"dateOfBirth\",\"type\":[\"null\"," + + "{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}],\"default\":null," + + "\"doc\":\"Date of birth of the person\"}]}") .build()) .build(); // Register V4 schema - var createSchemaResponse = ns4KafkaClient + ns4KafkaClient .toBlocking() .exchange(HttpRequest .create(HttpMethod.POST, "/api/namespaces/ns1/schemas") .bearerAuth(token) .body(schemaV4), Schema.class); - // Expects a new version - assertEquals("changed", createSchemaResponse.header("X-Ns4kafka-Result")); - // Delete latest schema version var deleteLatestVersionResponse = ns4KafkaClient .toBlocking()