Search in sources :

Example 26 with UserException

use of org.elasticsearch.cli.UserException in project elasticsearch by elastic.

the class RemoveSettingKeyStoreCommandTests method testNonExistentSetting.

public void testNonExistentSetting() throws Exception {
    createKeystore("");
    UserException e = expectThrows(UserException.class, () -> execute("foo"));
    assertEquals(ExitCodes.CONFIG, e.exitCode);
    assertThat(e.getMessage(), containsString("[foo] does not exist"));
}
Also used : UserException(org.elasticsearch.cli.UserException)

Example 27 with UserException

use of org.elasticsearch.cli.UserException in project elasticsearch by elastic.

the class AddStringKeyStoreCommandTests method testNonAsciiValue.

public void testNonAsciiValue() throws Exception {
    KeyStoreWrapper.create(new char[0]).save(env.configFile());
    terminal.addSecretInput("non-äsčîï");
    UserException e = expectThrows(UserException.class, () -> execute("foo"));
    assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
    assertEquals("String value must contain only ASCII", e.getMessage());
}
Also used : UserException(org.elasticsearch.cli.UserException)

Example 28 with UserException

use of org.elasticsearch.cli.UserException in project elasticsearch by elastic.

the class AddStringKeyStoreCommandTests method testNpe.

public void testNpe() throws Exception {
    createKeystore("");
    terminal.addTextInput("");
    UserException e = expectThrows(UserException.class, this::execute);
    assertEquals(ExitCodes.USAGE, e.exitCode);
    assertThat(e.getMessage(), containsString("The setting name can not be null"));
}
Also used : UserException(org.elasticsearch.cli.UserException)

Example 29 with UserException

use of org.elasticsearch.cli.UserException in project elasticsearch by elastic.

the class ListKeyStoreCommandTests method testMissing.

public void testMissing() throws Exception {
    UserException e = expectThrows(UserException.class, this::execute);
    assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
    assertThat(e.getMessage(), containsString("keystore not found"));
}
Also used : UserException(org.elasticsearch.cli.UserException)

Example 30 with UserException

use of org.elasticsearch.cli.UserException in project elasticsearch by elastic.

the class RemovePluginCommandTests method testRemoveUninstalledPluginErrors.

public void testRemoveUninstalledPluginErrors() throws Exception {
    UserException e = expectThrows(UserException.class, () -> removePlugin("fake", home));
    assertEquals(ExitCodes.CONFIG, e.exitCode);
    assertEquals("plugin fake not found; run 'elasticsearch-plugin list' to get list of installed plugins", e.getMessage());
    MockTerminal terminal = new MockTerminal();
    new RemovePluginCommand() {

        @Override
        protected boolean addShutdownHook() {
            return false;
        }
    }.main(new String[] { "-Epath.home=" + home, "fake" }, terminal);
    try (BufferedReader reader = new BufferedReader(new StringReader(terminal.getOutput()))) {
        assertEquals("-> Removing fake...", reader.readLine());
        assertEquals("ERROR: plugin fake not found; run 'elasticsearch-plugin list' to get list of installed plugins", reader.readLine());
        assertNull(reader.readLine());
    }
}
Also used : BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) UserException(org.elasticsearch.cli.UserException) MockTerminal(org.elasticsearch.cli.MockTerminal)

Aggregations

UserException (org.elasticsearch.cli.UserException)39 Path (java.nio.file.Path)24 Environment (org.elasticsearch.env.Environment)14 Matchers.containsString (org.hamcrest.Matchers.containsString)9 IOException (java.io.IOException)5 Settings (org.elasticsearch.common.settings.Settings)4 BufferedReader (java.io.BufferedReader)3 ArrayList (java.util.ArrayList)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 FileVisitOption (java.nio.file.FileVisitOption)2 FileVisitResult (java.nio.file.FileVisitResult)2 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)2 ZipInputStream (java.util.zip.ZipInputStream)2 Logger (org.apache.logging.log4j.Logger)2 LoggerContext (org.apache.logging.log4j.core.LoggerContext)2 AbstractConfiguration (org.apache.logging.log4j.core.config.AbstractConfiguration)2 CompositeConfiguration (org.apache.logging.log4j.core.config.composite.CompositeConfiguration)2 PropertiesConfiguration (org.apache.logging.log4j.core.config.properties.PropertiesConfiguration)2 PropertiesConfigurationFactory (org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory)2