Add tests that the identifier is correctly used
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 2 Jul 2015 05:33:27 +0000 (07:33 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 2 Jul 2015 05:33:27 +0000 (07:33 +0200)
src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java

index 5d7b441..4670828 100644 (file)
@@ -109,6 +109,44 @@ public class DefaultFcpClientTest {
        }
 
        @Test
+       public void clientGetDownloadsDataForCorrectIdentifier() throws InterruptedException, ExecutionException, IOException {
+               Future<Optional<Data>> dataFuture = fcpClient.clientGet().identifier("test").uri("KSK@foo.txt");
+               connectNode();
+               List<String> 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> 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<Optional<Data>> 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<Optional<Data>> dataFuture = fcpClient.clientGet().identifier("test").uri("KSK@foo.txt");
+               connectNode();
+               List<String> 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> data = dataFuture.get();
+               assertThat(data.isPresent(), is(false));
+       }
+
+       @Test
        public void clientGetRecognizesConnectionClosed() throws InterruptedException, ExecutionException, IOException {
                Future<Optional<Data>> dataFuture = fcpClient.clientGet().identifier("test").uri("KSK@foo.txt");
                connectNode();