Search in sources :

Example 1 with Person

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

the class AutoValueModelTest method testSelectAll.

@Test
public void testSelectAll() {
    List<Integer> added = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        added.add(randomPerson());
    }
    Result<Person> result = data.select(Person.class).get();
    for (Person p : result) {
        assertTrue(added.contains(p.getId()));
    }
}
Also used : ArrayList(java.util.ArrayList) Person(io.requery.test.autovalue.Person) Test(org.junit.Test)

Example 2 with Person

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

the class AutoValueModelTest method testDelete.

@Test
public void testDelete() throws MalformedURLException {
    Integer key = randomPerson();
    Person p = data.findByKey(Person.class, key);
    assertNotNull(p);
    data.delete(p);
    p = data.findByKey(Person.class, key);
    assertNull(p);
}
Also used : Person(io.requery.test.autovalue.Person) Test(org.junit.Test)

Example 3 with Person

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

the class AutoValueModelTest method testInsert.

@Test
public void testInsert() {
    Set<Integer> ids = new HashSet<>();
    for (int i = 0; i < 10; i++) {
        Person p = Person.builder().setName("person" + i).setAge(30).setEmail("test@example.com").setUUID(UUID.randomUUID()).setBirthday(new Date()).setAbout("About me").build();
        Integer key = data.insert(p, Integer.class);
        assertTrue(key > 0);
        ids.add(key);
    }
    final Set<Integer> selected = new HashSet<>();
    data.select(PersonType.ID).get().each(new Consumer<Tuple>() {

        @Override
        public void accept(Tuple tuple) {
            selected.add(tuple.get(PersonType.ID));
        }
    });
    assertEquals(ids, selected);
}
Also used : Person(io.requery.test.autovalue.Person) Date(java.util.Date) Tuple(io.requery.query.Tuple) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with Person

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

the class AutoValueModelTest method testUpdate.

@Test
public void testUpdate() {
    Person person = Person.builder().setName("Bob").setAge(30).setEmail("test@example.com").setUUID(UUID.randomUUID()).setBirthday(new Date()).setAbout("About me").build();
    Integer key = data.insert(person, Integer.class);
    Person renamed = person.toBuilder().setId(key).setName("Bobby").build();
    data.update(renamed);
    person = data.findByKey(Person.class, key);
    assertTrue(person.getName().equals("Bobby"));
}
Also used : Person(io.requery.test.autovalue.Person) Date(java.util.Date) Test(org.junit.Test)

Example 5 with Person

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

the class AutoValueModelTest method testRefresh.

@Test
public void testRefresh() throws MalformedURLException {
    Integer key = randomPerson();
    Integer count = data.update(Person.class).set(PersonType.NAME, "Unknown").get().value();
    assertTrue(count > 0);
    Person p = data.findByKey(Person.class, key);
    data.refresh(p);
    assertEquals(p.getName(), "Unknown");
}
Also used : Person(io.requery.test.autovalue.Person) Test(org.junit.Test)

Aggregations

Person (io.requery.test.autovalue.Person)7 Test (org.junit.Test)6 Date (java.util.Date)2 Tuple (io.requery.query.Tuple)1 Phone (io.requery.test.autovalue.Phone)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1