From a04b60f09eb2e6c4a7264db26789740ddb6e0637 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 13 Jul 2015 19:52:13 +0200 Subject: [PATCH] Add method to modify peers by host name and port number --- .../fcp/quelaton/ModifyPeerCommand.java | 1 + .../fcp/quelaton/ModifyPeerCommandImpl.java | 6 ++++++ .../fcp/quelaton/DefaultFcpClientTest.java | 24 ++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java index 7037e3b..09f01ec 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java @@ -16,5 +16,6 @@ public interface ModifyPeerCommand { Executable> byName(String name); Executable> byIdentity(String nodeIdentity); + Executable> byHostAndPort(String host, int port); } diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java index 50d780f..189e2e2 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java @@ -56,6 +56,12 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand { return this::execute; } + @Override + public Executable> byHostAndPort(String host, int port) { + nodeIdentifier.set(String.format("%s:%d", host, port)); + return this::execute; + } + private ListenableFuture> execute() { return threadPool.submit(this::executeSequence); } diff --git a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java index b0b50ae..39d2c6a 100644 --- a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java @@ -1311,4 +1311,28 @@ public class DefaultFcpClientTest { assertThat(peer.get().get().getIdentity(), is("id1")); } + @Test + public void defaultFcpClientCanEnablePeerByHostAndPort() + throws InterruptedException, ExecutionException, IOException { + Future> peer = fcpClient.modifyPeer().enable().byHostAndPort("1.2.3.4", 5678).execute(); + connectNode(); + List lines = fcpServer.collectUntil(is("EndMessage")); + String identifier = extractIdentifier(lines); + assertThat(lines, matchesFcpMessage( + "ModifyPeer", + "Identifier=" + identifier, + "NodeIdentifier=1.2.3.4:5678", + "IsDisabled=false", + "EndMessage" + )); + fcpServer.writeLine( + "Peer", + "Identifier=" + identifier, + "NodeIdentifier=Friend1", + "identity=id1", + "EndMessage" + ); + assertThat(peer.get().get().getIdentity(), is("id1")); + } + } -- 2.7.4