Search in sources :

Example 21 with Person

use of org.infinispan.test.data.Person 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();
}
Also used : Address(org.infinispan.test.data.Address) Person(org.infinispan.test.data.Person)

Example 22 with Person

use of org.infinispan.test.data.Person in project infinispan by infinispan.

the class TextObjectTranscoderTest method setUp.

@BeforeClass(alwaysRun = true)
public void setUp() {
    dataSrc = new Person("Joe");
    Address address = new Address();
    address.setCity("London");
    dataSrc.setAddress(address);
    transcoder = new DefaultTranscoder(TestingUtil.createProtoStreamMarshaller(RestTestSCI.INSTANCE));
    supportedMediaTypes = transcoder.getSupportedMediaTypes();
}
Also used : DefaultTranscoder(org.infinispan.commons.dataconversion.DefaultTranscoder) Address(org.infinispan.test.data.Address) Person(org.infinispan.test.data.Person) BeforeClass(org.testng.annotations.BeforeClass)

Example 23 with Person

use of org.infinispan.test.data.Person in project infinispan by infinispan.

the class AllowListMarshallingTest method testSafeClassAllowed.

public void testSafeClassAllowed() {
    remoteCacheManager.getCache().put("safe", new Person());
    remoteCacheManager.getCache().get("safe");
}
Also used : Person(org.infinispan.test.data.Person)

Example 24 with Person

use of org.infinispan.test.data.Person in project infinispan by infinispan.

the class ProtostreamTranscoderTest method testWrappedMessage.

@Test
public void testWrappedMessage() throws IOException {
    Person input = new Person("value");
    // Produces MessageWrapped and unwrapped payloads
    byte[] wrapped = (byte[]) transcoder.transcode(input, APPLICATION_OBJECT, APPLICATION_PROTOSTREAM);
    byte[] unwrapped = (byte[]) transcoder.transcode(input, APPLICATION_OBJECT, UNWRAPPED_PROTOSTREAM);
    assertEquals(input, ProtobufUtil.fromWrappedByteArray(ctx, wrapped));
    assertEquals(input, ProtobufUtil.fromByteArray(ctx, unwrapped, Person.class));
    // Convert from MessageWrapped back to object
    Object fromWrapped = transcoder.transcode(wrapped, APPLICATION_PROTOSTREAM, APPLICATION_OBJECT);
    assertEquals(input, fromWrapped);
    // Convert from unwrapped payload back to object, specifying the object type
    Object fromUnWrappedWithType = transcoder.transcode(unwrapped, UNWRAPPED_PROTOSTREAM, TYPED_OBJECT);
    assertEquals(input, fromUnWrappedWithType);
    // Should throw exception if trying to convert from unwrapped without passing the type
    try {
        transcoder.transcode(unwrapped, UNWRAPPED_PROTOSTREAM, APPLICATION_OBJECT);
        Assert.fail("should not convert from unwrapped without type");
    } catch (MarshallingException ignored) {
    }
}
Also used : MarshallingException(org.infinispan.commons.marshall.MarshallingException) Person(org.infinispan.test.data.Person) Test(org.testng.annotations.Test) AbstractTranscoderTest(org.infinispan.test.dataconversion.AbstractTranscoderTest)

Example 25 with Person

use of org.infinispan.test.data.Person in project infinispan by infinispan.

the class LazyCacheAPITest method testReplace.

public void testReplace(Method m) {
    Person key = new Person(m.getName());
    cache.put(key, "1");
    assert "1".equals(cache.get(new Person(m.getName())));
    Object oldValue = cache.replace(new Person(m.getName()), "2");
    assert "1".equals(oldValue);
    assert "2".equals(cache.get(new Person(m.getName())));
}
Also used : Person(org.infinispan.test.data.Person)

Aggregations

Person (org.infinispan.test.data.Person)42 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)10 Test (org.testng.annotations.Test)10 Address (org.infinispan.test.data.Address)9 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)8 Marshaller (org.infinispan.commons.marshall.Marshaller)5 PersistenceMarshaller (org.infinispan.marshall.persistence.PersistenceMarshaller)5 TransactionManager (javax.transaction.TransactionManager)4 Cache (org.infinispan.Cache)4 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)4 FunctionalTestUtils.await (org.infinispan.functional.FunctionalTestUtils.await)4 AssertJUnit.assertTrue (org.testng.AssertJUnit.assertTrue)4 BeforeClass (org.testng.annotations.BeforeClass)4 Properties (java.util.Properties)3 AdvancedCache (org.infinispan.AdvancedCache)3 GenericJBossMarshaller (org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller)3 DelegatingUserMarshaller (org.infinispan.marshall.core.impl.DelegatingUserMarshaller)3 CacheManagerCallable (org.infinispan.test.CacheManagerCallable)3 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2