Skip to content

Commit

Permalink
馃И #44 Add integration test for GetConnectorCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
iabudiab authored and gunnarmorling committed Jan 22, 2022
1 parent d9af412 commit 3bd48a1
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/main/java/org/kcctl/command/GetConnectorsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.github.freva.asciitable.Column;
import com.github.freva.asciitable.HorizontalAlign;

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

import static org.kcctl.util.Colors.ANSI_GREEN;
Expand All @@ -38,8 +39,15 @@
@Command(name = "connectors", description = "Displays information about deployed connectors")
public class GetConnectorsCommand implements Runnable {

private final ConfigurationContext context;

@CommandLine.Spec
CommandLine.Model.CommandSpec spec;

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

@Override
public void run() {
Expand All @@ -61,7 +69,7 @@ public void run() {
i++;
}

System.out.println();
spec.commandLine().getOut().println();
String table = AsciiTable.getTable(AsciiTable.NO_BORDERS,
new Column[]{
new Column().header("NAME").dataAlign(HorizontalAlign.LEFT),
Expand All @@ -71,8 +79,8 @@ public void run() {
},
data);

System.out.println(table.replace("RUNNING", ANSI_GREEN + "RUNNING" + ANSI_RESET).replace("FAILED", ANSI_RED + "FAILED" + ANSI_RESET));
System.out.println();
spec.commandLine().getOut().println(table.replace("RUNNING", ANSI_GREEN + "RUNNING" + ANSI_RESET).replace("FAILED", ANSI_RED + "FAILED" + ANSI_RESET));
spec.commandLine().getOut().println();
}

private String toString(List<TaskState> tasks) {
Expand All @@ -87,7 +95,7 @@ private String toString(List<TaskState> tasks) {
sb.append(", ");
}

sb.append(taskState.id + ": " + taskState.state);
sb.append(taskState.id).append(": ").append(taskState.state);
}

return sb.toString();
Expand Down
59 changes: 59 additions & 0 deletions src/test/java/org/kcctl/command/GetConnectorsCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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 GetConnectorsCommandTest extends IntegrationTest {

@InjectCommandContext
KcctlCommandContext<GetConnectorsCommand> context;

@Test
public void should_print_empty_connectors_() {
int exitCode = context.commandLine().execute();
assertThat(exitCode).isEqualTo(CommandLine.ExitCode.OK);
assertThat(context.output().toString().trim()).isEqualTo(
"NAME TYPE STATE TASKS");
}

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

int exitCode = context.commandLine().execute();
assertThat(exitCode).isEqualTo(CommandLine.ExitCode.OK);
assertThat(context.output().toString().trim().lines())
.map(String::trim)
.containsExactly(
"NAME TYPE STATE TASKS",
"test1 source \u001B[32mRUNNING\u001B[0m 0: \u001B[32mRUNNING\u001B[0m",
"test2 source \u001B[32mRUNNING\u001B[0m 0: \u001B[32mRUNNING\u001B[0m");
}
}

0 comments on commit 3bd48a1

Please sign in to comment.