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);
}
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());
}