Add method to modify peers by host name and port number
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 13 Jul 2015 17:52:13 +0000 (19:52 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 13 Jul 2015 17:52:13 +0000 (19:52 +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 7037e3b..09f01ec 100644 (file)
@@ -16,5 +16,6 @@ public interface ModifyPeerCommand {
 
        Executable<Optional<Peer>> byName(String name);
        Executable<Optional<Peer>> byIdentity(String nodeIdentity);
+       Executable<Optional<Peer>> byHostAndPort(String host, int port);
 
 }
index 50d780f..189e2e2 100644 (file)
@@ -56,6 +56,12 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand {
                return this::execute;
        }
 
+       @Override
+       public Executable<Optional<Peer>> byHostAndPort(String host, int port) {
+               nodeIdentifier.set(String.format("%s:%d", host, port));
+               return this::execute;
+       }
+
        private ListenableFuture<Optional<Peer>> execute() {
                return threadPool.submit(this::executeSequence);
        }
index b0b50ae..39d2c6a 100644 (file)
@@ -1311,4 +1311,28 @@ public class DefaultFcpClientTest {
                assertThat(peer.get().get().getIdentity(), is("id1"));
        }
 
+       @Test
+       public void defaultFcpClientCanEnablePeerByHostAndPort()
+       throws InterruptedException, ExecutionException, IOException {
+               Future<Optional<Peer>> peer = fcpClient.modifyPeer().enable().byHostAndPort("1.2.3.4", 5678).execute();
+               connectNode();
+               List<String> 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"));
+       }
+
 }