Browse Source

Improve AdapterBaseTestContext

JNI-96
heck 5 years ago
parent
commit
1571de6865
  1. 106
      test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java
  2. 2
      test/java/foundation/pEp/jniadapter/test/utils/AdapterTestUtils.java
  3. 19
      test/java/foundation/pEp/jniadapter/test/utils/TestCallbacks.java

106
test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java

@ -1,4 +1,5 @@
package foundation.pEp.jniadapter.test.utils; package foundation.pEp.jniadapter.test.utils;
import foundation.pEp.jniadapter.test.framework.*; import foundation.pEp.jniadapter.test.framework.*;
import foundation.pEp.jniadapter.*; import foundation.pEp.jniadapter.*;
@ -7,25 +8,49 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Vector; import java.util.Vector;
public class AdapterBaseTestContext implements AbstractTestContext { public class AdapterBaseTestContext extends AbstractTestContext {
public Sync.DefaultCallback cb = new Sync.DefaultCallback(); // Basic
public Engine engine;
public TestCallbacks callbacks;
// Identities
public Identity alice; public Identity alice;
public Identity bob; public Identity bob;
public Identity carol;
// Keys
public byte[] keyBobSec;
private String filenameBobSec = "../resources/test_keys/bob-sec.asc";
public byte[] keyBobPub;
private String filenameBobPub = "../resources/test_keys/bob-pub.asc";
public byte[] keyAlicePub;
private String filenameAlicePub = "../resources/test_keys/alice-pub.asc";
public byte[] keyAliceSec;
private String filenameAliceSec = "../resources/test_keys/alice-sec.asc";
// Messages
public Message msgToSelf; public Message msgToSelf;
public Message msgToBob; public Message msgToBob;
// Misc
public Vector<Identity> vID; public Vector<Identity> vID;
public Vector<String> vStr; public Vector<String> vStr;
public byte[] key;
private String fileName = "../resources/test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc";
public Engine engine;
public AdapterBaseTestContext() { } public AdapterBaseTestContext() {
setTestContextName("AdapterBaseTestContext");
}
public void init() throws Exception { public void init() throws Throwable {
vID = new Vector<Identity>(); vID = new Vector<Identity>();
vStr = new Vector<String>(); vStr = new Vector<String>();
callbacks = new TestCallbacks();
engine = new Engine(); engine = new Engine();
engine.setMessageToSendCallback(callbacks);
engine.setNotifyHandshakeCallback(callbacks);
alice = new Identity(); alice = new Identity();
alice.user_id = "23"; alice.user_id = "23";
@ -33,6 +58,7 @@ public class AdapterBaseTestContext implements AbstractTestContext {
alice.me = true; alice.me = true;
bob = new Identity(); bob = new Identity();
bob.username = "pEp Test Bob";
bob.user_id = "42"; bob.user_id = "42";
bob.address = "bob@peptest.org"; bob.address = "bob@peptest.org";
@ -42,64 +68,18 @@ public class AdapterBaseTestContext implements AbstractTestContext {
vID.add(bob); vID.add(bob);
vStr.add("StringItem"); vStr.add("StringItem");
try { Path path;
Path path = Paths.get(fileName); path = Paths.get(filenameBobPub);
key = Files.readAllBytes(path); keyBobPub = Files.readAllBytes(path);
} catch (Exception e) {
TestLogger.log("Could not open key file:" + fileName);
throw e;
}
}
}
path = Paths.get(filenameBobSec);
keyBobSec = Files.readAllBytes(path);
/*package foundation.pEp.jniadapter.test.framework; path = Paths.get(filenameAlicePub);
import foundation.pEp.jniadapter.test.utils.*; keyAlicePub = Files.readAllBytes(path);
import foundation.pEp.jniadapter.*;
import java.nio.file.Files; path = Paths.get(filenameAliceSec);
import java.nio.file.Path; keyAliceSec = Files.readAllBytes(path);
import java.nio.file.Paths;
import java.util.Vector;
public class TestContext {
public TestCallbacks cb = new TestCallbacks();
public Identity alice;
public Identity bob;
public Message msgToSelf;
public Message msgToBob;
public Vector<Identity> vID;
public Vector<String> vStr;
public byte[] key;
private String fileName = "../resources/test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc";
public Engine engine;
public TestContext() {
} }
public void init() throws Exception { }
this.vID = new Vector();
this.vStr = new Vector();
this.engine = new Engine();
this.alice = new Identity();
this.alice.user_id = "23";
this.alice.address = "alice@peptest.org";
this.alice.me = true;
this.bob = new Identity();
this.bob.user_id = "42";
this.bob.address = "bob@peptest.org";
this.msgToSelf = AdapterTestUtils.makeNewTestMessage(this.alice, this.alice, Message.Direction.Outgoing);
this.msgToBob = AdapterTestUtils.makeNewTestMessage(this.alice, this.bob, Message.Direction.Outgoing);
this.vID.add(this.bob);
this.vStr.add("StringItem");
try {
Path var1 = Paths.get(this.fileName);
this.key = Files.readAllBytes(var1);
} catch (Exception var2) {
TestLogger.log("Could not open key file:" + this.fileName);
throw var2;
}
}
}
*/

2
test/java/foundation/pEp/jniadapter/test/utils/AdapterTestUtils.java

@ -286,7 +286,7 @@ public class AdapterTestUtils {
msg.setFrom(from); msg.setFrom(from);
msg.setTo(vID); msg.setTo(vID);
msg.setDir(dir); msg.setDir(dir);
msg.setLongmsg("Hi i am the message longmsg"); msg.setLongmsg("Hi i am the message longmessage");
return msg; return msg;
} }
} }

19
test/java/foundation/pEp/jniadapter/test/utils/TestCallbacks.java

@ -1,21 +1,22 @@
package foundation.pEp.jniadapter.test.utils; package foundation.pEp.jniadapter.test.utils;
import static foundation.pEp.jniadapter.test.framework.TestLogger.*;
import foundation.pEp.jniadapter.test.framework.*; import foundation.pEp.jniadapter.test.framework.*;
import foundation.pEp.jniadapter.*; import foundation.pEp.jniadapter.*;
public class TestCallbacks implements Sync.MessageToSendCallback, Sync.NotifyHandshakeCallback { public class TestCallbacks implements Sync.MessageToSendCallback, Sync.NotifyHandshakeCallback {
public void messageToSend(Message message) { public void messageToSend(Message message) {
TestLogger.logH1("Message to send called"); logH1("Message to send called");
TestLogger.log("From: " + message.getFrom()); log("From: " + message.getFrom());
TestLogger.log("To: " + message.getTo()); log("To: " + message.getTo());
TestLogger.log("Subject: " + message.getShortmsg()); log("Subject: " + message.getShortmsg());
TestLogger.log("Attachement[0]: " + message.getAttachments().get(0).toString()); log("Attachement[0]: " + message.getAttachments().get(0).toString());
} }
public void notifyHandshake(Identity myself, Identity partner, SyncHandshakeSignal signal) { public void notifyHandshake(Identity myself, Identity partner, SyncHandshakeSignal signal) {
TestLogger.logH1("Notify handshake called"); logH1("Notify handshake called");
TestLogger.log("myself: " + AdapterTestUtils.identityToString(myself, false)); log("myself: " + AdapterTestUtils.identityToString(myself, false));
TestLogger.log("Partner: " + AdapterTestUtils.identityToString(partner, false)); log("Partner: " + AdapterTestUtils.identityToString(partner, false));
TestLogger.log("Signal: " + signal); log("Signal: " + signal);
} }
} }

Loading…
Cancel
Save