Add test for protocol error when reloading plugin
[jFCPlib.git] / src / test / java / net / pterodactylus / fcp / quelaton / DefaultFcpClientTest.java
index f7823d6..b21e15e 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
@@ -1022,6 +1030,15 @@ public class DefaultFcpClientTest {
                                verifyPluginInfo(pluginInfo);
                        }
 
+                       @Test
+                       public void protocolErrorIsRecognizedAsFailure()
+                       throws InterruptedException, ExecutionException, IOException {
+                               Future<Optional<PluginInfo>> pluginInfo = fcpClient.reloadPlugin().plugin(CLASS_NAME).execute();
+                               connectAndAssert(() -> matchReloadPluginMessage());
+                               replyWithProtocolError();
+                               assertThat(pluginInfo.get().isPresent(), is(false));
+                       }
+
                        private Matcher<List<String>> matchReloadPluginMessage() {
                                return matchesFcpMessage(
                                        "ReloadPlugin",