Search in sources :

Example 31 with QueryFilter

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

the class JPAUtilsFiltersTest method testNonExistingField.

@Test
public void testNonExistingField() {
    QueryFilter qf = new QueryFilter();
    qf.setField("asdas");
    qf.setOperation(FilterOperation.EQ);
    qf.setValue("test");
    QueryParameters q = new QueryParameters();
    q.getFilters().add(qf);
    try {
        JPAUtils.queryEntities(em, User.class, q);
        Assert.fail("No exception was thrown");
    } catch (NoSuchEntityFieldException e) {
        Assert.assertEquals("asdas", e.getField());
    }
}
Also used : QueryFilter(com.github.tfaga.lynx.beans.QueryFilter) QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) NoSuchEntityFieldException(com.github.tfaga.lynx.exceptions.NoSuchEntityFieldException) Test(org.junit.Test)

Example 32 with QueryFilter

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

the class JPAUtilsFiltersTest method testLt.

@Test
public void testLt() {
    QueryFilter qf = new QueryFilter();
    qf.setField("role");
    qf.setOperation(FilterOperation.LT);
    qf.setValue("1");
    QueryParameters q = new QueryParameters();
    q.getFilters().add(qf);
    List<User> users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(53, users.size());
    Date d = Date.from(ZonedDateTime.parse("2014-11-26T11:15:08Z").toInstant());
    qf = new QueryFilter();
    qf.setField("createdAt");
    qf.setOperation(FilterOperation.LT);
    qf.setDateValue(d);
    q = new QueryParameters();
    q.getFilters().add(qf);
    users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(60, 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 33 with QueryFilter

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

the class JPAUtilsFiltersTest method testEnumFilter.

@Test
public void testEnumFilter() {
    QueryFilter qf = new QueryFilter();
    qf.setField("status");
    qf.setOperation(FilterOperation.EQ);
    qf.setValue("ACTIVE");
    QueryParameters q = new QueryParameters();
    q.getFilters().add(qf);
    List<Project> projects = JPAUtils.queryEntities(em, Project.class, q);
    Assert.assertNotNull(projects);
    Assert.assertEquals(50, 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 34 with QueryFilter

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

the class JPAUtilsFiltersTest method testIntegerEq.

@Test
public void testIntegerEq() {
    QueryFilter qf = new QueryFilter();
    qf.setField("role");
    qf.setOperation(FilterOperation.EQ);
    qf.setValue("0");
    QueryParameters q = new QueryParameters();
    q.getFilters().add(qf);
    List<User> users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(53, 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 35 with QueryFilter

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

the class JPAUtilsFiltersTest method testUuidInFilter.

@Test
public void testUuidInFilter() {
    QueryFilter qf = new QueryFilter();
    qf.setField("publicId");
    qf.setOperation(FilterOperation.IN);
    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)

Aggregations

QueryFilter (com.github.tfaga.lynx.beans.QueryFilter)49 Test (org.junit.Test)47 QueryParameters (com.github.tfaga.lynx.beans.QueryParameters)44 User (com.github.tfaga.lynx.test.entities.User)28 Project (com.github.tfaga.lynx.test.entities.Project)10 Date (java.util.Date)6 NoSuchEntityFieldException (com.github.tfaga.lynx.exceptions.NoSuchEntityFieldException)3 OrderDirection (com.github.tfaga.lynx.enums.OrderDirection)2 ZonedDateTime (java.time.ZonedDateTime)2 DateTimeParseException (java.time.format.DateTimeParseException)2 java.util (java.util)2 Logger (java.util.logging.Logger)2 Collectors (java.util.stream.Collectors)2 CriteriaField (com.github.tfaga.lynx.beans.CriteriaField)1 CriteriaWhereQuery (com.github.tfaga.lynx.beans.CriteriaWhereQuery)1 QueryOrder (com.github.tfaga.lynx.beans.QueryOrder)1 FilterOperation (com.github.tfaga.lynx.enums.FilterOperation)1 QueryFormatError (com.github.tfaga.lynx.enums.QueryFormatError)1 InvalidEntityFieldException (com.github.tfaga.lynx.exceptions.InvalidEntityFieldException)1 InvalidFieldValueException (com.github.tfaga.lynx.exceptions.InvalidFieldValueException)1