From: David ‘Bombe’ Roden Date: Tue, 14 Jul 2015 19:58:04 +0000 (+0200) Subject: Add method to get the current values from the config X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=0cbff2edec655d3db4a1730c32483da952879494;p=jFCPlib.git Add method to get the current values from 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 2f36436..608baba 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommand.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommand.java @@ -9,4 +9,6 @@ import net.pterodactylus.fcp.ConfigData; */ public interface GetConfigCommand extends Executable { + GetConfigCommand withCurrent(); + } diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommandImpl.java index 2876661..dc4deb8 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommandImpl.java @@ -3,6 +3,7 @@ package net.pterodactylus.fcp.quelaton; import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import net.pterodactylus.fcp.ConfigData; @@ -21,6 +22,7 @@ public class GetConfigCommandImpl implements GetConfigCommand { private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; + private final AtomicBoolean withCurrent = new AtomicBoolean(); public GetConfigCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); @@ -28,12 +30,19 @@ public class GetConfigCommandImpl implements GetConfigCommand { } @Override + public GetConfigCommand withCurrent() { + withCurrent.set(true); + return this; + } + + @Override public ListenableFuture execute() { return threadPool.submit(this::executeDialog); } private ConfigData executeDialog() throws IOException, ExecutionException, InterruptedException { GetConfig getConfig = new GetConfig(new RandomIdentifierGenerator().generate()); + getConfig.setWithCurrent(withCurrent.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 664588c..20fe23f 100644 --- a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java @@ -1788,4 +1788,26 @@ public class DefaultFcpClientTest { assertThat(configData.get(), notNullValue()); } + @Test + public void defaultFcpClientCanGetConfigWithCurrent() + throws InterruptedException, ExecutionException, IOException { + Future configData = fcpClient.getConfig().withCurrent().execute(); + connectNode(); + List lines = fcpServer.collectUntil(is("EndMessage")); + String identifier = extractIdentifier(lines); + assertThat(lines, matchesFcpMessage( + "GetConfig", + "Identifier=" + identifier, + "WithCurrent=true", + "EndMessage" + )); + fcpServer.writeLine( + "ConfigData", + "Identifier=" + identifier, + "current.foo=bar", + "EndMessage" + ); + assertThat(configData.get().getCurrent("foo"), is("bar")); + } + }