Add method to clear listen only on a peer
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 13 Jul 2015 18:30:31 +0000 (20:30 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 13 Jul 2015 18:30:31 +0000 (20:30 +0200)
src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java
src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java
src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java

index ef00205..d421ae1 100644 (file)
@@ -18,6 +18,7 @@ public interface ModifyPeerCommand {
        ModifyPeerCommand setBurstOnly();
        ModifyPeerCommand clearBurstOnly();
        ModifyPeerCommand setListenOnly();
+       ModifyPeerCommand clearListenOnly();
 
        Executable<Optional<Peer>> byName(String name);
        Executable<Optional<Peer>> byIdentity(String nodeIdentity);
index 58d750d..6877245 100644 (file)
@@ -78,6 +78,12 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand {
        }
 
        @Override
+       public ModifyPeerCommand clearListenOnly() {
+               listenOnly.set(false);
+               return this;
+       }
+
+       @Override
        public Executable<Optional<Peer>> byName(String name) {
                nodeIdentifier.set(name);
                return this::execute;
index 8da2967..c87e47a 100644 (file)
@@ -1466,4 +1466,31 @@ public class DefaultFcpClientTest {
                assertThat(peer.get().get().getIdentity(), is("id1"));
        }
 
+       @Test
+       public void defaultFcpClientCanClearListenOnlyForPeer()
+       throws InterruptedException, ExecutionException, IOException {
+               Future<Optional<Peer>> peer = fcpClient.modifyPeer().clearListenOnly().byIdentity("id1").execute();
+               connectNode();
+               List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+               String identifier = extractIdentifier(lines);
+               assertThat(lines, matchesFcpMessage(
+                       "ModifyPeer",
+                       "Identifier=" + identifier,
+                       "NodeIdentifier=id1",
+                       "IsListenOnly=false",
+                       "EndMessage"
+               ));
+               assertThat(lines, not(contains(startsWith("AllowLocalAddresses="))));
+               assertThat(lines, not(contains(startsWith("IsDisabled="))));
+               assertThat(lines, not(contains(startsWith("IsBurstOnly="))));
+               fcpServer.writeLine(
+                       "Peer",
+                       "Identifier=" + identifier,
+                       "NodeIdentifier=Friend1",
+                       "identity=id1",
+                       "EndMessage"
+               );
+               assertThat(peer.get().get().getIdentity(), is("id1"));
+       }
+
 }