Search in sources :

Example 1 with Account

use of org.infinispan.protostream.domain.Account in project protostream by infinispan.

the class ProtobufUtilTest method testArrayOfEnum.

@Test
public void testArrayOfEnum() throws Exception {
    Account account = createAccount();
    SerializationContext context = createContext();
    byte[] bytes = ProtobufUtil.toWrappedByteArray(context, account);
    Account acc = ProtobufUtil.fromWrappedByteArray(context, bytes);
    assertEquals(acc, account);
}
Also used : Account(org.infinispan.protostream.domain.Account) Test(org.junit.Test) AbstractProtoStreamTest(org.infinispan.protostream.test.AbstractProtoStreamTest)

Example 2 with Account

use of org.infinispan.protostream.domain.Account in project protostream by infinispan.

the class ProtobufUtilTest method testJsonWithDifferentFieldOrder.

@Test
public void testJsonWithDifferentFieldOrder() throws Exception {
    SerializationContext ctx = createContext();
    String json = "{\"_type\":\"sample_bank_account.Account\",\"hardLimits\":{\"maxDailyLimit\":5,\"maxTransactionLimit\":35},\"limits\":{\"maxDailyLimit\":1.5,\"maxTransactionLimit\":3.5,\"payees\":[\"Madoff\", \"Ponzi\"]},\"description\":\"test account\",\"creationDate\":\"1500508800000\",\"blurb\":[\"\",\"ew==\",\"AQIDBA==\"],\"currencies\":[\"USD\",\"BRL\"],\"id\":1}";
    byte[] bytes = ProtobufUtil.fromCanonicalJSON(ctx, new StringReader(json));
    Account account = ProtobufUtil.fromWrappedByteArray(ctx, bytes);
    assertEquals(createAccount(), account);
}
Also used : Account(org.infinispan.protostream.domain.Account) StringReader(java.io.StringReader) Test(org.junit.Test) AbstractProtoStreamTest(org.infinispan.protostream.test.AbstractProtoStreamTest)

Example 3 with Account

use of org.infinispan.protostream.domain.Account in project protostream by infinispan.

the class MarshallingTest method doMarshallAccountTest.

private void doMarshallAccountTest(EncoderMethod<Account> encoderMethod) throws Exception {
    ImmutableSerializationContext ctx = createContext();
    Account account = new Account();
    account.setId(1);
    account.setDescription("test account");
    account.setCurrencies(new Account.Currency[] { Account.Currency.BRL });
    Date creationDate = new Date();
    account.setCreationDate(creationDate);
    Account.Limits limits = new Account.Limits();
    limits.setMaxDailyLimit(0.0);
    limits.setMaxTransactionLimit(0.0);
    account.setHardLimits(limits);
    List<byte[]> blurb = new ArrayList<>();
    blurb.add(new byte[0]);
    blurb.add(new byte[] { 1, 2, 3 });
    account.setBlurb(blurb);
    Account decoded = encoderMethod.encodeAndDecode(account, ctx);
    assertEquals(1, decoded.getId());
    assertEquals("test account", decoded.getDescription());
    assertEquals(creationDate, decoded.getCreationDate());
    assertNotNull(decoded.getBlurb());
    assertEquals(2, decoded.getBlurb().size());
    assertEquals(0, decoded.getBlurb().get(0).length);
    assertEquals(3, decoded.getBlurb().get(1).length);
    assertArrayEquals(new byte[] { 1, 2, 3 }, decoded.getBlurb().get(1));
    assertArrayEquals(new Account.Currency[] { Account.Currency.BRL }, decoded.getCurrencies());
}
Also used : Account(org.infinispan.protostream.domain.Account) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 4 with Account

use of org.infinispan.protostream.domain.Account in project protostream by infinispan.

the class ProtobufUtilTest method createAccount.

private Account createAccount() {
    Account account = new Account();
    account.setId(1);
    account.setDescription("test account");
    Account.Limits limits = new Account.Limits();
    limits.setMaxDailyLimit(1.5);
    limits.setMaxTransactionLimit(3.5);
    limits.setPayees(new String[] { "Madoff", "Ponzi" });
    account.setLimits(limits);
    Account.Limits hardLimits = new Account.Limits();
    hardLimits.setMaxDailyLimit(5d);
    hardLimits.setMaxTransactionLimit(35d);
    account.setHardLimits(hardLimits);
    Date creationDate = Date.from(LocalDate.of(2017, 7, 20).atStartOfDay().toInstant(ZoneOffset.UTC));
    account.setCreationDate(creationDate);
    List<byte[]> blurb = new ArrayList<>();
    blurb.add(new byte[0]);
    blurb.add(new byte[] { 123 });
    blurb.add(new byte[] { 1, 2, 3, 4 });
    account.setBlurb(blurb);
    account.setCurrencies(new Account.Currency[] { USD, BRL });
    return account;
}
Also used : Account(org.infinispan.protostream.domain.Account) ArrayList(java.util.ArrayList) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 5 with Account

use of org.infinispan.protostream.domain.Account in project protostream by infinispan.

the class ProtobufUtilTest method testCanonicalJSON.

@Test
public void testCanonicalJSON() throws Exception {
    ImmutableSerializationContext ctx = createContext();
    User user = new User();
    user.setId(1);
    user.setName("John");
    user.setSurname("Batman");
    user.setGender(User.Gender.MALE);
    user.setAccountIds(new HashSet<>(Arrays.asList(1, 3)));
    user.setAddresses(Arrays.asList(new Address("Old Street", "XYZ42", -12, false), new Address("Bond Street", "W23", 2, true)));
    Address address = new Address("Abbey Rd", "NW89AY", 3);
    Account account = createAccount();
    testJsonConversion(ctx, address);
    testJsonConversion(ctx, 3.14);
    testJsonConversion(ctx, 777L);
    testJsonConversion(ctx, 3.14f);
    testJsonConversion(ctx, 1);
    testJsonConversion(ctx, null);
    testJsonConversion(ctx, true);
    testJsonConversion(ctx, "Merry Christmas, you filthy animal. And a Happy New Year!");
    testJsonConversion(ctx, User.Gender.FEMALE);
    testJsonConversion(ctx, account);
    testJsonConversion(ctx, user);
}
Also used : Account(org.infinispan.protostream.domain.Account) User(org.infinispan.protostream.domain.User) Address(org.infinispan.protostream.domain.Address) Test(org.junit.Test) AbstractProtoStreamTest(org.infinispan.protostream.test.AbstractProtoStreamTest)

Aggregations

Account (org.infinispan.protostream.domain.Account)6 Date (java.util.Date)3 AbstractProtoStreamTest (org.infinispan.protostream.test.AbstractProtoStreamTest)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 StringReader (java.io.StringReader)1 LocalDate (java.time.LocalDate)1 Address (org.infinispan.protostream.domain.Address)1 User (org.infinispan.protostream.domain.User)1