Search in sources :

Example 1 with Nameable

use of org.qi4j.test.indexing.model.Nameable in project qi4j-sdk by Qi4j.

the class AbstractQueryTest method script19.

@Test
public void script19() throws EntityFinderException {
    QueryBuilder<Nameable> qb = this.module.newQueryBuilder(Nameable.class);
    // should return all Nameable entities with a name > "D" sorted by name
    Nameable nameable = templateFor(Nameable.class);
    Query<Nameable> query = unitOfWork.newQuery(qb.where(gt(nameable.name(), "D")));
    query.orderBy(orderBy(nameable.name()));
    System.out.println("*** script19: " + query);
    verifyOrderedResults(query, "Gaming", "Jack Doe", "Joe Doe", "Kuala Lumpur", "Penang", "Programming");
}
Also used : Nameable(org.qi4j.test.indexing.model.Nameable) Test(org.junit.Test)

Example 2 with Nameable

use of org.qi4j.test.indexing.model.Nameable in project qi4j-sdk by Qi4j.

the class NameableAssert method verifyUnorderedResults.

public static void verifyUnorderedResults(final Iterable<? extends Nameable> results, final String... names) {
    List<String> expected = new ArrayList<>(Arrays.asList(names));
    List<String> unexpected = new ArrayList<>();
    for (Nameable result : results) {
        String name = result.name().get();
        if (!expected.remove(name)) {
            unexpected.add(name);
        }
    }
    if (!unexpected.isEmpty() || !expected.isEmpty()) {
        String message = "";
        if (!unexpected.isEmpty()) {
            message += unexpected + " returned but not expected\n";
        }
        if (!expected.isEmpty()) {
            message += expected + " expected but not returned\n";
        }
        fail(message.substring(0, message.length() - 1));
    }
}
Also used : Nameable(org.qi4j.test.indexing.model.Nameable) ArrayList(java.util.ArrayList)

Example 3 with Nameable

use of org.qi4j.test.indexing.model.Nameable in project qi4j-sdk by Qi4j.

the class NameableAssert method verifyOrderedResults.

public static void verifyOrderedResults(final Iterable<? extends Nameable> results, final String... names) {
    List<String> expected = new ArrayList<>(Arrays.asList(names));
    List<String> actual = new ArrayList<>();
    for (Nameable result : results) {
        actual.add(result.name().get());
    }
    assertThat("Result is incorrect", actual, equalTo(expected));
}
Also used : Nameable(org.qi4j.test.indexing.model.Nameable) ArrayList(java.util.ArrayList)

Example 4 with Nameable

use of org.qi4j.test.indexing.model.Nameable in project qi4j-sdk by Qi4j.

the class AbstractNamedQueryTest method script18.

@Test
public void script18() throws EntityFinderException {
    Nameable nameable = templateFor(Nameable.class);
    final Query<Nameable> query = unitOfWork.newQuery(this.module.newQueryBuilder(Nameable.class).where(queries.get("script18")));
    query.orderBy(orderBy(nameable.name()));
    System.out.println("*** script18: " + query);
    verifyOrderedResults(query, "Ann Doe", "Cars", "Cooking", "Gaming", "Jack Doe", "Joe Doe", "Kuala Lumpur", "Penang", "Programming");
}
Also used : Nameable(org.qi4j.test.indexing.model.Nameable) Test(org.junit.Test)

Example 5 with Nameable

use of org.qi4j.test.indexing.model.Nameable in project qi4j-sdk by Qi4j.

the class AbstractNamedQueryTest method script19.

@Test
public void script19() throws EntityFinderException {
    Nameable nameable = templateFor(Nameable.class);
    final Query<Nameable> query = unitOfWork.newQuery(this.module.newQueryBuilder(Nameable.class).where(queries.get("script19")));
    query.orderBy(orderBy(nameable.name()));
    System.out.println("*** script19: " + query);
    verifyOrderedResults(query, "Gaming", "Jack Doe", "Joe Doe", "Kuala Lumpur", "Penang", "Programming");
}
Also used : Nameable(org.qi4j.test.indexing.model.Nameable) Test(org.junit.Test)

Aggregations

Nameable (org.qi4j.test.indexing.model.Nameable)19 Test (org.junit.Test)17 EntityReference (org.qi4j.api.entity.EntityReference)5 ArrayList (java.util.ArrayList)3 Domain (org.qi4j.test.indexing.model.Domain)2 HashMap (java.util.HashMap)1 Person (org.qi4j.test.indexing.model.Person)1