Search in sources :

Example 1 with Binder

use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.

the class BiMapperTest method serialize.

@Test
public void serialize() throws Exception {
    // Check proper serialization of the structure/single object
    ZonedDateTime now = ZonedDateTime.now();
    Binder res = DefaultBiMapper.serialize(Binder.of("time", now, "hello", "world"));
    assertEquals("world", res.get("hello"));
    assertEquals("unixtime", res.getStringOrThrow("time", "__type"));
    Binder restored = DefaultBiMapper.deserialize(res);
    assertEquals(now.truncatedTo(ChronoUnit.SECONDS), restored.get("time"));
    assertEquals(now.truncatedTo(ChronoUnit.SECONDS), DefaultBiMapper.deserialize(DefaultBiMapper.serialize(now)));
}
Also used : Binder(net.sergeych.tools.Binder) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.Test)

Example 2 with Binder

use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.

the class BiMapperTest method autoSerializable.

@Test
public void autoSerializable() throws Exception {
    Test1 t1 = new Test1("foo");
    DefaultBiMapper.registerClass(Test1.class);
    Binder s = DefaultBiMapper.serialize(t1);
    assertEquals(s.getStringOrThrow("__type"), "foobar1");
    assertEquals(s.getStringOrThrow("value"), "foo");
    Test1 t2 = DefaultBiMapper.deserialize(s);
    assertThat(t2, instanceOf(Test1.class));
    assertEquals("foo", t2.getValue());
}
Also used : Binder(net.sergeych.tools.Binder) Test(org.junit.Test)

Example 3 with Binder

use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.

the class BiMapperTest method autoSerializableInheritance.

@Test
public void autoSerializableInheritance() throws Exception {
    Test1 t1 = new Test2("foo");
    DefaultBiMapper.registerClass(Test2.class);
    Binder s = DefaultBiMapper.serialize(t1);
    assertEquals(s.getStringOrThrow("__type"), "net.sergeych.biserializer.Test2");
    Test2 t2 = DefaultBiMapper.deserialize(s);
    assertThat(t2, instanceOf(Test1.class));
    assertEquals("bad", t2.getValue());
    assertEquals("foo", t2.getBar());
}
Also used : Binder(net.sergeych.tools.Binder) Test(org.junit.Test)

Example 4 with Binder

use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.

the class TestBoss method emptyStrings.

@Test
public void emptyStrings() throws Exception {
    Object xo = JsonTool.fromJson("{\"text\":\"\",\"type\":\"p2pchat\",\"from_party_id\":\"1271\"}");
    Binder b = Binder.from(xo);
    Bytes bb = Boss.dump(b);
    String x = (String) Boss.unpack(bb.toArray()).getStringOrThrow("text");
    assertEquals("", x);
}
Also used : Binder(net.sergeych.tools.Binder) Bytes(net.sergeych.utils.Bytes) Test(org.junit.Test)

Example 5 with Binder

use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.

the class DeltaTest method nestedMaps.

@Test
public void nestedMaps() throws Exception {
    Binder a = Binder.fromKeysValues("hello", "world", "foo", "bar");
    Binder b = Binder.fromKeysValues("hello", "world", "foo", "bar");
    Binder r1 = Binder.fromKeysValues("nice", "day", "root", a);
    Binder r2 = Binder.fromKeysValues("nice", "day", "root", b);
    assertNull(Delta.between(r1, r2));
    b.put("foo", 117);
    MapDelta rd = Delta.between(r1, r2);
    assertNotNull(rd);
    assertFalse(rd.isEmpty());
    assertEquals(1, rd.getChanges().size());
    MapDelta md = (MapDelta) rd.getChange("root");
    assertNotNull(md);
    assertEquals(1, md.getChanges().size());
    ChangedItem ci = (ChangedItem) md.getChange("foo");
    assertEquals("bar", ci.oldValue());
    assertEquals(117, ci.newValue());
    assertEquals(1, rd.getNestedDelta().size());
}
Also used : Binder(net.sergeych.tools.Binder) Test(org.junit.Test)

Aggregations

Binder (net.sergeych.tools.Binder)136 Test (org.junit.Test)67 PrivateKey (com.icodici.crypto.PrivateKey)21 Contract (com.icodici.universa.contract.Contract)14 PublicKey (com.icodici.crypto.PublicKey)13 IOException (java.io.IOException)11 KeyRecord (com.icodici.universa.contract.KeyRecord)10 SimpleRole (com.icodici.universa.contract.roles.SimpleRole)10 Yaml (org.yaml.snakeyaml.Yaml)9 Bytes (net.sergeych.utils.Bytes)8 Decimal (com.icodici.universa.Decimal)7 ListRole (com.icodici.universa.contract.roles.ListRole)6 NonNull (org.checkerframework.checker.nullness.qual.NonNull)5 Gson (com.google.gson.Gson)4 GsonBuilder (com.google.gson.GsonBuilder)4 XStream (com.thoughtworks.xstream.XStream)4 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)4 List (java.util.List)4 RoleLink (com.icodici.universa.contract.roles.RoleLink)3 ItemResult (com.icodici.universa.node.ItemResult)3