Browse Source

Add test framework (extracted) and test template

JNI-104
heck 5 years ago
parent
commit
ca917573b1
  1. 1
      .hgignore
  2. 44
      test/java/foundation/pEp/jniadapter/test/framework/TestContext.java
  3. 28
      test/java/foundation/pEp/jniadapter/test/framework/TestUnit.java
  4. 34
      test/java/foundation/pEp/jniadapter/test/template/Makefile
  5. 14
      test/java/foundation/pEp/jniadapter/test/template/TestMain.java
  6. 12
      test/java/foundation/pEp/jniadapter/test/utils/TestUtils.java

1
.hgignore

@ -12,6 +12,7 @@ syntax: glob
*.orig
*~
.DS_Store
*.db
# ignore generated files

44
test/java/foundation/pEp/jniadapter/test/framework/TestContext.java

@ -0,0 +1,44 @@
package foundation.pEp.jniadapter.test.framework;
import foundation.pEp.jniadapter.test.utils.TestUtils;
import foundation.pEp.jniadapter.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Vector;
public class TestContext {
public Sync.DefaultCallback cb = new Sync.DefaultCallback();
public Identity alice = new Identity();
public Identity bob = new Identity();
public Message msgToSelf;
public Message msgToBob;
public Vector<Identity> vID = new Vector<Identity>();
public Vector<String> vStr = new Vector<String>();
public byte[] key;
private String fileName = "../resources/test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc";
public Engine engine = new Engine();
public TestContext() throws Exception {
alice.user_id = "23";
alice.address = "alice@peptest.org";
alice.me = true;
bob.user_id = "42";
bob.address = "bob@peptest.org";
msgToSelf = TestUtils.makeNewTestMessage(alice, alice, Message.Direction.Outgoing);
msgToBob = TestUtils.makeNewTestMessage(alice, bob, Message.Direction.Outgoing);
vID.add(bob);
vStr.add("StringItem");
try {
Path path = Paths.get(fileName);
key = Files.readAllBytes(path);
} catch (Exception e) {
TestUtils.log("Could not open key file:" + fileName);
throw e;
}
}
}

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

@ -0,0 +1,28 @@
package foundation.pEp.jniadapter.test.framework;
import foundation.pEp.jniadapter.test.utils.TestUtils;
import java.util.function.Consumer;
public class TestUnit {
String testUnitName = "default test unit";
TestContext ctx;
Consumer<TestContext> lambda;
public TestUnit(String name, TestContext c, Consumer<TestContext> consumer) throws Exception {
testUnitName = name;
lambda = consumer;
ctx = c;
}
public void run() {
TestUtils.logH1(testUnitName);
try {
lambda.accept(ctx);
} catch (Throwable e) {
TestUtils.logH1("TestUnit FAILED: " + e.toString());
return;
}
TestUtils.logH2("SUCCESS!");
}
}

34
test/java/foundation/pEp/jniadapter/test/template/Makefile

@ -0,0 +1,34 @@
include ../../../../../../../Makefile.conf
include ../Makefile.conf
TEST_UNIT_NAME=template
JAVA_CLASSES = \
TestMain.class \
../framework/TestUnit.class \
../framework/TestContext.class \
../utils/TestUtils.class
.PHONY: compile run test clean
all: compile
$(MAKE) run
run: compile clean-pep-home
cd $(JAVA_CWD);pwd;HOME=$(JAVA_PEP_HOME_DIR) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestMain
compile: $(JAVA_CLASSES)
%.class: %.java
cd $(JAVA_CWD);javac -cp $(CLASSPATH) $(JAVA_PKG_BASEPATH)/$(TEST_UNIT_NAME)/$<
clean:
rm -f $(JAVA_CLASSES)
rm -f *.class
rm -f *.log
rm -Rf .gnupg
rm -Rf .lldb
clean-pep-home:
rm -rf $(PEP_HOME_DIR)/*
rm -rf $(PEP_HOME_DIR)/.pEp

14
test/java/foundation/pEp/jniadapter/test/template/TestMain.java

@ -0,0 +1,14 @@
package foundation.pEp.jniadapter.test.template;
import foundation.pEp.jniadapter.test.framework.*;
import foundation.pEp.jniadapter.*;
class TestMain {
public static void main(String[] args) throws Exception {
new TestUnit("Engine.myself",new TestContext() , ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
}).run();
}
}

12
test/java/foundation/pEp/jniadapter/test/utils/TestUtils.java

@ -204,6 +204,18 @@ public class TestUtils {
return ret;
}
public static Message makeNewTestMessage(Identity from, Identity to, Message.Direction dir) {
Message msg = new Message();
Vector<Identity> vID = new Vector<Identity>();
vID.add(to);
msg.setFrom(from);
msg.setTo(vID);
msg.setDir(dir);
msg.setLongmsg("Hi i am the message longmsg");
return msg;
}
// ------------------------ Logging ------------------------
private static boolean logEnabled = true;

Loading…
Cancel
Save