diff --git a/src/main/java/com/michelin/ns4kafka/controller/ConnectorController.java b/src/main/java/com/michelin/ns4kafka/controller/ConnectorController.java index 1ccb1674..fd41b93f 100644 --- a/src/main/java/com/michelin/ns4kafka/controller/ConnectorController.java +++ b/src/main/java/com/michelin/ns4kafka/controller/ConnectorController.java @@ -65,7 +65,7 @@ public List list(String namespace, @QueryValue(defaultValue = "*") St * @param namespace The namespace * @param connector The name * @return A connector - * @deprecated use list(String, String name) instead. + * @deprecated use {@link #list(String, String)} instead. */ @Get("/{connector}") @Deprecated(since = "1.12.0") @@ -164,7 +164,7 @@ public Mono> apply(String namespace, @Valid @Body Connec * @param connector The current connector name to delete * @param dryrun Run in dry mode or not * @return A HTTP response - * @deprecated use bulkDelete instead. + * @deprecated use {@link #bulkDelete(String, String, boolean)} instead. */ @Status(HttpStatus.NO_CONTENT) @Delete("/{connector}{?dryrun}") diff --git a/src/test/java/com/michelin/ns4kafka/controller/ConnectorControllerTest.java b/src/test/java/com/michelin/ns4kafka/controller/ConnectorControllerTest.java index a6273eb5..6194e702 100644 --- a/src/test/java/com/michelin/ns4kafka/controller/ConnectorControllerTest.java +++ b/src/test/java/com/michelin/ns4kafka/controller/ConnectorControllerTest.java @@ -265,52 +265,52 @@ void shouldNotDeleteConnectorWhenNotFound() { @Test void shouldDeleteConnectors() { Namespace ns = Namespace.builder() - .metadata(Metadata.builder() - .name("test") - .cluster("local") - .build()) - .build(); + .metadata(Metadata.builder() + .name("test") + .cluster("local") + .build()) + .build(); Connector connector1 = Connector.builder().metadata(Metadata.builder().name("connect1").build()).build(); Connector connector2 = Connector.builder().metadata(Metadata.builder().name("connect2").build()).build(); when(namespaceService.findByName("test")) - .thenReturn(Optional.of(ns)); + .thenReturn(Optional.of(ns)); when(connectorService.isNamespaceOwnerOfConnect(ns, "connect1")) - .thenReturn(true); + .thenReturn(true); when(connectorService.isNamespaceOwnerOfConnect(ns, "connect2")) - .thenReturn(true); + .thenReturn(true); when(connectorService.findByWildcardName(ns, "connect*")) - .thenReturn(List.of(connector1, connector2)); + .thenReturn(List.of(connector1, connector2)); when(connectorService.delete(ns, connector1)) - .thenReturn(Mono.just(HttpResponse.noContent())); + .thenReturn(Mono.just(HttpResponse.noContent())); when(connectorService.delete(ns, connector2)) - .thenReturn(Mono.just(HttpResponse.noContent())); + .thenReturn(Mono.just(HttpResponse.noContent())); when(securityService.username()).thenReturn(Optional.of("test-user")); when(securityService.hasRole(ResourceBasedSecurityRule.IS_ADMIN)).thenReturn(false); doNothing().when(applicationEventPublisher).publishEvent(any()); StepVerifier.create(connectorController.bulkDelete("test", "connect*", false)) - .consumeNextWith(response -> assertEquals(HttpStatus.NO_CONTENT, response.getStatus())) - .verifyComplete(); + .consumeNextWith(response -> assertEquals(HttpStatus.NO_CONTENT, response.getStatus())) + .verifyComplete(); } @Test void shouldNotDeleteConnectorsWhenNotFound() { Namespace ns = Namespace.builder() - .metadata(Metadata.builder() - .name("test") - .cluster("local") - .build()) - .build(); + .metadata(Metadata.builder() + .name("test") + .cluster("local") + .build()) + .build(); when(namespaceService.findByName("test")) - .thenReturn(Optional.of(ns)); + .thenReturn(Optional.of(ns)); when(connectorService.findByWildcardName(ns, "connect*")) - .thenReturn(List.of()); + .thenReturn(List.of()); StepVerifier.create(connectorController.bulkDelete("test", "connect*", true)) - .consumeNextWith(response -> assertEquals(HttpStatus.NOT_FOUND, response.getStatus())) - .verifyComplete(); + .consumeNextWith(response -> assertEquals(HttpStatus.NOT_FOUND, response.getStatus())) + .verifyComplete(); verify(connectorService, never()).delete(any(), any()); } @@ -318,36 +318,36 @@ void shouldNotDeleteConnectorsWhenNotFound() { @Test void shouldDeleteConnectorsInDryRunMode() { Namespace ns = Namespace.builder() - .metadata(Metadata.builder() - .name("test") - .cluster("local") - .build()) - .build(); + .metadata(Metadata.builder() + .name("test") + .cluster("local") + .build()) + .build(); Connector connector1 = Connector.builder() - .metadata(Metadata.builder() - .name("connect1") - .build()) - .build(); + .metadata(Metadata.builder() + .name("connect1") + .build()) + .build(); Connector connector2 = Connector.builder() - .metadata(Metadata.builder() - .name("connect2") - .build()) - .build(); + .metadata(Metadata.builder() + .name("connect2") + .build()) + .build(); when(namespaceService.findByName("test")) - .thenReturn(Optional.of(ns)); + .thenReturn(Optional.of(ns)); when(connectorService.findByWildcardName(ns, "connect*")) - .thenReturn(List.of(connector1, connector2)); + .thenReturn(List.of(connector1, connector2)); when(connectorService.isNamespaceOwnerOfConnect(ns, "connect1")) - .thenReturn(true); + .thenReturn(true); when(connectorService.isNamespaceOwnerOfConnect(ns, "connect2")) - .thenReturn(true); + .thenReturn(true); StepVerifier.create(connectorController.bulkDelete("test", "connect*", true)) - .consumeNextWith(response -> assertEquals(HttpStatus.NO_CONTENT, response.getStatus())) - .verifyComplete(); + .consumeNextWith(response -> assertEquals(HttpStatus.NO_CONTENT, response.getStatus())) + .verifyComplete(); verify(connectorService, never()).delete(any(), any()); } @@ -355,43 +355,43 @@ void shouldDeleteConnectorsInDryRunMode() { @Test void shouldNotDeleteConnectorsWhenNotOwned() { Namespace ns = Namespace.builder() - .metadata(Metadata.builder() - .name("test") - .cluster("local") - .build()) - .build(); + .metadata(Metadata.builder() + .name("test") + .cluster("local") + .build()) + .build(); Connector connector1 = Connector.builder() - .metadata(Metadata.builder() - .name("connect1") - .build()) - .build(); + .metadata(Metadata.builder() + .name("connect1") + .build()) + .build(); Connector connector2 = Connector.builder() - .metadata(Metadata.builder() - .name("connect2") - .build()) - .build(); + .metadata(Metadata.builder() + .name("connect2") + .build()) + .build(); when(connectorService.findByWildcardName(ns, "connect*")) - .thenReturn(List.of(connector1, connector2)); + .thenReturn(List.of(connector1, connector2)); when(namespaceService.findByName("test")) - .thenReturn(Optional.of(ns)); + .thenReturn(Optional.of(ns)); when(connectorService.isNamespaceOwnerOfConnect(ns, "connect1")) - .thenReturn(false); + .thenReturn(false); when(connectorService.isNamespaceOwnerOfConnect(ns, "connect2")) - .thenReturn(true); + .thenReturn(true); StepVerifier.create(connectorController.bulkDelete("test", "connect*", false)) - .consumeErrorWith(error -> { - assertEquals(ResourceValidationException.class, error.getClass()); - assertEquals(1, ((ResourceValidationException) error).getValidationErrors().size()); - assertEquals( - "Invalid value \"connect1\" 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 \"connect1\" for field \"name\": namespace is not owner of the resource.", + ((ResourceValidationException) error).getValidationErrors().getFirst()); + }) + .verify(); } @Test