Add test for protocol error on ClientPutDiskDir
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 15 Oct 2015 20:11:18 +0000 (22:11 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 15 Oct 2015 21:23:52 +0000 (23:23 +0200)
src/main/java/net/pterodactylus/fcp/quelaton/ClientPutDiskDirCommandImpl.java
src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java

index 861522c..3a21922 100644 (file)
@@ -11,6 +11,7 @@ import java.util.function.Supplier;
 
 import net.pterodactylus.fcp.ClientPutDiskDir;
 import net.pterodactylus.fcp.Key;
+import net.pterodactylus.fcp.ProtocolError;
 import net.pterodactylus.fcp.PutSuccessful;
 
 import com.google.common.util.concurrent.ListeningExecutorService;
@@ -64,6 +65,11 @@ public class ClientPutDiskDirCommandImpl implements ClientPutDiskDirCommand {
                        setResult(Optional.of(new Key(putSuccessful.getURI())));
                }
 
+               @Override
+               protected void consumeProtocolError(ProtocolError protocolError) {
+                       finish();
+               }
+
        }
 
 }
index 0adb977..771cd25 100644 (file)
@@ -1642,14 +1642,26 @@ public class DefaultFcpClientTest {
                @Test
                public void commandIsSentCorrectly() throws InterruptedException, ExecutionException, IOException {
                        Future<Optional<Key>> key = fcpClient.clientPutDiskDir().fromDirectory(folder.getRoot()).uri("CHK@").execute();
-                       connectAndAssert(() -> matchesFcpMessage(
+                       connectAndAssert(this::matchesClientPutDiskDir);
+                       fcpServer.writeLine("PutSuccessful", "Identifier=" + identifier, "URI=CHK@abc", "EndMessage");
+                       assertThat(key.get().get().getKey(), is("CHK@abc"));
+               }
+
+               @Test
+               public void protocolErrorAbortsCommand() throws InterruptedException, ExecutionException, IOException {
+                       Future<Optional<Key>> key = fcpClient.clientPutDiskDir().fromDirectory(folder.getRoot()).uri("CHK@").execute();
+                       connectAndAssert(this::matchesClientPutDiskDir);
+                       replyWithProtocolError();
+                       assertThat(key.get().isPresent(), is(false));
+               }
+
+               private Matcher<List<String>> matchesClientPutDiskDir() {
+                       return matchesFcpMessage(
                                "ClientPutDiskDir",
                                "Identifier=" + identifier,
                                "URI=CHK@",
                                "Filename=" + folder.getRoot().getPath()
-                       ));
-                       fcpServer.writeLine("PutSuccessful", "Identifier=" + identifier, "URI=CHK@abc", "EndMessage");
-                       assertThat(key.get().get().getKey(), is("CHK@abc"));
+                       );
                }
 
        }