Add method to modify peer note by host and port
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Tue, 14 Jul 2015 19:25:56 +0000 (21:25 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Tue, 14 Jul 2015 19:25:56 +0000 (21:25 +0200)
src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerNoteCommand.java
src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerNoteCommandImpl.java
src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java

index 690671f..ee76487 100644 (file)
@@ -11,5 +11,6 @@ public interface ModifyPeerNoteCommand {
 
        Executable<Boolean> byName(String name);
        Executable<Boolean> byIdentifier(String identifier);
+       Executable<Boolean> byHostAndPort(String host, int port);
 
 }
index ecb4ed9..6e6dcc2 100644 (file)
@@ -55,6 +55,12 @@ public class ModifyPeerNoteCommandImpl implements ModifyPeerNoteCommand {
                return this::execute;
        }
 
+       @Override
+       public Executable<Boolean> byHostAndPort(String host, int port) {
+               nodeIdentifier.set(String.format("%s:%d", host, port));
+               return this::execute;
+       }
+
        private ListenableFuture<Boolean> execute() {
                if (darknetComment.get() == null) {
                        return Futures.immediateFuture(false);
index 4781101..fbfff9e 100644 (file)
@@ -1740,4 +1740,31 @@ public class DefaultFcpClientTest {
                assertThat(noteUpdated.get(), is(true));
        }
 
+       @Test
+       public void defaultFcpClientCanModifyPeerNoteByHostAndPort()
+       throws InterruptedException, ExecutionException, IOException {
+               Future<Boolean> noteUpdated =
+                       fcpClient.modifyPeerNote().darknetComment("foo").byHostAndPort("1.2.3.4", 5678).execute();
+               connectNode();
+               List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+               String identifier = extractIdentifier(lines);
+               assertThat(lines, matchesFcpMessage(
+                       "ModifyPeerNote",
+                       "Identifier=" + identifier,
+                       "NodeIdentifier=1.2.3.4:5678",
+                       "PeerNoteType=1",
+                       "NoteText=Zm9v",
+                       "EndMessage"
+               ));
+               fcpServer.writeLine(
+                       "PeerNote",
+                       "Identifier=" + identifier,
+                       "NodeIdentifier=1.2.3.4:5678",
+                       "NoteText=Zm9v",
+                       "PeerNoteType=1",
+                       "EndMessage"
+               );
+               assertThat(noteUpdated.get(), is(true));
+       }
+
 }