Search in sources :

Example 11 with QueryOrder

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

the class JPAUtilsPagingTest method testLimitWithOffset.

@Test
public void testLimitWithOffset() {
    QueryOrder qo = new QueryOrder();
    qo.setField("id");
    qo.setOrder(OrderDirection.ASC);
    QueryParameters q = new QueryParameters();
    q.setLimit(25);
    q.setOffset(0);
    q.getOrder().add(qo);
    List<User> users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(25, users.size());
    q.setOffset(24);
    List<User> usersOffseted = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(usersOffseted);
    Assert.assertEquals(25, usersOffseted.size());
    Assert.assertNotNull(users.get(24).getId());
    Assert.assertNotNull(usersOffseted.get(0).getId());
    Assert.assertEquals(users.get(24).getId().intValue(), usersOffseted.get(0).getId().intValue());
// Assert.assertEquals(65, users.get(24).getId().intValue());
}
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 12 with QueryOrder

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

the class JPAUtilsOrderTest method testManyToOne.

@Test
public void testManyToOne() {
    QueryOrder qo = new QueryOrder();
    qo.setField("user.firstname");
    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("Red", projects.get(0).getName());
    Assert.assertNotNull(projects.get(99).getName());
    Assert.assertEquals("Turquoise", 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 13 with QueryOrder

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

the class JPAUtilsOrderTest method testOneToManyOnlyField.

@Test(expected = InvalidEntityFieldException.class)
public void testOneToManyOnlyField() {
    QueryOrder qo = new QueryOrder();
    qo.setField("projects");
    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 14 with QueryOrder

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

the class JPAUtilsOrderTest method testSingleOrderDesc.

@Test
public void testSingleOrderDesc() {
    QueryOrder qo = new QueryOrder();
    qo.setField("lastname");
    qo.setOrder(OrderDirection.DESC);
    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("Willis", users.get(0).getLastname());
    Assert.assertNotNull(users.get(99).getLastname());
    Assert.assertEquals("Austin", 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

QueryOrder (com.github.tfaga.lynx.beans.QueryOrder)14 QueryParameters (com.github.tfaga.lynx.beans.QueryParameters)13 Test (org.junit.Test)13 User (com.github.tfaga.lynx.test.entities.User)7 NoSuchEntityFieldException (com.github.tfaga.lynx.exceptions.NoSuchEntityFieldException)2 Project (com.github.tfaga.lynx.test.entities.Project)2 QueryFormatException (com.github.tfaga.lynx.exceptions.QueryFormatException)1