Search in sources :

Example 56 with Person

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

the class CompletableEntityStoreTest method testInsert.

@Test
public void testInsert() throws Exception {
    Person person = randomPerson();
    data.insert(person).thenAccept(new Consumer<Person>() {

        @Override
        public void accept(Person person) {
            assertTrue(person.getId() > 0);
            Person cached = data.select(Person.class).where(Person.ID.equal(person.getId())).get().first();
            assertSame(cached, person);
        }
    }).toCompletableFuture().get();
    assertEquals(transactionState, TransactionState.COMMIT);
}
Also used : Person(io.requery.test.model.Person) Test(org.junit.Test)

Example 57 with Person

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

the class CompletableEntityStoreTest method testInsertCount.

@Test
public void testInsertCount() throws Exception {
    Person person = randomPerson();
    data.insert(person).thenAccept(new Consumer<Person>() {

        @Override
        public void accept(Person person) {
            assertTrue(person.getId() > 0);
        }
    }).thenCompose(new Function<Void, CompletionStage<Integer>>() {

        @Override
        public CompletionStage<Integer> apply(Void aVoid) {
            return data.count(Person.class).get().toCompletableFuture();
        }
    }).toCompletableFuture().get();
}
Also used : Consumer(java.util.function.Consumer) Person(io.requery.test.model.Person) CompletionStage(java.util.concurrent.CompletionStage) Test(org.junit.Test)

Example 58 with Person

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

the class CompletableEntityStoreTest method testInsertBlocking.

@Test
public void testInsertBlocking() throws Exception {
    final Person person = randomPerson();
    data.toBlocking().insert(person);
    assertTrue(person.getId() > 0);
}
Also used : Person(io.requery.test.model.Person) Test(org.junit.Test)

Example 59 with Person

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

the class RxTest method testSelfObservableDelete.

@Test
public void testSelfObservableDelete() 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();
    data.delete(person).toBlocking().value();
    assertEquals(3, count.get());
    subscription.unsubscribe();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(rx.Subscription) Person(io.requery.test.model.Person) RxResult(io.requery.rx.RxResult) Result(io.requery.query.Result) Test(org.junit.Test)

Example 60 with Person

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

the class RxTest method testSelfObservableDeleteQuery.

@Test
public void testSelfObservableDeleteQuery() 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();
    assertEquals(2, count.get());
    int rows = data.delete(Person.class).get().value();
    assertEquals(3, count.get());
    subscription.unsubscribe();
    assertEquals(rows, 1);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(rx.Subscription) Person(io.requery.test.model.Person) RxResult(io.requery.rx.RxResult) Result(io.requery.query.Result) Test(org.junit.Test)

Aggregations

Person (io.requery.test.model.Person)120 Test (org.junit.Test)117 Group_Person (io.requery.test.model.Group_Person)75 Phone (io.requery.test.model.Phone)22 ArrayList (java.util.ArrayList)18 Tuple (io.requery.query.Tuple)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 Result (io.requery.query.Result)8 Address (io.requery.test.model.Address)8 Group (io.requery.test.model.Group)8 HashSet (java.util.HashSet)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 ReactiveResult (io.requery.reactivex.ReactiveResult)5 RxResult (io.requery.rx.RxResult)5 SQLException (java.sql.SQLException)5 Disposable (io.reactivex.disposables.Disposable)4 Calendar (java.util.Calendar)4 Subscription (rx.Subscription)4 Function (io.reactivex.functions.Function)3 PersistenceException (io.requery.PersistenceException)3