From 872b858bdb4fd4bfadf50491567d0dd5207851b4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 15 Oct 2015 22:11:18 +0200 Subject: [PATCH] Add test for protocol error on ClientPutDiskDir --- .../fcp/quelaton/ClientPutDiskDirCommandImpl.java | 6 ++++++ .../fcp/quelaton/DefaultFcpClientTest.java | 20 ++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ClientPutDiskDirCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/ClientPutDiskDirCommandImpl.java index 861522c..3a21922 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ClientPutDiskDirCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ClientPutDiskDirCommandImpl.java @@ -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(); + } + } } diff --git a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java index 0adb977..771cd25 100644 --- a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java @@ -1642,14 +1642,26 @@ public class DefaultFcpClientTest { @Test public void commandIsSentCorrectly() throws InterruptedException, ExecutionException, IOException { Future> 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> key = fcpClient.clientPutDiskDir().fromDirectory(folder.getRoot()).uri("CHK@").execute(); + connectAndAssert(this::matchesClientPutDiskDir); + replyWithProtocolError(); + assertThat(key.get().isPresent(), is(false)); + } + + private Matcher> 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")); + ); } } -- 2.7.4