use of org.infinispan.test.data.Address in project infinispan by infinispan.
the class JavaSerializationTranscoderTest method setUp.
@BeforeClass(alwaysRun = true)
public void setUp() {
dataSrc = new Person("Joe");
Address address = new Address();
address.setCity("London");
dataSrc.setAddress(address);
transcoder = new JavaSerializationTranscoder(new ClassAllowList(Collections.singletonList(".*")));
supportedMediaTypes = transcoder.getSupportedMediaTypes();
}
use of org.infinispan.test.data.Address in project infinispan by infinispan.
the class ProtostreamTranscoderTest method testToFromJson.
@Test
public void testToFromJson() throws IOException {
String type = "org.infinispan.test.core.Address";
String street = "Elm Street";
String city = "NYC";
int zip = 123;
Address data = new Address(street, city, zip);
String jsonString = Json.object().set("_type", type).set("street", street).set("city", city).set("zip", zip).toString();
byte[] byteJson = jsonString.getBytes(UTF_8);
// Converting from json strings to protostream with different binary encodings
Object protoWithNoEncoding = transcoder.transcode(jsonString, APPLICATION_JSON, APPLICATION_PROTOSTREAM);
assertArrayEquals(toWrappedByteArray(ctx, data), (byte[]) protoWithNoEncoding);
Object protoHex = transcoder.transcode(jsonString, APPLICATION_JSON, APPLICATION_PROTOSTREAM.withEncoding("hex"));
assertEquals(protoHex, Base16Codec.encode((byte[]) protoWithNoEncoding));
Object protoBase64 = transcoder.transcode(jsonString, APPLICATION_JSON, APPLICATION_PROTOSTREAM.withEncoding("base64"));
assertEquals(protoBase64, Base64.getEncoder().encode((byte[]) protoWithNoEncoding));
// Converting from json byte[] to protostream with different binary encodings
protoWithNoEncoding = transcoder.transcode(byteJson, APPLICATION_JSON, APPLICATION_PROTOSTREAM);
assertArrayEquals(toWrappedByteArray(ctx, data), (byte[]) protoWithNoEncoding);
protoHex = transcoder.transcode(byteJson, APPLICATION_JSON, APPLICATION_PROTOSTREAM.withEncoding("hex"));
assertEquals(protoHex, Base16Codec.encode((byte[]) protoWithNoEncoding));
protoBase64 = transcoder.transcode(byteJson, APPLICATION_JSON, APPLICATION_PROTOSTREAM.withEncoding("base64"));
assertEquals(protoBase64, Base64.getEncoder().encode((byte[]) protoWithNoEncoding));
// Converting from protostream to json with different output binary encoding
Object result = transcoder.transcode(protoWithNoEncoding, APPLICATION_PROTOSTREAM, APPLICATION_JSON);
assertTrue(result instanceof byte[]);
assertJsonCorrect(result);
result = transcoder.transcode(protoHex, APPLICATION_PROTOSTREAM.withEncoding("hex"), APPLICATION_JSON);
assertTrue(result instanceof byte[]);
assertJsonCorrect(result);
result = transcoder.transcode(protoBase64, APPLICATION_PROTOSTREAM.withEncoding("base64"), APPLICATION_JSON);
assertTrue(result instanceof byte[]);
assertJsonCorrect(result);
result = transcoder.transcode(protoHex, APPLICATION_PROTOSTREAM.withEncoding("hex"), APPLICATION_JSON.withClassType(String.class));
assertTrue(result instanceof String);
assertJsonCorrect(result);
}
use of org.infinispan.test.data.Address in project infinispan by infinispan.
the class BaseStoreFunctionalTest method testPreloadStoredAsBinary.
public void testPreloadStoredAsBinary() {
ConfigurationBuilder cb = getDefaultCacheConfiguration();
createCacheStoreConfig(cb.persistence(), "testPreloadStoredAsBinary", true).memory().storageType(StorageType.BINARY);
TestingUtil.defineConfiguration(cacheManager, "testPreloadStoredAsBinary", cb.build());
Cache<String, Person> cache = cacheManager.getCache("testPreloadStoredAsBinary");
cache.start();
assert cache.getCacheConfiguration().persistence().preload();
assertEquals(StorageType.BINARY, cache.getCacheConfiguration().memory().storageType());
byte[] pictureBytes = new byte[] { 1, 82, 123, 19 };
cache.put("k1", new Person("1"));
cache.put("k2", new Person("2", null, pictureBytes, null, null, false), 111111, TimeUnit.MILLISECONDS);
cache.put("k3", new Person("3", null, null, Sex.MALE, null, false), -1, TimeUnit.MILLISECONDS, 222222, TimeUnit.MILLISECONDS);
cache.put("k4", new Person("4", new Address("Street", "City", 12345), null, null, null, true), 333333, TimeUnit.MILLISECONDS, 444444, TimeUnit.MILLISECONDS);
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("EST"));
calendar.set(2009, Calendar.MARCH, 18, 3, 22, 57);
// Chop off the last milliseconds as some databases don't have that high of accuracy
calendar.setTimeInMillis((calendar.getTimeInMillis() / 1000) * 1000);
Date infinispanBirthDate = calendar.getTime();
Person infinispanPerson = createEmptyPerson("Infinispan");
infinispanPerson.setBirthDate(infinispanBirthDate);
infinispanPerson.setAcceptedToS(true);
cache.put("Infinispan", infinispanPerson);
// Just to prove nothing in memory even with stop
cache.getAdvancedCache().getDataContainer().clear();
assertEquals(createEmptyPerson("1"), cache.get("k1"));
Person person2 = createEmptyPerson("2");
person2.setPicture(pictureBytes);
assertEquals(person2, cache.get("k2"));
Person person3 = createEmptyPerson("3");
person3.setSex(Sex.MALE);
assertEquals(person3, cache.get("k3"));
assertEquals(new Person("4", new Address("Street", "City", 12345), null, null, null, true), cache.get("k4"));
assertEquals(infinispanPerson, cache.get("Infinispan"));
cache.stop();
cache.start();
assertEquals(5, cache.entrySet().size());
assertEquals(createEmptyPerson("1"), cache.get("k1"));
assertEquals(person2, cache.get("k2"));
assertEquals(person3, cache.get("k3"));
assertEquals(new Person("4", new Address("Street", "City", 12345), null, null, null, true), cache.get("k4"));
assertEquals(infinispanPerson, cache.get("Infinispan"));
}
use of org.infinispan.test.data.Address in project infinispan by infinispan.
the class QueriesJdbcJoinTest method samplePerson.
private Person samplePerson(String name) {
Address address = new Address();
address.setCity("London");
address.setStreet("Cool Street");
address.setZip(1321);
return new Person(name, address, new byte[] { 0x1, 0x12 }, Sex.MALE, new java.util.Date(1629495308), true);
}
use of org.infinispan.test.data.Address in project infinispan by infinispan.
the class PersonKey2StringMapper method getStringMapping.
public String getStringMapping(Object key) {
Person person = (Person) key;
Address addr = person.getAddress();
if (addr == null)
return person.getName();
return person.getName() + "_" + addr.getStreet() + "_" + addr.getCity() + "_" + addr.getZip();
}
Aggregations