Search in sources :

Example 26 with QueryParameters

use of com.github.tfaga.lynx.beans.QueryParameters in project lynx by TFaga.

the class JPAUtilsOrderTest method testCaseSensitiveField.

@Test
public void testCaseSensitiveField() {
    QueryOrder qo = new QueryOrder();
    qo.setField("firsTNAmE");
    qo.setOrder(OrderDirection.ASC);
    QueryParameters q = new QueryParameters();
    q.getOrder().add(qo);
    try {
        JPAUtils.queryEntities(em, User.class, q);
        Assert.fail("No exception was thrown");
    } catch (NoSuchEntityFieldException e) {
        Assert.assertEquals("firsTNAmE", e.getField());
    }
}
Also used : QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) QueryOrder(com.github.tfaga.lynx.beans.QueryOrder) NoSuchEntityFieldException(com.github.tfaga.lynx.exceptions.NoSuchEntityFieldException) Test(org.junit.Test)

Example 27 with QueryParameters

use of com.github.tfaga.lynx.beans.QueryParameters in project lynx by TFaga.

the class JPAUtilsOrderTest method testOneToMany.

@Test(expected = InvalidEntityFieldException.class)
public void testOneToMany() {
    QueryOrder qo = new QueryOrder();
    qo.setField("projects.name");
    QueryParameters q = new QueryParameters();
    q.getOrder().add(qo);
    JPAUtils.queryEntities(em, User.class, q);
    Assert.fail("No exception was thrown");
}
Also used : QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) QueryOrder(com.github.tfaga.lynx.beans.QueryOrder) Test(org.junit.Test)

Example 28 with QueryParameters

use of com.github.tfaga.lynx.beans.QueryParameters in project lynx by TFaga.

the class JPAUtilsOrderTest method testSingleOrder.

@Test
public void testSingleOrder() {
    QueryOrder qo = new QueryOrder();
    qo.setField("firstname");
    qo.setOrder(OrderDirection.ASC);
    QueryParameters q = new QueryParameters();
    q.getOrder().add(qo);
    List<User> users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(100, users.size());
    Assert.assertNotNull(users.get(0).getFirstname());
    Assert.assertEquals("Amanda", users.get(0).getFirstname());
    Assert.assertNotNull(users.get(99).getFirstname());
    Assert.assertEquals("Victor", users.get(99).getFirstname());
}
Also used : User(com.github.tfaga.lynx.test.entities.User) QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) QueryOrder(com.github.tfaga.lynx.beans.QueryOrder) Test(org.junit.Test)

Example 29 with QueryParameters

use of com.github.tfaga.lynx.beans.QueryParameters in project lynx by TFaga.

the class JPAUtilsOrderTest method testManyToOneOnlyField.

@Test
public void testManyToOneOnlyField() {
    QueryOrder qo = new QueryOrder();
    qo.setField("user");
    QueryParameters q = new QueryParameters();
    q.getOrder().add(qo);
    List<Project> projects = JPAUtils.queryEntities(em, Project.class, q);
    Assert.assertNotNull(projects);
    Assert.assertEquals(100, projects.size());
    Assert.assertNotNull(projects.get(0).getName());
    Assert.assertEquals("Goldenrod", projects.get(0).getName());
    Assert.assertNotNull(projects.get(99).getName());
    Assert.assertEquals("Yellow", projects.get(99).getName());
}
Also used : Project(com.github.tfaga.lynx.test.entities.Project) QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) QueryOrder(com.github.tfaga.lynx.beans.QueryOrder) Test(org.junit.Test)

Example 30 with QueryParameters

use of com.github.tfaga.lynx.beans.QueryParameters in project lynx by TFaga.

the class JPAUtilsOrderTest method testNullDirection.

@Test
public void testNullDirection() {
    QueryOrder qo = new QueryOrder();
    qo.setField("lastname");
    QueryParameters q = new QueryParameters();
    q.getOrder().add(qo);
    List<User> users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(100, users.size());
    Assert.assertNotNull(users.get(0).getLastname());
    Assert.assertEquals("Austin", users.get(0).getLastname());
    Assert.assertNotNull(users.get(99).getLastname());
    Assert.assertEquals("Willis", users.get(99).getLastname());
}
Also used : User(com.github.tfaga.lynx.test.entities.User) QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) QueryOrder(com.github.tfaga.lynx.beans.QueryOrder) Test(org.junit.Test)

Aggregations

QueryParameters (com.github.tfaga.lynx.beans.QueryParameters)158 Test (org.junit.Test)155 User (com.github.tfaga.lynx.test.entities.User)46 QueryFilter (com.github.tfaga.lynx.beans.QueryFilter)44 QueryStringDefaults (com.github.tfaga.lynx.utils.QueryStringDefaults)14 QueryOrder (com.github.tfaga.lynx.beans.QueryOrder)13 Project (com.github.tfaga.lynx.test.entities.Project)12 NoSuchEntityFieldException (com.github.tfaga.lynx.exceptions.NoSuchEntityFieldException)6 Date (java.util.Date)6 URI (java.net.URI)4 CriteriaField (com.github.tfaga.lynx.beans.CriteriaField)2 CriteriaWhereQuery (com.github.tfaga.lynx.beans.CriteriaWhereQuery)2 OrderDirection (com.github.tfaga.lynx.enums.OrderDirection)2 InvalidEntityFieldException (com.github.tfaga.lynx.exceptions.InvalidEntityFieldException)2 InvalidFieldValueException (com.github.tfaga.lynx.exceptions.InvalidFieldValueException)2 CriteriaFilter (com.github.tfaga.lynx.interfaces.CriteriaFilter)2 Field (java.lang.reflect.Field)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ZonedDateTime (java.time.ZonedDateTime)2 DateTimeParseException (java.time.format.DateTimeParseException)2