From: David ‘Bombe’ Roden Date: Thu, 2 Jul 2015 05:33:27 +0000 (+0200) Subject: Add tests that the identifier is correctly used X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=b7618a3c0254a1af2e59ac0f432fd5bafb585b3d;p=jFCPlib.git Add tests that the identifier is correctly used --- diff --git a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java index 5d7b441..4670828 100644 --- a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java @@ -109,6 +109,44 @@ public class DefaultFcpClientTest { } @Test + public void clientGetDownloadsDataForCorrectIdentifier() throws InterruptedException, ExecutionException, IOException { + Future> dataFuture = fcpClient.clientGet().identifier("test").uri("KSK@foo.txt"); + connectNode(); + List lines = fcpServer.collectUntil(is("EndMessage")); + assertThat(lines, containsInAnyOrder( + "ClientGet", + "Identifier=test", + "ReturnType=direct", + "URI=KSK@foo.txt", + "EndMessage" + )); + fcpServer.writeLine( + "AllData", + "Identifier=not-test", + "DataLength=12", + "StartupTime=1435610539000", + "CompletionTime=1435610540000", + "Metadata.ContentType=text/plain;charset=latin-9", + "Data", + "Hello World" + ); + fcpServer.writeLine( + "AllData", + "Identifier=test", + "DataLength=6", + "StartupTime=1435610539000", + "CompletionTime=1435610540000", + "Metadata.ContentType=text/plain;charset=utf-8", + "Data", + "Hello" + ); + Optional data = dataFuture.get(); + assertThat(data.get().getMimeType(), is("text/plain;charset=utf-8")); + assertThat(data.get().size(), is(6L)); + assertThat(ByteStreams.toByteArray(data.get().getInputStream()), is("Hello\n".getBytes(StandardCharsets.UTF_8))); + } + + @Test public void clientGetRecognizesGetFailed() throws InterruptedException, ExecutionException, IOException { Future> dataFuture = fcpClient.clientGet().identifier("test").uri("KSK@foo.txt"); connectNode(); @@ -131,6 +169,34 @@ public class DefaultFcpClientTest { } @Test + public void clientGetRecognizesGetFailedForCorrectIdentifier() throws InterruptedException, ExecutionException, IOException { + Future> dataFuture = fcpClient.clientGet().identifier("test").uri("KSK@foo.txt"); + connectNode(); + List lines = fcpServer.collectUntil(is("EndMessage")); + assertThat(lines, containsInAnyOrder( + "ClientGet", + "Identifier=test", + "ReturnType=direct", + "URI=KSK@foo.txt", + "EndMessage" + )); + fcpServer.writeLine( + "GetFailed", + "Identifier=not-test", + "Code=3", + "EndMessage" + ); + fcpServer.writeLine( + "GetFailed", + "Identifier=test", + "Code=3", + "EndMessage" + ); + Optional data = dataFuture.get(); + assertThat(data.isPresent(), is(false)); + } + + @Test public void clientGetRecognizesConnectionClosed() throws InterruptedException, ExecutionException, IOException { Future> dataFuture = fcpClient.clientGet().identifier("test").uri("KSK@foo.txt"); connectNode();