mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
Use dedicated classes for transport properties and configs.
This commit is contained in:
@@ -16,6 +16,7 @@ import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.crypto.CryptoComponent;
|
||||
import net.sf.briar.api.protocol.Ack;
|
||||
import net.sf.briar.api.protocol.Author;
|
||||
@@ -75,7 +76,7 @@ public class ProtocolIntegrationTest extends TestCase {
|
||||
private final Message message, message1, message2, message3;
|
||||
private final String authorName = "Alice";
|
||||
private final String messageBody = "Hello world";
|
||||
private final Map<TransportId, Map<String, String>> transports;
|
||||
private final Map<TransportId, TransportProperties> transports;
|
||||
|
||||
public ProtocolIntegrationTest() throws Exception {
|
||||
super();
|
||||
@@ -116,8 +117,9 @@ public class ProtocolIntegrationTest extends TestCase {
|
||||
message3 = messageEncoder.encodeMessage(null, group1,
|
||||
groupKeyPair.getPrivate(), author, authorKeyPair.getPrivate(),
|
||||
messageBody.getBytes("UTF-8"));
|
||||
transports = Collections.singletonMap(transportId,
|
||||
Collections.singletonMap("bar", "baz"));
|
||||
TransportProperties p =
|
||||
new TransportProperties(Collections.singletonMap("bar", "baz"));
|
||||
transports = Collections.singletonMap(transportId, p);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -10,7 +10,9 @@ import junit.framework.TestCase;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.Rating;
|
||||
import net.sf.briar.api.TransportConfig;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.db.DatabaseComponent;
|
||||
import net.sf.briar.api.db.DatabaseListener;
|
||||
import net.sf.briar.api.db.DatabaseListener.Event;
|
||||
@@ -54,8 +56,8 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
private final Message message, privateMessage;
|
||||
private final Group group;
|
||||
private final TransportId transportId;
|
||||
private final Map<TransportId, Map<String, String>> transports;
|
||||
private final Map<TransportId, Map<ContactId, Map<String, String>>>
|
||||
private final Map<TransportId, TransportProperties> transports;
|
||||
private final Map<TransportId, Map<ContactId, TransportProperties>>
|
||||
remoteTransports;
|
||||
private final byte[] secret;
|
||||
|
||||
@@ -76,10 +78,11 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
new TestMessage(messageId, null, null, null, timestamp, raw);
|
||||
group = new TestGroup(groupId, "The really exciting group", null);
|
||||
transportId = new TransportId(123);
|
||||
Map<String, String> properties = Collections.singletonMap("foo", "bar");
|
||||
transports = Collections.singletonMap(transportId, properties);
|
||||
TransportProperties p =
|
||||
new TransportProperties(Collections.singletonMap("foo", "bar"));
|
||||
transports = Collections.singletonMap(transportId, p);
|
||||
remoteTransports = Collections.singletonMap(transportId,
|
||||
Collections.singletonMap(contactId, properties));
|
||||
Collections.singletonMap(contactId, p));
|
||||
secret = new byte[123];
|
||||
}
|
||||
|
||||
@@ -1271,10 +1274,10 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
@Test
|
||||
public void testTransportPropertiesChangedCallsListeners()
|
||||
throws Exception {
|
||||
final Map<String, String> properties =
|
||||
Collections.singletonMap("bar", "baz");
|
||||
final Map<String, String> properties1 =
|
||||
Collections.singletonMap("baz", "bam");
|
||||
final TransportProperties properties =
|
||||
new TransportProperties(Collections.singletonMap("bar", "baz"));
|
||||
final TransportProperties properties1 =
|
||||
new TransportProperties(Collections.singletonMap("baz", "bam"));
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
@@ -1302,8 +1305,8 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
@Test
|
||||
public void testTransportPropertiesUnchangedDoesNotCallListeners()
|
||||
throws Exception {
|
||||
final Map<String, String> properties =
|
||||
Collections.singletonMap("bar", "baz");
|
||||
final TransportProperties properties =
|
||||
new TransportProperties(Collections.singletonMap("bar", "baz"));
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
@@ -1327,10 +1330,10 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testTransportConfigChangedCallsListeners() throws Exception {
|
||||
final Map<String, String> config =
|
||||
Collections.singletonMap("bar", "baz");
|
||||
final Map<String, String> config1 =
|
||||
Collections.singletonMap("baz", "bam");
|
||||
final TransportConfig config =
|
||||
new TransportConfig(Collections.singletonMap("bar", "baz"));
|
||||
final TransportConfig config1 =
|
||||
new TransportConfig(Collections.singletonMap("baz", "bam"));
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
@@ -1356,8 +1359,8 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
@Test
|
||||
public void testTransportConfigUnchangedDoesNotCallListeners()
|
||||
throws Exception {
|
||||
final Map<String, String> config =
|
||||
Collections.singletonMap("bar", "baz");
|
||||
final TransportConfig config =
|
||||
new TransportConfig(Collections.singletonMap("bar", "baz"));
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
|
||||
@@ -21,7 +21,9 @@ import net.sf.briar.TestDatabaseModule;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.Rating;
|
||||
import net.sf.briar.api.TransportConfig;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.crypto.Password;
|
||||
import net.sf.briar.api.db.DbException;
|
||||
import net.sf.briar.api.db.Status;
|
||||
@@ -71,8 +73,8 @@ public class H2DatabaseTest extends TestCase {
|
||||
private final Message message, privateMessage;
|
||||
private final Group group;
|
||||
private final TransportId transportId;
|
||||
private final Map<TransportId, Map<String, String>> transports;
|
||||
private final Map<TransportId, Map<ContactId, Map<String, String>>>
|
||||
private final Map<TransportId, TransportProperties> transports;
|
||||
private final Map<TransportId, Map<ContactId, TransportProperties>>
|
||||
remoteTransports;
|
||||
private final Map<Group, Long> subscriptions;
|
||||
private final byte[] secret;
|
||||
@@ -100,10 +102,11 @@ public class H2DatabaseTest extends TestCase {
|
||||
new TestMessage(privateMessageId, null, null, null, timestamp, raw);
|
||||
group = groupFactory.createGroup(groupId, "Group name", null);
|
||||
transportId = new TransportId(0);
|
||||
Map<String, String> properties = Collections.singletonMap("foo", "bar");
|
||||
transports = Collections.singletonMap(transportId, properties);
|
||||
TransportProperties p =
|
||||
new TransportProperties(Collections.singletonMap("foo", "bar"));
|
||||
transports = Collections.singletonMap(transportId, p);
|
||||
remoteTransports = Collections.singletonMap(transportId,
|
||||
Collections.singletonMap(contactId, properties));
|
||||
Collections.singletonMap(contactId, p));
|
||||
subscriptions = Collections.singletonMap(group, 0L);
|
||||
secret = new byte[123];
|
||||
}
|
||||
@@ -988,9 +991,10 @@ public class H2DatabaseTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testUpdateTransportProperties() throws Exception {
|
||||
Map<String, String> properties = Collections.singletonMap("foo", "bar");
|
||||
Map<String, String> properties1 =
|
||||
Collections.singletonMap("baz", "bam");
|
||||
TransportProperties properties =
|
||||
new TransportProperties(Collections.singletonMap("foo", "bar"));
|
||||
TransportProperties properties1 =
|
||||
new TransportProperties(Collections.singletonMap("baz", "bam"));
|
||||
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
@@ -1001,12 +1005,12 @@ public class H2DatabaseTest extends TestCase {
|
||||
|
||||
// Replace the transport properties
|
||||
TransportId transportId1 = new TransportId(1);
|
||||
Map<TransportId, Map<String, String>> transports1 =
|
||||
new TreeMap<TransportId, Map<String, String>>();
|
||||
Map<TransportId, TransportProperties> transports1 =
|
||||
new TreeMap<TransportId, TransportProperties>();
|
||||
transports1.put(transportId, properties);
|
||||
transports1.put(transportId1, properties1);
|
||||
Map<TransportId, Map<ContactId, Map<String, String>>> remoteTransports1
|
||||
= new TreeMap<TransportId, Map<ContactId, Map<String, String>>>();
|
||||
Map<TransportId, Map<ContactId, TransportProperties>> remoteTransports1
|
||||
= new TreeMap<TransportId, Map<ContactId, TransportProperties>>();
|
||||
remoteTransports1.put(transportId, Collections.singletonMap(contactId,
|
||||
properties));
|
||||
remoteTransports1.put(transportId1, Collections.singletonMap(contactId,
|
||||
@@ -1016,19 +1020,18 @@ public class H2DatabaseTest extends TestCase {
|
||||
|
||||
// Remove the transport properties
|
||||
db.setTransports(txn, contactId,
|
||||
Collections.<TransportId, Map<String, String>>emptyMap(), 2);
|
||||
Collections.<TransportId, TransportProperties>emptyMap(), 2);
|
||||
assertEquals(Collections.emptyMap(), db.getRemoteTransports(txn));
|
||||
|
||||
// Set the local transport properties
|
||||
for(Entry<TransportId, Map<String, String>> e : transports.entrySet()) {
|
||||
for(Entry<TransportId, TransportProperties> e : transports.entrySet()) {
|
||||
db.setTransportProperties(txn, e.getKey(), e.getValue());
|
||||
}
|
||||
assertEquals(transports, db.getLocalTransports(txn));
|
||||
|
||||
// Remove the local transport properties
|
||||
for(TransportId t : transports.keySet()) {
|
||||
db.setTransportProperties(txn, t,
|
||||
Collections.<String, String>emptyMap());
|
||||
db.setTransportProperties(txn, t, new TransportProperties());
|
||||
}
|
||||
assertEquals(Collections.emptyMap(), db.getLocalTransports(txn));
|
||||
|
||||
@@ -1039,8 +1042,10 @@ public class H2DatabaseTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testUpdateTransportConfig() throws Exception {
|
||||
Map<String, String> config = Collections.singletonMap("foo", "bar");
|
||||
Map<String, String> config1 = Collections.singletonMap("baz", "bam");
|
||||
TransportConfig config =
|
||||
new TransportConfig(Collections.singletonMap("foo", "bar"));
|
||||
TransportConfig config1 =
|
||||
new TransportConfig(Collections.singletonMap("baz", "bam"));
|
||||
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
@@ -1054,8 +1059,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
assertEquals(config1, db.getTransportConfig(txn, transportId));
|
||||
|
||||
// Remove the transport config
|
||||
db.setTransportConfig(txn, transportId,
|
||||
Collections.<String, String>emptyMap());
|
||||
db.setTransportConfig(txn, transportId, new TransportConfig());
|
||||
assertEquals(Collections.emptyMap(),
|
||||
db.getTransportConfig(txn, transportId));
|
||||
|
||||
@@ -1065,11 +1069,12 @@ public class H2DatabaseTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testTransportsNotUpdatedIfTimestampIsOld() throws Exception {
|
||||
Map<String, String> properties = Collections.singletonMap("foo", "bar");
|
||||
Map<String, String> properties1 =
|
||||
Collections.singletonMap("baz", "bam");
|
||||
Map<String, String> properties2 =
|
||||
Collections.singletonMap("quux", "etc");
|
||||
TransportProperties properties =
|
||||
new TransportProperties(Collections.singletonMap("foo", "bar"));
|
||||
TransportProperties properties1 =
|
||||
new TransportProperties(Collections.singletonMap("baz", "bam"));
|
||||
TransportProperties properties2 =
|
||||
new TransportProperties(Collections.singletonMap("quux", "etc"));
|
||||
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
@@ -1080,12 +1085,12 @@ public class H2DatabaseTest extends TestCase {
|
||||
|
||||
// Replace the transport properties using a timestamp of 2
|
||||
TransportId transportId1 = new TransportId(1);
|
||||
Map<TransportId, Map<String, String>> transports1 =
|
||||
new TreeMap<TransportId, Map<String, String>>();
|
||||
Map<TransportId, TransportProperties> transports1 =
|
||||
new TreeMap<TransportId, TransportProperties>();
|
||||
transports1.put(transportId, properties);
|
||||
transports1.put(transportId1, properties1);
|
||||
Map<TransportId, Map<ContactId, Map<String, String>>> remoteTransports1
|
||||
= new TreeMap<TransportId, Map<ContactId, Map<String, String>>>();
|
||||
Map<TransportId, Map<ContactId, TransportProperties>> remoteTransports1
|
||||
= new TreeMap<TransportId, Map<ContactId, TransportProperties>>();
|
||||
remoteTransports1.put(transportId, Collections.singletonMap(contactId,
|
||||
properties));
|
||||
remoteTransports1.put(transportId1, Collections.singletonMap(contactId,
|
||||
@@ -1095,8 +1100,8 @@ public class H2DatabaseTest extends TestCase {
|
||||
|
||||
// Try to replace the transport properties using a timestamp of 1
|
||||
TransportId transportId2 = new TransportId(2);
|
||||
Map<TransportId, Map<String, String>> transports2 =
|
||||
new TreeMap<TransportId, Map<String, String>>();
|
||||
Map<TransportId, TransportProperties> transports2 =
|
||||
new TreeMap<TransportId, TransportProperties>();
|
||||
transports2.put(transportId1, properties1);
|
||||
transports2.put(transportId2, properties2);
|
||||
db.setTransports(txn, contactId, transports2, 1);
|
||||
|
||||
@@ -10,6 +10,8 @@ import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.db.DatabaseComponent;
|
||||
import net.sf.briar.api.db.DbException;
|
||||
import net.sf.briar.api.invitation.InvitationCallback;
|
||||
@@ -107,8 +109,11 @@ public class InvitationWorkerTest extends TestCase {
|
||||
|
||||
private void testInstallerCreation(final boolean createExe,
|
||||
final boolean createJar) throws IOException, DbException {
|
||||
final Map<String, String> transports =
|
||||
Collections.singletonMap("foo", "bar");
|
||||
TransportProperties properties =
|
||||
new TransportProperties(Collections.singletonMap("foo", "bar"));
|
||||
TransportId transportId = new TransportId(123);
|
||||
final Map<TransportId, TransportProperties> transports =
|
||||
Collections.singletonMap(transportId, properties);
|
||||
final File setup = new File(testDir, "setup.dat");
|
||||
TestUtils.createFile(setup, "foo bar baz");
|
||||
final File invitation = new File(testDir, "invitation.dat");
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package net.sf.briar.plugins;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.plugins.StreamTransportCallback;
|
||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
||||
|
||||
public class StubStreamCallback implements StreamTransportCallback {
|
||||
|
||||
public Map<String, String> localProperties = null;
|
||||
public volatile int incomingConnections = 0;
|
||||
|
||||
public void setLocalProperties(Map<String, String> properties) {
|
||||
localProperties = properties;
|
||||
}
|
||||
|
||||
public void setConfig(Map<String, String> config) {
|
||||
}
|
||||
|
||||
public void showMessage(String... message) {
|
||||
}
|
||||
|
||||
public boolean showConfirmationMessage(String... message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int showChoice(String[] choices, String... message) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void incomingConnectionCreated(StreamTransportConnection c) {
|
||||
incomingConnections++;
|
||||
}
|
||||
|
||||
public void outgoingConnectionCreated(ContactId contactId,
|
||||
StreamTransportConnection c) {
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
package net.sf.briar.plugins.bluetooth;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportConfig;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.plugins.StreamTransportCallback;
|
||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
||||
import net.sf.briar.plugins.ImmediateExecutor;
|
||||
@@ -24,16 +24,16 @@ public class BluetoothClientTest {
|
||||
System.exit(1);
|
||||
}
|
||||
ContactId contactId = new ContactId(0);
|
||||
Map<String, String> localProperties = Collections.emptyMap();
|
||||
Map<ContactId, Map<String, String>> remoteProperties =
|
||||
new HashMap<ContactId, Map<String, String>>();
|
||||
Map<String, String> config = Collections.emptyMap();
|
||||
TransportProperties localProperties = new TransportProperties();
|
||||
Map<ContactId, TransportProperties> remoteProperties =
|
||||
new HashMap<ContactId, TransportProperties>();
|
||||
TransportConfig config = new TransportConfig();
|
||||
StreamTransportCallback callback = new ClientCallback();
|
||||
// Store the server's Bluetooth address and UUID
|
||||
Map<String, String> properties = new TreeMap<String, String>();
|
||||
properties.put("address", args[0]);
|
||||
properties.put("uuid", BluetoothServerTest.UUID);
|
||||
remoteProperties.put(contactId, properties);
|
||||
TransportProperties p = new TransportProperties();
|
||||
p.put("address", args[0]);
|
||||
p.put("uuid", BluetoothServerTest.UUID);
|
||||
remoteProperties.put(contactId, p);
|
||||
// Create the plugin
|
||||
BluetoothPlugin plugin =
|
||||
new BluetoothPlugin(new ImmediateExecutor(), callback, 0L);
|
||||
@@ -66,9 +66,9 @@ public class BluetoothClientTest {
|
||||
|
||||
private static class ClientCallback implements StreamTransportCallback {
|
||||
|
||||
public void setLocalProperties(Map<String, String> properties) {}
|
||||
public void setLocalProperties(TransportProperties p) {}
|
||||
|
||||
public void setConfig(Map<String, String> config) {}
|
||||
public void setConfig(TransportConfig c) {}
|
||||
|
||||
public void showMessage(String... message) {}
|
||||
|
||||
|
||||
@@ -5,9 +5,10 @@ import java.io.PrintStream;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportConfig;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.plugins.StreamTransportCallback;
|
||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
||||
import net.sf.briar.plugins.ImmediateExecutor;
|
||||
@@ -20,10 +21,10 @@ public class BluetoothServerTest {
|
||||
public static final String CHALLENGE = "Potatoes!";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Map<String, String> localProperties = Collections.emptyMap();
|
||||
Map<ContactId, Map<String, String>> remoteProperties =
|
||||
TransportProperties localProperties = new TransportProperties();
|
||||
Map<ContactId, TransportProperties> remoteProperties =
|
||||
Collections.emptyMap();
|
||||
Map<String, String> config = new TreeMap<String, String>();
|
||||
TransportConfig config = new TransportConfig();
|
||||
StreamTransportCallback callback = new ServerCallback();
|
||||
// Store the UUID
|
||||
config.put("uuid", UUID);
|
||||
@@ -45,9 +46,9 @@ public class BluetoothServerTest {
|
||||
|
||||
private static class ServerCallback implements StreamTransportCallback {
|
||||
|
||||
public void setLocalProperties(Map<String, String> properties) {}
|
||||
public void setLocalProperties(TransportProperties p) {}
|
||||
|
||||
public void setConfig(Map<String, String> config) {}
|
||||
public void setConfig(TransportConfig c) {}
|
||||
|
||||
public void showMessage(String... message) {}
|
||||
|
||||
|
||||
@@ -8,12 +8,13 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportConfig;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.plugins.BatchTransportCallback;
|
||||
import net.sf.briar.api.transport.BatchTransportWriter;
|
||||
import net.sf.briar.api.transport.TransportConstants;
|
||||
@@ -31,16 +32,16 @@ public class RemovableDrivePluginTest extends TestCase {
|
||||
private final File testDir = TestUtils.getTestDirectory();
|
||||
private final ContactId contactId = new ContactId(0);
|
||||
|
||||
private Map<String, String> localProperties = null;
|
||||
private Map<ContactId, Map<String, String>> remoteProperties = null;
|
||||
private Map<String, String> config = null;
|
||||
private TransportProperties localProperties = null;
|
||||
private Map<ContactId, TransportProperties> remoteProperties = null;
|
||||
private TransportConfig config = null;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
localProperties = new TreeMap<String, String>();
|
||||
remoteProperties = new HashMap<ContactId, Map<String, String>>();
|
||||
remoteProperties.put(contactId, new TreeMap<String, String>());
|
||||
config = new TreeMap<String, String>();
|
||||
localProperties = new TransportProperties();
|
||||
remoteProperties = new HashMap<ContactId, TransportProperties>();
|
||||
remoteProperties.put(contactId, new TransportProperties());
|
||||
config = new TransportConfig();
|
||||
testDir.mkdirs();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,16 +6,17 @@ import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportConfig;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.plugins.StreamTransportCallback;
|
||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
||||
import net.sf.briar.plugins.ImmediateExecutor;
|
||||
import net.sf.briar.plugins.StubStreamCallback;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -24,21 +25,21 @@ public class SimpleSocketPluginTest extends TestCase {
|
||||
|
||||
private final ContactId contactId = new ContactId(0);
|
||||
|
||||
private Map<String, String> localProperties = null;
|
||||
private Map<ContactId, Map<String, String>> remoteProperties = null;
|
||||
private Map<String, String> config = null;
|
||||
private TransportProperties localProperties = null;
|
||||
private Map<ContactId, TransportProperties> remoteProperties = null;
|
||||
private TransportConfig config = null;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
localProperties = new TreeMap<String, String>();
|
||||
remoteProperties = new HashMap<ContactId, Map<String, String>>();
|
||||
remoteProperties.put(contactId, new TreeMap<String, String>());
|
||||
config = new TreeMap<String, String>();
|
||||
localProperties = new TransportProperties();
|
||||
remoteProperties = new HashMap<ContactId, TransportProperties>();
|
||||
remoteProperties.put(contactId, new TransportProperties());
|
||||
config = new TransportConfig();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncomingConnection() throws Exception {
|
||||
StubStreamCallback callback = new StubStreamCallback();
|
||||
StubCallback callback = new StubCallback();
|
||||
localProperties.put("host", "127.0.0.1");
|
||||
localProperties.put("port", "0");
|
||||
SimpleSocketPlugin plugin =
|
||||
@@ -74,7 +75,7 @@ public class SimpleSocketPluginTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testOutgoingConnection() throws Exception {
|
||||
StubStreamCallback callback = new StubStreamCallback();
|
||||
StubCallback callback = new StubCallback();
|
||||
SimpleSocketPlugin plugin =
|
||||
new SimpleSocketPlugin(new ImmediateExecutor(), callback, 0L);
|
||||
plugin.start(localProperties, remoteProperties, config);
|
||||
@@ -96,7 +97,7 @@ public class SimpleSocketPluginTest extends TestCase {
|
||||
}
|
||||
}.start();
|
||||
// Tell the plugin about the port
|
||||
Map<String, String> properties = new TreeMap<String, String>();
|
||||
TransportProperties properties = new TransportProperties();
|
||||
properties.put("host", "127.0.0.1");
|
||||
properties.put("port", String.valueOf(port));
|
||||
plugin.setRemoteProperties(contactId, properties);
|
||||
@@ -114,7 +115,7 @@ public class SimpleSocketPluginTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testUpdatingPropertiesReopensSocket() throws Exception {
|
||||
StubStreamCallback callback = new StubStreamCallback();
|
||||
StubCallback callback = new StubCallback();
|
||||
localProperties.put("host", "127.0.0.1");
|
||||
localProperties.put("port", "0");
|
||||
SimpleSocketPlugin plugin =
|
||||
@@ -169,4 +170,36 @@ public class SimpleSocketPluginTest extends TestCase {
|
||||
fail();
|
||||
} catch(IOException expected) {}
|
||||
}
|
||||
|
||||
private static class StubCallback implements StreamTransportCallback {
|
||||
|
||||
public TransportProperties localProperties = null;
|
||||
public volatile int incomingConnections = 0;
|
||||
|
||||
public void setLocalProperties(TransportProperties properties) {
|
||||
localProperties = properties;
|
||||
}
|
||||
|
||||
public void setConfig(TransportConfig config) {
|
||||
}
|
||||
|
||||
public void showMessage(String... message) {
|
||||
}
|
||||
|
||||
public boolean showConfirmationMessage(String... message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int showChoice(String[] choices, String... message) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void incomingConnectionCreated(StreamTransportConnection c) {
|
||||
incomingConnections++;
|
||||
}
|
||||
|
||||
public void outgoingConnectionCreated(ContactId contactId,
|
||||
StreamTransportConnection c) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.Map;
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.protocol.Ack;
|
||||
import net.sf.briar.api.protocol.Batch;
|
||||
import net.sf.briar.api.protocol.BatchId;
|
||||
@@ -49,7 +50,7 @@ public class ProtocolReadWriteTest extends TestCase {
|
||||
private final BitSet bitSet;
|
||||
private final Map<Group, Long> subscriptions;
|
||||
private final TransportId transportId;
|
||||
private final Map<TransportId, Map<String, String>> transports;
|
||||
private final Map<TransportId, TransportProperties> transports;
|
||||
private final long timestamp = System.currentTimeMillis();
|
||||
|
||||
public ProtocolReadWriteTest() throws Exception {
|
||||
@@ -70,8 +71,9 @@ public class ProtocolReadWriteTest extends TestCase {
|
||||
bitSet.set(7);
|
||||
subscriptions = Collections.singletonMap(group, 123L);
|
||||
transportId = new TransportId(123);
|
||||
transports = Collections.singletonMap(transportId,
|
||||
Collections.singletonMap("bar", "baz"));
|
||||
TransportProperties p =
|
||||
new TransportProperties(Collections.singletonMap("bar", "baz"));
|
||||
transports = Collections.singletonMap(transportId, p);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.TreeMap;
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.crypto.CryptoComponent;
|
||||
import net.sf.briar.api.protocol.Author;
|
||||
import net.sf.briar.api.protocol.AuthorFactory;
|
||||
@@ -191,18 +192,18 @@ public class ConstantsTest extends TestCase {
|
||||
public void testTransportsFitIntoUpdate() throws Exception {
|
||||
// Create the maximum number of plugins, each with the maximum number
|
||||
// of maximum-length properties
|
||||
Map<TransportId, Map<String, String>> transports =
|
||||
new TreeMap<TransportId, Map<String, String>>();
|
||||
Map<TransportId, TransportProperties> transports =
|
||||
new TreeMap<TransportId, TransportProperties>();
|
||||
for(int i = 0; i < TransportUpdate.MAX_PLUGINS_PER_UPDATE; i++) {
|
||||
Map<String, String> properties = new TreeMap<String, String>();
|
||||
TransportProperties p = new TransportProperties();
|
||||
for(int j = 0; j < TransportUpdate.MAX_PROPERTIES_PER_PLUGIN; j++) {
|
||||
String key = createRandomString(
|
||||
TransportUpdate.MAX_KEY_OR_VALUE_LENGTH);
|
||||
String value = createRandomString(
|
||||
TransportUpdate.MAX_KEY_OR_VALUE_LENGTH);
|
||||
properties.put(key, value);
|
||||
p.put(key, value);
|
||||
}
|
||||
transports.put(new TransportId(i), properties);
|
||||
transports.put(new TransportId(i), p);
|
||||
}
|
||||
// Add the transports to an update
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.sf.briar.TestDatabaseModule;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.db.DatabaseComponent;
|
||||
import net.sf.briar.api.db.DatabaseListener;
|
||||
import net.sf.briar.api.protocol.Message;
|
||||
@@ -45,7 +46,7 @@ public class BatchConnectionReadWriteTest extends TestCase {
|
||||
private final File aliceDir = new File(testDir, "alice");
|
||||
private final File bobDir = new File(testDir, "bob");
|
||||
private final TransportId transportId = new TransportId(123);
|
||||
private final Map<TransportId, Map<String, String>> transports =
|
||||
private final Map<TransportId, TransportProperties> transports =
|
||||
Collections.emptyMap();
|
||||
private final byte[] aliceSecret, bobSecret;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user