Skip to content

Commit

Permalink
Improve javadoc & remove extra indents
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasCAI-mlv committed Oct 8, 2024
1 parent 7630ba7 commit 57d0590
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public List<Connector> 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")
Expand Down Expand Up @@ -164,7 +164,7 @@ public Mono<HttpResponse<Connector>> 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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,133 +265,133 @@ 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());
}

@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());
}

@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
Expand Down

0 comments on commit 57d0590

Please sign in to comment.