Browse Source

TestFramework Multiple TestSuites support

JNI-96
heck 5 years ago
parent
commit
efc2ee8000
  1. 28
      test/java/foundation/pEp/jniadapter/test/basic/TestMain.java
  2. 64
      test/java/foundation/pEp/jniadapter/test/framework/TestSuite.java
  3. 11
      test/java/foundation/pEp/jniadapter/test/framework/TestUnit.java
  4. 27
      test/java/foundation/pEp/jniadapter/test/framework/examples/ctxinitfail/TestMain.java
  5. 11
      test/java/foundation/pEp/jniadapter/test/framework/examples/testsuite/TestMain.java
  6. 108
      test/java/foundation/pEp/jniadapter/test/regression/TestMain.java
  7. 8
      test/java/foundation/pEp/jniadapter/test/templateAlice/TestAlice.java
  8. 11
      test/java/foundation/pEp/jniadapter/test/templateAliceBob/TestAlice.java
  9. 10
      test/java/foundation/pEp/jniadapter/test/templateAliceBob/TestBob.java
  10. 8
      test/java/foundation/pEp/jniadapter/test/templateAliceBobCarol/TestAlice.java
  11. 8
      test/java/foundation/pEp/jniadapter/test/templateAliceBobCarol/TestBob.java
  12. 8
      test/java/foundation/pEp/jniadapter/test/templateAliceBobCarol/TestCarol.java
  13. 30
      test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/ctx/FsMQManagerBaseTestContext.java
  14. 137
      test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/identities/TestMain.java
  15. 20
      test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/stateless_rxtx/TestMain.java
  16. 29
      test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/stateless_rxtx_mp/TestAlice.java
  17. 36
      test/java/foundation/pEp/jniadapter/test/utils/transport/fsmsgqueue/test/regression/TestMain.java

28
test/java/foundation/pEp/jniadapter/test/basic/TestMain.java

@ -24,24 +24,24 @@ class BasicTestContext extends AdapterBaseTestContext {
class TestMain {
public static void main(String[] args) {
TestSuite.setVerbose(true);
TestSuite.getDefault().setVerbose(false);
BasicTestContext btc = new BasicTestContext();
new TestUnit<BasicTestContext>("Gen Keys", btc, ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
log("Keys generated: " + ctx.alice.fpr);
}).add();
});
new TestUnit<BasicTestContext>("Import key", btc, ctx -> {
ctx.engine.importKey(ctx.keyBobPub);
}).add();
});
new TestUnit<BasicTestContext>("Trustwords", btc, ctx -> {
ctx.carol = new Identity();
ctx.carol.fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
String t = ctx.engine.trustwords(ctx.carol);
log("Trustwords: " + t);
}).add();
});
new TestUnit<BasicTestContext>("setAttachments", btc, ctx -> {
int nrAttachemnts = 3;
@ -56,33 +56,33 @@ class TestMain {
attachments.add(blb);
}
ctx.msgToBob.setAttachments(attachments);
}).add();
});
new TestUnit<BasicTestContext>("Encrypt", btc, ctx -> {
ctx.enc = ctx.engine.encrypt_message(ctx.msgToBob, null, Message.EncFormat.PEP);
log(AdapterTestUtils.msgToString(ctx.enc, false));
}).add();
});
new TestUnit<BasicTestContext>("Rating Preview", btc, ctx -> {
log("Rating preview: " + ctx.engine.outgoing_message_rating_preview(ctx.msgToBob));
}).add();
});
new TestUnit<BasicTestContext>("Rating", btc, ctx -> {
log("Rating" + ctx.engine.outgoing_message_rating(ctx.msgToBob));
}).add();
});
new TestUnit<BasicTestContext>("Decrypt", btc, ctx -> {
ctx.result = ctx.engine.decrypt_message(ctx.enc, new Vector<>(), 0);
log(AdapterTestUtils.msgToString(ctx.result.dst, false));
}).add();
});
new TestUnit<BasicTestContext>("key_reset_all_own_keys()", btc, ctx -> {
ctx.engine.key_reset_all_own_keys();
}).add();
});
new TestUnit<BasicTestContext>("startSync()", btc, ctx -> {
ctx.engine.startSync();
}).add();
});
new TestUnit<BasicTestContext>("Keygen2", btc, ctx -> {
Identity user2 = new Identity();
@ -92,13 +92,13 @@ class TestMain {
user2.address = "jniTestUser2@peptest.ch";
user2 = ctx.engine.myself(user2);
log("Keys generated: " + user2.fpr);
}).add();
});
new TestUnit<BasicTestContext>("stopSync()", btc, ctx -> {
ctx.engine.stopSync();
}).add();
});
TestSuite.run();
TestSuite.getDefault().run();
}
}

64
test/java/foundation/pEp/jniadapter/test/framework/TestSuite.java

@ -1,47 +1,79 @@
package foundation.pEp.jniadapter.test.framework;
import static foundation.pEp.jniadapter.test.framework.TestLogger.*;
import static foundation.pEp.jniadapter.test.framework.TestUtils.TermColor;
import java.util.ArrayList;
// There is a static defaultTestSuite
// The last created instance is the defaultTestSuite by default
// Env var: TFVERBOSE
public class TestSuite {
private static ArrayList<TestUnit> tests = new ArrayList<TestUnit>();
private static boolean verbose = false;
private static TermColor testColor = TermColor.CYAN;
private static TestSuite defaultTestSuite = null;
private static int instanceCount = 0;
private ArrayList<TestUnit> tests = new ArrayList<TestUnit>();
private boolean verboseMode = false;
private TermColor testColor = TermColor.CYAN;
public TestSuite() {
setDefault();
instanceCount++;
}
private TestSuite() { }
public TestSuite(boolean makeDefault) {
if (makeDefault) {
setDefault();
}
}
public static boolean isVerbose() {
return verbose;
public void setDefault() {
defaultTestSuite = this;
}
public static void setVerbose(boolean v) {
verbose = v;
public static TestSuite getDefault() {
if (defaultTestSuite == null) {
defaultTestSuite = new TestSuite(true);
}
return defaultTestSuite;
}
public static TermColor getTestColor() {
public boolean isDefault() {
return getDefault() == this;
}
public boolean isVerbose() {
return verboseMode;
}
public void setVerbose(boolean v) {
verboseMode = v;
}
public TermColor getTestColor() {
return testColor;
}
public static void setTestColor(TermColor color) {
public void setTestColor(TermColor color) {
testColor = color;
}
public static void add(TestUnit t) {
public void add(TestUnit t) {
tests.add(t);
}
public static void run() {
public void run() {
setVerbose(Boolean.valueOf(System.getenv("TFVERBOSE")));
for (TestUnit t : tests) {
t.setVerboseMode(verbose);
t.setVerboseMode(verboseMode);
t.setTestColor(testColor);
t.run();
}
printStats();
}
private static void printStats() {
private void printStats() {
int totalCount = tests.size();
int skippedCount = 0;
int failedCount = 0;
@ -60,7 +92,7 @@ public class TestSuite {
failedColor = TermColor.RESET;
}
String failedStr = "FAILED : " + failedCount;
if(skippedCount > 0 ) failedStr += " ("+skippedCount + " Skipped)";
if (skippedCount > 0) failedStr += " (" + skippedCount + " Skipped)";
log(failedStr, failedColor);
log("TOTAL : " + totalCount);
}

11
test/java/foundation/pEp/jniadapter/test/framework/TestUnit.java

@ -6,6 +6,9 @@ import static foundation.pEp.jniadapter.test.framework.TestUtils.colorString;
import java.util.function.Consumer;
//Automatically get added to the default TestSuite always
//Can be added to any nr of TestSuites
public class TestUnit<T extends TestContextInterface> implements Runnable {
private String testUnitName = "default test unit";
private T ctx;
@ -28,6 +31,7 @@ public class TestUnit<T extends TestContextInterface> implements Runnable {
this.lambda = lambda;
this.ctx = context;
logLayout();
add(TestSuite.getDefault());
}
public boolean isVerboseMode() {
@ -54,8 +58,13 @@ public class TestUnit<T extends TestContextInterface> implements Runnable {
return lastException;
}
public TestUnit<T> add(TestSuite suite) {
suite.add(this);
return this;
}
public TestUnit<T> add() {
TestSuite.add(this);
TestSuite.getDefault().add(this);
return this;
}

27
test/java/foundation/pEp/jniadapter/test/framework/examples/ctxinitfail/TestMain.java

@ -1,11 +1,14 @@
package foundation.pEp.jniadapter.test.framework.examples.ctxinitfail;
import static foundation.pEp.jniadapter.test.framework.TestLogger.*;
import foundation.pEp.jniadapter.test.framework.*;
class CtxInitFailContext extends AbstractTestContext {
String name;
int result;
@Override
public void init() throws Throwable {
name = "UnitTestFrameWorkWithoutAName";
@ -15,41 +18,41 @@ class CtxInitFailContext extends AbstractTestContext {
class TestMain {
public static void main(String[] args) throws Exception {
TestSuite.setVerbose(true);
TestSuite.getDefault().setVerbose(true);
new TestUnit<CtxInitFailContext>("ctxinitfail1",new CtxInitFailContext() , ctx -> {
new TestUnit<CtxInitFailContext>("ctxinitfail1", new CtxInitFailContext(), ctx -> {
// do stuff using the context
// Test FAILS on unhandled exception, otherwise SUCCESS
log("Hello World from: " + ctx.name);
}).add();
});
new TestUnit<CtxInitFailContext>("ctxinitfail1",new CtxInitFailContext() , ctx -> {
new TestUnit<CtxInitFailContext>("ctxinitfail1", new CtxInitFailContext(), ctx -> {
// do stuff using the context
// Test FAILS on unhandled exception, otherwise SUCCESS
log("Hello World from: " + ctx.name);
}).add();
});
CtxInitFailContext failingContext = new CtxInitFailContext();
new TestUnit<CtxInitFailContext>("ctxinitfail2",failingContext , ctx -> {
new TestUnit<CtxInitFailContext>("ctxinitfail2", failingContext, ctx -> {
// do stuff using the context
// Test FAILS on unhandled exception, otherwise SUCCESS
log("Hello World from: " + ctx.name);
}).add();
});
new TestUnit<CtxInitFailContext>("ctxinitfail3",failingContext , ctx -> {
new TestUnit<CtxInitFailContext>("ctxinitfail3", failingContext, ctx -> {
// do stuff using the context
// Test FAILS on unhandled exception, otherwise SUCCESS
log("Hello World from: " + ctx.name);
}).add();
});
new TestUnit<CtxInitFailContext>("ctxinitfail4",failingContext , ctx -> {
new TestUnit<CtxInitFailContext>("ctxinitfail4", failingContext, ctx -> {
// do stuff using the context
// Test FAILS on unhandled exception, otherwise SUCCESS
log("Hello World from: " + ctx.name);
}).add();
});
TestSuite.run();
TestSuite.getDefault().run();
}
}

11
test/java/foundation/pEp/jniadapter/test/framework/examples/testsuite/TestMain.java

@ -13,29 +13,28 @@ class TestSuiteContext extends AbstractTestContext {
class TestMain {
public static void main(String[] args) throws Exception {
// TestSuite.setVerbose(true);
TestSuite.getDefault().setVerbose(true);
new TestUnit<TestSuiteContext>("Unit Test 1", new TestSuiteContext(), ctx -> {
log("=== OUTPUT FROM THE TEST ITSELF BEGIN ===");
log("Unit Test 1 " + ctx.name);
ctx.name = "new name";
log("=== OUTPUT FROM THE TEST ITSELF END ===");
}).add();
});
new TestUnit<TestSuiteContext>("Unit Test 3", new TestSuiteContext(), ctx -> {
log("=== OUTPUT FROM THE TEST ITSELF BEGIN ===");
log("Unit Test 3 Failing " + ctx.name);
int x = 4 / 0;
log("=== OUTPUT FROM THE TEST ITSELF END ===");
}).add();
});
new TestUnit<TestSuiteContext>("Unit Test 2", new TestSuiteContext(), ctx -> {
log("=== OUTPUT FROM THE TEST ITSELF BEGIN ===");
log("Unit Test 2 " + ctx.name);
log("=== OUTPUT FROM THE TEST ITSELF END ===");
}).add();
});
TestSuite.run();
TestSuite.getDefault().run();
}
}

108
test/java/foundation/pEp/jniadapter/test/regression/TestMain.java

@ -15,29 +15,29 @@ class RegTestContext extends AdapterBaseTestContext {
class TestMain {
public static void main(String[] args) {
TestSuite.setVerbose(false);
TestSuite.getDefault().setVerbose(false);
new TestUnit<RegTestContext>("Engine.myself", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
}).add();
});
new TestUnit<RegTestContext>("Engine.encrypt_message", new RegTestContext(), ctx -> {
ctx.engine.encrypt_message(ctx.msgToBob, null, Message.EncFormat.PEP);
}).add();
});
new TestUnit<RegTestContext>("Engine.encrypt_message_and_add_priv_key", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
ctx.engine.encrypt_message_and_add_priv_key(ctx.msgToSelf, ctx.alice.fpr);
}).add();
});
new TestUnit<RegTestContext>("Engine.encrypt_message_for_self", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
ctx.engine.encrypt_message_for_self(ctx.alice, ctx.msgToSelf, null);
}).add();
});
new TestUnit<RegTestContext>("Engine.decrypt_message", new RegTestContext(), ctx -> {
ctx.engine.decrypt_message(ctx.msgToSelf, ctx.vStr, 0);
}).add();
});
//TODO: Coredump
// new TestUnit<RegTestContext>("Engine.re_evaluate_message_rating", new RegTestContext(), ctx -> {
@ -45,29 +45,29 @@ class TestMain {
// ctx.bob = ctx.engine.myself(ctx.bob);
// Message msg = ctx.engine.encrypt_message(ctx.msgToBob,null, Message.EncFormat.PEP);
// ctx.engine.re_evaluate_message_rating(msg);
// }).add();
// });
new TestUnit<RegTestContext>("Engine.outgoing_message_rating", new RegTestContext(), ctx -> {
ctx.engine.outgoing_message_rating(ctx.msgToBob);
}).add();
});
new TestUnit<RegTestContext>("Engine.outgoing_message_rating_preview", new RegTestContext(), ctx -> {
ctx.engine.outgoing_message_rating_preview(ctx.msgToBob);
}).add();
});
new TestUnit<RegTestContext>("Engine.get_identity", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
ctx.engine.get_identity(ctx.alice.address, ctx.alice.user_id);
}).add();
});
new TestUnit<RegTestContext>("Engine.identity_rating", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
ctx.engine.identity_rating(ctx.alice);
}).add();
});
new TestUnit<RegTestContext>("Engine.blacklist_retrieve", new RegTestContext(), ctx -> {
ctx.engine.blacklist_retrieve();
}).add();
});
//FAIL
new TestUnit<RegTestContext>("Engine.own_message_private_key_details", new RegTestContext(), ctx -> {
@ -76,67 +76,67 @@ class TestMain {
ctx.engine.encrypt_message(ctx.msgToBob, null, Message.EncFormat.PEP);
ctx.engine.own_message_private_key_details(ctx.msgToBob);
}).add();
});
new TestUnit<RegTestContext>("Engine.OpenPGP_list_keyinfo", new RegTestContext(), ctx -> {
ctx.engine.OpenPGP_list_keyinfo("");
}).add();
});
new TestUnit<RegTestContext>("Engine.set_identity_flags", new RegTestContext(), ctx -> {
ctx.engine.set_identity_flags(ctx.alice, 0);
}).add();
});
new TestUnit<RegTestContext>("Engine.unset_identity_flags", new RegTestContext(), ctx -> {
ctx.engine.unset_identity_flags(ctx.alice, 0);
}).add();
});
new TestUnit<RegTestContext>("Engine.own_identities_retrieve", new RegTestContext(), ctx -> {
ctx.engine.own_identities_retrieve();
}).add();
});
new TestUnit<RegTestContext>("Engine.get_trustwords", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
ctx.bob = ctx.engine.myself(ctx.bob);
ctx.engine.get_trustwords(ctx.alice, ctx.bob, "en", false);
}).add();
});
new TestUnit<RegTestContext>("Engine.get_trustwords_for_fprs", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
ctx.bob = ctx.engine.myself(ctx.bob);
ctx.engine.get_trustwords_for_fprs(ctx.alice.fpr, ctx.bob.fpr, "en", false);
}).add();
});
new TestUnit<RegTestContext>("Engine.get_message_trustwords", new RegTestContext(), ctx -> {
ctx.engine.get_message_trustwords(ctx.msgToBob, null, ctx.bob, "en", false);
}).add();
});
new TestUnit<RegTestContext>("Engine.get_languagelist", new RegTestContext(), ctx -> {
ctx.engine.get_languagelist();
}).add();
});
new TestUnit<RegTestContext>("Engine.key_reset_trust", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
ctx.engine.key_reset_trust(ctx.alice);
}).add();
});
new TestUnit<RegTestContext>("Engine.key_reset_identity", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
ctx.engine.key_reset_identity(ctx.alice, "");
}).add();
});
new TestUnit<RegTestContext>("Engine.key_reset_user", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
ctx.engine.key_reset_user("fsdjugsh", ctx.alice.fpr);
}).add();
});
new TestUnit<RegTestContext>("Engine.key_reset_all_own_keys", new RegTestContext(), ctx -> {
ctx.engine.key_reset_all_own_keys();
}).add();
});
new TestUnit<RegTestContext>("Engine.deliverHandshakeResult", new RegTestContext(), ctx -> {
ctx.engine.deliverHandshakeResult(SyncHandshakeResult.SyncHandshakeCancel, ctx.vID);
}).add();
});
//[17:51] < heck> | this one fails since: 4665:f067c9e95455
@ -148,119 +148,119 @@ class TestMain {
// new TestUnit<RegTestContext>("Engine.leave_device_group", new RegTestContext(), ctx -> {
// ctx.engine.startSync();
// ctx.engine.leave_device_group();
// }).add();
// });
new TestUnit<RegTestContext>("Engine.enable_identity_for_sync", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
ctx.engine.enable_identity_for_sync(ctx.alice);
}).add();
});
new TestUnit<RegTestContext>("Engine.disable_identity_for_sync", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
ctx.engine.disable_identity_for_sync(ctx.alice);
}).add();
});
new TestUnit<RegTestContext>("Engine.config_cipher_suite", new RegTestContext(), ctx -> {
ctx.engine.config_cipher_suite(CipherSuite.pEpCipherSuiteDefault);
}).add();
});
new TestUnit<RegTestContext>("Engine.trustwords", new RegTestContext(), ctx -> {
ctx.engine.trustwords(ctx.alice);
}).add();
});
new TestUnit<RegTestContext>("Engine.updateIdentity", new RegTestContext(), ctx -> {
ctx.engine.updateIdentity(ctx.alice);
}).add();
});
new TestUnit<RegTestContext>("Engine.setOwnKey", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
ctx.engine.setOwnKey(ctx.alice, ctx.alice.fpr);
}).add();
});
new TestUnit<RegTestContext>("Engine.keyMistrusted", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
ctx.engine.keyMistrusted(ctx.alice);
}).add();
});
new TestUnit<RegTestContext>("Engine.keyResetTrust", new RegTestContext(), ctx -> {
ctx.engine.keyResetTrust(ctx.alice);
}).add();
});
new TestUnit<RegTestContext>("Engine.trustPersonalKey", new RegTestContext(), ctx -> {
ctx.engine.trustPersonalKey(ctx.alice);
}).add();
});
new TestUnit<RegTestContext>("Engine.trustOwnKey", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
ctx.engine.trustOwnKey(ctx.alice);
}).add();
});
new TestUnit<RegTestContext>("Engine.importKey", new RegTestContext(), ctx -> {
ctx.engine.importKey(ctx.keyBobPub);
}).add();
});
new TestUnit<RegTestContext>("Engine.blacklist_add", new RegTestContext(), ctx -> {
ctx.engine.blacklist_add("43");
}).add();
});
new TestUnit<RegTestContext>("Engine.blacklist_delete", new RegTestContext(), ctx -> {
ctx.engine.blacklist_delete("43");
}).add();
});
new TestUnit<RegTestContext>("Engine.blacklist_is_listed", new RegTestContext(), ctx -> {
ctx.engine.blacklist_is_listed("43");
}).add();
});
new TestUnit<RegTestContext>("Engine.config_passive_mode", new RegTestContext(), ctx -> {
ctx.engine.config_passive_mode(false);
}).add();
});
new TestUnit<RegTestContext>("Engine.config_unencrypted_subject", new RegTestContext(), ctx -> {
ctx.engine.config_unencrypted_subject(false);
}).add();
});
new TestUnit<RegTestContext>("Engine.getCrashdumpLog", new RegTestContext(), ctx -> {
ctx.engine.getCrashdumpLog(0);
}).add();
});
new TestUnit<RegTestContext>("Engine.getUserDirectory", new RegTestContext(), ctx -> {
ctx.engine.getUserDirectory();
}).add();
});
new TestUnit<RegTestContext>("Engine.getMachineDirectory", new RegTestContext(), ctx -> {
ctx.engine.getMachineDirectory();
}).add();
});
// AbstractEngine.java
new TestUnit<RegTestContext>("Engine.close", new RegTestContext(), ctx -> {
ctx.engine.close();
}).add();
});
new TestUnit<RegTestContext>("Engine.getVersion", new RegTestContext(), ctx -> {
ctx.engine.getVersion();
}).add();
});
new TestUnit<RegTestContext>("Engine.getProtocolVersion", new RegTestContext(), ctx -> {
ctx.engine.getProtocolVersion();
}).add();
});
new TestUnit<RegTestContext>("Engine.startKeyserverLookup", new RegTestContext(), ctx -> {
ctx.engine.startKeyserverLookup();
}).add();
});
new TestUnit<RegTestContext>("Engine.startSync", new RegTestContext(), ctx -> {
ctx.engine.startSync();
}).add();
});
new TestUnit<RegTestContext>("Engine.stopSync", new RegTestContext(), ctx -> {
ctx.engine.stopSync();
}).add();
});
new TestUnit<RegTestContext>("Engine.isSyncRunning", new RegTestContext(), ctx -> {
ctx.engine.isSyncRunning();
}).add();
});
TestSuite.run();
TestSuite.getDefault().run();
}
}

8
test/java/foundation/pEp/jniadapter/test/templateAlice/TestAlice.java

@ -5,8 +5,8 @@ import foundation.pEp.jniadapter.test.utils.*;
class TestAlice {
public static void main(String[] args) throws Exception {
TestSuite.setVerbose(true);
TestSuite.setTestColor(TestUtils.TermColor.GREEN);
TestSuite.getDefault().setVerbose(true);
TestSuite.getDefault().setTestColor(TestUtils.TermColor.GREEN);
new TestUnit<AdapterBaseTestContext>("Test Alice",new AdapterBaseTestContext() , ctx -> {
// do stuff using the context
@ -23,9 +23,9 @@ class TestAlice {
TestUtils.sleep(1000);
}
}).add();
});
TestSuite.run();
TestSuite.getDefault().run();
}
}

11
test/java/foundation/pEp/jniadapter/test/templateAliceBob/TestAlice.java

@ -7,8 +7,8 @@ import foundation.pEp.jniadapter.test.utils.*;
class TestAlice {
public static void main(String[] args) throws Exception {
TestSuite.setVerbose(true);
TestSuite.setTestColor(TestUtils.TermColor.GREEN);
TestSuite.getDefault().setVerbose(true);
TestSuite.getDefault().setTestColor(TestUtils.TermColor.GREEN);
new TestUnit<AdapterBaseTestContext>("Alice tx msg", new AdapterBaseTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
@ -18,7 +18,7 @@ class TestAlice {
}
//send message
}).add();
});
new TestUnit<AdapterBaseTestContext>("Alice rx msg", new AdapterBaseTestContext(), ctx -> {
for (int i = 0; i < 1000; i++) {
@ -26,10 +26,9 @@ class TestAlice {
TestUtils.sleep(1000);
}
}).add();
});
TestSuite.run();
TestSuite.getDefault().run();
}
}

10
test/java/foundation/pEp/jniadapter/test/templateAliceBob/TestBob.java

@ -7,8 +7,8 @@ import foundation.pEp.jniadapter.test.utils.*;
class TestBob {
public static void main(String[] args) throws Exception {
TestSuite.setVerbose(true);
TestSuite.setTestColor(TestUtils.TermColor.YELLOW);
TestSuite.getDefault().setVerbose(true);
TestSuite.getDefault().setTestColor(TestUtils.TermColor.YELLOW);
new TestUnit<AdapterBaseTestContext>("Bob rx msg", new AdapterBaseTestContext(), ctx -> {
for (int i = 0; i < 1000; i++) {
@ -16,7 +16,7 @@ class TestBob {
TestUtils.sleep(1000);
}
}).add();
});
new TestUnit<AdapterBaseTestContext>("Bob tx msg", new AdapterBaseTestContext(), ctx -> {
ctx.bob = ctx.engine.myself(ctx.bob);
@ -26,10 +26,10 @@ class TestBob {
}
//send message
}).add();
});
TestSuite.run();
TestSuite.getDefault().run();
}
}

8
test/java/foundation/pEp/jniadapter/test/templateAliceBobCarol/TestAlice.java

@ -5,8 +5,8 @@ import foundation.pEp.jniadapter.test.utils.*;
class TestAlice {
public static void main(String[] args) throws Exception {
TestSuite.setVerbose(true);
TestSuite.setTestColor(TestUtils.TermColor.GREEN);
TestSuite.getDefault().setVerbose(true);
TestSuite.getDefault().setTestColor(TestUtils.TermColor.GREEN);
new TestUnit<AdapterBaseTestContext>("Test Alice",new AdapterBaseTestContext() , ctx -> {
// do stuff using the context
@ -23,9 +23,9 @@ class TestAlice {
TestUtils.sleep(1000);
}
}).add();
});
TestSuite.run();
TestSuite.getDefault().run();
}
}

8
test/java/foundation/pEp/jniadapter/test/templateAliceBobCarol/TestBob.java

@ -5,8 +5,8 @@ import foundation.pEp.jniadapter.test.utils.*;
class TestBob {
public static void main(String[] args) throws Exception {
TestSuite.setVerbose(true);
TestSuite.setTestColor(TestUtils.TermColor.YELLOW);
TestSuite.getDefault().setVerbose(true);
TestSuite.getDefault().setTestColor(TestUtils.TermColor.YELLOW);
new TestUnit<AdapterBaseTestContext>("Test Bob",new AdapterBaseTestContext() , ctx -> {
// do stuff using the context
@ -23,9 +23,9 @@ class TestBob {
TestUtils.sleep(1000);
}
}).add();
});
TestSuite.run();
TestSuite.getDefault().run();
}
}

8
test/java/foundation/pEp/jniadapter/test/templateAliceBobCarol/TestCarol.java

@ -5,8 +5,8 @@ import foundation.pEp.jniadapter.test.utils.*;
class TestCarol {
public static void main(String[] args) throws Exception {
TestSuite.setVerbose(true);
TestSuite.setTestColor(TestUtils.TermColor.RED);
TestSuite.getDefault().setVerbose(true);
TestSuite.getDefault().setTestColor(TestUtils.TermColor.RED);
new TestUnit<AdapterBaseTestContext>("Test Carol",new AdapterBaseTestContext() , ctx -> {
// do stuff using the context
@ -23,9 +23,9 @@ class TestCarol {
TestUtils.sleep(1000);
}
}).add();
});
TestSuite.run();
TestSuite.getDefault().run();
}
}

30
test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/ctx/FsMQManagerBaseTestContext.java

@ -2,6 +2,7 @@ package foundation.pEp.jniadapter.test.utils.transport.fsmqmanager.test.ctx;
import foundation.pEp.jniadapter.test.utils.transport.fsmqmanager.*;
import foundation.pEp.jniadapter.test.framework.*;
import foundation.pEp.jniadapter.test.utils.transport.fsmqmanager.test.utils.FsMQManagerTestUtils;
import java.util.ArrayList;
import java.util.HashMap;
@ -11,10 +12,19 @@ import java.util.Map;
public class FsMQManagerBaseTestContext extends AbstractTestContext {
private String qDirBase = "../resources/fsmsgqueue-test/";
public String address = null;
public FsMQIdentity self = null;
private List<String> peerNames = null;
public Map<String, FsMQIdentity> peerMap = null;
public List<FsMQIdentity> peerList = null;
private int MSG_COUNT = 10;
private List<String> messages;
public FsMQManagerBaseTestContext(String selfAddress) {
address = selfAddress;
}
@Override
public void init() throws Throwable {
peerNames = new ArrayList<>();
@ -22,19 +32,35 @@ public class FsMQManagerBaseTestContext extends AbstractTestContext {
peerNames.add("Bob");
peerNames.add("Carol");
createPeerMapAndPeerList();
messages = FsMQManagerTestUtils.createTestMessages(self.getAddress(), MSG_COUNT);
}
private void createPeerMapAndPeerList() {
peerMap = new HashMap<>();
peerList = new ArrayList<>();
for (String addr : peerNames) {
FsMQIdentity ident = new FsMQIdentity(addr, getQDir(addr));
FsMQIdentity ident = new FsMQIdentity(addr, getOwnQDir());
peerMap.put(addr, ident);
peerList.add(ident);
}
}
private String getQDir(String address) {
private void defineSelfAndUpdatePeers() {
self = peerMap.get(address);
if (self == null) {
throw new RuntimeException("selfAddress not found");
}
peerMap.remove(address);
peerList.removeIf(p -> p.getAddress().equals(self.getAddress()));
}
private String getOwnQDir() {
return qDirBase + "/" + address;
}
public List<String> getMessages() {
return messages;
}
}

137
test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/identities/TestMain.java

@ -4,14 +4,13 @@ import static foundation.pEp.jniadapter.test.framework.TestLogger.*;
import foundation.pEp.jniadapter.test.utils.transport.fsmqmanager.*;
import foundation.pEp.jniadapter.test.framework.*;
import foundation.pEp.jniadapter.test.utils.transport.fsmqmanager.test.utils.FsMQManagerTestUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeoutException;
class FsMQManagerTestContext extends AbstractTestContext {
class FsMQManagerIdentitiesTestContext extends AbstractTestContext {
String ownAddress = "Alice";
String ownQDir = "../resources/fsmsgqueue-test/alice";
String bobAddress = "Bob";
@ -21,160 +20,148 @@ class FsMQManagerTestContext extends AbstractTestContext {
String carolQDirWrong = "../resources/fsmsgqueue-test/Wr0ngD1r3ct0ry";
String carolQDir = "../resources/fsmsgqueue-test/carol";
int msgCount = 10;
ArrayList<String> messages;
FsMQManager qm;
FsMQIdentity self = null;
FsMQIdentity bob = null;
FsMQIdentity carol = null;
FsMQManager qm;
List<FsMQIdentity> identList = null;
int MSG_COUNT = 10;
List<String> messages;
@Override
public void init() throws Throwable {
messages = createTestMessages(msgCount);
}
public java.util.ArrayList<String> createTestMessages(int count) {
log("Creating Test messages");
ArrayList<String> messages = new ArrayList<>();
for (int i = 0; i < count; i++) {
String msg = "TestMessage " + i;
// msg += "\nLine 2 of " + msg;
messages.add(msg);
log("Creating msg: " + msg);
}
return messages;
messages = FsMQManagerTestUtils.createTestMessages(ownAddress, MSG_COUNT);
}
}
class TestMain {
public static void main(String[] args) throws Exception {
TestSuite.setVerbose(true);
FsMQManagerTestContext testCtx = new FsMQManagerTestContext();
// TestSuite.getDefault().setVerbose(true);
FsMQManagerIdentitiesTestContext testCtx = new FsMQManagerIdentitiesTestContext();
new TestUnit<FsMQManagerTestContext>("Create own ident: " + testCtx.ownAddress, testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("Create own ident: " + testCtx.ownAddress, testCtx, ctx -> {
ctx.self = new FsMQIdentity(ctx.ownAddress, ctx.ownQDir);
assert ctx.self != null : "null";
assert ctx.self.getAddress().equals(ctx.ownAddress) : "Address mismatch";
assert ctx.self.getqDir().equals(ctx.ownQDir) : "qDir mismatch";
}).add();
});
new TestUnit<FsMQManagerTestContext>("Constructor with: " + testCtx.ownAddress, testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("Constructor with: " + testCtx.ownAddress, testCtx, ctx -> {
ctx.qm = new FsMQManager(ctx.self);
assert ctx.qm != null : "null";
}).add();
});
new TestUnit<FsMQManagerTestContext>("getIdentities", testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("getIdentities", testCtx, ctx -> {
List<FsMQIdentity> idents = ctx.qm.getIdentities();
for (FsMQIdentity i : idents) {
log(i.toString());
}
assert idents.size() == 1 : "identity count wrong";
}).add();
});
new TestUnit<FsMQManagerTestContext>("Ident known: " + testCtx.ownAddress, testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("Ident known: " + testCtx.ownAddress, testCtx, ctx -> {
assert ctx.qm.identityExists(ctx.self.getAddress()) : "Own identity unknown";
}).add();
});
new TestUnit<FsMQManagerTestContext>("Create ident " + testCtx.bobAddress, testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("Create ident " + testCtx.bobAddress, testCtx, ctx -> {
ctx.bob = new FsMQIdentity(ctx.bobAddress, ctx.bobQDirWrong);
assert ctx.bob != null : "null";
assert ctx.bob.getAddress().equals(ctx.bobAddress) : "Address mismatch";
assert ctx.bob.getqDir().equals(ctx.bobQDirWrong) : "qDir mismatch";
}).add();
});
new TestUnit<FsMQManagerTestContext>("Ident unknown: " + testCtx.bobAddress, testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("Ident unknown: " + testCtx.bobAddress, testCtx, ctx -> {
assert !ctx.qm.identityExists(ctx.bobAddress) : "Ident is known but shouldnt";
}).add();
});
new TestUnit<FsMQManagerTestContext>("Add ident " + testCtx.bobAddress, testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("Add ident " + testCtx.bobAddress, testCtx, ctx -> {
assert ctx.qm.addOrUpdateIdentity(ctx.bob) : "Identity updated but should have been added";
}).add();
});
new TestUnit<FsMQManagerTestContext>("Ident known: " + testCtx.bobAddress, testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("Ident known: " + testCtx.bobAddress, testCtx, ctx -> {
assert ctx.qm.identityExists(ctx.bobAddress) : "Ident is not known";
}).add();
});
new TestUnit<FsMQManagerTestContext>("Create/Add Ident " + testCtx.carolAddress, testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("Create/Add Ident " + testCtx.carolAddress, testCtx, ctx -> {
ctx.carol = new FsMQIdentity(ctx.carolAddress, ctx.carolQDirWrong);
assert ctx.carol != null : "null";
assert ctx.carol.getAddress().equals(ctx.carolAddress) : "Address mismatch";
assert ctx.carol.getqDir().equals(ctx.carolQDirWrong) : "qDir mismatch";
assert ctx.qm.addOrUpdateIdentity(ctx.carol) : "Ident got updated but should have been added";
}).add();
});
new TestUnit<FsMQManagerTestContext>("getIdentities", testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("getIdentities", testCtx, ctx -> {
List<FsMQIdentity> idents = ctx.qm.getIdentities();
for (FsMQIdentity i : idents) {
log(i.toString());
}
assert idents.size() == 3 : "identity count wrong";
}).add();
});
new TestUnit<FsMQManagerTestContext>("getIdents is copy", testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("getIdents is copy", testCtx, ctx -> {
List<FsMQIdentity> idents = ctx.qm.getIdentities();
int identSize = idents.size();
idents.add(new FsMQIdentity("Eve", "EvilEveDir"));
assert identSize == ctx.qm.getIdentities().size() : "ident count wrong";
assert !ctx.qm.identityExists("Eve") : "Identity Eve should not be known";
}).add();
});
new TestUnit<FsMQManagerTestContext>("AddOrUpdate ident " + testCtx.bobAddress, testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("AddOrUpdate ident " + testCtx.bobAddress, testCtx, ctx -> {
ctx.bob.setqDir(ctx.bobQDir);
assert ctx.bob.getqDir().equals(ctx.bobQDir);
assert !ctx.qm.addOrUpdateIdentity(ctx.bob) : "Ident got added but should have been updated";
}).add();
});
new TestUnit<FsMQManagerTestContext>("Update ident " + testCtx.carolAddress, testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("Update ident " + testCtx.carolAddress, testCtx, ctx -> {
ctx.carol.setqDir(ctx.carolQDir);
assert ctx.qm.updateIdentity(ctx.carol) : "Error updating ident";
}).add();
});
new TestUnit<FsMQManagerTestContext>("Update ownIdent Fails " + testCtx.carolAddress, testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("Update ownIdent Fails " + testCtx.carolAddress, testCtx, ctx -> {
assert !ctx.qm.updateIdentity(ctx.self) : "upadted own ident";
}).add();
});
new TestUnit<FsMQManagerTestContext>("getIdentities", testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("getIdentities", testCtx, ctx -> {
List<FsMQIdentity> idents = ctx.qm.getIdentities();
for (FsMQIdentity i : idents) {
log(i.toString());
}
assert idents.size() == 3 : "identity count wrong";
}).add();
});
new TestUnit<FsMQManagerTestContext>("removeAllIdents", testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("removeAllIdents", testCtx, ctx -> {
ctx.qm.removeAllIdentities();
}).add();
});
new TestUnit<FsMQManagerTestContext>("getIdentities", testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("getIdentities", testCtx, ctx -> {
List<FsMQIdentity> idents = ctx.qm.getIdentities();
for (FsMQIdentity i : idents) {
log(i.toString());
}
assert idents.size() == 1 : "identity count wrong";
}).add();
});
new TestUnit<FsMQManagerTestContext>("addIdentities", testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("addIdentities", testCtx, ctx -> {
ctx.identList = new ArrayList<>();
ctx.identList.add(ctx.self);
ctx.identList.add(ctx.bob);
ctx.identList.add(ctx.carol);
assert ctx.qm.addIdentities(ctx.identList) == 2 : "indents added count wrong";
}).add();
});
new TestUnit<FsMQManagerTestContext>("getIdentities", testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("getIdentities", testCtx, ctx -> {
List<FsMQIdentity> idents = ctx.qm.getIdentities();
for (FsMQIdentity i : idents) {
log(i.toString());
}
assert idents.size() == 3 : "identity count wrong";
}).add();
});
new TestUnit<FsMQManagerTestContext>("isOwnIdent", testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("isOwnIdent", testCtx, ctx -> {
for (FsMQIdentity i : ctx.qm.getIdentities()) {
if (ctx.qm.isOwnIdentity(i.getAddress())) {
log("isOwnIdent: " + i.getAddress() + "... YES");
@ -184,44 +171,44 @@ class TestMain {
assert !i.getAddress().equals(ctx.self.getAddress()) : "shouldnt be own ident";
}
}
}).add();
});
new TestUnit<FsMQManagerTestContext>("removeIdent" + testCtx.carolAddress, testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("removeIdent" + testCtx.carolAddress, testCtx, ctx -> {
ctx.qm.removeIdentity(ctx.carol.getAddress());
assert ctx.qm.getIdentities().size() == 2 : "identity count wrong";
assert !ctx.qm.identityExists(ctx.carol.getAddress()) : "Remove failed";
}).add();
});
new TestUnit<FsMQManagerTestContext>("getIdentities", testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("getIdentities", testCtx, ctx -> {
List<FsMQIdentity> idents = ctx.qm.getIdentities();
for (FsMQIdentity i : idents) {
log(i.toString());
}
assert idents.size() == 2 : "identity count wrong";
}).add();
});
new TestUnit<FsMQManagerTestContext>("cant remove own ident", testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("cant remove own ident", testCtx, ctx -> {
ctx.qm.removeIdentity(ctx.self.getAddress());
assert ctx.qm.getIdentities().size() == 2 : "identity count wrong";
assert ctx.qm.identityExists(ctx.self.getAddress()) : "removed own identity";
}).add();
});
new TestUnit<FsMQManagerTestContext>("getIdentForAddr" + testCtx.bobAddress, testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("getIdentForAddr" + testCtx.bobAddress, testCtx, ctx -> {
FsMQIdentity found = ctx.qm.getIdentityForAddress(ctx.bob.getAddress());
assert found != null :"failed to find known address";
assert found.getAddress().equals(ctx.bob.getAddress()) :"found wrong ident";
}).add();
});
new TestUnit<FsMQManagerTestContext>("getIdentForAdd" + testCtx.ownAddress, testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("getIdentForAdd" + testCtx.ownAddress, testCtx, ctx -> {
FsMQIdentity found = ctx.qm.getIdentityForAddress(ctx.self.getAddress());
assert found != null :"failed to find known address";
assert found.getAddress().equals(ctx.self.getAddress()) :"found wrong ident";
}).add();
});
new TestUnit<FsMQManagerTestContext>("getIdentityForAddress not existing", testCtx, ctx -> {
new TestUnit<FsMQManagerIdentitiesTestContext>("getIdentityForAddress not existing", testCtx, ctx -> {
assert ctx.qm.getIdentityForAddress("UNKNOWN") == null : "Found an unknown address";
}).add();
});
TestSuite.run();
TestSuite.getDefault().run();
}
}

20
test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/stateless_rxtx/TestMain.java

@ -62,14 +62,14 @@ class FsMQManagerTestContext extends AbstractTestContext {
class TestMain {
public static void main(String[] args) throws Exception {
TestSuite.setVerbose(true);
TestSuite.getDefault().setVerbose(true);
FsMQManagerTestContext testCtx = new FsMQManagerTestContext();
new TestUnit<FsMQManagerTestContext>("a/b/c ClearOwnQueue: ", testCtx, ctx -> {
ctx.alice.qm.clearOwnQueue();
ctx.bob.qm.clearOwnQueue();
ctx.carol.qm.clearOwnQueue();
}).add();
});
new TestUnit<FsMQManagerTestContext>("alice rx with timeout", testCtx, ctx -> {
log("waitForMessage with timeout...");
@ -81,7 +81,7 @@ class TestMain {
} catch (Exception e) {
assert false : "Error receiving message";
}
}).add();
});
new TestUnit<FsMQManagerTestContext>("tx to null fails", testCtx, ctx -> {
try {
@ -90,7 +90,7 @@ class TestMain {
return;
}
assert false : "receiver cant be null";
}).add();
});
new TestUnit<FsMQManagerTestContext>("tx null msg fails", testCtx, ctx -> {
try {
@ -99,7 +99,7 @@ class TestMain {
return;
}
assert false : "msg cant be null";
}).add();
});
new TestUnit<FsMQManagerTestContext>("a2a rx==tx seq", testCtx, ctx -> {
for (int i = 0; i < ctx.alice.msgCount; i++) {
@ -128,7 +128,7 @@ class TestMain {
throw new RuntimeException(e.toString());
}
}).add();
});
new TestUnit<FsMQManagerTestContext>("a2b rx==tx seq", testCtx, ctx -> {
for (int i = 0; i < ctx.alice.msgCount; i++) {
@ -158,7 +158,7 @@ class TestMain {
throw new RuntimeException(e.toString());
}
}).add();
});
new TestUnit<FsMQManagerTestContext>("b2a not known", testCtx, ctx -> {
try {
@ -168,7 +168,7 @@ class TestMain {
} catch (Exception e) {
}
assert false : "identity should not be known";
}).add();
});
new TestUnit<FsMQManagerTestContext>("b add a, tx again", testCtx, ctx -> {
ctx.bob.add(ctx.alice);
@ -179,9 +179,9 @@ class TestMain {
} catch (Exception e) {
assert false : e.toString();
}
}).add();
});
TestSuite.run();
TestSuite.getDefault().run();
}
}

29
test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/stateless_rxtx_mp/TestAlice.java

@ -12,50 +12,31 @@ import java.util.List;
class FsMQManagerTestContext extends FsMQManagerBaseTestContext {
private String selfAddress = null;
public FsMQIdentity self = null;
public FsMQManager qm;
private int MSG_COUNT = 10;
private List<String> messages;
public FsMQManagerTestContext(String selfAddress) {
this.selfAddress = selfAddress;
super(selfAddress);
}
@Override
public void init() throws Throwable {
super.init();
defineSelfAndUpdatePeers();
qm = new FsMQManager(self);
qm.addIdentities(peerList);
messages = FsMQManagerTestUtils.createTestMessages(self.getAddress(), MSG_COUNT);
}
private void defineSelfAndUpdatePeers() {
self = peerMap.get(selfAddress);
if (self == null) {
throw new RuntimeException("selfAddress not found");
}
peerMap.remove(selfAddress);
peerList.removeIf(p -> p.getAddress().equals(self.getAddress()));
}
public List<String> getMessages() {
return messages;
}
}
class TestAlice {
public static void main(String[] args) throws Exception {
TestSuite.setVerbose(true);
TestSuite.getDefault().setVerbose(true);
String myself = "Alice";
FsMQManagerTestContext testCtx = new FsMQManagerTestContext(myself);
new TestUnit<FsMQManagerTestContext>("I am: " + myself, testCtx, ctx -> {
log("I am: " + ctx.self.getAddress());
assert ctx.self.getAddress().equals(myself);
}).add();
});
new TestUnit<FsMQManagerTestContext>("I know Bob and Carol", testCtx, ctx -> {
log("I know:");
@ -74,8 +55,8 @@ class TestAlice {
assert !ctx.peerMap.containsKey(myself) : "peers should not contain" + myself;
assert ctx.peerMap.containsKey("Bob") : "peers must contain Bob";
assert ctx.peerMap.containsKey("Carol") : "peers must contain Carol";
}).add();
});
TestSuite.run();
TestSuite.getDefault().run();
}
}

36
test/java/foundation/pEp/jniadapter/test/utils/transport/fsmsgqueue/test/regression/TestMain.java

@ -50,52 +50,52 @@ class FsMsgQueueTestContext extends AbstractTestContext {
class TestMain {
public static void main(String[] args) throws Exception {
TestSuite.setVerbose(false);
TestSuite.getDefault().setVerbose(false);
FsMsgQueueTestContext testCtx = new FsMsgQueueTestContext();
new TestUnit<FsMsgQueueTestContext>("Constructor", testCtx, ctx -> {
log("Creating queue obj on dir:" + ctx.qDirPath);
ctx.queue = new FsMsgQueue(ctx.qDirPath);
}).add();
});
TestUnit isEmpty = new TestUnit<FsMsgQueueTestContext>("isEmpty", testCtx, ctx -> {
log("Checking queue is empty");
assert ctx.queue.isEmpty();
}).add();
});
TestUnit size0 = new TestUnit<FsMsgQueueTestContext>("Size == 0", testCtx, ctx -> {
log("Checking queue size == 0");
assert ctx.queue.size() == 0;
}).add();
});
new TestUnit<FsMsgQueueTestContext>("write msg[0]", testCtx, ctx -> {
String msg = ctx.messages.get(0);
log("adding msg[0]:" + msg);
ctx.queue.add(msg);
}).add();
});
TestUnit notEmpty = new TestUnit<FsMsgQueueTestContext>("Not empty", testCtx, ctx -> {
log("Checking queue not empty");
assert !ctx.queue.isEmpty();
}).add();
});
new TestUnit<FsMsgQueueTestContext>("Size == 1", testCtx, ctx -> {
log("Checking queue size == 1");
assert ctx.queue.size() == 1;
}).add();
});
new TestUnit<FsMsgQueueTestContext>("read equals write (element)", testCtx, ctx -> {
String msg = ctx.queue.element();
log("Read:" + msg);
assert msg.equals(ctx.messages.get(0));
}).add();
});
new TestUnit<FsMsgQueueTestContext>("read equals write (remove)", testCtx, ctx -> {
String msg = ctx.queue.remove();
log("Read:" + msg);
assert msg.equals(ctx.messages.get(0));
}).add();
});
isEmpty.add();
size0.add();
@ -105,13 +105,13 @@ class TestMain {
log("Adding msg:" + msg);
ctx.queue.add(msg);
}
}).add();
});
TestUnit sizeFull = new TestUnit<FsMsgQueueTestContext>("Size == " + testCtx.msgCount, testCtx, ctx -> {
int size = ctx.queue.size();
log("Size: " + size);
assert size == ctx.msgCount;
}).add();
});
notEmpty.add();
@ -125,7 +125,7 @@ class TestMain {
assert msg.equals(expected);
msgIndex++;
}
}).add();
});
addAllMsgs.add();
notEmpty.add();
@ -133,7 +133,7 @@ class TestMain {
TestUnit clear = new TestUnit<FsMsgQueueTestContext>("Clear", testCtx, ctx -> {
ctx.queue.clear();
}).add();
});
isEmpty.add();
size0.add();
@ -143,25 +143,25 @@ class TestMain {
ctx.queue.element();
} catch (NoSuchElementException e) {
}
}).add();
});
new TestUnit<FsMsgQueueTestContext>("Empty queue: peek()", testCtx, ctx -> {
assert ctx.queue.peek() == null;
}).add();
});
new TestUnit<FsMsgQueueTestContext>("Empty queue: remove()", testCtx, ctx -> {
try {
ctx.queue.remove();
} catch (NoSuchElementException e) {
}
}).add();
});
new TestUnit<FsMsgQueueTestContext>("Empty queue: poll()", testCtx, ctx -> {
assert ctx.queue.poll() == null;
}).add();
});
TestSuite.run();
TestSuite.getDefault().run();
}
}

Loading…
Cancel
Save