Add hamcrest matchers
[jFCPlib.git] / test / main / java / net / pterodactylus / fcp / FcpTest.java
1 /*
2  * jFCPlib - FcpTest.java - Copyright © 2008 David Roden
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18
19 package net.pterodactylus.fcp;
20
21 import java.io.IOException;
22
23 import junit.framework.TestCase;
24
25 /**
26  * Tests various commands and the FCP connection.
27  *
28  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
29  */
30 public class FcpTest extends TestCase {
31
32         /** The FCP connection. */
33         private FcpConnection fcpConnection;
34
35         /**
36          * {@inheritDoc}
37          */
38         @Override
39         protected void setUp() throws Exception {
40                 fcpConnection = new FcpConnection("wing");
41                 fcpConnection.connect();
42                 fcpConnection.sendMessage(new ClientHello("FcpTest"));
43         }
44
45         /**
46          * {@inheritDoc}
47          */
48         @Override
49         protected void tearDown() throws Exception {
50                 fcpConnection.close();
51         }
52
53         /**
54          * Tests the FCP connection be simply {@link #setUp() setting it up} and
55          * {@link #tearDown() tearing it down} again.
56          */
57         public void testFcpConnection() {
58                 /* do nothing. */
59         }
60
61         /**
62          * Generates an SSK key pair.
63          *
64          * @throws IOException
65          *             if an I/O error occurs
66          * @throws InterruptedException
67          *             if {@link Object#wait()} wakes up spuriously
68          */
69         public void testGenerateSSK() throws IOException, InterruptedException {
70                 final SSKKeypair[] keypair = new SSKKeypair[1];
71                 FcpAdapter fcpAdapter = new FcpAdapter() {
72
73                         /**
74                          * {@inheritDoc}
75                          */
76                         @Override
77                         public void receivedSSKKeypair(FcpConnection fcpConnection, SSKKeypair sskKeypair) {
78                                 keypair[0] = sskKeypair;
79                                 synchronized (this) {
80                                         notify();
81                                 }
82                         }
83                 };
84                 fcpConnection.addFcpListener(fcpAdapter);
85                 synchronized (fcpAdapter) {
86                         fcpConnection.sendMessage(new GenerateSSK());
87                         fcpAdapter.wait();
88                 }
89                 assertNotNull("ssk keypair", keypair[0]);
90         }
91
92 }