Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasCAI-mlv committed Oct 11, 2024
1 parent d945682 commit a174014
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,37 +278,57 @@ void shouldNotCreateSchemaInDryRunModeWhenNotCompatible() {
}

@Test
void shouldListSchemasWithoutParameter() {
void shouldListMultipleSchemas() {
Namespace namespace = buildNamespace();
SchemaList schema = buildSchemaList();
SchemaList schema2 = buildSchemaList2();

when(namespaceService.findByName("myNamespace"))
.thenReturn(Optional.of(namespace));
when(schemaService.findByWildcardName(namespace, "*"))
.thenReturn(Flux.fromIterable(List.of(schema)));
.thenReturn(Flux.fromIterable(List.of(schema, schema2)));

StepVerifier.create(schemaController.list("myNamespace", "*"))
.consumeNextWith(
schemaResponse -> assertEquals("prefix.subject-value", schemaResponse.getMetadata().getName()))
.consumeNextWith(
schemaResponse -> assertEquals("prefix.subject2-value", schemaResponse.getMetadata().getName()))
.verifyComplete();
verify(schemaService, never()).getSubjectListLatestVersion(any(), any());
}

@Test
void shouldListSchemaWithNameParameter() {
void shouldListOneSchemaWithNameParameter() {
Namespace namespace = buildNamespace();
SchemaList schema = buildSchemaList();

when(namespaceService.findByName("myNamespace"))
.thenReturn(Optional.of(namespace));
when(schemaService.findByWildcardName(namespace, "prefix.subject-value"))
.thenReturn(Flux.fromIterable(List.of(schema)));
when(schemaService.getSubjectListLatestVersion(namespace, "prefix.subject-value"))
.thenReturn(Mono.just(schema));

StepVerifier.create(schemaController.list("myNamespace", "prefix.subject-value"))
.consumeNextWith(
schemaResponse -> assertEquals("prefix.subject-value", schemaResponse.getMetadata().getName()))
.verifyComplete();
}

@Test
void shouldListSchemaWhenNoSchema() {
Namespace namespace = buildNamespace();

when(namespaceService.findByName("myNamespace"))
.thenReturn(Optional.of(namespace));
when(schemaService.findByWildcardName(namespace, "prefix.subject-value"))
.thenReturn(Flux.fromIterable(List.of()));

StepVerifier.create(schemaController.list("myNamespace", "prefix.subject-value"))
.verifyComplete();
verify(schemaService, never()).getSubjectListLatestVersion(any(), any());
}

@Test
@SuppressWarnings("deprecation")
void shouldGetSchema() {
Expand Down Expand Up @@ -669,4 +689,12 @@ private SchemaList buildSchemaList() {
.build())
.build();
}

private SchemaList buildSchemaList2() {
return SchemaList.builder()
.metadata(Metadata.builder()
.name("prefix.subject2-value")
.build())
.build();
}
}
23 changes: 21 additions & 2 deletions src/test/java/com/michelin/ns4kafka/service/SchemaServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void shouldListSchemaWithWildcardNameParameter() {
}

@Test
void shouldGetBySubjectAndVersion() {
void shouldGetSubjectLatestVersion() {
Namespace namespace = buildNamespace();
SchemaCompatibilityResponse compatibilityResponse = buildCompatibilityResponse();

Expand All @@ -228,6 +228,25 @@ void shouldGetBySubjectAndVersion() {
.verifyComplete();
}

@Test
void shouldGetSubjectListLatestVersion() {
Namespace namespace = buildNamespace();
SchemaCompatibilityResponse compatibilityResponse = buildCompatibilityResponse();

when(schemaRegistryClient.getSubject(namespace.getMetadata().getCluster(),
"prefix.schema-one", "latest")).thenReturn(Mono.just(buildSchemaResponse("prefix.schema-one")));
when(schemaRegistryClient.getCurrentCompatibilityBySubject(any(), any())).thenReturn(
Mono.just(compatibilityResponse));

StepVerifier.create(schemaService.getSubjectListLatestVersion(namespace, "prefix.schema-one"))
.consumeNextWith(latestSubject -> {
assertEquals("prefix.schema-one", latestSubject.getMetadata().getName());
assertEquals("local", latestSubject.getMetadata().getCluster());
assertEquals("myNamespace", latestSubject.getMetadata().getNamespace());
})
.verifyComplete();
}

@Test
void shouldGetAllSubjectVersions() {
Namespace namespace = buildNamespace();
Expand All @@ -247,7 +266,7 @@ void shouldGetAllSubjectVersions() {
}

@Test
void shouldGetBySubjectAndVersionWhenEmpty() {
void shouldNotGetSubjectLatestVersionWhenEmpty() {
Namespace namespace = buildNamespace();

when(schemaRegistryClient.getSubject(namespace.getMetadata().getCluster(), "prefix.schema-one", "latest"))
Expand Down

0 comments on commit a174014

Please sign in to comment.