Add method to modify peer by node identity
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 13 Jul 2015 17:37:44 +0000 (19:37 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 13 Jul 2015 17:37:44 +0000 (19:37 +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 4e83048..7037e3b 100644 (file)
@@ -15,5 +15,6 @@ public interface ModifyPeerCommand {
        ModifyPeerCommand disable();
 
        Executable<Optional<Peer>> byName(String name);
+       Executable<Optional<Peer>> byIdentity(String nodeIdentity);
 
 }
index 4bac846..50d780f 100644 (file)
@@ -50,6 +50,12 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand {
                return this::execute;
        }
 
+       @Override
+       public Executable<Optional<Peer>> byIdentity(String nodeIdentity) {
+               nodeIdentifier.set(nodeIdentity);
+               return this::execute;
+       }
+
        private ListenableFuture<Optional<Peer>> execute() {
                return threadPool.submit(this::executeSequence);
        }
index 2ac40bd..b0b50ae 100644 (file)
@@ -1288,4 +1288,27 @@ public class DefaultFcpClientTest {
                assertThat(peer.get().get().getIdentity(), is("id1"));
        }
 
+       @Test
+       public void defaultFcpClientCanEnablePeerByIdentity() throws InterruptedException, ExecutionException, IOException {
+               Future<Optional<Peer>> peer = fcpClient.modifyPeer().enable().byIdentity("id1").execute();
+               connectNode();
+               List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+               String identifier = extractIdentifier(lines);
+               assertThat(lines, matchesFcpMessage(
+                       "ModifyPeer",
+                       "Identifier=" + identifier,
+                       "NodeIdentifier=id1",
+                       "IsDisabled=false",
+                       "EndMessage"
+               ));
+               fcpServer.writeLine(
+                       "Peer",
+                       "Identifier=" + identifier,
+                       "NodeIdentifier=Friend1",
+                       "identity=id1",
+                       "EndMessage"
+               );
+               assertThat(peer.get().get().getIdentity(), is("id1"));
+       }
+
 }