use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery in project stdlib by petergeneric.
the class DynamicQueryTest method testOrderDesc.
@Test
public void testOrderDesc() throws Exception {
ParentEntity obj1 = new ParentEntity();
obj1.setName("Name1");
dao.save(obj1);
ParentEntity obj2 = new ParentEntity();
obj2.setName("Name2");
dao.save(obj2);
assertEquals(getIds(obj2, obj1), getIds(dao.findByUriQuery(new WebQuery().orderDesc("id")).getList()));
}
use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery in project stdlib by petergeneric.
the class DynamicQueryTest method testEntityWrappedId.
@Test
public void testEntityWrappedId() throws Exception {
ParentEntity obj = new ParentEntity();
obj.setName("Name");
obj.setOtherObject(new ChildEntity());
obj.getOtherObject().setName("Name");
childDao.save(obj.getOtherObject());
dao.save(obj);
final ConstrainedResultSet<ParentEntity> results = dao.find(new WebQuery(), JPASearchStrategy.ENTITY_WRAPPED_ID);
assertEquals(1, results.list.size());
// should be populated
assertNotNull(results.uniqueResult().getId());
// should not be populated
assertNull(results.uniqueResult().getName());
}
use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery in project stdlib by petergeneric.
the class DynamicQueryTest method testComputeSizeWithOrder.
/**
* Tests that computing size while applying ordering and limiting to the resultset still works
*
* @throws Exception
*/
@Test
public void testComputeSizeWithOrder() throws Exception {
{
ParentEntity obj1 = new ParentEntity();
obj1.setName("Name1");
dao.save(obj1);
ParentEntity obj2 = new ParentEntity();
obj2.setName("Name2");
dao.save(obj2);
ParentEntity obj3 = new ParentEntity();
obj3.setName("Name3");
dao.save(obj3);
}
final WebQuery query = new WebQuery().orderDesc("name").limit(2);
// First, test that the correct results are returned with computeSize=false
{
ConstrainedResultSet<ParentEntity> results = dao.findByUriQuery(query);
// Must honour limit
assertEquals("without computeSize; must only have returned 2 results", 2, results.getList().size());
assertEquals("without computeSize; must have returned right 2 entities", Arrays.asList("Name3", "Name2"), results.getList().stream().map(e -> e.getName()).collect(Collectors.toList()));
}
// Next, test that we get the same results with computeSize=true (ensures the order is still present after size is computed)
query.computeSize(true);
{
ConstrainedResultSet<ParentEntity> results = dao.findByUriQuery(query);
// Must have correct total size
assertEquals("with computeSize; must have computed correct total size", Long.valueOf(3), results.getTotal());
// Must honour limit
assertEquals("with computeSize; must only have returned 2 results", 2, results.getList().size());
assertEquals("with computeSize; must have returned right 2 entities", Arrays.asList("Name3", "Name2"), results.getList().stream().map(e -> e.getName()).collect(Collectors.toList()));
}
}
use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery in project stdlib by petergeneric.
the class DynamicQueryTest method testGetByRelationIdIsNull.
@Test
public void testGetByRelationIdIsNull() throws Exception {
ParentEntity obj = new ParentEntity();
obj.setName("Name");
dao.save(obj);
assertEquals(1, dao.findByUriQuery(new WebQuery().isNull("otherObject.id")).getList().size());
}
use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery in project stdlib by petergeneric.
the class DynamicQueryTest method testNestedAssociatorThatIsMadeUpDoesNotWork.
@Test(expected = IllegalArgumentException.class)
public void testNestedAssociatorThatIsMadeUpDoesNotWork() throws Exception {
WebQuery query = new WebQuery().eq("otherObject.parent.fictionalfield.name", "Alice");
// Nonsense field shouldn't work
dao.findByUriQuery(query);
}
Aggregations