
4 changed files with 137 additions and 119 deletions
@ -1,53 +1,55 @@ |
|||
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; |
|||
import java.util.function.Supplier; |
|||
|
|||
|
|||
public class TestModel { |
|||
private Map<Role, TestIdentity> idents = new HashMap<>(); |
|||
private Map<NodeName, TestNode> nodes = new HashMap<>(); |
|||
public class TestModel<IdentityType extends TestIdentity, NodeType extends TestNode> { |
|||
private Map<Role, IdentityType> idents = new HashMap<>(); |
|||
private Map<NodeName, NodeType> nodes = new HashMap<>(); |
|||
|
|||
public String dataDir = "../resources/";; |
|||
public String dataDir = "../resources/"; |
|||
public String nodesDir = dataDir + "nodes/"; |
|||
|
|||
public TestModel() { |
|||
public TestModel(Supplier<IdentityType> identityTypeSupplier, Supplier<NodeType> nodeTypeSupplier) { |
|||
// Creating all Roles
|
|||
for (Role r : Role.values()) { |
|||
new TestIdentity(this, r); |
|||
IdentityType tmp = identityTypeSupplier.get(); |
|||
tmp.initialize(this,r); |
|||
addIdent(tmp); |
|||
} |
|||
// Creating all Nodes
|
|||
for (NodeName n : NodeName.values()) { |
|||
new TestNode(this, n); |
|||
NodeType tmp = nodeTypeSupplier.get(); |
|||
tmp.initialize(this, n); |
|||
addNode(tmp); |
|||
} |
|||
} |
|||
|
|||
public void addIdent(TestIdentity ident) { |
|||
public void addIdent(IdentityType ident) { |
|||
idents.put(ident.getRole(), ident); |
|||
} |
|||
|
|||
public TestIdentity getIdent(Role name) { |
|||
public IdentityType getIdent(Role name) { |
|||
return idents.get(name); |
|||
} |
|||
|
|||
public List<TestIdentity> getAllIdents() { |
|||
return new ArrayList<TestIdentity>(idents.values()); |
|||
public List<IdentityType> getAllIdents() { |
|||
return new ArrayList<>(idents.values()); |
|||
} |
|||
|
|||
public void addNode(TestNode node) { |
|||
public void addNode(NodeType node) { |
|||
nodes.put(node.getName(), node); |
|||
} |
|||
|
|||
public TestNode getNode(NodeName name) { |
|||
TestNode re = nodes.get(name); |
|||
return re; |
|||
public NodeType getNode(NodeName name) { |
|||
return nodes.get(name); |
|||
} |
|||
|
|||
public List<TestNode> getAllNodes() { |
|||
return new ArrayList<TestNode>(nodes.values()); |
|||
public List<NodeType> getAllNodes() { |
|||
return new ArrayList<>(nodes.values()); |
|||
} |
|||
} |
|||
|
@ -1,74 +1,59 @@ |
|||
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 { |
|||
public class TestNode<IdentityType extends TestIdentity> { |
|||
private NodeName name = null; |
|||
private TestModel model = null; |
|||
private TestModel<IdentityType,TestNode<IdentityType>> 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; |
|||
private boolean isInitialized = false; |
|||
|
|||
public TestNode(TestModel model, NodeName name) { |
|||
this.model = model; |
|||
public TestNode() { |
|||
} |
|||
|
|||
// this method has to be called before you can do ANYTHING with this object
|
|||
public void initialize(TestModel model, NodeName name) { |
|||
this.name = name; |
|||
homeDir = model.nodesDir + name.toString() + "/"; |
|||
transportDir = homeDir + "inboxes/"; |
|||
this.model.addNode(this); |
|||
this.model = model; |
|||
this.homeDir = model.nodesDir + name.toString() + "/"; |
|||
this.transportDir = homeDir + "inboxes/"; |
|||
this.isInitialized = true; |
|||
} |
|||
|
|||
public NodeName getName() { |
|||
ensureInitialized(); |
|||
return name; |
|||
} |
|||
|
|||
// public TestModel getModel() {
|
|||
// return model;
|
|||
// }
|
|||
|
|||
public void setRole(Role role) { |
|||
public void setDefaultRole(Role role) { |
|||
ensureInitialized(); |
|||
this.defaultRole = role; |
|||
TestIdentity ident = model.getIdent(role); |
|||
if(!ident.hasNode(getName())) { |
|||
IdentityType ident = model.getIdent(role); |
|||
if (!ident.hasNode(getName())) { |
|||
ident.addNode(this); |
|||
} |
|||
} |
|||
|
|||
public TestIdentity getIdent() { |
|||
public IdentityType getIdent() { |
|||
ensureInitialized(); |
|||
return model.getIdent(defaultRole); |
|||
} |
|||
|
|||
// 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() { |
|||
ensureInitialized(); |
|||
return homeDir; |
|||
} |
|||
|
|||
public String getTransportDir() { |
|||
ensureInitialized(); |
|||
return transportDir; |
|||
} |
|||
|
|||
private void ensureInitialized() { |
|||
if (!isInitialized) { |
|||
throw new IllegalStateException("Not initialized"); |
|||
} |
|||
} |
|||
} |
|||
|
@ -0,0 +1,61 @@ |
|||
package foundation.pEp.jniadapter.test.utils.model; |
|||
|
|||
import foundation.pEp.jniadapter.Identity; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.stream.Collectors; |
|||
|
|||
public class pEpTestIdentity extends TestIdentity { |
|||
private List<pEpTestKeyPair> keys = new ArrayList<>(); |
|||
public Identity pEpIdent = null; |
|||
private pEpTestKeyPair defaultKey = null; |
|||
private pEpTestKeyPair defaultKeyPP = null; |
|||
|
|||
public pEpTestIdentity() { |
|||
super(); |
|||
} |
|||
|
|||
@Override |
|||
public void initialize(TestModel model, Role role) { |
|||
super.initialize(model, role); |
|||
pEpIdent = new Identity(); |
|||
pEpIdent.username = role.toString(); |
|||
pEpIdent.address = role + "@peptest.org"; |
|||
} |
|||
|
|||
public void addKey(pEpTestKeyPair kp, boolean isDefault) { |
|||
keys.add(kp); |
|||
if (isDefault) { |
|||
if (kp.getType() == KeyType.NORMAL) { |
|||
defaultKey = kp; |
|||
} else { |
|||
defaultKeyPP = kp; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public pEpTestKeyPair getDefaultKey(boolean passphrase) { |
|||
if (!passphrase) { |
|||
return defaultKey; |
|||
} else { |
|||
return defaultKeyPP; |
|||
} |
|||
} |
|||
|
|||
public List<pEpTestKeyPair> getAllKeys() { |
|||
return keys; |
|||
} |
|||
|
|||
public List<pEpTestKeyPair> getNormalKeys() { |
|||
return keys.stream().filter(i -> { |
|||
return i.getType().equals(KeyType.NORMAL); |
|||
}).collect(Collectors.toList()); |
|||
} |
|||
|
|||
public List<pEpTestKeyPair> getPassphraseKeys() { |
|||
return keys.stream().filter(i -> { |
|||
return i.getType().equals(KeyType.PASSPHRASE); |
|||
}).collect(Collectors.toList()); |
|||
} |
|||
} |
Loading…
Reference in new issue