Skip to content

Commit

Permalink
馃И #44 Add integration test for DeleteConnectorCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
iabudiab authored and gunnarmorling committed Jan 22, 2022
1 parent 5473c6a commit d9af412
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/main/java/org/kcctl/command/DeleteConnectorCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,26 @@
import org.kcctl.service.KafkaConnectException;
import org.kcctl.util.ConfigurationContext;

import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Parameters;

@Command(name = "delete", description = "Deletes the specified connector")
public class DeleteConnectorCommand implements Callable<Integer> {

@Inject
ConfigurationContext context;

@Parameters(paramLabel = "CONNECTOR NAME", description = "Name of the connector", completionCandidates = ConnectorNameCompletions.class)
String name;

@CommandLine.Spec
CommandLine.Model.CommandSpec spec;

private final ConfigurationContext context;

@Inject
public DeleteConnectorCommand(ConfigurationContext context) {
this.context = context;
}

@Override
public Integer call() {
KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
Expand All @@ -49,15 +57,15 @@ public Integer call() {
}
catch (KafkaConnectException kce) {
if (kce.getErrorCode() == HttpStatus.SC_NOT_FOUND) {
System.out.println(kce.getMessage());
spec.commandLine().getOut().println(kce.getMessage());
}
else {
System.out.println(kce);
spec.commandLine().getOut().println(kce);
}
return 1;
}

System.out.println("Deleted connector " + name);
spec.commandLine().getOut().println("Deleted connector " + name);

return 0;
}
Expand Down
45 changes: 45 additions & 0 deletions src/test/java/org/kcctl/command/DeleteConnectorCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2021 The original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kcctl.command;

import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
import org.junit.jupiter.api.Test;
import org.kcctl.IntegrationTest;
import org.kcctl.support.InjectCommandContext;
import org.kcctl.support.KcctlCommandContext;

import io.quarkus.test.junit.QuarkusTest;
import picocli.CommandLine;

import static org.assertj.core.api.Assertions.assertThat;

@QuarkusTest
@DisplayNameGeneration(ReplaceUnderscores.class)
class DeleteConnectorCommandTest extends IntegrationTest {

@InjectCommandContext
KcctlCommandContext<DeleteConnectorCommand> context;

@Test
public void should_delete_connector() {
registerTestConnector("test");

int exitCode = context.commandLine().execute("test");
assertThat(exitCode).isEqualTo(CommandLine.ExitCode.OK);
assertThat(context.output().toString().trim()).isEqualTo("Deleted connector test");
}
}

0 comments on commit d9af412

Please sign in to comment.