Search in sources :

Example 6 with Person

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

the class AutoValueModelTest method randomPerson.

int randomPerson() {
    Random random = new Random();
    String[] firstNames = new String[] { "Alice", "Bob", "Carol" };
    String[] lastNames = new String[] { "Smith", "Lee", "Jones" };
    String name = firstNames[random.nextInt(firstNames.length)] + " " + lastNames[random.nextInt(lastNames.length)];
    Calendar calendar = Calendar.getInstance();
    //noinspection MagicConstant
    calendar.set(1900 + random.nextInt(90), random.nextInt(12), random.nextInt(30));
    return data.insert(Person.class).value(PersonType.NAME, name).value(PersonType.AGE, random.nextInt(50)).value(PersonType.EMAIL, name.replaceAll(" ", "").toLowerCase() + "@example.com").value(PersonType.UUID, UUID.randomUUID()).value(PersonType.BIRTHDAY, calendar.getTime()).value(PersonType.ABOUT, "About this person").get().first().get(PersonType.ID);
}
Also used : Random(java.util.Random) Calendar(java.util.Calendar) Person(io.requery.test.autovalue.Person)

Example 7 with Person

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

the class AutoValueModelTest method testInsertReference.

@Test
public void testInsertReference() {
    randomPerson();
    Result<Person> result = data.select(Person.class).get();
    Person person = result.first();
    int id = data.insert(Phone.class).value(PhoneType.PHONE_NUMBER, "5555555").value(PhoneType.NORMALIZED, false).value(PhoneType.OWNER_ID, person.getId()).get().first().get(PhoneType.ID);
    assertTrue(id != 0);
    Phone phone = data.select(Phone.class).get().first();
    assertSame(phone.getOwnerId(), person.getId());
}
Also used : Phone(io.requery.test.autovalue.Phone) 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