Skip to content

Commit

Permalink
馃И #44 Add integration test for GetPluginsCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
iabudiab authored and gunnarmorling committed Jan 22, 2022
1 parent 36f3700 commit 017708c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/main/java/org/kcctl/command/GetPluginsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.kcctl.command;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import javax.inject.Inject;
Expand All @@ -30,13 +29,21 @@
import com.github.freva.asciitable.Column;
import com.github.freva.asciitable.HorizontalAlign;

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

@Command(name = "plugins", description = "Displays information about available connector plug-ins")
public class GetPluginsCommand implements Runnable {

private final ConfigurationContext context;

@CommandLine.Spec
CommandLine.Model.CommandSpec spec;

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

@Override
public void run() {
Expand All @@ -45,13 +52,13 @@ public void run() {
.build(KafkaConnectApi.class);

List<ConnectorPlugin> connectorPlugins = kafkaConnectApi.getConnectorPlugins();
Collections.sort(connectorPlugins, (c1, c2) -> -c1.type.compareTo(c2.type));
connectorPlugins.sort((c1, c2) -> -c1.type.compareTo(c2.type));

System.out.println();
System.out.println(AsciiTable.getTable(AsciiTable.NO_BORDERS, connectorPlugins, Arrays.asList(
spec.commandLine().getOut().println();
spec.commandLine().getOut().println(AsciiTable.getTable(AsciiTable.NO_BORDERS, connectorPlugins, Arrays.asList(
new Column().header("TYPE").dataAlign(HorizontalAlign.LEFT).with(plugin -> plugin.type),
new Column().header(" CLASS").dataAlign(HorizontalAlign.LEFT).with(plugin -> " " + plugin.clazz),
new Column().header(" VERSION").dataAlign(HorizontalAlign.LEFT).with(plugin -> " " + plugin.version))));
System.out.println();
spec.commandLine().getOut().println();
}
}
58 changes: 58 additions & 0 deletions src/test/java/org/kcctl/command/GetPluginsCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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 GetPluginsCommandTest extends IntegrationTest {

@InjectCommandContext
KcctlCommandContext<GetPluginsCommand> context;

@Test
public void should_print_info() {
int exitCode = context.commandLine().execute();
assertThat(exitCode).isEqualTo(CommandLine.ExitCode.OK);
assertThat(context.output().toString().trim().lines())
.map(String::trim)
.containsExactly(
"TYPE CLASS VERSION",
"source io.debezium.connector.db2.Db2Connector 1.7.1.Final",
"source io.debezium.connector.mongodb.MongoDbConnector 1.7.1.Final",
"source io.debezium.connector.mysql.MySqlConnector 1.7.1.Final",
"source io.debezium.connector.oracle.OracleConnector 1.7.1.Final",
"source io.debezium.connector.postgresql.PostgresConnector 1.7.1.Final",
"source io.debezium.connector.sqlserver.SqlServerConnector 1.7.1.Final",
"source io.debezium.connector.vitess.VitessConnector 1.7.1.Final",
"source org.apache.kafka.connect.file.FileStreamSourceConnector 2.8.1",
"source org.apache.kafka.connect.mirror.MirrorCheckpointConnector 1",
"source org.apache.kafka.connect.mirror.MirrorHeartbeatConnector 1",
"source org.apache.kafka.connect.mirror.MirrorSourceConnector 1",
"sink org.apache.kafka.connect.file.FileStreamSinkConnector 2.8.1");
}
}

0 comments on commit 017708c

Please sign in to comment.