2 * jSite2 - FcpTest.java -
3 * Copyright © 2008 David Roden
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 package net.pterodactylus.util.fcp;
22 import java.io.IOException;
24 import junit.framework.TestCase;
25 import net.pterodactylus.util.fcp.message.ClientHello;
26 import net.pterodactylus.util.fcp.message.CloseConnectionDuplicateClientName;
27 import net.pterodactylus.util.fcp.message.GenerateSSK;
28 import net.pterodactylus.util.fcp.message.NodeHello;
31 * Tests various commands and the FCP connection.
33 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
36 public class FcpTest extends TestCase {
38 /** The FCP connection. */
39 private FcpConnection fcpConnection;
45 protected void setUp() throws Exception {
46 fcpConnection = new FcpConnection("wing");
47 fcpConnection.connect();
48 fcpConnection.sendMessage(new ClientHello("FcpTest"));
55 protected void tearDown() throws Exception {
56 fcpConnection.disconnect();
60 * Tests the FCP connection be simply {@link #setUp() setting it up} and
61 * {@link #tearDown() tearing it down} again.
63 * @throws FcpException
64 * if an FCP error occurs
66 * if an I/O error occurs
68 public void testFcpConnection() throws FcpException, IOException {
72 // public void testListPeers() throws FcpException, IOException {
73 // List<Map<String, String>> peers = fcpConnection.sendListPeers(true, true);
74 // for (Map<String, String> peer: peers) {
75 // for (Map.Entry<String, String> entry: peer.entrySet()) {
76 // System.out.println(entry.getKey() + ": " + entry.getValue());
81 // public void testListPeerNotes() throws FcpException, IOException {
82 // List<Map<String, String>> peers = fcpConnection.sendListPeerNotes("AY6rGAGjayoyQD2CkvQibf1Ct3mh6iwqyntzNpfRsiM");
83 // for (Map<String, String> peer: peers) {
84 // for (Map.Entry<String, String> entry: peer.entrySet()) {
85 // System.out.println(entry.getKey() + ": " + entry.getValue());
91 * Generates an SSK key pair.
93 * @throws FcpException
94 * if an FCP error occurs
96 * if an I/O error occurs
97 * @throws InterruptedException
98 * if {@link Object#wait()} wakes up spuriously
100 public void testGenerateSSK() throws IOException, FcpException, InterruptedException {
101 final boolean[] result = new boolean[1];
102 FcpAdapter fcpAdapter = new FcpAdapter() {
104 * @see net.pterodactylus.util.fcp.FcpAdapter#receivedNodeHello(net.pterodactylus.util.fcp.FcpConnection,
105 * net.pterodactylus.util.fcp.message.NodeHello)
108 public void receivedNodeHello(FcpConnection fcpConnection, NodeHello nodeHello) {
110 synchronized (this) {
116 * @see net.pterodactylus.util.fcp.FcpAdapter#receivedCloseConnectionDuplicateClientName(net.pterodactylus.util.fcp.FcpConnection,
117 * net.pterodactylus.util.fcp.message.CloseConnectionDuplicateClientName)
120 public void receivedCloseConnectionDuplicateClientName(FcpConnection fcpConnection, CloseConnectionDuplicateClientName closeConnectionDuplicateClientName) {
122 synchronized (this) {
127 synchronized (fcpAdapter) {
128 fcpConnection.sendMessage(new GenerateSSK());
131 assertTrue("received NodeHello", result[0]);