From 61a084d73ec6a24d9be80a7f7192b8ce33ba8986 Mon Sep 17 00:00:00 2001 From: Alexis Souquiere Date: Tue, 28 Nov 2023 14:08:31 +0100 Subject: [PATCH] Light refactoring --- .../michelin/ns4kafka/controllers/SchemaController.java | 8 ++++---- .../ns4kafka/controllers/SchemaControllerTest.java | 8 +++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/michelin/ns4kafka/controllers/SchemaController.java b/src/main/java/com/michelin/ns4kafka/controllers/SchemaController.java index 3012f49c..f59d83a2 100644 --- a/src/main/java/com/michelin/ns4kafka/controllers/SchemaController.java +++ b/src/main/java/com/michelin/ns4kafka/controllers/SchemaController.java @@ -116,10 +116,6 @@ public Mono> 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 -> { @@ -130,6 +126,10 @@ public Mono> 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() diff --git a/src/test/java/com/michelin/ns4kafka/controllers/SchemaControllerTest.java b/src/test/java/com/michelin/ns4kafka/controllers/SchemaControllerTest.java index 60751760..f0b91d98 100644 --- a/src/test/java/com/michelin/ns4kafka/controllers/SchemaControllerTest.java +++ b/src/test/java/com/michelin/ns4kafka/controllers/SchemaControllerTest.java @@ -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)); @@ -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)) @@ -198,7 +196,7 @@ void applyDryRunChanged() { }) .verifyComplete(); - verify(schemaService, never()).register(namespace, schema); + verify(schemaService, never()).register(namespace, schemaV2); } @Test