From 1571de6865cf5e4a2dd27e575a4ee5584779566d Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 20 May 2020 23:24:13 +0200 Subject: [PATCH] Improve AdapterBaseTestContext --- .../test/utils/AdapterBaseTestContext.java | 106 +++++++----------- .../test/utils/AdapterTestUtils.java | 2 +- .../jniadapter/test/utils/TestCallbacks.java | 19 ++-- 3 files changed, 54 insertions(+), 73 deletions(-) diff --git a/test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java b/test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java index e8d5100..ec925e3 100644 --- a/test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java +++ b/test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java @@ -1,4 +1,5 @@ package foundation.pEp.jniadapter.test.utils; + import foundation.pEp.jniadapter.test.framework.*; import foundation.pEp.jniadapter.*; @@ -7,25 +8,49 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Vector; -public class AdapterBaseTestContext implements AbstractTestContext { - public Sync.DefaultCallback cb = new Sync.DefaultCallback(); +public class AdapterBaseTestContext extends AbstractTestContext { + // Basic + public Engine engine; + public TestCallbacks callbacks; + + // Identities public Identity alice; 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 msgToBob; + + // Misc public Vector vID; public Vector 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(); vStr = new Vector(); + callbacks = new TestCallbacks(); engine = new Engine(); + engine.setMessageToSendCallback(callbacks); + engine.setNotifyHandshakeCallback(callbacks); alice = new Identity(); alice.user_id = "23"; @@ -33,6 +58,7 @@ public class AdapterBaseTestContext implements AbstractTestContext { alice.me = true; bob = new Identity(); + bob.username = "pEp Test Bob"; bob.user_id = "42"; bob.address = "bob@peptest.org"; @@ -42,64 +68,18 @@ public class AdapterBaseTestContext implements AbstractTestContext { vID.add(bob); vStr.add("StringItem"); - try { - Path path = Paths.get(fileName); - key = Files.readAllBytes(path); - } catch (Exception e) { - TestLogger.log("Could not open key file:" + fileName); - throw e; - } - } -} + Path path; + path = Paths.get(filenameBobPub); + keyBobPub = Files.readAllBytes(path); + path = Paths.get(filenameBobSec); + keyBobSec = Files.readAllBytes(path); -/*package foundation.pEp.jniadapter.test.framework; -import foundation.pEp.jniadapter.test.utils.*; -import foundation.pEp.jniadapter.*; + path = Paths.get(filenameAlicePub); + keyAlicePub = Files.readAllBytes(path); -import java.nio.file.Files; -import java.nio.file.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 vID; - public Vector vStr; - public byte[] key; - private String fileName = "../resources/test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc"; - public Engine engine; - - public TestContext() { + path = Paths.get(filenameAliceSec); + keyAliceSec = Files.readAllBytes(path); } - 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; - } - } -} -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/test/java/foundation/pEp/jniadapter/test/utils/AdapterTestUtils.java b/test/java/foundation/pEp/jniadapter/test/utils/AdapterTestUtils.java index 371e41f..9cc55e8 100644 --- a/test/java/foundation/pEp/jniadapter/test/utils/AdapterTestUtils.java +++ b/test/java/foundation/pEp/jniadapter/test/utils/AdapterTestUtils.java @@ -286,7 +286,7 @@ public class AdapterTestUtils { msg.setFrom(from); msg.setTo(vID); msg.setDir(dir); - msg.setLongmsg("Hi i am the message longmsg"); + msg.setLongmsg("Hi i am the message longmessage"); return msg; } } \ No newline at end of file diff --git a/test/java/foundation/pEp/jniadapter/test/utils/TestCallbacks.java b/test/java/foundation/pEp/jniadapter/test/utils/TestCallbacks.java index 15ab223..de03c83 100644 --- a/test/java/foundation/pEp/jniadapter/test/utils/TestCallbacks.java +++ b/test/java/foundation/pEp/jniadapter/test/utils/TestCallbacks.java @@ -1,21 +1,22 @@ package foundation.pEp.jniadapter.test.utils; +import static foundation.pEp.jniadapter.test.framework.TestLogger.*; import foundation.pEp.jniadapter.test.framework.*; import foundation.pEp.jniadapter.*; public class TestCallbacks implements Sync.MessageToSendCallback, Sync.NotifyHandshakeCallback { public void messageToSend(Message message) { - TestLogger.logH1("Message to send called"); - TestLogger.log("From: " + message.getFrom()); - TestLogger.log("To: " + message.getTo()); - TestLogger.log("Subject: " + message.getShortmsg()); - TestLogger.log("Attachement[0]: " + message.getAttachments().get(0).toString()); + logH1("Message to send called"); + log("From: " + message.getFrom()); + log("To: " + message.getTo()); + log("Subject: " + message.getShortmsg()); + log("Attachement[0]: " + message.getAttachments().get(0).toString()); } public void notifyHandshake(Identity myself, Identity partner, SyncHandshakeSignal signal) { - TestLogger.logH1("Notify handshake called"); - TestLogger.log("myself: " + AdapterTestUtils.identityToString(myself, false)); - TestLogger.log("Partner: " + AdapterTestUtils.identityToString(partner, false)); - TestLogger.log("Signal: " + signal); + logH1("Notify handshake called"); + log("myself: " + AdapterTestUtils.identityToString(myself, false)); + log("Partner: " + AdapterTestUtils.identityToString(partner, false)); + log("Signal: " + signal); } }