Add method to include data types in config data
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Tue, 14 Jul 2015 20:16:04 +0000 (22:16 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Tue, 14 Jul 2015 20:16:04 +0000 (22:16 +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 c937f2b..0df93c7 100644 (file)
@@ -16,5 +16,6 @@ public interface GetConfigCommand extends Executable<ConfigData> {
        GetConfigCommand withForceWriteFlag();
        GetConfigCommand withShortDescription();
        GetConfigCommand withLongDescription();
+       GetConfigCommand withDataTypes();
 
 }
index cc78f96..c2095b3 100644 (file)
@@ -29,6 +29,7 @@ public class GetConfigCommandImpl implements GetConfigCommand {
        private final AtomicBoolean withForceWriteFlag = new AtomicBoolean();
        private final AtomicBoolean withShortDescription = new AtomicBoolean();
        private final AtomicBoolean withLongDescription = new AtomicBoolean();
+       private final AtomicBoolean withDataTypes = new AtomicBoolean();
 
        public GetConfigCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
                this.threadPool = MoreExecutors.listeningDecorator(threadPool);
@@ -78,6 +79,12 @@ public class GetConfigCommandImpl implements GetConfigCommand {
        }
 
        @Override
+       public GetConfigCommand withDataTypes() {
+               withDataTypes.set(true);
+               return this;
+       }
+
+       @Override
        public ListenableFuture<ConfigData> execute() {
                return threadPool.submit(this::executeDialog);
        }
@@ -91,6 +98,7 @@ public class GetConfigCommandImpl implements GetConfigCommand {
                getConfig.setWithForceWriteFlag(withForceWriteFlag.get());
                getConfig.setWithShortDescription(withShortDescription.get());
                getConfig.setWithLongDescription(withLongDescription.get());
+               getConfig.setWithDataTypes(withDataTypes.get());
                try (GetConfigDialog getConfigDialog = new GetConfigDialog()) {
                        return getConfigDialog.send(getConfig).get();
                }
index 01c7175..88f25a8 100644 (file)
@@ -1942,4 +1942,26 @@ public class DefaultFcpClientTest {
                assertThat(configData.get().getLongDescription("foo"), is("bar"));
        }
 
+       @Test
+       public void defaultFcpClientCanGetConfigWithDataTypes()
+       throws InterruptedException, ExecutionException, IOException {
+               Future<ConfigData> configData = fcpClient.getConfig().withDataTypes().execute();
+               connectNode();
+               List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+               String identifier = extractIdentifier(lines);
+               assertThat(lines, matchesFcpMessage(
+                       "GetConfig",
+                       "Identifier=" + identifier,
+                       "WithDataTypes=true",
+                       "EndMessage"
+               ));
+               fcpServer.writeLine(
+                       "ConfigData",
+                       "Identifier=" + identifier,
+                       "dataType.foo=number",
+                       "EndMessage"
+               );
+               assertThat(configData.get().getDataType("foo"), is("number"));
+       }
+
 }