From: David ‘Bombe’ Roden Date: Mon, 13 Jul 2015 19:02:10 +0000 (+0200) Subject: Add method to remove peer by identity X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=722c2e534b560da777f87e025d320667ef8ae1d9;p=jFCPlib.git Add method to remove peer by identity --- diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommand.java b/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommand.java index 02b0d44..cd43adb 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommand.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommand.java @@ -8,5 +8,6 @@ package net.pterodactylus.fcp.quelaton; public interface RemovePeerCommand { Executable byName(String name); + Executable byIdentity(String nodeIdentity); } diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommandImpl.java index 9578477..6b791e8 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommandImpl.java @@ -36,6 +36,12 @@ public class RemovePeerCommandImpl implements RemovePeerCommand { return this::execute; } + @Override + public Executable byIdentity(String nodeIdentity) { + nodeIdentifier.set(nodeIdentity); + return this::execute; + } + private ListenableFuture execute() { return threadPool.submit(this::executeDialog); } diff --git a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java index c1d09ea..eb0e193 100644 --- a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java @@ -1593,4 +1593,25 @@ public class DefaultFcpClientTest { assertThat(peer.get(), is(true)); } + @Test + public void defaultFcpClientCanRemovePeerByIdentity() throws InterruptedException, ExecutionException, IOException { + Future peer = fcpClient.removePeer().byIdentity("id1").execute(); + connectNode(); + List 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)); + } + }