Search in sources :

Example 21 with QueryParameters

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

the class JPAUtilsFiltersTest method testWrongDateField.

@Test
public void testWrongDateField() {
    Date d = Date.from(ZonedDateTime.parse("2014-11-26T11:15:08Z").toInstant());
    QueryFilter qf = new QueryFilter();
    qf.setField("lastname");
    qf.setOperation(FilterOperation.LTE);
    qf.setDateValue(d);
    QueryParameters q = new QueryParameters();
    q.getFilters().add(qf);
    List<User> users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(100, users.size());
}
Also used : QueryFilter(com.github.tfaga.lynx.beans.QueryFilter) User(com.github.tfaga.lynx.test.entities.User) QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) Date(java.util.Date) Test(org.junit.Test)

Example 22 with QueryParameters

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

the class JPAUtilsFiltersTest method testUuidNinFilter.

@Test
public void testUuidNinFilter() {
    QueryFilter qf = new QueryFilter();
    qf.setField("publicId");
    qf.setOperation(FilterOperation.NIN);
    qf.getValues().add("b3781a0e-fb85-45d1-bd5f-d38802a546d2");
    qf.getValues().add("6a749969-9990-4ef0-856a-7e2533b6dc9e");
    QueryParameters q = new QueryParameters();
    q.getFilters().add(qf);
    List<Project> projects = JPAUtils.queryEntities(em, Project.class, q);
    Assert.assertNotNull(projects);
    Assert.assertEquals(0, projects.size());
}
Also used : Project(com.github.tfaga.lynx.test.entities.Project) QueryFilter(com.github.tfaga.lynx.beans.QueryFilter) QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) Test(org.junit.Test)

Example 23 with QueryParameters

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

the class JPAUtilsFiltersTest method testNinic.

@Test
public void testNinic() {
    QueryFilter qf = new QueryFilter();
    qf.setField("firstname");
    qf.setOperation(FilterOperation.NINIC);
    qf.getValues().add("sArAH");
    qf.getValues().add("ricHArd");
    qf.getValues().add("jACk");
    QueryParameters q = new QueryParameters();
    q.getFilters().add(qf);
    List<User> users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(96, users.size());
}
Also used : QueryFilter(com.github.tfaga.lynx.beans.QueryFilter) User(com.github.tfaga.lynx.test.entities.User) QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) Test(org.junit.Test)

Example 24 with QueryParameters

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

the class JPAUtilsFiltersTest method testEnumNonexistantFilter.

@Test(expected = InvalidFieldValueException.class)
public void testEnumNonexistantFilter() {
    QueryFilter qf = new QueryFilter();
    qf.setField("status");
    qf.setOperation(FilterOperation.EQ);
    qf.setValue("NONACTIVE");
    QueryParameters q = new QueryParameters();
    q.getFilters().add(qf);
    JPAUtils.queryEntities(em, Project.class, q);
    Assert.fail("No exception was thrown");
}
Also used : QueryFilter(com.github.tfaga.lynx.beans.QueryFilter) QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) Test(org.junit.Test)

Example 25 with QueryParameters

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

the class JPAUtilsOrderTest method testMultipleOrders.

@Test
public void testMultipleOrders() {
    QueryParameters q = new QueryParameters();
    QueryOrder qo = new QueryOrder();
    qo.setField("role");
    qo.setOrder(OrderDirection.DESC);
    q.getOrder().add(qo);
    qo = new QueryOrder();
    qo.setField("lastname");
    qo.setOrder(OrderDirection.ASC);
    q.getOrder().add(qo);
    qo = new QueryOrder();
    qo.setField("firstname");
    qo.setOrder(OrderDirection.DESC);
    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.assertNotNull(users.get(0).getLastname());
    Assert.assertEquals("Larry", users.get(0).getFirstname());
    Assert.assertEquals("Bailey", users.get(0).getLastname());
    Assert.assertNotNull(users.get(99).getFirstname());
    Assert.assertNotNull(users.get(99).getLastname());
    Assert.assertEquals("Bonnie", users.get(99).getFirstname());
    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