use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class ListRoleTest method serializeQuorum.
@Test
public void serializeQuorum() throws Exception {
SimpleRole s1 = new SimpleRole("owner");
SimpleRole s2 = new SimpleRole("owner2");
SimpleRole s3 = new SimpleRole("owner3");
s1.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
s2.addKeyRecord(new KeyRecord(keys.get(2).getPublicKey()));
s3.addKeyRecord(new KeyRecord(keys.get(1).getPublicKey()));
ListRole roleList = new ListRole("listAnyMode", 2, Do.listOf(s1, s2, s3));
Binder serialized = DefaultBiMapper.serialize(roleList);
Role r1 = DefaultBiMapper.deserialize(serialized);
assertEquals(r1, roleList);
}
use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class ListRoleTest method serializeWithMoreRoles.
@Test
public void serializeWithMoreRoles() {
SimpleRole s1 = new SimpleRole("s1");
SimpleRole s2 = new SimpleRole("s2");
ListRole lr1 = new ListRole("lr1", ListRole.Mode.ALL, Do.listOf(s1, s2));
ListRole lr2 = new ListRole("lr2", ListRole.Mode.ANY, Do.listOf(s1, s2));
assertEquals(lr1.getRoles(), lr2.getRoles());
Binder blr = BossBiMapper.serialize(lr1);
ListRole slr1 = DefaultBiMapper.deserialize(blr);
blr = BossBiMapper.serialize(lr1);
ListRole slr2 = DefaultBiMapper.deserialize(blr);
assertEquals(slr1.getRoles(), slr2.getRoles());
}
use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class RoleLinkTest method serialize.
@Test
public void serialize() throws Exception {
RoleLink r1 = new RoleLink("name", "target");
r1.addRequiredReference("ref", Role.RequiredMode.ALL_OF);
Binder s = DefaultBiMapper.serialize(r1);
RoleLink r2 = DefaultBiMapper.deserialize(s);
assertEquals(r1, r2);
assertEquals(r1.getName(), r2.getName());
}
use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class RoleReferencesTest method serializeBoth.
@Test
public void serializeBoth() throws Exception {
SimpleRole sr = new SimpleRole("tr1");
sr.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
sr.addRequiredReference("ref1", Role.RequiredMode.ALL_OF);
sr.addRequiredReference("ref2", Role.RequiredMode.ANY_OF);
Binder serialized = DefaultBiMapper.serialize(sr);
Role r1 = DefaultBiMapper.deserialize(serialized);
assertEquals(sr, r1);
assertEquals(r1.getReferences(Role.RequiredMode.ALL_OF).size(), 1);
assertEquals(r1.getReferences(Role.RequiredMode.ANY_OF).size(), 1);
assertEquals(r1.getReferences(Role.RequiredMode.ALL_OF).iterator().next(), "ref1");
assertEquals(r1.getReferences(Role.RequiredMode.ANY_OF).iterator().next(), "ref2");
}
use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class YamlTest method createFromDsl.
@Test
public void createFromDsl() throws Exception {
Yaml yaml = new Yaml();
String fileName = rootPath + "simple_key.yml";
try (FileReader r = new FileReader(fileName)) {
Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
Role role = Role.fromDslBinder("role", binder);
assertTrue(role instanceof SimpleRole);
assertTrue(role.getKeyRecords().size() == 1);
}
fileName = rootPath + "simple_keys.yml";
try (FileReader r = new FileReader(fileName)) {
Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
Role role = Role.fromDslBinder("role", binder);
assertTrue(role instanceof SimpleRole);
assertTrue(role.getKeyRecords().size() == 2);
}
fileName = rootPath + "simple_no_type.yml";
try (FileReader r = new FileReader(fileName)) {
Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
Role role = Role.fromDslBinder("role", binder);
assertTrue(role instanceof SimpleRole);
assertTrue(role.getKeyRecords().size() == 1);
}
fileName = rootPath + "simple_address.yml";
try (FileReader r = new FileReader(fileName)) {
Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
Role role = Role.fromDslBinder("role", binder);
assertTrue(role instanceof SimpleRole);
assertTrue(role.getKeyAddresses().size() == 1);
}
fileName = rootPath + "simple_addresses.yml";
try (FileReader r = new FileReader(fileName)) {
Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
Role role = Role.fromDslBinder("role", binder);
assertTrue(role instanceof SimpleRole);
assertTrue(role.getKeyAddresses().size() == 2);
}
fileName = rootPath + "simple_anonId.yml";
try (FileReader r = new FileReader(fileName)) {
Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
Role role = Role.fromDslBinder("role", binder);
assertTrue(role instanceof SimpleRole);
assertTrue(role.getAnonymousIds().size() == 1);
}
fileName = rootPath + "simple_anonIds.yml";
try (FileReader r = new FileReader(fileName)) {
Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
Role role = Role.fromDslBinder("role", binder);
assertTrue(role instanceof SimpleRole);
assertTrue(role.getAnonymousIds().size() == 2);
}
fileName = rootPath + "link.yml";
try (FileReader r = new FileReader(fileName)) {
Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
Role role = Role.fromDslBinder("role", binder);
assertTrue(role instanceof RoleLink);
}
fileName = rootPath + "list_all.yml";
try (FileReader r = new FileReader(fileName)) {
Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
Role role = Role.fromDslBinder("role", binder);
assertTrue(role instanceof ListRole);
}
fileName = rootPath + "list_any.yml";
try (FileReader r = new FileReader(fileName)) {
Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
Role role = Role.fromDslBinder("role", binder);
assertTrue(role instanceof ListRole);
}
fileName = rootPath + "list_quorum.yml";
try (FileReader r = new FileReader(fileName)) {
Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
Role role = Role.fromDslBinder("role", binder);
assertTrue(role instanceof ListRole);
}
fileName = rootPath + "simple_requires.yml";
try (FileReader r = new FileReader(fileName)) {
Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
Role role = Role.fromDslBinder("role", binder);
assertTrue(role instanceof SimpleRole);
assertTrue(role.getReferences(Role.RequiredMode.ALL_OF).size() == 3);
assertTrue(role.getReferences(Role.RequiredMode.ANY_OF).size() == 2);
}
}
Aggregations