Class CommandTestCase

java.lang.Object
org.junit.Assert
org.apache.lucene.tests.util.LuceneTestCase
org.elasticsearch.test.ESTestCase
org.elasticsearch.cli.CommandTestCase

public abstract class CommandTestCase extends ESTestCase
A base test case for cli tools.
  • Field Details

    • terminal

      protected final MockTerminal terminal
      The terminal that execute uses
    • sysprops

      protected final Map<String,String> sysprops
      The system properties that execute uses
    • envVars

      protected final Map<String,String> envVars
      The environment variables that execute uses
    • esHomeDir

      protected Path esHomeDir
      The working directory that execute uses
  • Constructor Details

    • CommandTestCase

      public CommandTestCase()
  • Method Details

    • resetTerminal

      public void resetTerminal()
    • mockSystemProperties

      protected static Map<String,String> mockSystemProperties(Path homeDir)
    • newCommand

      protected abstract Command newCommand()
      Creates a Command to test execution.
    • executeMain

      public int executeMain(String... args) throws Exception
      Run the main method of a new command with the given args. Output can be found in terminal.
      Throws:
      Exception
    • execute

      public String execute(String... args) throws Exception
      Runs a new command with the given args. Output can be found in terminal.
      Throws:
      Exception
    • execute

      public String execute(Command command, String... args) throws Exception
      Runs the specified command with the given args, throwing exceptions on errors.

      Output can be found in terminal.

      Throws:
      Exception
    • assertOk

      protected void assertOk(String... args) throws Exception
      Throws:
      Exception
    • assertOkWithOutput

      protected void assertOkWithOutput(org.hamcrest.Matcher<String> outMatcher, org.hamcrest.Matcher<String> errMatcher, String... args) throws Exception
      Throws:
      Exception
    • assertUsage

      protected void assertUsage(org.hamcrest.Matcher<String> matcher, String... args) throws Exception
      Throws:
      Exception