Fix junit compile fails due to data structure moves

This commit is contained in:
zzz
2014-09-23 14:15:27 +00:00
parent b06f772647
commit 36fdb4ee2f
12 changed files with 40 additions and 19 deletions

View File

@ -23,9 +23,6 @@ public class DataTestSuite {
suite.addTestSuite(PayloadTest.class);
suite.addTestSuite(PrivateKeyTest.class);
suite.addTestSuite(PublicKeyTest.class);
suite.addTestSuite(RouterAddressTest.class);
suite.addTestSuite(RouterIdentityTest.class);
suite.addTestSuite(RouterInfoTest.class);
suite.addTestSuite(SessionKeyTest.class);
suite.addTestSuite(SignatureTest.class);
suite.addTestSuite(SigningPrivateKeyTest.class);

View File

@ -1,106 +0,0 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayOutputStream;
import java.util.Properties;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
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();
options.setProperty("hostname", "localhost");
options.setProperty("portnum", "1234");
addr.setOptions(options);
addr.setTransportStyle("Blah");
return addr;
}
public DataStructure createStructureToRead() { return new RouterAddress(); }
public void testSetNullOptions(){
RouterAddress addr = new RouterAddress();
boolean error = false;
try{
addr.setOptions(null);
}catch(NullPointerException dfe){
error = true;
}
assertTrue(error);
}
public void testSetOptionsAgain(){
RouterAddress addr = new RouterAddress();
Properties options = new Properties();
options.setProperty("hostname", "localhost");
options.setProperty("portnum", "1234");
addr.setOptions(options);
options.setProperty("portnum", "2345");
boolean error = false;
try{
addr.setOptions(options);
}catch(IllegalStateException dfe){
error = true;
}
assertTrue(error);
}
public void testBadWrite() throws Exception{
RouterAddress addr = new RouterAddress();
boolean error = false;
try{
addr.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
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();
options.setProperty("hostname", "localhost");
options.setProperty("portnum", "1234");
addr.setOptions(options);
addr.setTransportStyle("Blah");
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();
options.setProperty("hostname", "localhost");
options.setProperty("portnum", "1234");
addr.setOptions(options);
addr.setTransportStyle("Blah");
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

@ -1,116 +0,0 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayOutputStream;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class RouterIdentityTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
RouterIdentity ident = new RouterIdentity();
Certificate cert = (Certificate)(new CertificateTest()).createDataStructure();
ident.setCertificate(cert);
PublicKey pk = (PublicKey)(new PublicKeyTest()).createDataStructure();
ident.setPublicKey(pk);
SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
ident.setSigningPublicKey(k);
return ident;
}
public DataStructure createStructureToRead() { return new RouterIdentity(); }
public void testNullCert() throws Exception{
RouterIdentity ident = new RouterIdentity();
ident.setCertificate(null);
PublicKey pk = (PublicKey)(new PublicKeyTest()).createDataStructure();
ident.setPublicKey(pk);
SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
ident.setSigningPublicKey(k);
boolean error = false;
try{
ident.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
public void testNullPublicKey() throws Exception{
RouterIdentity ident = new RouterIdentity();
Certificate cert = (Certificate)(new CertificateTest()).createDataStructure();
ident.setCertificate(cert);
ident.setPublicKey(null);
SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
ident.setSigningPublicKey(k);
boolean error = false;
try{
ident.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
public void testNullSigningKey() throws Exception{
RouterIdentity ident = new RouterIdentity();
Certificate cert = (Certificate)(new CertificateTest()).createDataStructure();
ident.setCertificate(cert);
PublicKey pk = (PublicKey)(new PublicKeyTest()).createDataStructure();
ident.setPublicKey(pk);
ident.setSigningPublicKey(null);
boolean error = false;
try{
ident.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
public void testNullEquals() throws Exception{
RouterIdentity ident = new RouterIdentity();
assertFalse(ident.equals(null));
}
public void testCalculatedHash() throws Exception{
RouterIdentity ident = new RouterIdentity();
Certificate cert = (Certificate)(new CertificateTest()).createDataStructure();
ident.setCertificate(cert);
PublicKey pk = (PublicKey)(new PublicKeyTest()).createDataStructure();
ident.setPublicKey(pk);
SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
ident.setSigningPublicKey(k);
ident.calculateHash();
ident.calculateHash();
ident.calculateHash();
ident.calculateHash();
ident.calculateHash();
}
public void testBadHash() throws Exception {
RouterIdentity ident = new RouterIdentity();
boolean error = false;
try {
ident.getHash();
} catch (IllegalStateException ise) {
error = true;
}
assertTrue(error);
}
}

View File

@ -1,73 +0,0 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.util.HashSet;
import java.util.Properties;
import net.i2p.crypto.KeyGenerator;
import net.i2p.util.Log;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class RouterInfoTest extends StructureTest {
private final static Log _log = new Log(RouterInfoTest.class);
public DataStructure createDataStructure() throws DataFormatException {
RouterInfo info = new RouterInfo();
HashSet<RouterAddress> addresses = new HashSet<RouterAddress>();
DataStructure structure = (new RouterAddressTest()).createDataStructure();
addresses.add((RouterAddress) structure);
info.setAddresses(addresses);
PublicKey pubKey = null;
SigningPublicKey signingPubKey = null;
PrivateKey privKey = null;
SigningPrivateKey signingPrivKey = null;
Object obj[] = KeyGenerator.getInstance().generatePKIKeypair();
pubKey = (PublicKey)obj[0];
privKey = (PrivateKey)obj[1];
obj = KeyGenerator.getInstance().generateSigningKeypair();
signingPubKey = (SigningPublicKey)obj[0];
signingPrivKey = (SigningPrivateKey)obj[1];
_log.debug("SigningPublicKey: " + signingPubKey);
_log.debug("SigningPrivateKey: " + signingPrivKey);
RouterIdentity ident = new RouterIdentity();
ident.setCertificate(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null));
ident.setPublicKey(pubKey);
ident.setSigningPublicKey(signingPubKey);
info.setIdentity(ident);
Properties options = new Properties();
for (int i = 0; i < 16; i++) {
options.setProperty("option." + i, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890$:." + i);
}
options.setProperty("netConnectionSpeed", "OC12");
info.setOptions(options);
HashSet<Hash> peers = new HashSet<Hash>();
structure = (new HashTest()).createDataStructure();
peers.add((Hash) structure);
info.setPeers(peers);
info.setPublished(System.currentTimeMillis());
//info.setVersion(69);
info.sign(signingPrivKey);
return info;
}
public DataStructure createStructureToRead() { return new RouterInfo(); }
}