Router tests: Remove or supporess deprecation warnings

Remove cast warnings
Fix RouterAddress.setExpiration() to match javadoc, used only by tests
This commit is contained in:
zzz
2017-12-02 13:56:13 +00:00
parent 2becaaa593
commit e6f17ec1ab
15 changed files with 38 additions and 53 deletions

View File

@ -146,7 +146,10 @@ public class RouterAddress extends DataStructureImpl {
*/
@Deprecated
public void setExpiration(Date expiration) {
if (expiration != null)
_expiration = expiration.getDate();
else
_expiration = 0;
}
/**

View File

@ -22,8 +22,8 @@ import net.i2p.data.TunnelId;
public class DeliveryInstructionsTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
DeliveryInstructions instructions = new DeliveryInstructions();
instructions.setDelayRequested(true);
instructions.setDelaySeconds(42);
//instructions.setDelayRequested(true);
//instructions.setDelaySeconds(42);
instructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_TUNNEL);
// encryption key read/write disabled
//instructions.setEncrypted(true);

View File

@ -14,6 +14,7 @@ import java.util.Properties;
import net.i2p.data.DataFormatException;
import net.i2p.data.DataStructure;
import net.i2p.data.StructureTest;
import net.i2p.util.OrderedProperties;
/**
* Test harness for loading / storing Hash objects
@ -22,21 +23,16 @@ import net.i2p.data.StructureTest;
*/
public class RouterAddressTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
RouterAddress addr = new RouterAddress();
byte data[] = new byte[32];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
addr.setCost(42);
//addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
Properties options = new Properties();
OrderedProperties options = new OrderedProperties();
options.setProperty("hostname", "localhost");
options.setProperty("portnum", "1234");
addr.setOptions(options);
addr.setTransportStyle("Blah");
RouterAddress addr = new RouterAddress("Blah", options, 42);
return addr;
}
public DataStructure createStructureToRead() { return new RouterAddress(); }
@SuppressWarnings("deprecation")
public void testSetNullOptions(){
RouterAddress addr = new RouterAddress();
boolean error = false;
@ -48,12 +44,12 @@ public class RouterAddressTest extends StructureTest {
assertTrue(error);
}
@SuppressWarnings("deprecation")
public void testSetOptionsAgain(){
RouterAddress addr = new RouterAddress();
Properties options = new Properties();
OrderedProperties options = new OrderedProperties();
options.setProperty("hostname", "localhost");
options.setProperty("portnum", "1234");
addr.setOptions(options);
RouterAddress addr = new RouterAddress("Blah", options, 42);
options.setProperty("portnum", "2345");
boolean error = false;
try{
@ -76,33 +72,21 @@ public class RouterAddressTest extends StructureTest {
}
public void testNullEquals(){
RouterAddress addr = new RouterAddress();
byte data[] = new byte[32];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
addr.setCost(42);
//addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
Properties options = new Properties();
OrderedProperties options = new OrderedProperties();
options.setProperty("hostname", "localhost");
options.setProperty("portnum", "1234");
addr.setOptions(options);
addr.setTransportStyle("Blah");
RouterAddress addr = new RouterAddress("Blah", options, 42);
assertFalse(addr.equals(null));
assertFalse(addr.equals(""));
}
public void testToString(){
RouterAddress addr = new RouterAddress();
byte data[] = new byte[32];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
addr.setCost(42);
//addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
Properties options = new Properties();
OrderedProperties options = new OrderedProperties();
options.setProperty("hostname", "localhost");
options.setProperty("portnum", "1234");
addr.setOptions(options);
addr.setTransportStyle("Blah");
RouterAddress addr = new RouterAddress("Blah", options, 42);
String ret = addr.toString();
//assertEquals("[RouterAddress: \n\tTransportStyle: Blah\n\tCost: 42\n\tExpiration: Fri Jan 02 00:00:00 UTC 1970\n\tOptions: #: 2\n\t\t[hostname] = [localhost]\n\t\t[portnum] = [1234]]", ret);
assertEquals("[RouterAddress: \n\tType: Blah\n\tCost: 42\n\tOptions (2):\n\t\t[hostname] = [localhost]\n\t\t[portnum] = [1234]]", ret);

View File

@ -31,6 +31,8 @@ import net.i2p.util.Log;
*/
public class RouterInfoTest extends StructureTest {
private final static Log _log = new Log(RouterInfoTest.class);
@SuppressWarnings("deprecation")
public DataStructure createDataStructure() throws DataFormatException {
RouterInfo info = new RouterInfo();
HashSet<RouterAddress> addresses = new HashSet<RouterAddress>();

View File

@ -219,6 +219,7 @@ public class SSUDemo {
* Deal with an Foo message received
*/
private class FooJobBuilder implements HandlerJobBuilder {
@SuppressWarnings("deprecation")
public FooJobBuilder() {
I2NPMessageImpl.registerBuilder(new FooBuilder(), FooMessage.MESSAGE_TYPE);
}

View File

@ -48,7 +48,7 @@ public class SessionEncryptionTest extends TestCase{
byte[] msg = DataHelper.getASCII("msg 1");
byte emsg[] = _context.elGamalAESEngine().encrypt(msg, pubKey, curKey, 64);
byte emsg[] = _context.elGamalAESEngine().encrypt(msg, pubKey, curKey, null, null, 64);
byte dmsg[] = _context.elGamalAESEngine().decrypt(emsg, privKey, skm);
assertTrue(DataHelper.eq(dmsg, msg));
}
@ -62,7 +62,7 @@ public class SessionEncryptionTest extends TestCase{
byte[] msg = DataHelper.getASCII("msg 2");
byte emsg[] = _context.elGamalAESEngine().encrypt(msg, pubKey, curKey, 64);
byte emsg[] = _context.elGamalAESEngine().encrypt(msg, pubKey, curKey, null, null, 64);
byte dmsg[] = _context.elGamalAESEngine().decrypt(emsg, privKey, skm);
assertTrue(DataHelper.eq(dmsg, msg));
}
@ -101,7 +101,7 @@ public class SessionEncryptionTest extends TestCase{
byte[] msg4 = DataHelper.getASCII("msg 4");
byte[] msg5 = DataHelper.getASCII("msg 5");
byte emsg1[] = _context.elGamalAESEngine().encrypt(msg1, pubKey, curKey, firstTags, 64);
byte emsg1[] = _context.elGamalAESEngine().encrypt(msg1, pubKey, curKey, firstTags, null, 64);
byte dmsg1[] = _context.elGamalAESEngine().decrypt(emsg1, privKey, skm);
assertTrue(DataHelper.eq(dmsg1, msg1));
@ -201,7 +201,7 @@ public class SessionEncryptionTest extends TestCase{
byte[] msg4 = DataHelper.getASCII("msg 4");
byte[] msg5 = DataHelper.getASCII("msg 5");
byte emsg1[] = _context.elGamalAESEngine().encrypt(msg1, pubKey, curKey, firstTags, 64);
byte emsg1[] = _context.elGamalAESEngine().encrypt(msg1, pubKey, curKey, firstTags, null, 64);
byte dmsg1[] = _context.elGamalAESEngine().decrypt(emsg1, privKey, skm);
assertTrue(DataHelper.eq(dmsg1, msg1));

View File

@ -110,10 +110,6 @@ public class BuildTestMessageJob extends JobImpl {
DeliveryInstructions instructions = new DeliveryInstructions();
instructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_ROUTER);
instructions.setDelayRequested(false);
instructions.setDelaySeconds(0);
instructions.setEncrypted(false);
instructions.setEncryptionKey(null);
instructions.setRouter(_target.getIdentity().getHash());
instructions.setTunnelId(null);
@ -135,9 +131,6 @@ public class BuildTestMessageJob extends JobImpl {
DeliveryInstructions ackInstructions = new DeliveryInstructions();
ackInstructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_ROUTER);
ackInstructions.setRouter(_replyTo); // yikes!
ackInstructions.setDelayRequested(false);
ackInstructions.setDelaySeconds(0);
ackInstructions.setEncrypted(false);
DeliveryStatusMessage msg = new DeliveryStatusMessage(getContext());
msg.setArrival(getContext().clock().now());

View File

@ -25,6 +25,7 @@ import net.i2p.data.router.RouterInfo;
import net.i2p.data.SigningPrivateKey;
import net.i2p.data.SigningPublicKey;
import net.i2p.util.Clock;
import net.i2p.util.OrderedProperties;
public class RouterGenerator {
public static void main(String args[]) {
@ -121,16 +122,12 @@ public class RouterGenerator {
}
private static RouterAddress createTCPAddress(int num) {
RouterAddress addr = new RouterAddress();
addr.setCost(10);
addr.setExpiration(null);
Properties props = new Properties();
OrderedProperties props = new OrderedProperties();
String name = "blah.random.host.org";
String port = "" + (1024+num);
props.setProperty("host", name);
props.setProperty("port", port);
addr.setOptions(props);
addr.setTransportStyle("TCP");
RouterAddress addr = new RouterAddress("TCP", props, 10);
return addr;
}

View File

@ -75,7 +75,7 @@ class UDPFlooder implements Runnable {
if (now >= nextSend) {
// peers always grows, so this is fairly safe
for (int i = 0; i < _peers.size(); i++) {
PeerState peer = (PeerState)_peers.get(i);
PeerState peer = _peers.get(i);
DataMessage m = new DataMessage(_context);
byte data[] = _floodData; // new byte[4096];
//_context.random().nextBytes(data);

View File

@ -10,7 +10,7 @@ package net.i2p.router.tunnel;
import java.util.ArrayList;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;

View File

@ -56,7 +56,7 @@ public class BuildMessageTestStandalone extends TestCase {
// populate and encrypt the message
TunnelBuildMessage msg = new TunnelBuildMessage(ctx);
for (int i = 0; i < order.size(); i++) {
int hop = ((Integer)order.get(i)).intValue();
int hop = order.get(i).intValue();
PublicKey key = null;
if (hop < _pubKeys.length)
key = _pubKeys[hop];
@ -119,7 +119,7 @@ public class BuildMessageTestStandalone extends TestCase {
boolean allAgree = true;
for (int i = 0; i < cfg.getLength(); i++) {
Hash peer = cfg.getPeer(i);
int record = ((Integer)order.get(i)).intValue();
int record = order.get(i).intValue();
if (statuses[record] != 0)
allAgree = false;
//else

View File

@ -1,6 +1,6 @@
package net.i2p.router.tunnel;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
@ -154,6 +154,8 @@ public abstract class GatewayTestBase extends RouterTestBase {
_handler = new FragmentHandler(_context, TestReceiver.this);
_received = new ArrayList<I2NPMessage>(1000);
}
@SuppressWarnings("deprecation")
public long receiveEncrypted(byte[] encrypted) {
// fake all the hops...

View File

@ -35,6 +35,7 @@ public class InboundGatewayTest extends GatewayTestBase {
}
@Override
@SuppressWarnings("deprecation")
protected void handleAtEndpoint(byte []encrypted) {
// now handle it at the endpoint
InboundEndpointProcessor end = new InboundEndpointProcessor(_context, _config);

View File

@ -13,7 +13,7 @@ import org.junit.Test;
import net.i2p.data.DataHelper;
import net.i2p.data.Hash;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
/**
* Quick unit test for base functionality of inbound tunnel
@ -23,6 +23,7 @@ import static junit.framework.Assert.assertTrue;
public class InboundTest extends RouterTestBase {
@Test
@SuppressWarnings("deprecation")
public void testInbound() {
int numHops = 8;

View File

@ -25,6 +25,7 @@ public class OutboundTest extends TestCase{
_context = new RouterContext(null);
}
@SuppressWarnings("deprecation")
public void testOutbound() {
int numHops = 8;
TunnelCreatorConfig config = prepareConfig(numHops);