Skip to content

Commit

Permalink
test6
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasCAI-mlv committed Aug 27, 2024
1 parent a88596b commit 607c270
Showing 1 changed file with 64 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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()
Expand Down

0 comments on commit 607c270

Please sign in to comment.