Add method to remove peer by identity
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 13 Jul 2015 19:02:10 +0000 (21:02 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 13 Jul 2015 19:02:10 +0000 (21:02 +0200)
src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommand.java
src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommandImpl.java
src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java

index 02b0d44..cd43adb 100644 (file)
@@ -8,5 +8,6 @@ package net.pterodactylus.fcp.quelaton;
 public interface RemovePeerCommand {
 
        Executable<Boolean> byName(String name);
+       Executable<Boolean> byIdentity(String nodeIdentity);
 
 }
index 9578477..6b791e8 100644 (file)
@@ -36,6 +36,12 @@ public class RemovePeerCommandImpl implements RemovePeerCommand {
                return this::execute;
        }
 
+       @Override
+       public Executable<Boolean> byIdentity(String nodeIdentity) {
+               nodeIdentifier.set(nodeIdentity);
+               return this::execute;
+       }
+
        private ListenableFuture<Boolean> execute() {
                return threadPool.submit(this::executeDialog);
        }
index c1d09ea..eb0e193 100644 (file)
@@ -1593,4 +1593,25 @@ public class DefaultFcpClientTest {
                assertThat(peer.get(), is(true));
        }
 
+       @Test
+       public void defaultFcpClientCanRemovePeerByIdentity() throws InterruptedException, ExecutionException, IOException {
+               Future<Boolean> peer = fcpClient.removePeer().byIdentity("id1").execute();
+               connectNode();
+               List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+               String identifier = extractIdentifier(lines);
+               assertThat(lines, matchesFcpMessage(
+                       "RemovePeer",
+                       "Identifier=" + identifier,
+                       "NodeIdentifier=id1",
+                       "EndMessage"
+               ));
+               fcpServer.writeLine(
+                       "PeerRemoved",
+                       "Identifier=" + identifier,
+                       "NodeIdentifier=Friend1",
+                       "EndMessage"
+               );
+               assertThat(peer.get(), is(true));
+       }
+
 }