Search in sources :

Example 6 with QueryParameters

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

the class JPAUtilsFieldsTest method testEmbeddedField.

// Currently unsupported
@Test(expected = NoSuchEntityFieldException.class)
public void testEmbeddedField() {
    QueryParameters q = new QueryParameters();
    q.getFields().add("address.country");
    JPAUtils.queryEntities(em, User.class, q);
}
Also used : QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) Test(org.junit.Test)

Example 7 with QueryParameters

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

the class JPAUtilsFieldsTest method testMultipleFields.

@Test
public void testMultipleFields() {
    QueryParameters q = new QueryParameters();
    q.getFields().add("firstname");
    q.getFields().add("email");
    q.getFields().add("role");
    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).getEmail());
    Assert.assertNotNull(users.get(0).getRole());
    Assert.assertNull(users.get(0).getLastname());
    Assert.assertEquals("Jason", users.get(0).getFirstname());
    Assert.assertEquals("jramos0@ox.ac.uk", users.get(0).getEmail());
    Assert.assertEquals(0, users.get(0).getRole().intValue());
}
Also used : User(com.github.tfaga.lynx.test.entities.User) QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) Test(org.junit.Test)

Example 8 with QueryParameters

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

the class JPAUtilsFiltersTest method testNotEqual.

@Test
public void testNotEqual() {
    QueryFilter qf = new QueryFilter();
    qf.setField("lastname");
    qf.setOperation(FilterOperation.NEQ);
    qf.setValue("Willis");
    QueryParameters q = new QueryParameters();
    q.getFilters().add(qf);
    List<User> users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(97, 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 9 with QueryParameters

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

the class JPAUtilsFiltersTest method testSingleDateFilter.

@Test
public void testSingleDateFilter() {
    Date d = Date.from(ZonedDateTime.parse("2014-11-26T11:15:08Z").toInstant());
    QueryFilter qf = new QueryFilter();
    qf.setField("createdAt");
    qf.setOperation(FilterOperation.GT);
    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(39, 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 10 with QueryParameters

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

the class JPAUtilsFiltersTest method testLikeic.

@Test
public void testLikeic() {
    QueryFilter qf = new QueryFilter();
    qf.setField("firstname");
    qf.setOperation(FilterOperation.LIKEIC);
    qf.setValue("jA%");
    QueryParameters q = new QueryParameters();
    q.getFilters().add(qf);
    List<User> users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(5, 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)

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