Add method to include the defaults in the config
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Tue, 14 Jul 2015 20:01:36 +0000 (22:01 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Tue, 14 Jul 2015 20:04:39 +0000 (22:04 +0200)
src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommand.java
src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommandImpl.java
src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java

index 608baba..7ae47b5 100644 (file)
@@ -10,5 +10,6 @@ import net.pterodactylus.fcp.ConfigData;
 public interface GetConfigCommand extends Executable<ConfigData> {
 
        GetConfigCommand withCurrent();
+       GetConfigCommand withDefaults();
 
 }
index dc4deb8..6e91c00 100644 (file)
@@ -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<ConfigData> 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();
                }
index 20fe23f..8fe4774 100644 (file)
@@ -1810,4 +1810,26 @@ public class DefaultFcpClientTest {
                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"));
+       }
+
 }