private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
private final AtomicBoolean withCurrent = new AtomicBoolean();
+ private final AtomicBoolean withDefaults = new AtomicBoolean();
public GetConfigCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
}
@Override
+ public GetConfigCommand withDefaults() {
+ withDefaults.set(true);
+ return this;
+ }
+
+ @Override
public ListenableFuture<ConfigData> execute() {
return threadPool.submit(this::executeDialog);
}
private ConfigData executeDialog() throws IOException, ExecutionException, InterruptedException {
GetConfig getConfig = new GetConfig(new RandomIdentifierGenerator().generate());
getConfig.setWithCurrent(withCurrent.get());
+ getConfig.setWithDefaults(withDefaults.get());
try (GetConfigDialog getConfigDialog = new GetConfigDialog()) {
return getConfigDialog.send(getConfig).get();
}
assertThat(configData.get().getCurrent("foo"), is("bar"));
}
+ @Test
+ public void defaultFcpClientCanGetConfigWithDefaults()
+ throws InterruptedException, ExecutionException, IOException {
+ Future<ConfigData> configData = fcpClient.getConfig().withDefaults().execute();
+ connectNode();
+ List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+ String identifier = extractIdentifier(lines);
+ assertThat(lines, matchesFcpMessage(
+ "GetConfig",
+ "Identifier=" + identifier,
+ "WithDefaults=true",
+ "EndMessage"
+ ));
+ fcpServer.writeLine(
+ "ConfigData",
+ "Identifier=" + identifier,
+ "default.foo=bar",
+ "EndMessage"
+ );
+ assertThat(configData.get().getDefault("foo"), is("bar"));
+ }
+
}