Search in sources :

Example 6 with Address

use of io.requery.test.model.Address in project requery by requery.

the class EntityCacheTest method testSerializeGetPut.

@Test
public void testSerializeGetPut() {
    CachingProvider provider = Caching.getCachingProvider();
    CacheManager cacheManager = provider.getCacheManager();
    EntityCache cache = new EntityCacheBuilder(Models.DEFAULT).useReferenceCache(false).useSerializableCache(true).useCacheManager(cacheManager).build();
    Person p = new Person();
    p.setName("Alice");
    p.setUUID(UUID.randomUUID());
    p.setAddress(new Address());
    p.getAddress().setType(AddressType.HOME);
    int id = 100;
    cache.put(Person.class, id, p);
    Person d = cache.get(Person.class, id);
    Assert.assertNotNull(d);
    Assert.assertNotSame(p, d);
    Assert.assertEquals(p.getName(), d.getName());
    Assert.assertEquals(p.getUUID(), d.getUUID());
}
Also used : EntityCache(io.requery.EntityCache) Address(io.requery.test.model.Address) CacheManager(javax.cache.CacheManager) EntityCacheBuilder(io.requery.cache.EntityCacheBuilder) Person(io.requery.test.model.Person) CachingProvider(javax.cache.spi.CachingProvider) Test(org.junit.Test)

Example 7 with Address

use of io.requery.test.model.Address in project requery by requery.

the class FunctionalTest method testQueryJoinOrderBy.

@Test
public void testQueryJoinOrderBy() {
    Person person = randomPerson();
    person.setAddress(randomAddress());
    data.insert(person);
    // not a useful query just tests the sql output
    Result<Address> result = data.select(Address.class).join(Person.class).on(Person.ADDRESS_ID.eq(Person.ID)).where(Person.ID.eq(person.getId())).orderBy(Address.CITY.desc()).get();
    List<Address> addresses = result.toList();
    assertTrue(addresses.size() > 0);
}
Also used : Address(io.requery.test.model.Address) Person(io.requery.test.model.Person) Group_Person(io.requery.test.model.Group_Person) Test(org.junit.Test)

Example 8 with Address

use of io.requery.test.model.Address in project requery by requery.

the class FunctionalTest method testFindByKeyDelete.

@Test
public void testFindByKeyDelete() {
    Person person = randomPerson();
    Address address = randomAddress();
    person.setAddress(address);
    data.insert(person);
    assertTrue(address.getId() > 0);
    Person other = data.findByKey(Person.class, person.getId());
    assertSame(person, other);
    data.delete(other);
    other = data.findByKey(Person.class, person.getId());
    assertNull(other);
    Address cached = data.findByKey(Address.class, address.getId());
    assertNull(cached);
}
Also used : Address(io.requery.test.model.Address) Person(io.requery.test.model.Person) Group_Person(io.requery.test.model.Group_Person) Test(org.junit.Test)

Example 9 with Address

use of io.requery.test.model.Address in project requery by requery.

the class FunctionalTest method testUpdateOneToOneCascade.

@Test
public void testUpdateOneToOneCascade() {
    Address address = randomAddress();
    Person person = randomPerson();
    data.insert(person);
    person.setAddress(address);
    data.update(person);
    assertSame(address.getPerson(), person);
}
Also used : Address(io.requery.test.model.Address) Person(io.requery.test.model.Person) Group_Person(io.requery.test.model.Group_Person) Test(org.junit.Test)

Example 10 with Address

use of io.requery.test.model.Address in project requery by requery.

the class FunctionalTest method testFindByKeyDeleteInverse.

@Test
public void testFindByKeyDeleteInverse() {
    Person person = randomPerson();
    Address address = randomAddress();
    person.setAddress(address);
    data.insert(person);
    data.delete(address);
    person = data.findByKey(Person.class, person.getId());
    assertNull(person);
    Address cached = data.findByKey(Address.class, address.getId());
    assertNull(cached);
}
Also used : Address(io.requery.test.model.Address) Person(io.requery.test.model.Person) Group_Person(io.requery.test.model.Group_Person) Test(org.junit.Test)

Aggregations

Address (io.requery.test.model.Address)11 Test (org.junit.Test)10 Person (io.requery.test.model.Person)8 Group_Person (io.requery.test.model.Group_Person)7 EntityCache (io.requery.EntityCache)1 EntityCacheBuilder (io.requery.cache.EntityCacheBuilder)1 Random (java.util.Random)1 CacheManager (javax.cache.CacheManager)1 CachingProvider (javax.cache.spi.CachingProvider)1