Search in sources :

Example 6 with CliResult

use of com.quorum.tessera.cli.CliResult in project tessera by ConsenSys.

the class PicoCliDelegateTest method legacyConfigOverride.

@Test
public void legacyConfigOverride() throws Exception {
    Path configFile = Paths.get(getClass().getResource("/sample-config.json").toURI());
    CliResult result = cliDelegate.execute("-configfile", configFile.toString(), "-jdbc.autoCreateTables", "true", "-useWhiteList", "true");
    assertThat(result).isNotNull();
    assertThat(result.getConfig()).isPresent();
    assertThat(result.getStatus()).isEqualTo(0);
    assertThat(result.isSuppressStartup()).isFalse();
    Config config = result.getConfig().get();
    assertThat(config.getJdbcConfig()).isNotNull();
    assertThat(config.getJdbcConfig().isAutoCreateTables()).isTrue();
    assertThat(config.isUseWhiteList()).isTrue();
}
Also used : Path(java.nio.file.Path) CliResult(com.quorum.tessera.cli.CliResult) KeyDataConfig(com.quorum.tessera.config.KeyDataConfig) Config(com.quorum.tessera.config.Config) Test(org.junit.Test)

Example 7 with CliResult

use of com.quorum.tessera.cli.CliResult in project tessera by ConsenSys.

the class PicoCliDelegateTest method help.

@Test
public void help() throws Exception {
    final CliResult result = cliDelegate.execute("help");
    final String sysout = systemOutOutput.getLog();
    final String syserr = systemErrOutput.getLog();
    assertThat(result).isNotNull();
    assertThat(result.getConfig()).isNotPresent();
    assertThat(result.getStatus()).isEqualTo(0);
    assertThat(result.isSuppressStartup()).isTrue();
    assertThat(syserr).isEmpty();
    assertThat(sysout).isNotEmpty();
    assertThat(sysout).contains("Usage: tessera [OPTIONS] [COMMAND]", "Description:", "Options:", "Commands:");
}
Also used : CliResult(com.quorum.tessera.cli.CliResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 8 with CliResult

use of com.quorum.tessera.cli.CliResult in project tessera by ConsenSys.

the class PicoCliDelegateTest method keygenHelp.

@Test
public void keygenHelp() throws Exception {
    final CliResult result = cliDelegate.execute("keygen", "help");
    final String sysout = systemOutOutput.getLog();
    final String syserr = systemErrOutput.getLog();
    assertThat(result).isNotNull();
    assertThat(result.getConfig()).isNotPresent();
    assertThat(result.getStatus()).isEqualTo(0);
    assertThat(result.isSuppressStartup()).isTrue();
    assertThat(syserr).isEmpty();
    assertThat(sysout).isNotEmpty();
    assertThat(sysout).contains("Usage: tessera keygen [OPTIONS] [COMMAND]", "Description:", "Options:", "Commands:");
}
Also used : CliResult(com.quorum.tessera.cli.CliResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 9 with CliResult

use of com.quorum.tessera.cli.CliResult in project tessera by ConsenSys.

the class PicoCliDelegateTest method keygenThenExit.

@Test
public void keygenThenExit() throws Exception {
    FilesystemKeyPair keypair = mock(FilesystemKeyPair.class);
    when(keyGenerator.generate(anyString(), eq(null), eq(null))).thenReturn(keypair);
    final CliResult result = cliDelegate.execute("-keygen", "--encryptor.type", "NACL");
    assertThat(result).isNotNull();
    assertThat(result.isSuppressStartup()).isTrue();
    verify(keyGenerator).generate(anyString(), eq(null), eq(null));
}
Also used : FilesystemKeyPair(com.quorum.tessera.config.keypairs.FilesystemKeyPair) CliResult(com.quorum.tessera.cli.CliResult) Test(org.junit.Test)

Example 10 with CliResult

use of com.quorum.tessera.cli.CliResult in project tessera by ConsenSys.

the class PicoCliDelegateTest method configOverride.

// @Test
// public void keygenFileUpdateOptionsRequireConfigfile() {
// 
// FilesystemKeyPair keypair = mock(FilesystemKeyPair.class);
// when(keyGenerator.generate(anyString(), eq(null), eq(null))).thenReturn(keypair);
// 
// Throwable ex = catchThrowable(() -> cliDelegate.execute("-keygen", "-output",
// "somepath"));
// 
// assertThat(ex).isNotNull();
// assertThat(ex).isExactlyInstanceOf(CliException.class);
// assertThat(ex.getMessage()).contains("Missing required argument(s):
// --configfile=<config>");
// }
@Test
public void configOverride() throws Exception {
    Path configFile = Paths.get(getClass().getResource("/sample-config.json").toURI());
    CliResult result = cliDelegate.execute("-configfile", configFile.toString(), "-o", "jdbc.autoCreateTables=true", "-o", "useWhiteList=true");
    assertThat(result).isNotNull();
    assertThat(result.getConfig()).isPresent();
    assertThat(result.getConfig().get().getJdbcConfig().isAutoCreateTables()).isTrue();
    assertThat(result.getConfig().get().isUseWhiteList()).isTrue();
}
Also used : Path(java.nio.file.Path) CliResult(com.quorum.tessera.cli.CliResult) Test(org.junit.Test)

Aggregations

CliResult (com.quorum.tessera.cli.CliResult)38 Test (org.junit.Test)29 Path (java.nio.file.Path)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 CommandLine (picocli.CommandLine)9 CliException (com.quorum.tessera.cli.CliException)7 ConstraintViolationException (jakarta.validation.ConstraintViolationException)7 FilesystemKeyPair (com.quorum.tessera.config.keypairs.FilesystemKeyPair)6 Config (com.quorum.tessera.config.Config)5 ConfigConverter (com.quorum.tessera.cli.parsers.ConfigConverter)4 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)4 KeyDataConfig (com.quorum.tessera.config.KeyDataConfig)3 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)3 ConstraintViolation (jakarta.validation.ConstraintViolation)3 UncheckedIOException (java.io.UncheckedIOException)3 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)3 HashMap (java.util.HashMap)3 Enclave (com.quorum.tessera.enclave.Enclave)2 EnclaveCliAdapter (com.quorum.tessera.enclave.server.EnclaveCliAdapter)2 TesseraServer (com.quorum.tessera.server.TesseraServer)2