Skip to content

Commit

Permalink
Light refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisSouquiere committed Nov 28, 2023
1 parent 0976934 commit 61a084d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ public Mono<HttpResponse<Schema>> apply(String namespace, @Valid @Body Schema sc
schema.getSpec().setCompatibility(latestSubjectOptional.get().getSpec().getCompatibility());
}

schema.getMetadata().setCreationTimestamp(Date.from(Instant.now()));
schema.getMetadata().setCluster(ns.getMetadata().getCluster());
schema.getMetadata().setNamespace(ns.getMetadata().getName());

return schemaService
.validateSchemaCompatibility(ns.getMetadata().getCluster(), schema)
.flatMap(validationErrors -> {
Expand All @@ -130,6 +126,10 @@ public Mono<HttpResponse<Schema>> apply(String namespace, @Valid @Body Schema sc
schema.getMetadata().getName()));
}

schema.getMetadata().setCreationTimestamp(Date.from(Instant.now()));
schema.getMetadata().setCluster(ns.getMetadata().getCluster());
schema.getMetadata().setNamespace(ns.getMetadata().getName());

if (dryrun) {
return Mono.just(formatHttpResponse(schema,
latestSubjectOptional.isPresent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ void applyChanged() {

when(namespaceService.findByName("myNamespace")).thenReturn(Optional.of(namespace));
when(schemaService.isNamespaceOwnerOfSubject(namespace, schema.getMetadata().getName())).thenReturn(true);
when(schemaService.validateSchemaCompatibility(eq("local"), any(Schema.class)))
.thenReturn(Mono.just(List.of()));
when(schemaService.validateSchemaCompatibility("local", schemaV2)).thenReturn(Mono.just(List.of()));
when(schemaService.getLatestSubject(namespace, schema.getMetadata().getName()))
.thenReturn(Mono.just(schema));
when(schemaService.register(namespace, schemaV2)).thenReturn(Mono.just(2));
Expand Down Expand Up @@ -186,8 +185,7 @@ void applyDryRunChanged() {
when(namespaceService.findByName("myNamespace")).thenReturn(Optional.of(namespace));
when(schemaService.isNamespaceOwnerOfSubject(namespace, schema.getMetadata().getName()))
.thenReturn(true);
when(schemaService.validateSchemaCompatibility(eq("local"), any(Schema.class)))
.thenReturn(Mono.just(List.of()));
when(schemaService.validateSchemaCompatibility("local", schemaV2)).thenReturn(Mono.just(List.of()));
when(schemaService.getLatestSubject(namespace, schema.getMetadata().getName())).thenReturn(Mono.just(schema));

StepVerifier.create(schemaController.apply("myNamespace", schemaV2, true))
Expand All @@ -198,7 +196,7 @@ void applyDryRunChanged() {
})
.verifyComplete();

verify(schemaService, never()).register(namespace, schema);
verify(schemaService, never()).register(namespace, schemaV2);
}

@Test
Expand Down

0 comments on commit 61a084d

Please sign in to comment.