use of org.infinispan.protostream.domain.Address in project protostream by infinispan.
the class MarshallingTest method doMarshallUserTest.
private void doMarshallUserTest(EncoderMethod<User> method) 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(Collections.singletonList(new Address("Old Street", "XYZ42", -12)));
User decoded = method.encodeAndDecode(user, ctx);
assertEquals(1, decoded.getId());
assertEquals("John", decoded.getName());
assertEquals("Batman", decoded.getSurname());
assertEquals(User.Gender.MALE, decoded.getGender());
assertNotNull(decoded.getAddresses());
assertEquals(1, decoded.getAddresses().size());
assertEquals("Old Street", decoded.getAddresses().get(0).getStreet());
assertEquals("XYZ42", decoded.getAddresses().get(0).getPostCode());
assertNotNull(decoded.getAccountIds());
assertEquals(2, decoded.getAccountIds().size());
assertTrue(decoded.getAccountIds().contains(1));
assertTrue(decoded.getAccountIds().contains(3));
}
use of org.infinispan.protostream.domain.Address in project protostream by infinispan.
the class ProtobufUtilTest method testFromByteArrayWithExtraPadding.
@Test(expected = MalformedProtobufException.class)
public void testFromByteArrayWithExtraPadding() 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), new Address("Bond Street", "W23", 2)));
byte[] userBytes = ProtobufUtil.toByteArray(ctx, user);
byte[] userBytesWithPadding = new byte[userBytes.length + 20];
System.arraycopy(userBytes, 0, userBytesWithPadding, 0, userBytes.length);
Arrays.fill(userBytesWithPadding, userBytes.length, userBytes.length + 20, (byte) 42);
// this must fail
ProtobufUtil.fromByteArray(ctx, userBytesWithPadding, User.class);
}
use of org.infinispan.protostream.domain.Address 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);
}
use of org.infinispan.protostream.domain.Address in project protostream by infinispan.
the class AddressMarshaller method readFrom.
@Override
public Address readFrom(ProtoStreamReader reader) throws IOException {
String street = reader.readString("street");
String postCode = reader.readString("postCode");
int number = reader.readInt("number");
Boolean isCommercial = reader.readBoolean("isCommercial");
Address address = new Address();
address.setStreet(street);
address.setPostCode(postCode);
address.setNumber(number);
address.setCommercial(isCommercial);
return address;
}
Aggregations