Search in sources :

Example 41 with QueryFilter

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

the class JPAUtilsFiltersTest method testIsNullFilter.

@Test
public void testIsNullFilter() {
    QueryFilter qf = new QueryFilter();
    qf.setField("description");
    qf.setOperation(FilterOperation.ISNULL);
    qf.setValue("");
    QueryParameters q = new QueryParameters();
    q.getFilters().add(qf);
    List<Project> projects = JPAUtils.queryEntities(em, Project.class, q);
    Assert.assertNotNull(projects);
    Assert.assertEquals(1, 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 42 with QueryFilter

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

the class JPAUtilsFiltersTest method testNeqic.

@Test
public void testNeqic() {
    QueryFilter qf = new QueryFilter();
    qf.setField("firstname");
    qf.setOperation(FilterOperation.NEQIC);
    qf.setValue("JaCK");
    QueryParameters q = new QueryParameters();
    q.getFilters().add(qf);
    List<User> users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(98, 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 43 with QueryFilter

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

the class JPAUtilsFiltersTest method testDateEq.

@Test
public void testDateEq() {
    QueryFilter qf = new QueryFilter();
    qf.setField("createdAt");
    qf.setOperation(FilterOperation.EQ);
    qf.setValue("2014-09-11T12:35:07Z");
    QueryParameters q = new QueryParameters();
    q.getFilters().add(qf);
    List<User> users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(1, 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 44 with QueryFilter

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

the class JPAUtilsFiltersTest method testEmbeddedRelation.

@Test
public void testEmbeddedRelation() {
    QueryFilter qf = new QueryFilter();
    qf.setField("address.country");
    qf.setOperation(FilterOperation.EQ);
    qf.setValue("China");
    QueryParameters q = new QueryParameters();
    q.getFilters().add(qf);
    List<User> users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(24, users.size());
    Assert.assertNotNull(users.get(0).getAddress());
    Assert.assertNotNull(users.get(0).getAddress().getCountry());
    Assert.assertEquals("China", users.get(0).getAddress().getCountry());
    Assert.assertNotNull(users.get(23).getAddress());
    Assert.assertNotNull(users.get(23).getAddress().getCountry());
    Assert.assertEquals("China", users.get(23).getAddress().getCountry());
}
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 45 with QueryFilter

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

the class JPAUtilsFiltersTest method testUuidFilter.

@Test
public void testUuidFilter() {
    QueryFilter qf = new QueryFilter();
    qf.setField("publicId");
    qf.setOperation(FilterOperation.EQ);
    qf.setValue("b3781a0e-fb85-45d1-bd5f-d38802a546d2");
    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