Search in sources :

Example 6 with Phone

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

the class CompletableEntityStoreTest method testInsertOneToMany.

@Test
public void testInsertOneToMany() throws Exception {
    final Person person = randomPerson();
    data.insert(person).thenApply(new Function<Person, Phone>() {

        @Override
        public Phone apply(Person person) {
            Phone phone1 = randomPhone();
            phone1.setOwner(person);
            return phone1;
        }
    }).thenCompose(new Function<Phone, CompletionStage<Phone>>() {

        @Override
        public CompletionStage<Phone> apply(Phone phone) {
            return data.insert(phone);
        }
    }).toCompletableFuture().get();
    HashSet<Phone> set = new HashSet<>(person.getPhoneNumbers().toList());
    assertEquals(1, set.size());
}
Also used : Function(java.util.function.Function) Phone(io.requery.test.model.Phone) Person(io.requery.test.model.Person) CompletionStage(java.util.concurrent.CompletionStage) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with Phone

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

the class FunctionalTest method testDeleteOneToManyResult.

@Test
public void testDeleteOneToManyResult() {
    Person person = randomPerson();
    data.insert(person);
    Phone phone1 = randomPhone();
    Phone phone2 = randomPhone();
    phone1.setOwner(person);
    phone2.setOwner(person);
    data.insert(phone1);
    data.insert(phone2);
    data.refresh(person);
    assertEquals(2, person.getPhoneNumbers().toList().size());
    data.delete(person.getPhoneNumbers());
    Phone cached = data.findByKey(Phone.class, phone1.getId());
    assertNull(cached);
}
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 8 with Phone

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

the class FunctionalTest method testInsertOneToManyInverseUpdate.

@Test
public void testInsertOneToManyInverseUpdate() {
    Person person = randomPerson();
    data.insert(person);
    Phone phone1 = randomPhone();
    Phone phone2 = randomPhone();
    person.getPhoneNumbers().add(phone1);
    person.getPhoneNumbers().add(phone2);
    data.update(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 9 with Phone

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

the class FunctionalTest method testInsertEmptyObject.

@Test
public void testInsertEmptyObject() {
    Phone phone = new Phone();
    data.insert(phone);
    assertTrue(phone.getId() > 0);
}
Also used : Phone(io.requery.test.model.Phone) Test(org.junit.Test)

Example 10 with Phone

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

the class FunctionalTest method testRefreshAll.

@Test
public void testRefreshAll() {
    Person person = randomPerson();
    data.insert(person);
    Phone phone = randomPhone();
    person.getPhoneNumbers().add(phone);
    data.update(person);
    data.refreshAll(person);
    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)

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