Search in sources :

Example 11 with UserException

use of org.opensearch.cli.UserException in project OpenSearch by opensearch-project.

the class InstallPluginCommandTests method testPluginAlreadyInstalled.

public void testPluginAlreadyInstalled() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    String pluginZip = createPluginUrl("fake", pluginDir);
    installPlugin(pluginZip, env.v1());
    final UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1(), randomFrom(skipJarHellCommand, defaultCommand)));
    assertThat(e.getMessage(), equalTo("plugin directory [" + env.v2().pluginsDir().resolve("fake") + "] already exists; " + "if you need to update the plugin, uninstall it first using command 'remove fake'"));
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) UserException(org.opensearch.cli.UserException)

Example 12 with UserException

use of org.opensearch.cli.UserException in project OpenSearch by opensearch-project.

the class InstallPluginCommandTests method testBuiltinModule.

public void testBuiltinModule() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    String pluginZip = createPluginUrl("lang-painless", pluginDir);
    UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
    assertTrue(e.getMessage(), e.getMessage().contains("is a system module"));
    assertInstallCleaned(env.v2());
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) UserException(org.opensearch.cli.UserException)

Example 13 with UserException

use of org.opensearch.cli.UserException in project OpenSearch by opensearch-project.

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.opensearch.cli.UserException)

Example 14 with UserException

use of org.opensearch.cli.UserException in project OpenSearch by opensearch-project.

the class RemoveSettingKeyStoreCommandTests method testMissing.

public void testMissing() {
    String password = "keystorepassword";
    terminal.addSecretInput(password);
    UserException e = expectThrows(UserException.class, () -> execute("foo"));
    assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
    assertThat(e.getMessage(), containsString("keystore not found"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) UserException(org.opensearch.cli.UserException)

Example 15 with UserException

use of org.opensearch.cli.UserException in project OpenSearch by opensearch-project.

the class RemoveSettingKeyStoreCommandTests method testNoSettings.

public void testNoSettings() throws Exception {
    String password = "keystorepassword";
    createKeystore(password);
    terminal.addSecretInput(password);
    UserException e = expectThrows(UserException.class, this::execute);
    assertEquals(ExitCodes.USAGE, e.exitCode);
    assertThat(e.getMessage(), containsString("Must supply at least one setting"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) UserException(org.opensearch.cli.UserException)

Aggregations

UserException (org.opensearch.cli.UserException)76 Path (java.nio.file.Path)44 Matchers.containsString (org.hamcrest.Matchers.containsString)38 Environment (org.opensearch.env.Environment)29 Matchers.hasToString (org.hamcrest.Matchers.hasToString)25 TestEnvironment (org.opensearch.env.TestEnvironment)25 IOException (java.io.IOException)16 Settings (org.opensearch.common.settings.Settings)16 ArrayList (java.util.ArrayList)12 BufferedReader (java.io.BufferedReader)11 Files (java.nio.file.Files)11 MockTerminal (org.opensearch.cli.MockTerminal)11 OpenSearchTestCase (org.opensearch.test.OpenSearchTestCase)11 InputStream (java.io.InputStream)10 List (java.util.List)10 Collectors (java.util.stream.Collectors)10 Terminal (org.opensearch.cli.Terminal)10 Tuple (org.opensearch.common.collect.Tuple)10 StringReader (java.io.StringReader)9 URL (java.net.URL)9