From dc9905f91a2c4d45acc0a7c90e87ed768ce6d3be Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 14 Jul 2015 22:01:36 +0200 Subject: [PATCH] Add method to include the defaults in the config --- .../fcp/quelaton/GetConfigCommand.java | 1 + .../fcp/quelaton/GetConfigCommandImpl.java | 8 ++++++++ .../fcp/quelaton/DefaultFcpClientTest.java | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommand.java b/src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommand.java index 608baba..7ae47b5 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommand.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommand.java @@ -10,5 +10,6 @@ import net.pterodactylus.fcp.ConfigData; public interface GetConfigCommand extends Executable { GetConfigCommand withCurrent(); + GetConfigCommand withDefaults(); } diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommandImpl.java index dc4deb8..6e91c00 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommandImpl.java @@ -23,6 +23,7 @@ public class GetConfigCommandImpl implements GetConfigCommand { 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); @@ -36,6 +37,12 @@ public class GetConfigCommandImpl implements GetConfigCommand { } @Override + public GetConfigCommand withDefaults() { + withDefaults.set(true); + return this; + } + + @Override public ListenableFuture execute() { return threadPool.submit(this::executeDialog); } @@ -43,6 +50,7 @@ public class GetConfigCommandImpl implements GetConfigCommand { 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(); } diff --git a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java index 20fe23f..8fe4774 100644 --- a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java @@ -1810,4 +1810,26 @@ public class DefaultFcpClientTest { assertThat(configData.get().getCurrent("foo"), is("bar")); } + @Test + public void defaultFcpClientCanGetConfigWithDefaults() + throws InterruptedException, ExecutionException, IOException { + Future configData = fcpClient.getConfig().withDefaults().execute(); + connectNode(); + List 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")); + } + } -- 2.7.4