Add test that protocol error ends AddPeer command
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 15 Oct 2015 05:17:57 +0000 (07:17 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 15 Oct 2015 05:17:57 +0000 (07:17 +0200)
src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java

index f7823d6..8adf900 100644 (file)
@@ -215,6 +215,14 @@ public class DefaultFcpClientTest {
                assertThat(lines, requestMatcher.get());
        }
 
+       private void replyWithProtocolError() throws IOException {
+               fcpServer.writeLine(
+                       "ProtocolError",
+                       "Identifier=" + identifier,
+                       "EndMessage"
+               );
+       }
+
        public class ConnectionsAndKeyPairs {
 
                public class Connections {
@@ -438,6 +446,14 @@ public class DefaultFcpClientTest {
                                        assertThat(peer.get().get().getIdentity(), is("id1"));
                                }
 
+                               @Test
+                               public void protocolErrorEndsCommand() throws InterruptedException, ExecutionException, IOException {
+                                       Future<Optional<Peer>> peer = fcpClient.addPeer().fromFile(new File("/tmp/ref.txt")).execute();
+                                       connectAndAssert(() -> allOf(matchesAddPeer(), hasItem("File=/tmp/ref.txt")));
+                                       replyWithProtocolError();
+                                       assertThat(peer.get().isPresent(), is(false));
+                               }
+
                                private NodeRef createNodeRef() {
                                        NodeRef nodeRef = new NodeRef();
                                        nodeRef.setIdentity("id1");
@@ -974,14 +990,6 @@ public class DefaultFcpClientTest {
 
                }
 
-               private void replyWithProtocolError() throws IOException {
-                       fcpServer.writeLine(
-                               "ProtocolError",
-                               "Identifier=" + identifier,
-                               "EndMessage"
-                       );
-               }
-
                public class ReloadPlugin {
 
                        @Test