Search in sources :

Example 6 with QueryOrder

use of com.github.tfaga.lynx.beans.QueryOrder 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 7 with QueryOrder

use of com.github.tfaga.lynx.beans.QueryOrder 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)

Example 8 with QueryOrder

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

the class JPAUtilsOrderTest method testNonExistentColumn.

@Test
public void testNonExistentColumn() {
    QueryOrder qo = new QueryOrder();
    qo.setField("lstnm");
    qo.setOrder(OrderDirection.DESC);
    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("lstnm", 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 9 with QueryOrder

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

the class JPAUtilsOrderTest method testEmbedded.

@Test
public void testEmbedded() {
    QueryOrder qo = new QueryOrder();
    qo.setField("address.country");
    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).getAddress());
    Assert.assertNotNull(users.get(0).getAddress().getCountry());
    Assert.assertEquals("Argentina", users.get(0).getAddress().getCountry());
    Assert.assertNotNull(users.get(99).getAddress());
    Assert.assertNotNull(users.get(99).getAddress().getCountry());
    Assert.assertEquals("Venezuela", users.get(99).getAddress().getCountry());
}
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 10 with QueryOrder

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

the class JPAUtilsOrderTest method testNullField.

@Test
public void testNullField() {
    QueryOrder qo = new QueryOrder();
    QueryParameters q = new QueryParameters();
    q.getOrder().add(qo);
    List<User> users = JPAUtils.queryEntities(em, User.class, q).stream().sorted(Comparator.comparing(User::getId)).collect(Collectors.toList());
    Assert.assertNotNull(users);
    Assert.assertEquals(100, users.size());
    Assert.assertNotNull(users.get(0).getLastname());
    Assert.assertEquals("Ramos", users.get(0).getLastname());
    Assert.assertNotNull(users.get(99).getLastname());
    Assert.assertEquals("Hall", 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