From b7618a3c0254a1af2e59ac0f432fd5bafb585b3d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 2 Jul 2015 07:33:27 +0200 Subject: [PATCH] Add tests that the identifier is correctly used --- .../fcp/quelaton/DefaultFcpClientTest.java | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) 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(); -- 2.7.4