Skip to content

Commit

Permalink
馃И #44 Add integration test for GetLoggerCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
iabudiab authored and gunnarmorling committed Jan 22, 2022
1 parent 3bd48a1 commit 704ae1d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/main/java/org/kcctl/command/GetLoggerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import java.util.Iterator;
import java.util.Map;

import javax.inject.Inject;

import org.eclipse.microprofile.rest.client.RestClientBuilder;
import org.kcctl.completion.LoggerNameCompletions;
import org.kcctl.service.KafkaConnectApi;
Expand All @@ -43,13 +41,19 @@
@CommandLine.Command(name = "logger", description = "Displays information about a specific logger")
public class GetLoggerCommand implements Runnable {

@Parameters(paramLabel = "LOGGER NAME", description = "Name of the logger", completionCandidates = LoggerNameCompletions.class)
String path;

@CommandLine.Spec
CommandLine.Model.CommandSpec spec;

private static final String DEFAULT_PATH = "ALL";

@Inject
ConfigurationContext context;
private final ConfigurationContext context;

@Parameters(paramLabel = "LOGGER NAME", description = "Name of the logger", completionCandidates = LoggerNameCompletions.class)
String path;
public GetLoggerCommand(ConfigurationContext context) {
this.context = context;
}

@Override
public void run() {
Expand Down Expand Up @@ -84,14 +88,14 @@ public void run() {
connectorLoggers.findValue("level").textValue()
};
}
System.out.println();
spec.commandLine().getOut().println();
String table = AsciiTable.getTable(AsciiTable.NO_BORDERS,
new Column[]{
new Column().header("LOGGER").dataAlign(HorizontalAlign.LEFT),
new Column().header(" LEVEL").dataAlign(HorizontalAlign.LEFT)
},
data);
System.out.println(table.replace("ERROR", ANSI_RED + "ERROR" + ANSI_RESET)
spec.commandLine().getOut().println(table.replace("ERROR", ANSI_RED + "ERROR" + ANSI_RESET)
.replace("WARN", ANSI_RED + "WARN" + ANSI_RESET)
.replace("FATAL", ANSI_RED + "FATAL" + ANSI_RESET)
.replace("DEBUG", ANSI_YELLOW + "DEBUG" + ANSI_RESET)
Expand Down
70 changes: 70 additions & 0 deletions src/test/java/org/kcctl/command/GetLoggerCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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 GetLoggerCommandTest extends IntegrationTest {

@InjectCommandContext
KcctlCommandContext<GetLoggerCommand> context;

@Test
public void should_print_all_loggers() {
int exitCode = context.commandLine().execute("ALL");
assertThat(exitCode).isEqualTo(CommandLine.ExitCode.OK);
assertThat(context.output().toString().trim().lines())
.map(String::trim)
.containsExactly(
"LOGGER LEVEL",
"org.reflections \u001B[31mERROR\u001B[0m",
"root \u001B[32mINFO\u001B[0m");
}

@Test
public void should_print_root_logger() {
int exitCode = context.commandLine().execute("root");
assertThat(exitCode).isEqualTo(CommandLine.ExitCode.OK);
assertThat(context.output().toString().trim().lines())
.map(String::trim)
.containsExactly(
"LOGGER LEVEL",
"root \u001B[32mINFO\u001B[0m");
}

@Test
public void should_print_reflections_logger() {
int exitCode = context.commandLine().execute("org.reflections");
assertThat(exitCode).isEqualTo(CommandLine.ExitCode.OK);
assertThat(context.output().toString().trim().lines())
.map(String::trim)
.containsExactly(
"LOGGER LEVEL",
"org.reflections \u001B[31mERROR\u001B[0m");
}
}

0 comments on commit 704ae1d

Please sign in to comment.