Skip to content

Commit

Permalink
馃И #44 Add integration test for PauseConnectorCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
iabudiab authored and gunnarmorling committed Jan 22, 2022
1 parent 71f7dbe commit 1f73cd3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/main/java/org/kcctl/command/PauseConnectorCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,33 @@
import org.kcctl.service.KafkaConnectApi;
import org.kcctl.util.ConfigurationContext;

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

@Command(name = "connector", description = "Pauses the specified connector")
public class PauseConnectorCommand implements Runnable {

@Inject
ConfigurationContext context;

@Parameters(paramLabel = "NAME", description = "Name of the connector (e.g. 'my-connector')", completionCandidates = ConnectorNameCompletions.class)
String name;

@CommandLine.Spec
private CommandLine.Model.CommandSpec spec;

private final ConfigurationContext context;

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

@Override
public void run() {
KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
.baseUri(context.getCurrentContext().getCluster())
.build(KafkaConnectApi.class);

kafkaConnectApi.pauseConnector(name);
System.out.println("Paused connector " + name);
spec.commandLine().getOut().println("Paused connector " + name);
}
}
50 changes: 50 additions & 0 deletions src/test/java/org/kcctl/command/PauseConnectorCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.debezium.testing.testcontainers.Connector;
import io.quarkus.test.junit.QuarkusTest;
import picocli.CommandLine;

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

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

@InjectCommandContext
KcctlCommandContext<PauseConnectorCommand> context;

@Test
public void should_pause_connector() {
registerTestConnector("test1");
registerTestConnector("test2");

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

kafkaConnect.ensureConnectorState("test1", Connector.State.PAUSED);
kafkaConnect.ensureConnectorState("test2", Connector.State.RUNNING);
}
}

0 comments on commit 1f73cd3

Please sign in to comment.