From: David ‘Bombe’ Roden Date: Thu, 15 Oct 2015 20:11:18 +0000 (+0200) Subject: Add test for protocol error on ClientPutDiskDir X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=872b858bdb4fd4bfadf50491567d0dd5207851b4;p=jFCPlib.git Add test for protocol error on ClientPutDiskDir --- 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")); + ); } }