Search in sources :

Example 11 with Phone

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));
}
Also used : Phone(io.requery.test.model.Phone) Person(io.requery.test.model.Person) Group_Person(io.requery.test.model.Group_Person) Test(org.junit.Test)

Example 12 with 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());
}
Also used : Phone(io.requery.test.model.Phone) Person(io.requery.test.model.Person) Group_Person(io.requery.test.model.Group_Person) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with Phone

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());
    }
}
Also used : Phone(io.requery.test.model.Phone) Person(io.requery.test.model.Person) Group_Person(io.requery.test.model.Group_Person) Test(org.junit.Test)

Example 14 with Phone

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;
}
Also used : Random(java.util.Random) Phone(io.requery.test.model.Phone)

Example 15 with 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);
}
Also used : Single(rx.Single) Phone(io.requery.test.model.Phone) Func1(rx.functions.Func1) Person(io.requery.test.model.Person) Test(org.junit.Test)

Aggregations

Phone (io.requery.test.model.Phone)25 Test (org.junit.Test)24 Person (io.requery.test.model.Person)22 Group_Person (io.requery.test.model.Group_Person)13 HashSet (java.util.HashSet)6 Function (java.util.function.Function)3 Function (io.reactivex.functions.Function)2 Result (io.requery.query.Result)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Single (rx.Single)2 Func1 (rx.functions.Func1)2 Disposable (io.reactivex.disposables.Disposable)1 ReactiveResult (io.requery.reactivex.ReactiveResult)1 RxResult (io.requery.rx.RxResult)1 Random (java.util.Random)1 CompletionStage (java.util.concurrent.CompletionStage)1 Subscription (rx.Subscription)1