From 80ee63c3eea721f3b0f536d5d812e34549332264 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 23 Aug 2015 16:58:25 +0200 Subject: [PATCH] Refactor generate key pair command test --- .../fcp/quelaton/DefaultFcpClientTest.java | 38 +++++++++++++--------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java index f423e97..abe32d5 100644 --- a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java @@ -110,22 +110,6 @@ public class DefaultFcpClientTest { keyPairFuture.get(); } - @Test - public void defaultFcpClientCanGenerateKeypair() throws ExecutionException, InterruptedException, IOException { - Future keyPairFuture = fcpClient.generateKeypair().execute(); - connectNode(); - List lines = fcpServer.collectUntil(is("EndMessage")); - String identifier = extractIdentifier(lines); - fcpServer.writeLine("SSKKeypair", - "InsertURI=" + INSERT_URI + "", - "RequestURI=" + REQUEST_URI + "", - "Identifier=" + identifier, - "EndMessage"); - FcpKeyPair keyPair = keyPairFuture.get(); - assertThat(keyPair.getPublicKey(), is(REQUEST_URI)); - assertThat(keyPair.getPrivateKey(), is(INSERT_URI)); - } - private void connectNode() throws InterruptedException, ExecutionException, IOException { fcpServer.connect().get(); fcpServer.collectUntil(is("EndMessage")); @@ -1070,6 +1054,28 @@ public class DefaultFcpClientTest { assertThat(lines, requestMatcher.get()); } + public class GenerateKeyPair { + + @Test + public void defaultFcpClientCanGenerateKeypair() throws ExecutionException, InterruptedException, IOException { + Future keyPairFuture = fcpClient.generateKeypair().execute(); + connectAndAssert(() ->matchesFcpMessage("GenerateSSK", "EndMessage")); + replyWithKeyPair(); + FcpKeyPair keyPair = keyPairFuture.get(); + assertThat(keyPair.getPublicKey(), is(REQUEST_URI)); + assertThat(keyPair.getPrivateKey(), is(INSERT_URI)); + } + + private void replyWithKeyPair() throws IOException { + fcpServer.writeLine("SSKKeypair", + "InsertURI=" + INSERT_URI + "", + "RequestURI=" + REQUEST_URI + "", + "Identifier=" + identifier, + "EndMessage"); + } + + } + public class Peers { public class PeerCommands { -- 2.7.4