Search in sources :

Example 66 with QueryParameters

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

the class QueryStringDefaultsTest method testEmpty.

@Test
public void testEmpty() {
    QueryParameters query = new QueryStringDefaults().builder().query("").build();
    Assert.assertNotNull(query);
    Assert.assertNotNull(query.getLimit());
    Assert.assertNotNull(query.getOffset());
    Assert.assertEquals(10, query.getLimit().longValue());
    Assert.assertEquals(0, query.getOffset().longValue());
}
Also used : QueryStringDefaults(com.github.tfaga.lynx.utils.QueryStringDefaults) QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) Test(org.junit.Test)

Example 67 with QueryParameters

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

the class QueryStringDefaultsTest method testEnabledFilters.

@Test
public void testEnabledFilters() {
    QueryParameters query = new QueryStringDefaults().enableFilters(true).builder().query("where=name:eq:tilen").build();
    Assert.assertNotNull(query);
    Assert.assertNotNull(query.getFilters());
    Assert.assertEquals(1, query.getFilters().size());
    Assert.assertNotNull(query.getFilters().get(0));
    Assert.assertEquals("name", query.getFilters().get(0).getField());
    Assert.assertEquals(FilterOperation.EQ, query.getFilters().get(0).getOperation());
    Assert.assertEquals("tilen", query.getFilters().get(0).getValue());
    query = new QueryStringDefaults().builder().query("where=name:eq:tilen").build();
    Assert.assertNotNull(query);
    Assert.assertNotNull(query.getFilters());
    Assert.assertEquals(1, query.getFilters().size());
    Assert.assertNotNull(query.getFilters().get(0));
    Assert.assertEquals("name", query.getFilters().get(0).getField());
    Assert.assertEquals(FilterOperation.EQ, query.getFilters().get(0).getOperation());
    Assert.assertEquals("tilen", query.getFilters().get(0).getValue());
}
Also used : QueryStringDefaults(com.github.tfaga.lynx.utils.QueryStringDefaults) QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) Test(org.junit.Test)

Example 68 with QueryParameters

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

the class QueryStringDefaultsTest method testMaxLimit.

@Test
public void testMaxLimit() {
    QueryParameters query = new QueryStringDefaults().maxLimit(60).builder().query("limit=200").build();
    Assert.assertNotNull(query);
    Assert.assertNotNull(query.getLimit());
    Assert.assertEquals(60, query.getLimit().longValue());
}
Also used : QueryStringDefaults(com.github.tfaga.lynx.utils.QueryStringDefaults) QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) Test(org.junit.Test)

Example 69 with QueryParameters

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

the class QueryStringDefaultsTest method testDisabledFields.

@Test
public void testDisabledFields() {
    QueryParameters query = new QueryStringDefaults().enableFields(false).builder().query("fields=name,email").build();
    Assert.assertNotNull(query);
    Assert.assertNotNull(query.getFields());
    Assert.assertEquals(0, query.getFields().size());
}
Also used : QueryStringDefaults(com.github.tfaga.lynx.utils.QueryStringDefaults) QueryParameters(com.github.tfaga.lynx.beans.QueryParameters) Test(org.junit.Test)

Example 70 with QueryParameters

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

the class JPAUtilsPagingTest method testLimitWithOffset.

@Test
public void testLimitWithOffset() {
    QueryOrder qo = new QueryOrder();
    qo.setField("id");
    qo.setOrder(OrderDirection.ASC);
    QueryParameters q = new QueryParameters();
    q.setLimit(25);
    q.setOffset(0);
    q.getOrder().add(qo);
    List<User> users = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(users);
    Assert.assertEquals(25, users.size());
    q.setOffset(24);
    List<User> usersOffseted = JPAUtils.queryEntities(em, User.class, q);
    Assert.assertNotNull(usersOffseted);
    Assert.assertEquals(25, usersOffseted.size());
    Assert.assertNotNull(users.get(24).getId());
    Assert.assertNotNull(usersOffseted.get(0).getId());
    Assert.assertEquals(users.get(24).getId().intValue(), usersOffseted.get(0).getId().intValue());
// Assert.assertEquals(65, users.get(24).getId().intValue());
}
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