Search in sources :

Example 1 with Phone

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

the class RxTest method testQuerySelfObservableRelational.

@Test
public void testQuerySelfObservableRelational() throws Exception {
    final AtomicInteger count = new AtomicInteger();
    Subscription subscription = data.select(Person.class).get().toSelfObservable().subscribe(new Action1<Result<Person>>() {

        @Override
        public void call(Result<Person> persons) {
            count.incrementAndGet();
        }
    });
    Person person = randomPerson();
    data.insert(person).toBlocking().value();
    Phone phone = randomPhone();
    person.getPhoneNumbers().add(phone);
    data.update(person).toBlocking().value();
    data.delete(phone).toBlocking().value();
    assertEquals(4, count.get());
    subscription.unsubscribe();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Phone(io.requery.test.model.Phone) Subscription(rx.Subscription) Person(io.requery.test.model.Person) RxResult(io.requery.rx.RxResult) Result(io.requery.query.Result) Test(org.junit.Test)

Example 2 with Phone

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

the class RxTest method testQueryObservableFromEntity.

@Test
public void testQueryObservableFromEntity() 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();
    int count = person.getPhoneNumbers().toList().size();
    assertEquals(1, count);
}
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)

Example 3 with Phone

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

the class ReactiveTest method testQuerySelfObservableRelational.

@Test
public void testQuerySelfObservableRelational() 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();
    Phone phone = randomPhone();
    person.getPhoneNumbers().add(phone);
    data.update(person).blockingGet();
    data.delete(phone).blockingGet();
    assertEquals(4, count.get());
    disposable.dispose();
}
Also used : Disposable(io.reactivex.disposables.Disposable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Phone(io.requery.test.model.Phone) Person(io.requery.test.model.Person) ReactiveResult(io.requery.reactivex.ReactiveResult) Result(io.requery.query.Result) Test(org.junit.Test)

Example 4 with Phone

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

the class ReactiveTest method testQueryObservableFromEntity.

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

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

        @Override
        public Single<?> apply(Phone phone) {
            return data.insert(phone);
        }
    }).blockingGet();
    int count = person.getPhoneNumbers().toList().size();
    assertEquals(1, count);
}
Also used : Function(io.reactivex.functions.Function) Phone(io.requery.test.model.Phone) Person(io.requery.test.model.Person) Test(org.junit.Test)

Example 5 with Phone

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

the class ReactorTest method testInsertOneToMany.

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

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

        @Override
        public Mono<?> apply(Phone phone) {
            return data.insert(phone);
        }
    }).blockFirst();
    assertTrue(person.getPhoneNumbers().toList().size() == 1);
}
Also used : Function(java.util.function.Function) Phone(io.requery.test.model.Phone) 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