From: David ‘Bombe’ Roden Date: Tue, 14 Jul 2015 20:01:36 +0000 (+0200) Subject: Add method to include the defaults in the config X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=dc9905f91a2c4d45acc0a7c90e87ed768ce6d3be;p=jFCPlib.git Add method to include the defaults in the config --- 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")); + } + }