use of io.requery.test.model.Phone in project requery by requery.
the class FunctionalTest method testRefreshAttributes.
@Test
public void testRefreshAttributes() {
Person person = randomPerson();
data.insert(person);
Phone phone = randomPhone();
person.getPhoneNumbers().add(phone);
data.update(person);
data.refresh(person, Person.NAME, Person.PHONE_NUMBERS_SET, Person.ADDRESS, Person.EMAIL);
assertTrue(person.getPhoneNumbersSet().contains(phone));
}
use of io.requery.test.model.Phone in project requery by requery.
the class FunctionalTest method testInsertOneToManyInverse.
@Test
public void testInsertOneToManyInverse() {
Person person = randomPerson();
Phone phone1 = randomPhone();
Phone phone2 = randomPhone();
phone1.setOwner(person);
person.getPhoneNumbers().add(phone1);
person.getPhoneNumbers().add(phone2);
data.insert(person);
HashSet<Phone> set = new HashSet<>(person.getPhoneNumbers().toList());
assertEquals(2, set.size());
assertTrue(set.containsAll(Arrays.asList(phone1, phone2)));
assertEquals(person, phone1.getOwner());
assertEquals(person, phone2.getOwner());
}
use of io.requery.test.model.Phone in project requery by requery.
the class FunctionalTest method testQueryByForeignKey.
@Test
public void testQueryByForeignKey() {
Person person = randomPerson();
data.insert(person);
Phone phone1 = randomPhone();
Phone phone2 = randomPhone();
person.getPhoneNumbers().add(phone1);
person.getPhoneNumbers().add(phone2);
data.update(person);
assertTrue(person.getPhoneNumbersSet().contains(phone1));
try (Result<Phone> result = data.select(Phone.class).where(Phone.OWNER.eq(person)).get()) {
assertTrue(person.getPhoneNumbersList().containsAll(result.toList()));
assertEquals(2, person.getPhoneNumbersList().size());
assertEquals(2, result.toList().size());
}
// by id
try (Result<Phone> result = data.select(Phone.class).where(Phone.OWNER_ID.eq(person.getId())).get()) {
assertTrue(person.getPhoneNumbersList().containsAll(result.toList()));
assertEquals(2, person.getPhoneNumbersList().size());
assertEquals(2, result.toList().size());
}
}
use of io.requery.test.model.Phone in project requery by requery.
the class RandomData method randomPhone.
static Phone randomPhone() {
Phone phone = new Phone();
phone.setPhoneNumber("555-" + (1000 + new Random().nextInt(8000)));
phone.setNormalized(true);
return phone;
}
use of io.requery.test.model.Phone in project requery by requery.
the class RxTest method testInsertOneToMany.
@Test
public void testInsertOneToMany() throws Exception {
final Person person = randomPerson();
data.insert(person).map(new Func1<Person, Phone>() {
@Override
public Phone call(Person person) {
Phone phone1 = randomPhone();
phone1.setOwner(person);
return phone1;
}
}).flatMap(new Func1<Phone, Single<?>>() {
@Override
public Single<?> call(Phone phone) {
return data.insert(phone);
}
}).toBlocking().value();
assertTrue(person.getPhoneNumbers().toList().size() == 1);
}
Aggregations