1 package net.pterodactylus.fcp.quelaton;
3 import static org.hamcrest.MatcherAssert.assertThat;
4 import static org.hamcrest.Matchers.is;
6 import java.io.IOException;
7 import java.util.concurrent.ExecutionException;
8 import java.util.concurrent.ExecutorService;
9 import java.util.concurrent.Executors;
10 import java.util.concurrent.Future;
12 import net.pterodactylus.fcp.FcpKeyPair;
13 import net.pterodactylus.fcp.fake.FakeTcpServer;
15 import org.junit.After;
16 import org.junit.Test;
19 * Unit test for {@link DefaultFcpClient}.
21 * @author <a href="bombe@freenetproject.org">David ‘Bombe’ Roden</a>
23 public class DefaultFcpClientTest {
25 private static final String INSERT_URI = "SSK@RVCHbJdkkyTCeNN9AYukEg76eyqmiosSaNKgE3U9zUw,7SHH53gletBVb9JD7nBsyClbLQsBubDPEIcwg908r7Y,AQECAAE/";
26 private static final String REQUEST_URI = "SSK@wtbgd2loNcJCXvtQVOftl2tuWBomDQHfqS6ytpPRhfw,7SHH53gletBVb9JD7nBsyClbLQsBubDPEIcwg908r7Y,AQACAAE/";
28 private final ExecutorService threadPool = Executors.newCachedThreadPool();
29 private final FakeTcpServer fcpServer;
30 private final DefaultFcpClient fcpClient;
32 public DefaultFcpClientTest() throws IOException {
33 fcpServer = new FakeTcpServer(threadPool);
34 fcpClient = new DefaultFcpClient(threadPool, "localhost", fcpServer.getPort(), () -> "Test", () -> "2.0");
38 public void tearDown() throws IOException {
43 public void defaultFcpClientCanGenerateKeypair() throws ExecutionException, InterruptedException, IOException {
44 Future<FcpKeyPair> keyPairFuture = fcpClient.generateKeypair().execute();
46 fcpServer.collectUntil(is("EndMessage"));
47 fcpServer.writeLine("SSKKeypair",
48 "InsertURI=" + INSERT_URI + "",
49 "RequestURI=" + REQUEST_URI + "",
50 "Identifier=My Identifier from GenerateSSK",
52 FcpKeyPair keyPair = keyPairFuture.get();
53 assertThat(keyPair.getPublicKey(), is(REQUEST_URI));
54 assertThat(keyPair.getPrivateKey(), is(INSERT_URI));
57 private void connectNode() throws InterruptedException, ExecutionException, IOException {
58 fcpServer.connect().get();
59 fcpServer.collectUntil(is("EndMessage"));
60 fcpServer.writeLine("NodeHello",
61 "CompressionCodecs=4 - GZIP(0), BZIP2(1), LZMA(2), LZMA_NEW(3)",
62 "Revision=build01466",
64 "Version=Fred,0.7,1.0,1466",
66 "ConnectionIdentifier=14318898267048452a81b36e7f13a3f0",
70 "NodeLanguage=ENGLISH",