@Test public void withoutCliArgsAllConfigIsSetFromTomlFile() throws Exception { dataDirectory = Paths.get("data"); Files.createDirectory(dataDirectory); Path alwaysSendTo1 = Files.createFile(dataDirectory.resolve("alwayssendto1")); Files.write( alwaysSendTo1, ("/+UuD63zItL1EbjxkKUljMgG8Z1w0AJ8pNOR4iq2yQc=\n" + "jWKqelS4XjJ67JBbuKE7x9CVGFJ706wRYy/ev/OCOzk=") .getBytes()); Path alwaysSendTo2 = Files.createFile(dataDirectory.resolve("alwayssendto2")); Files.write(alwaysSendTo2, "yGcjkFyZklTTXrn8+WIkYwicA2EGBn9wZFkctAad4X0=".getBytes()); Path sampleFile = Paths.get(getClass().getResource("/sample-toml-no-nulls.conf").toURI()); Map<String, Object> params = new HashMap<>(); params.put("alwaysSendToPath1", "alwayssendto1"); params.put("alwaysSendToPath2", "alwayssendto2"); String data = ElUtil.process(new String(Files.readAllBytes(sampleFile)), params); Path configFile = Files.createTempFile("noOptions", ".txt"); Files.write(configFile, data.getBytes()); commandLine.execute("--tomlfile", configFile.toString()); final CliResult result = commandLine.getExecutionResult(); assertThat(result).isNotNull(); assertThat(result.getConfig()).isPresent(); final Config config = result.getConfig().get(); final ServerConfig p2pServer = config.getP2PServerConfig(); final SslConfig sslConfig = p2pServer.getSslConfig(); assertThat(p2pServer.getServerAddress()).isEqualTo("http: assertThat(p2pServer.getBindingAddress()).isEqualTo("http: assertThat(this.getUnixSocketServerAddress(config)) .isEqualTo("unix:" + Paths.get("data/constellation.ipc").toAbsolutePath()); assertThat(config.getPeers()) .hasSize(2) .extracting("url") .containsExactlyInAnyOrder("http: assertThat(config.getKeys().getKeyData()) .hasSize(2) .extracting("publicKeyPath", "privateKeyPath") .containsExactlyInAnyOrder( Tuple.tuple(Paths.get("data/foo.pub"), Paths.get("data/foo.key")), Tuple.tuple(Paths.get("data/foo2.pub"), Paths.get("data/foo2.key"))); assertThat(config.getAlwaysSendTo()) .hasSize(3) .containsExactlyInAnyOrder( "/+UuD63zItL1EbjxkKUljMgG8Z1w0AJ8pNOR4iq2yQc=", "jWKqelS4XjJ67JBbuKE7x9CVGFJ706wRYy/ev/OCOzk=", "yGcjkFyZklTTXrn8+WIkYwicA2EGBn9wZFkctAad4X0="); assertThat(config.getKeys().getPasswordFile().toString()).isEqualTo("data/passwords"); assertThat(config.getJdbcConfig().getUrl()).isEqualTo("jdbc:h2:mem:tessera"); assertThat(config.isUseWhiteList()).isTrue(); assertThat(sslConfig.getTls()).isEqualByComparingTo(SslAuthenticationMode.STRICT); assertThat(sslConfig.getServerTlsCertificatePath().toString()).isEqualTo("data/tls-server-cert.pem"); assertThat(sslConfig.getServerTrustCertificates()) .hasSize(2) .containsExactlyInAnyOrder(Paths.get("data/chain1"), Paths.get("data/chain2")); assertThat(sslConfig.getServerTlsKeyPath().toString()).isEqualTo("data/tls-server-key.pem"); assertThat(sslConfig.getServerTrustMode()).isEqualByComparingTo(SslTrustMode.TOFU); assertThat(sslConfig.getKnownClientsFile().toString()).isEqualTo("data/tls-known-clients"); assertThat(sslConfig.getClientTlsCertificatePath().toString()).isEqualTo("data/tls-client-cert.pem"); assertThat(sslConfig.getClientTrustCertificates()) .hasSize(2) .containsExactlyInAnyOrder(Paths.get("data/clientchain1"), Paths.get("data/clientchain2")); assertThat(sslConfig.getClientTlsKeyPath().toString()).isEqualTo("data/tls-client-key.pem"); assertThat(sslConfig.getClientTrustMode()).isEqualByComparingTo(SslTrustMode.CA_OR_TOFU); assertThat(sslConfig.getKnownServersFile().toString()).isEqualTo("data/tls-known-servers"); }
@Override public CliResult execute(String... args) throws Exception { final ConfigBuilder configBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(stream -> this.configFactory.create(stream, null)) .orElse(ConfigBuilder.create()); final KeyDataBuilder keyDataBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(configFactory::createKeyDataBuilder) .orElse(KeyDataBuilder.create()); ConfigBuilder adjustedConfig = applyOverrides(configBuilder, keyDataBuilder); Config config = adjustedConfig.build(); return writeToOutputFile(config, outputPath); }
LegacyCliAdapter implements CliAdapter, Callable<CliResult> { @Override public CliResult execute(String... args) throws Exception { final ConfigBuilder configBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(stream -> this.configFactory.create(stream, null)) .orElse(ConfigBuilder.create()); final KeyDataBuilder keyDataBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(configFactory::createKeyDataBuilder) .orElse(KeyDataBuilder.create()); ConfigBuilder adjustedConfig = applyOverrides(configBuilder, keyDataBuilder); Config config = adjustedConfig.build(); return writeToOutputFile(config, outputPath); } }
LegacyCliAdapter implements CliAdapter, Callable<CliResult> { @Override public CliResult execute(String... args) throws Exception { final ConfigBuilder configBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(stream -> this.configFactory.create(stream, null)) .orElse(ConfigBuilder.create()); final KeyDataBuilder keyDataBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(configFactory::createKeyDataBuilder) .orElse(KeyDataBuilder.create()); ConfigBuilder adjustedConfig = applyOverrides(configBuilder, keyDataBuilder); Config config = adjustedConfig.build(); return writeToOutputFile(config, outputPath); } LegacyCliAdapter(); }
LegacyCliAdapter implements CliAdapter, Callable<CliResult> { @Override public CliResult execute(String... args) throws Exception { final ConfigBuilder configBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(stream -> this.configFactory.create(stream, null)) .orElse(ConfigBuilder.create()); final KeyDataBuilder keyDataBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(configFactory::createKeyDataBuilder) .orElse(KeyDataBuilder.create()); ConfigBuilder adjustedConfig = applyOverrides(configBuilder, keyDataBuilder); Config config = adjustedConfig.build(); return writeToOutputFile(config, outputPath); } LegacyCliAdapter(); @Override CliType getType(); @Override CliResult call(); @Override CliResult execute(String... args); void setOverrides(final LegacyOverridesMixin overrides); }
LegacyCliAdapter implements CliAdapter, Callable<CliResult> { @Override public CliResult execute(String... args) throws Exception { final ConfigBuilder configBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(stream -> this.configFactory.create(stream, null)) .orElse(ConfigBuilder.create()); final KeyDataBuilder keyDataBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(configFactory::createKeyDataBuilder) .orElse(KeyDataBuilder.create()); ConfigBuilder adjustedConfig = applyOverrides(configBuilder, keyDataBuilder); Config config = adjustedConfig.build(); return writeToOutputFile(config, outputPath); } LegacyCliAdapter(); @Override CliType getType(); @Override CliResult call(); @Override CliResult execute(String... args); void setOverrides(final LegacyOverridesMixin overrides);  }