Search in sources :

Example 36 with CliResult

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

the class KeyGenCommandTest method onlyConfigWithKeysProvided.

@Test
public void onlyConfigWithKeysProvided() throws Exception {
    // given
    when(keyGeneratorFactory.create(eq(null), any(EncryptorConfig.class))).thenReturn(keyGenerator);
    CommandLine commandLine = new CommandLine(keyGenCommand);
    Config config = mock(Config.class);
    KeyConfiguration keyConfiguration = mock(KeyConfiguration.class);
    when(config.getKeys()).thenReturn(keyConfiguration);
    CommandLine.ITypeConverter<Config> configConverter = mock(CommandLine.ITypeConverter.class);
    when(configConverter.convert("myconfig.file")).thenReturn(config);
    commandLine.registerConverter(Config.class, configConverter);
    int exceptionExitCode = 999;
    List<Exception> exceptions = new ArrayList<>();
    commandLine.setExecutionExceptionHandler((ex, cmd, parseResult) -> {
        exceptions.add(ex);
        return exceptionExitCode;
    });
    int exitCode = commandLine.execute("--configfile=myconfig.file");
    assertThat(exitCode).isZero();
    assertThat(exceptions).isEmpty();
    verify(configConverter).convert("myconfig.file");
    CliResult result = commandLine.getExecutionResult();
    assertThat(result).isNotNull();
    assertThat(result.isSuppressStartup()).isTrue();
    assertThat(result.getStatus()).isZero();
    verifyNoMoreInteractions(configConverter);
    verify(keyGeneratorFactory).create(eq(null), any(EncryptorConfig.class));
    verify(configFileUpdaterWriter).updateAndWriteToCLI(anyList(), eq(null), any(Config.class));
    verify(keyDataMarshaller).marshal(null);
    verify(keyGenerator).generate("", null, null);
}
Also used : CommandLine(picocli.CommandLine) CliResult(com.quorum.tessera.cli.CliResult) ArrayList(java.util.ArrayList) ConstraintViolationException(jakarta.validation.ConstraintViolationException) CliException(com.quorum.tessera.cli.CliException) Test(org.junit.Test)

Example 37 with CliResult

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

the class VersionCommandTest method call.

@Test
public void call() {
    VersionCommand cmd = new VersionCommand();
    CliResult result = cmd.call();
    CliResult want = new CliResult(0, true, null);
    assertThat(result).isEqualToComparingFieldByField(want);
}
Also used : CliResult(com.quorum.tessera.cli.CliResult) Test(org.junit.Test)

Example 38 with CliResult

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

the class MigrationCliAdapter method execute.

@Override
public CliResult execute(String... args) {
    EntityManagerFactory primaryEntityManagerFactory = JdbcConfigUtil.entityManagerFactory(configPrimary.getJdbcConfig());
    EntityManagerFactory secondaryEntityManagerFactory = JdbcConfigUtil.entityManagerFactory(configSecondary.getJdbcConfig());
    // migrate raw
    new MigrationRunner(primaryEntityManagerFactory, secondaryEntityManagerFactory).run();
    return new CliResult(0, true, null);
}
Also used : CliResult(com.quorum.tessera.cli.CliResult) EntityManagerFactory(jakarta.persistence.EntityManagerFactory)

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