Search in sources :

Example 6 with Nameable

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

the class AbstractEntityFinderTest method script23.

@Test
public void script23() throws EntityFinderException {
    Nameable nameable = templateFor(Nameable.class);
    // Try using variables
    Map<String, Object> variables = new HashMap<>(1);
    variables.put("domain", "Gaming");
    Iterable<EntityReference> entities = entityFinder.findEntities(Domain.class, eq(nameable.name(), variable("domain")), NO_SORTING, NO_FIRST_RESULT, NO_MAX_RESULTS, variables);
    assertNames(entities, "Gaming");
}
Also used : Nameable(org.qi4j.test.indexing.model.Nameable) HashMap(java.util.HashMap) EntityReference(org.qi4j.api.entity.EntityReference) Test(org.junit.Test)

Example 7 with Nameable

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

the class AbstractEntityFinderTest method script22.

@Test
public void script22() throws EntityFinderException {
    Nameable nameable = templateFor(Nameable.class);
    // should return Jack and Joe Doe
    Iterable<EntityReference> entities = entityFinder.findEntities(Nameable.class, matches(nameable.name(), "J.*Doe"), NO_SORTING, NO_FIRST_RESULT, NO_MAX_RESULTS, NO_VARIABLES);
    assertNames(entities, JACK, JOE);
}
Also used : Nameable(org.qi4j.test.indexing.model.Nameable) EntityReference(org.qi4j.api.entity.EntityReference) Test(org.junit.Test)

Example 8 with Nameable

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

the class AbstractEntityFinderTest method script18.

@Test
public void script18() throws EntityFinderException {
    // should return all Nameable entities sorted by name
    Nameable nameable = templateFor(Nameable.class);
    final String[] allNames = NameableAssert.allNames();
    Arrays.sort(allNames);
    Iterable<EntityReference> entities = entityFinder.findEntities(Nameable.class, ALL, new OrderBy[] { orderBy(nameable.name()) }, NO_FIRST_RESULT, NO_MAX_RESULTS, NO_VARIABLES);
    assertNames(false, entities, allNames);
}
Also used : Nameable(org.qi4j.test.indexing.model.Nameable) EntityReference(org.qi4j.api.entity.EntityReference) Test(org.junit.Test)

Example 9 with Nameable

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

the class AbstractEntityFinderTest method script19.

@Test
public void script19() throws EntityFinderException {
    // should return all Nameable entities with a name > "B" sorted by name
    Nameable nameable = templateFor(Nameable.class);
    List<String> largerThanB = new ArrayList<>();
    for (String name : NameableAssert.allNames()) {
        if (name.compareTo("B") > 0) {
            largerThanB.add(name);
        }
    }
    Collections.sort(largerThanB);
    Iterable<EntityReference> entities = entityFinder.findEntities(Nameable.class, gt(nameable.name(), "B"), new OrderBy[] { orderBy(nameable.name()) }, NO_FIRST_RESULT, NO_MAX_RESULTS, NO_VARIABLES);
    assertNames(false, entities, largerThanB.toArray(new String[largerThanB.size()]));
}
Also used : Nameable(org.qi4j.test.indexing.model.Nameable) ArrayList(java.util.ArrayList) EntityReference(org.qi4j.api.entity.EntityReference) Test(org.junit.Test)

Example 10 with Nameable

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

the class AbstractQueryTest method script16.

@Test
public void script16() throws EntityFinderException {
    QueryBuilder<Nameable> qb = this.module.newQueryBuilder(Nameable.class);
    // should return only 2 entities
    Nameable nameable = templateFor(Nameable.class);
    Query<Nameable> query = unitOfWork.newQuery(qb);
    query.orderBy(orderBy(nameable.name()));
    query.maxResults(2);
    System.out.println("*** script16: " + query);
    verifyOrderedResults(query, "Ann Doe", "Cars");
}
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