Search in sources :

Example 1 with Person

use of com.amplifyframework.testmodels.phonecall.Person in project amplify-android by aws-amplify.

the class SQLiteStorageAdapterQueryTest method querySavedDataWithMultipleForeignKeysOfSameType.

/**
 * Test that querying the saved item with multiple foreign keys from the same
 * model also populates that instance variable with object.
 * @throws DataStoreException On unexpected failure manipulating items in/out of DataStore
 */
@Test
public void querySavedDataWithMultipleForeignKeysOfSameType() throws DataStoreException {
    setupForCallModel();
    final Person personCalling = Person.builder().name("Alan Turing").build();
    final Person personCalled = Person.builder().name("Grace Hopper").build();
    final Phone phoneCalling = Phone.builder().number("123-456-7890").ownedBy(personCalling).build();
    final Phone phoneCalled = Phone.builder().number("567-890-1234").ownedBy(personCalled).build();
    final Call phoneCall = Call.builder().startTime(new Temporal.Time("10:35:22Z")).caller(phoneCalling).callee(phoneCalled).build();
    adapter.save(personCalling);
    adapter.save(personCalled);
    adapter.save(phoneCalling);
    adapter.save(phoneCalled);
    adapter.save(phoneCall);
    final List<Call> phoneCalls = adapter.query(Call.class);
    assertTrue(phoneCalls.contains(phoneCall));
}
Also used : Call(com.amplifyframework.testmodels.phonecall.Call) Phone(com.amplifyframework.testmodels.phonecall.Phone) Person(com.amplifyframework.testmodels.phonecall.Person) Test(org.junit.Test)

Example 2 with Person

use of com.amplifyframework.testmodels.phonecall.Person in project amplify-android by aws-amplify.

the class SQLiteStorageAdapterQueryTest method querySavedDataWithTimePredicates.

/**
 * Test querying the saved item in the SQLite database with Time
 * predicate conditions.
 * @throws DataStoreException On unexpected failure manipulating items in/out of DataStore
 */
@Test
public void querySavedDataWithTimePredicates() throws DataStoreException {
    setupForCallModel();
    final Person personCalling = Person.builder().name("Alan Turing").build();
    final Person personCalled = Person.builder().name("Grace Hopper").build();
    final Phone phoneCalling = Phone.builder().number("123-456-7890").ownedBy(personCalling).build();
    final Phone phoneCalled = Phone.builder().number("567-890-1234").ownedBy(personCalled).build();
    adapter.save(personCalling);
    adapter.save(personCalled);
    adapter.save(phoneCalling);
    adapter.save(phoneCalled);
    final List<Call> savedModels = new ArrayList<>();
    final int numModels = 8;
    final List<Temporal.Time> callStartTimes = Arrays.asList(new Temporal.Time("19:30:45.000000000"), new Temporal.Time("19:30:45.100000000Z"), new Temporal.Time("19:30:45.100250000Z"), new Temporal.Time("19:30:45.1000Z"), new Temporal.Time("20:30:45.111Z"), new Temporal.Time("19:30:45.111+00:00"), new Temporal.Time("19:30:45.111+01:00"), new Temporal.Time("19:30:45.111222333Z"));
    for (int counter = 0; counter < numModels; counter++) {
        Call phoneCall = Call.builder().startTime(callStartTimes.get(counter)).caller(phoneCalling).callee(phoneCalled).build();
        adapter.save(phoneCall);
        savedModels.add(phoneCall);
    }
    // 0, 1, 3, 6
    QueryPredicate predicate = Call.STARTTIME.le(new Temporal.Time("19:30:45.100000000Z"));
    assertEquals(Observable.fromArray(0, 1, 3, 6).map(savedModels::get).map(Call::getId).toList().map(HashSet::new).blockingGet(), Observable.fromIterable(adapter.query(Call.class, Where.matches(predicate))).map(Call::getId).toList().map(HashSet::new).blockingGet());
}
Also used : Call(com.amplifyframework.testmodels.phonecall.Call) Temporal(com.amplifyframework.core.model.temporal.Temporal) QueryPredicate(com.amplifyframework.core.model.query.predicate.QueryPredicate) Phone(com.amplifyframework.testmodels.phonecall.Phone) ArrayList(java.util.ArrayList) Person(com.amplifyframework.testmodels.phonecall.Person) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Call (com.amplifyframework.testmodels.phonecall.Call)2 Person (com.amplifyframework.testmodels.phonecall.Person)2 Phone (com.amplifyframework.testmodels.phonecall.Phone)2 Test (org.junit.Test)2 QueryPredicate (com.amplifyframework.core.model.query.predicate.QueryPredicate)1 Temporal (com.amplifyframework.core.model.temporal.Temporal)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1