simplify creation of payload input stream
[jSite2.git] / src / net / pterodactylus / util / fcp / FcpTest.java
index cedce1d..c17dadc 100644 (file)
 package net.pterodactylus.util.fcp;
 
 import java.io.IOException;
-import java.util.List;
-import java.util.Map;
 
 import junit.framework.TestCase;
 
-
 /**
- * TODO
+ * Tests various commands and the FCP connection.
+ * 
  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
  * @version $Id$
  */
 public class FcpTest extends TestCase {
 
+       /** The FCP connection. */
        private FcpConnection fcpConnection;
-       
+
        /**
         * {@inheritDoc}
         */
        @Override
        protected void setUp() throws Exception {
-               fcpConnection = new FcpConnection("wing", "FcpTest");
+               fcpConnection = new FcpConnection("wing");
                fcpConnection.connect();
+               fcpConnection.sendMessage(new ClientHello("FcpTest"));
        }
-       
+
        /**
         * {@inheritDoc}
         */
@@ -51,32 +51,44 @@ public class FcpTest extends TestCase {
        protected void tearDown() throws Exception {
                fcpConnection.disconnect();
        }
-       
-       public void testFcpConnection() throws FcpException, IOException {
-       }
-       
-       public void testListPeers() throws FcpException, IOException {
-               List<Map<String, String>> peers = fcpConnection.sendListPeers(true, true);
-               for (Map<String, String> peer: peers) {
-                       for (Map.Entry<String, String> entry: peer.entrySet()) {
-                               System.out.println(entry.getKey() + ": " + entry.getValue());
-                       }
-               }
+
+       /**
+        * Tests the FCP connection be simply {@link #setUp() setting it up} and
+        * {@link #tearDown() tearing it down} again.
+        */
+       public void testFcpConnection() {
+               /* do nothing. */
        }
-       
-       public void testListPeerNotes() throws FcpException, IOException {
-               List<Map<String, String>> peers = fcpConnection.sendListPeerNotes("AY6rGAGjayoyQD2CkvQibf1Ct3mh6iwqyntzNpfRsiM");
-               for (Map<String, String> peer: peers) {
-                       for (Map.Entry<String, String> entry: peer.entrySet()) {
-                               System.out.println(entry.getKey() + ": " + entry.getValue());
+
+       /**
+        * Generates an SSK key pair.
+        * 
+        * @throws IOException
+        *             if an I/O error occurs
+        * @throws InterruptedException
+        *             if {@link Object#wait()} wakes up spuriously
+        */
+       public void testGenerateSSK() throws IOException, InterruptedException {
+               final SSKKeypair[] keypair = new SSKKeypair[1];
+               FcpAdapter fcpAdapter = new FcpAdapter() {
+
+                       /**
+                        * {@inheritDoc}
+                        */
+                       @Override
+                       public void receivedSSKKeypair(FcpConnection fcpConnection, SSKKeypair sskKeypair) {
+                               keypair[0] = sskKeypair;
+                               synchronized (this) {
+                                       notify();
+                               }
                        }
+               };
+               fcpConnection.addFcpListener(fcpAdapter);
+               synchronized (fcpAdapter) {
+                       fcpConnection.sendMessage(new GenerateSSK());
+                       fcpAdapter.wait();
                }
+               assertNotNull("ssk keypair", keypair[0]);
        }
-       
-       public void testGenerateSSK() throws IOException, FcpException {
-               FcpKeyPair keyPair = fcpConnection.generateSSK();
-               System.out.println("PrivateKey: " + keyPair.getPrivateKey());
-               System.out.println("PublicKey: " + keyPair.getPublicKey());
-       }
-       
+
 }