Search in sources :

Example 91 with Person

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

the class FunctionalTest method testQueryConditions.

@Test
public void testQueryConditions() {
    Person person = randomPerson();
    person.setAge(75);
    data.insert(person);
    Person p = data.select(Person.class).where(Person.AGE.greaterThanOrEqual(75)).get().first();
    assertSame(p, person);
    p = data.select(Person.class).where(Person.AGE.lessThanOrEqual(75)).get().first();
    assertSame(p, person);
    p = data.select(Person.class).where(Person.AGE.greaterThan(75)).get().firstOrNull();
    assertNull(p);
    p = data.select(Person.class).where(Person.AGE.notEqual(75)).get().firstOrNull();
    assertNull(p);
    p = data.select(Person.class).where(Person.AGE.gte(75)).get().first();
    assertSame(p, person);
    assertSame(p, person);
    p = data.select(Person.class).where(Person.AGE.lte(75)).get().first();
    assertSame(p, person);
    p = data.select(Person.class).where(Person.AGE.gt(75)).get().firstOrNull();
    assertNull(p);
    p = data.select(Person.class).where(Person.AGE.ne(75)).get().firstOrNull();
    assertNull(p);
}
Also used : Person(io.requery.test.model.Person) Group_Person(io.requery.test.model.Group_Person) Test(org.junit.Test)

Example 92 with Person

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

the class RandomData method randomPerson.

static Person randomPerson() {
    Random random = new Random();
    Person person = new Person();
    String[] firstNames = new String[] { "Alice", "Bob", "Carol" };
    String[] lastNames = new String[] { "Smith", "Lee", "Jones" };
    person.setName(firstNames[random.nextInt(firstNames.length)] + " " + lastNames[random.nextInt(lastNames.length)]);
    person.setEmail(person.getName().replaceAll(" ", "").toLowerCase() + "@example.com");
    person.setUUID(UUID.randomUUID());
    try {
        person.setHomepage(new URL("http://www.google.com"));
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
    Calendar calendar = Calendar.getInstance();
    //noinspection MagicConstant
    calendar.set(1900 + random.nextInt(90), random.nextInt(12), random.nextInt(30));
    person.setBirthday(calendar.getTime());
    return person;
}
Also used : MalformedURLException(java.net.MalformedURLException) Random(java.util.Random) Calendar(java.util.Calendar) Person(io.requery.test.model.Person) URL(java.net.URL)

Example 93 with Person

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

the class ReactiveTest method testSelfObservableDelete.

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

Example 94 with Person

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

the class FunctionalTest method testDeleteManyToMany.

@Test
public void testDeleteManyToMany() {
    final Person person = randomPerson();
    data.insert(person);
    final Collection<Group> groups = new ArrayList<>();
    data.runInTransaction(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            for (int i = 0; i < 10; i++) {
                Group group = new Group();
                group.setName("DeleteGroup" + i);
                data.insert(group);
                person.getGroups().add(group);
                groups.add(group);
            }
            data.update(person);
            return null;
        }
    });
    for (Group g : groups) {
        person.getGroups().remove(g);
    }
    data.update(person);
}
Also used : Group(io.requery.test.model.Group) ArrayList(java.util.ArrayList) Person(io.requery.test.model.Person) Group_Person(io.requery.test.model.Group_Person) RollbackException(io.requery.RollbackException) SQLException(java.sql.SQLException) PersistenceException(io.requery.PersistenceException) Test(org.junit.Test)

Example 95 with Person

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

the class FunctionalTest method testFindByKeyDelete.

@Test
public void testFindByKeyDelete() {
    Person person = randomPerson();
    Address address = randomAddress();
    person.setAddress(address);
    data.insert(person);
    assertTrue(address.getId() > 0);
    Person other = data.findByKey(Person.class, person.getId());
    assertSame(person, other);
    data.delete(other);
    other = data.findByKey(Person.class, person.getId());
    assertNull(other);
    Address cached = data.findByKey(Address.class, address.getId());
    assertNull(cached);
}
Also used : Address(io.requery.test.model.Address) Person(io.requery.test.model.Person) Group_Person(io.requery.test.model.Group_Person) 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