Add method to modify peer note by node identifier
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Tue, 14 Jul 2015 19:19:02 +0000 (21:19 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Tue, 14 Jul 2015 19:19:38 +0000 (21:19 +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 713c8eb..690671f 100644 (file)
@@ -10,5 +10,6 @@ public interface ModifyPeerNoteCommand {
        ModifyPeerNoteCommand darknetComment(String text);
 
        Executable<Boolean> byName(String name);
+       Executable<Boolean> byIdentifier(String identifier);
 
 }
index 6b2ff71..ecb4ed9 100644 (file)
@@ -49,6 +49,12 @@ public class ModifyPeerNoteCommandImpl implements ModifyPeerNoteCommand {
                return this::execute;
        }
 
+       @Override
+       public Executable<Boolean> byIdentifier(String identifier) {
+               nodeIdentifier.set(identifier);
+               return this::execute;
+       }
+
        private ListenableFuture<Boolean> execute() {
                if (darknetComment.get() == null) {
                        return Futures.immediateFuture(false);
index e0b5a2e..4781101 100644 (file)
@@ -1714,4 +1714,30 @@ public class DefaultFcpClientTest {
                assertThat(noteUpdated.get(), is(false));
        }
 
+       @Test
+       public void defaultFcpClientCanModifyPeerNoteByIdentifier()
+       throws InterruptedException, ExecutionException, IOException {
+               Future<Boolean> noteUpdated = fcpClient.modifyPeerNote().darknetComment("foo").byIdentifier("id1").execute();
+               connectNode();
+               List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+               String identifier = extractIdentifier(lines);
+               assertThat(lines, matchesFcpMessage(
+                       "ModifyPeerNote",
+                       "Identifier=" + identifier,
+                       "NodeIdentifier=id1",
+                       "PeerNoteType=1",
+                       "NoteText=Zm9v",
+                       "EndMessage"
+               ));
+               fcpServer.writeLine(
+                       "PeerNote",
+                       "Identifier=" + identifier,
+                       "NodeIdentifier=id1",
+                       "NoteText=Zm9v",
+                       "PeerNoteType=1",
+                       "EndMessage"
+               );
+               assertThat(noteUpdated.get(), is(true));
+       }
+
 }