Browse Source

Tests: TestModel - refine

JNI-153
heck 9 months ago
parent
commit
926db0ae25
4 changed files with 132 additions and 29 deletions
  1. +1
    -1
      test/java/foundation/pEp/jniadapter/test/utils/model/NodeName.java
  2. +47
    -3
      test/java/foundation/pEp/jniadapter/test/utils/model/TestIdentity.java
  3. +31
    -12
      test/java/foundation/pEp/jniadapter/test/utils/model/TestModel.java
  4. +53
    -13
      test/java/foundation/pEp/jniadapter/test/utils/model/TestNode.java

test/java/foundation/pEp/jniadapter/test/utils/model/Node.java → test/java/foundation/pEp/jniadapter/test/utils/model/NodeName.java View File


+ 47
- 3
test/java/foundation/pEp/jniadapter/test/utils/model/TestIdentity.java View File

@ -1,29 +1,66 @@
package foundation.pEp.jniadapter.test.utils.model;
import foundation.pEp.jniadapter.Identity;
import foundation.pEp.jniadapter.test.utils.transport.fsmqmanager.FsMQIdentity;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
public class TestIdentity {
private TestModel model = null;
private Role role = null;
private Role defaultPartner = null;
public Identity pEpIdent = null;
private List<TestKeyPair> keys = new ArrayList<>();
private TestKeyPair defaultKey = null;
private TestKeyPair defaultKeyPP = null;
private Map<NodeName,FsMQIdentity> transportIdents = new HashMap<>();
public TestIdentity(Role role) {
public TestIdentity(TestModel model, Role role) {
this.model = model;
this.role = role;
pEpIdent = new Identity();
pEpIdent.username = role.toString();
pEpIdent.address = role + "@peptest.org";
this.model.addIdent(this);
}
// public TestModel getModel() {
// return model;
// }
public Role getRole() {
return role;
}
public TestIdentity getDefaultPartner() {
return model.getIdent(defaultPartner);
}
public void setDefaultPartner(Role defaultPartner) {
this.defaultPartner = defaultPartner;
}
public boolean hasNode(NodeName nodeName) {
return transportIdents.keySet().contains(nodeName);
}
public void addNode(TestNode node) {
FsMQIdentity tmp = createTransportIdentity(node);
transportIdents.put(node.getName(),tmp);
if (node.getIdent().getRole() != getRole()) {
node.setRole(getRole());
}
}
public List<FsMQIdentity> getAllTransportIdents() {
return new ArrayList<>(transportIdents.values());
}
public FsMQIdentity getTransportIdent(NodeName nodeName) {
return transportIdents.get(nodeName);
}
public void addKey(TestKeyPair kp, boolean isDefault) {
keys.add(kp);
if (isDefault) {
@ -35,6 +72,7 @@ public class TestIdentity {
}
}
public TestKeyPair getDefaultKey(boolean passphrase) {
if (!passphrase) {
return defaultKey;
@ -58,4 +96,10 @@ public class TestIdentity {
return i.getType().equals(KeyType.PASSPHRASE);
}).collect(Collectors.toList());
}
private FsMQIdentity createTransportIdentity(TestNode node) {
String transportAddress = node.getName().toString() + getRole().toString();
String transportDir = node.getTransportDir() + getRole().toString();
return new FsMQIdentity(transportAddress, transportDir);
}
}

+ 31
- 12
test/java/foundation/pEp/jniadapter/test/utils/model/TestModel.java View File

@ -1,34 +1,53 @@
package foundation.pEp.jniadapter.test.utils.model;
import foundation.pEp.jniadapter.test.utils.transport.fsmqmanager.FsMQIdentity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TestModel {
private Map<Role, TestIdentity> idents = new HashMap<>();
private Map<Node, TestNode> nodes = new HashMap<>();
private TestNode myNode = null;
private Map<NodeName, TestNode> nodes = new HashMap<>();
public TestModel() {
}
public String dataDir = "../resources/";;
public String nodesDir = dataDir + "nodes/";
public TestNode getMyNode() {
return myNode;
public TestModel() {
// Creating all Roles
for (Role r : Role.values()) {
new TestIdentity(this, r);
}
// Creating all Nodes
for (NodeName n : NodeName.values()) {
new TestNode(this, n);
}
}
public void add(TestIdentity ident) {
public void addIdent(TestIdentity ident) {
idents.put(ident.getRole(), ident);
}
public TestIdentity get(Role name) {
public TestIdentity getIdent(Role name) {
return idents.get(name);
}
public void add(TestNode node) {
public List<TestIdentity> getAllIdents() {
return new ArrayList<TestIdentity>(idents.values());
}
public void addNode(TestNode node) {
nodes.put(node.getName(), node);
}
// public TestNode get(Node name) {
// return nodes.get(name);
// }
public TestNode getNode(NodeName name) {
TestNode re = nodes.get(name);
return re;
}
public List<TestNode> getAllNodes() {
return new ArrayList<TestNode>(nodes.values());
}
}

+ 53
- 13
test/java/foundation/pEp/jniadapter/test/utils/model/TestNode.java View File

@ -1,34 +1,74 @@
package foundation.pEp.jniadapter.test.utils.model;
import foundation.pEp.jniadapter.test.utils.transport.fsmqmanager.FsMQIdentity;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class TestNode {
private Node name = null;
private Map<Role, TestIdentity> ownIdents = new HashMap<>();
private String TransportAddress = null;
private NodeName name = null;
private TestModel model = null;
// TODO: Just one role per node for now
// private Set<Role> ownRoles = new HashSet();
private Role defaultRole = null;
private String homeDir = null;
private String transportDir = null;
public TestNode(Node name) {
public TestNode(TestModel model, NodeName name) {
this.model = model;
this.name = name;
homeDir = model.nodesDir + name.toString() + "/";
transportDir = homeDir + "inboxes/";
this.model.addNode(this);
}
public Node getName() {
public NodeName getName() {
return name;
}
public Map<Role, TestIdentity> getOwnIdents() {
return ownIdents;
// public TestModel getModel() {
// return model;
// }
public void setRole(Role role) {
this.defaultRole = role;
TestIdentity ident = model.getIdent(role);
if(!ident.hasNode(getName())) {
ident.addNode(this);
}
}
public void addOwnIdent(TestIdentity ident) {
this.ownIdents.put(ident.getRole(), ident);
public TestIdentity getIdent() {
return model.getIdent(defaultRole);
}
public String getTransportAddress() {
return TransportAddress;
// public void addRole(Role role) {
// this.ownRoles.add(role);
// TestIdentity ident = model.getIdent(role);
// if(!ident.hasNode(getName())) {
// ident.addNode(this);
// }
// }
// public boolean hasRole(Role role) {
// return ownRoles.contains(role);
// }
// public Set<TestIdentity> getIdents() {
// Set<TestIdentity> ret = new HashSet();
// for(Role r : ownRoles) {
// ret.add(model.getIdent(r));
// }
// return ret;
// }
public String getHomeDir() {
return homeDir;
}
public void setTransportAddress(String transportAddress) {
TransportAddress = transportAddress;
public String getTransportDir() {
return transportDir;
}
}

Loading…
Cancel
Save