Skip to content

Commit

Permalink
split integration test for delete schema + fix style/indent
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasCAI-mlv committed Aug 27, 2024
1 parent b1e5904 commit c0ff8cd
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,14 @@ public Mono<HttpResponse<Schema>> apply(String namespace, @Valid @Body Schema sc
*
* @param namespace The namespace
* @param subject The subject
* @param version The version of the schema to delete (optional)
* @param version The version of the schema to delete
* @param dryrun Run in dry mode or not
* @return A HTTP response
*/
@Status(HttpStatus.NO_CONTENT)
@Delete("/{subject}")
public Mono<HttpResponse<Void>> delete(String namespace, @PathVariable String subject,
public Mono<HttpResponse<Void>> delete(String namespace,
@PathVariable String subject,
@QueryValue Optional<String> version,
@QueryValue(defaultValue = "false") boolean dryrun) {
Namespace ns = getNamespace(namespace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public Mono<Integer[]> deleteSubject(String kafkaCluster, String subject, boolea
*
* @param kafkaCluster The Kafka cluster
* @param subject The subject
* @param version The version
* @param version The version
* @param hardDelete Should the subject be hard deleted or not
* @return The version of the deleted subject
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,19 +447,19 @@ void shouldNotDeleteAllSchemaVersionsWhenNotOwner() {
Namespace namespace = buildNamespace();

when(namespaceService.findByName("myNamespace"))
.thenReturn(Optional.of(namespace));
.thenReturn(Optional.of(namespace));
when(schemaService.isNamespaceOwnerOfSubject(namespace, "prefix.subject-value"))
.thenReturn(false);
.thenReturn(false);

StepVerifier.create(schemaController.delete("myNamespace", "prefix.subject-value", Optional.empty(), false))
.consumeErrorWith(error -> {
assertEquals(ResourceValidationException.class, error.getClass());
assertEquals(1, ((ResourceValidationException) error).getValidationErrors().size());
assertEquals("Invalid value \"prefix.subject-value\" for field \"name\": "
+ "namespace is not owner of the resource.",
((ResourceValidationException) error).getValidationErrors().getFirst());
})
.verify();
.consumeErrorWith(error -> {
assertEquals(ResourceValidationException.class, error.getClass());
assertEquals(1, ((ResourceValidationException) error).getValidationErrors().size());
assertEquals("Invalid value \"prefix.subject-value\" for field \"name\": "
+ "namespace is not owner of the resource.",
((ResourceValidationException) error).getValidationErrors().getFirst());
})
.verify();

verify(schemaService, never()).getLatestSubject(any(), any());
verify(schemaService, never()).deleteAllVersions(any(), any());
Expand Down Expand Up @@ -561,7 +561,7 @@ void shouldDeleteLatestSchemaVersionBySpecifyingLatest() {
.consumeNextWith(response -> assertEquals(HttpStatus.NO_CONTENT, response.getStatus()))
.verifyComplete();

verify(applicationEventPublisher, times(1)).publishEvent(any());
verify(applicationEventPublisher).publishEvent(any());
}

@Test
Expand All @@ -588,7 +588,7 @@ void shouldDeleteLatestSchemaVersionBySpecifyingVersion() {
.consumeNextWith(response -> assertEquals(HttpStatus.NO_CONTENT, response.getStatus()))
.verifyComplete();

verify(applicationEventPublisher, times(1)).publishEvent(any());
verify(applicationEventPublisher).publishEvent(any());
}

@Test
Expand All @@ -614,7 +614,7 @@ void shouldDeleteLastSchemaVersion() {
.consumeNextWith(response -> assertEquals(HttpStatus.NO_CONTENT, response.getStatus()))
.verifyComplete();

verify(applicationEventPublisher, times(1)).publishEvent(any());
verify(applicationEventPublisher).publishEvent(any());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,12 +766,110 @@ void shouldRegisterSameSchemaTwice() {
assertNotNull(schemaAfterPostOnRegistry.id());
assertEquals(2, schemaAfterPostOnRegistry.version());
assertEquals("ns1-subject3-value", schemaAfterPostOnRegistry.subject());
}

@Test
void shouldDeleteSchema() {
Schema schemaV1 = Schema.builder()
.metadata(Metadata.builder()
.name("ns1-subject4-value")
.build())
.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\"]}]}")
.build())
.build();

// Register V1 schema
var createV1Response = ns4KafkaClient
.toBlocking()
.exchange(HttpRequest
.create(HttpMethod.POST, "/api/namespaces/ns1/schemas")
.bearerAuth(token)
.body(schemaV1), Schema.class);

assertEquals("created", createV1Response.header("X-Ns4kafka-Result"));

Schema schemaV2 = Schema.builder()
.metadata(Metadata.builder()
.name("ns1-subject4-value")
.build())
.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\"]}]}")
.build())
.build();

// Register V2 schema
var createV2Response = ns4KafkaClient
.toBlocking()
.exchange(HttpRequest
.create(HttpMethod.POST, "/api/namespaces/ns1/schemas")
.bearerAuth(token)
.body(schemaV2), Schema.class);

assertEquals("created", createV2Response.header("X-Ns4kafka-Result"));

Check failure on line 817 in src/test/java/com/michelin/ns4kafka/integration/SchemaIntegrationTest.java

View workflow job for this annotation

GitHub Actions / JUnit Test Report

SchemaIntegrationTest.shouldDeleteSchema()

org.opentest4j.AssertionFailedError: expected: <created> but was: <unchanged>
Raw output
org.opentest4j.AssertionFailedError: expected: <created> but was: <unchanged>
	at app//org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at app//org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at app//org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
	at app//org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
	at app//org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177)
	at app//org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1145)
	at app//com.michelin.ns4kafka.integration.SchemaIntegrationTest.shouldDeleteSchema(SchemaIntegrationTest.java:817)
	at [email protected]/java.lang.reflect.Method.invoke(Method.java:580)
	at app//io.micronaut.test.extensions.junit5.MicronautJunit5Extension$2.proceed(MicronautJunit5Extension.java:142)
	at app//io.micronaut.test.extensions.AbstractMicronautExtension.interceptEach(AbstractMicronautExtension.java:162)
	at app//io.micronaut.test.extensions.AbstractMicronautExtension.interceptTest(AbstractMicronautExtension.java:119)
	at app//io.micronaut.test.extensions.junit5.MicronautJunit5Extension.interceptTestMethod(MicronautJunit5Extension.java:129)
	at [email protected]/java.util.ArrayList.forEach(ArrayList.java:1596)
	at [email protected]/java.util.ArrayList.forEach(ArrayList.java:1596)

Schema schemaV3 = Schema.builder()
.metadata(Metadata.builder()
.name("ns1-subject4-value")
.build())
.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\"]}]}")
.build())
.build();

// Register V3 schema
var createV3Response = ns4KafkaClient
.toBlocking()
.exchange(HttpRequest
.create(HttpMethod.POST, "/api/namespaces/ns1/schemas")
.bearerAuth(token)
.body(schemaV3), Schema.class);

assertEquals("created", createV3Response.header("X-Ns4kafka-Result"));

Schema schemaV4 = Schema.builder()
.metadata(Metadata.builder()
.name("ns1-subject4-value")
.build())
.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\"]}]}")
.build())
.build();

// Register V4 schema
var createV4Response = ns4KafkaClient
.toBlocking()
.exchange(HttpRequest
.create(HttpMethod.POST, "/api/namespaces/ns1/schemas")
.bearerAuth(token)
.body(schemaV4), Schema.class);

assertEquals("created", createV4Response.header("X-Ns4kafka-Result"));

// Delete latest schema version
var deleteLatestVersionResponse = ns4KafkaClient
.toBlocking()
.exchange(HttpRequest
.create(HttpMethod.DELETE, "/api/namespaces/ns1/schemas/ns1-subject3-value?version=latest")
.create(HttpMethod.DELETE, "/api/namespaces/ns1/schemas/ns1-subject4-value?version=latest")
.bearerAuth(token), Schema.class);

assertEquals(HttpStatus.NO_CONTENT, deleteLatestVersionResponse.getStatus());
Expand All @@ -780,26 +878,18 @@ void shouldRegisterSameSchemaTwice() {
var getSchemaAfterLatestVersionDeletionResponse = ns4KafkaClient
.toBlocking()
.exchange(HttpRequest
.create(HttpMethod.GET, "/api/namespaces/ns1/schemas/ns1-subject3-value")
.create(HttpMethod.GET, "/api/namespaces/ns1/schemas/ns1-subject4-value")
.bearerAuth(token), Schema.class);

// Expects v1 is returned by ns4kafka
// Expects v3 is returned by ns4kafka
assertTrue(getSchemaAfterLatestVersionDeletionResponse.getBody().isPresent());
assertEquals(1, getSchemaAfterLatestVersionDeletionResponse.getBody().get().getSpec().getVersion());

// Post the v2 schema again
ns4KafkaClient
.toBlocking()
.exchange(HttpRequest
.create(HttpMethod.POST, "/api/namespaces/ns1/schemas")
.bearerAuth(token)
.body(sameSchemaWithSwappedFields), Schema.class);
assertEquals(3, getSchemaAfterLatestVersionDeletionResponse.getBody().get().getSpec().getVersion());

// Delete old schema version
var deleteOldVersionResponse = ns4KafkaClient
.toBlocking()
.exchange(HttpRequest
.create(HttpMethod.DELETE, "/api/namespaces/ns1/schemas/ns1-subject3-value?version=1")
.create(HttpMethod.DELETE, "/api/namespaces/ns1/schemas/ns1-subject4-value?version=1")
.bearerAuth(token), Schema.class);

assertEquals(HttpStatus.NO_CONTENT, deleteOldVersionResponse.getStatus());
Expand All @@ -808,11 +898,30 @@ void shouldRegisterSameSchemaTwice() {
var getSchemaAfterOldVersionDeletionResponse = ns4KafkaClient
.toBlocking()
.exchange(HttpRequest
.create(HttpMethod.GET, "/api/namespaces/ns1/schemas/ns1-subject3-value")
.create(HttpMethod.GET, "/api/namespaces/ns1/schemas/ns1-subject4-value")
.bearerAuth(token), Schema.class);

// Expects v2 as returned schema
// Expects v3 as returned schema
assertTrue(getSchemaAfterOldVersionDeletionResponse.getBody().isPresent());
assertEquals(2, getSchemaAfterOldVersionDeletionResponse.getBody().get().getSpec().getVersion());
assertEquals(3, getSchemaAfterOldVersionDeletionResponse.getBody().get().getSpec().getVersion());

// Delete all remaining schema versions
var deleteAllVersionsResponse = ns4KafkaClient
.toBlocking()
.exchange(HttpRequest
.create(HttpMethod.DELETE, "/api/namespaces/ns1/schemas/ns1-subject4-value")
.bearerAuth(token), Schema.class);

assertEquals(HttpStatus.NO_CONTENT, deleteAllVersionsResponse.getStatus());

// Get all schemas
var getSchemaAfterAllVersionsDeletionResponse = ns4KafkaClient
.toBlocking()
.exchange(HttpRequest
.create(HttpMethod.GET, "/api/namespaces/ns1/schemas/ns1-subject4-value")
.bearerAuth(token), Schema.class);

// Expects no returned schema
assertTrue(getSchemaAfterAllVersionsDeletionResponse.getBody().isEmpty());
}
}

0 comments on commit c0ff8cd

Please sign in to comment.