use of io.requery.test.model.Person in project requery by requery.
the class FunctionalTest method testQueryConditions.
@Test
public void testQueryConditions() {
Person person = randomPerson();
person.setAge(75);
data.insert(person);
Person p = data.select(Person.class).where(Person.AGE.greaterThanOrEqual(75)).get().first();
assertSame(p, person);
p = data.select(Person.class).where(Person.AGE.lessThanOrEqual(75)).get().first();
assertSame(p, person);
p = data.select(Person.class).where(Person.AGE.greaterThan(75)).get().firstOrNull();
assertNull(p);
p = data.select(Person.class).where(Person.AGE.notEqual(75)).get().firstOrNull();
assertNull(p);
p = data.select(Person.class).where(Person.AGE.gte(75)).get().first();
assertSame(p, person);
assertSame(p, person);
p = data.select(Person.class).where(Person.AGE.lte(75)).get().first();
assertSame(p, person);
p = data.select(Person.class).where(Person.AGE.gt(75)).get().firstOrNull();
assertNull(p);
p = data.select(Person.class).where(Person.AGE.ne(75)).get().firstOrNull();
assertNull(p);
}
use of io.requery.test.model.Person in project requery by requery.
the class RandomData method randomPerson.
static Person randomPerson() {
Random random = new Random();
Person person = new Person();
String[] firstNames = new String[] { "Alice", "Bob", "Carol" };
String[] lastNames = new String[] { "Smith", "Lee", "Jones" };
person.setName(firstNames[random.nextInt(firstNames.length)] + " " + lastNames[random.nextInt(lastNames.length)]);
person.setEmail(person.getName().replaceAll(" ", "").toLowerCase() + "@example.com");
person.setUUID(UUID.randomUUID());
try {
person.setHomepage(new URL("http://www.google.com"));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
Calendar calendar = Calendar.getInstance();
//noinspection MagicConstant
calendar.set(1900 + random.nextInt(90), random.nextInt(12), random.nextInt(30));
person.setBirthday(calendar.getTime());
return person;
}
use of io.requery.test.model.Person in project requery by requery.
the class ReactiveTest method testSelfObservableDelete.
@Test
public void testSelfObservableDelete() throws Exception {
final AtomicInteger count = new AtomicInteger();
Disposable disposable = data.select(Person.class).get().observableResult().subscribe(new Consumer<Result<Person>>() {
@Override
public void accept(Result<Person> persons) {
count.incrementAndGet();
}
});
Person person = randomPerson();
data.insert(person).blockingGet();
data.delete(person).blockingGet();
assertEquals(3, count.get());
disposable.dispose();
}
use of io.requery.test.model.Person in project requery by requery.
the class FunctionalTest method testDeleteManyToMany.
@Test
public void testDeleteManyToMany() {
final Person person = randomPerson();
data.insert(person);
final Collection<Group> groups = new ArrayList<>();
data.runInTransaction(new Callable<Object>() {
@Override
public Object call() throws Exception {
for (int i = 0; i < 10; i++) {
Group group = new Group();
group.setName("DeleteGroup" + i);
data.insert(group);
person.getGroups().add(group);
groups.add(group);
}
data.update(person);
return null;
}
});
for (Group g : groups) {
person.getGroups().remove(g);
}
data.update(person);
}
use of io.requery.test.model.Person 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);
}
Aggregations