Clean up duplicate test
[jFCPlib.git] / src / test / java / net / pterodactylus / fcp / quelaton / DefaultFcpClientTest.java
index 3374556..32837dd 100644 (file)
@@ -88,29 +88,6 @@ public class DefaultFcpClientTest {
                threadPool.shutdown();
        }
 
-       @Test(expected = ExecutionException.class)
-       public void defaultFcpClientThrowsExceptionIfItCanNotConnect()
-       throws IOException, ExecutionException, InterruptedException {
-               Future<FcpKeyPair> keyPairFuture = fcpClient.generateKeypair().execute();
-               fcpServer.connect().get();
-               fcpServer.collectUntil(is("EndMessage"));
-               fcpServer.writeLine(
-                       "CloseConnectionDuplicateClientName",
-                       "EndMessage"
-               );
-               keyPairFuture.get();
-       }
-
-       @Test(expected = ExecutionException.class)
-       public void defaultFcpClientThrowsExceptionIfConnectionIsClosed()
-       throws IOException, ExecutionException, InterruptedException {
-               Future<FcpKeyPair> keyPairFuture = fcpClient.generateKeypair().execute();
-               fcpServer.connect().get();
-               fcpServer.collectUntil(is("EndMessage"));
-               fcpServer.close();
-               keyPairFuture.get();
-       }
-
        private void connectNode() throws InterruptedException, ExecutionException, IOException {
                fcpServer.connect().get();
                fcpServer.collectUntil(is("EndMessage"));
@@ -130,30 +107,6 @@ public class DefaultFcpClientTest {
                );
        }
 
-       @Test
-       public void clientGetCanDownloadData() throws InterruptedException, ExecutionException, IOException {
-               Future<Optional<Data>> dataFuture = fcpClient.clientGet().uri("KSK@foo.txt").execute();
-               connectNode();
-               List<String> lines = fcpServer.collectUntil(is("EndMessage"));
-               assertThat(lines, matchesFcpMessage("ClientGet", "ReturnType=direct", "URI=KSK@foo.txt"));
-               String identifier = extractIdentifier(lines);
-               fcpServer.writeLine(
-                       "AllData",
-                       "Identifier=" + identifier,
-                       "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)));
-       }
-
        private String extractIdentifier(List<String> lines) {
                return lines.stream()
                        .filter(s -> s.startsWith("Identifier="))
@@ -961,6 +914,29 @@ public class DefaultFcpClientTest {
                assertThat(lines, requestMatcher.get());
        }
 
+       public class Connections {
+
+               @Test(expected = ExecutionException.class)
+               public void throwsExceptionOnFailure() throws IOException, ExecutionException, InterruptedException {
+                       Future<FcpKeyPair> keyPairFuture = fcpClient.generateKeypair().execute();
+                       connectAndAssert(() -> matchesFcpMessage("GenerateSSK"));
+                       fcpServer.writeLine(
+                               "CloseConnectionDuplicateClientName",
+                               "EndMessage"
+                       );
+                       keyPairFuture.get();
+               }
+
+               @Test(expected = ExecutionException.class)
+               public void throwsExceptionIfConnectionIsClosed() throws IOException, ExecutionException, InterruptedException {
+                       Future<FcpKeyPair> keyPairFuture = fcpClient.generateKeypair().execute();
+                       connectAndAssert(() -> matchesFcpMessage("GenerateSSK"));
+                       fcpServer.close();
+                       keyPairFuture.get();
+               }
+
+       }
+
        public class GenerateKeyPair {
 
                @Test