use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery in project stdlib by petergeneric.
the class LargeTableQueryTest method testSearchComplexPK.
/**
* Test that searching works even with a complex primary key
*/
@Test
@Transactional
public void testSearchComplexPK() {
complexPKdao.save(new LargeTableComplexPKEntity("Alice"));
complexPKdao.save(new LargeTableComplexPKEntity("Bob"));
complexPKdao.save(new LargeTableComplexPKEntity("Carol"));
complexPKdao.save(new LargeTableComplexPKEntity("Dave"));
complexPKdao.save(new LargeTableComplexPKEntity("Eve"));
assertEquals(2, complexPKdao.findByUriQuery(new WebQuery().contains("name", "a")).getList().size());
}
use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery in project stdlib by petergeneric.
the class LargeTableQueryTest method testSearchComplexPKIDs.
/**
* Test that searching for IDs works even with a complex primary key
*/
@Test
@Transactional
public void testSearchComplexPKIDs() {
complexPKdao.save(new LargeTableComplexPKEntity("Alice"));
complexPKdao.save(new LargeTableComplexPKEntity("Bob"));
complexPKdao.save(new LargeTableComplexPKEntity("Carol"));
complexPKdao.save(new LargeTableComplexPKEntity("Dave"));
complexPKdao.save(new LargeTableComplexPKEntity("Eve"));
final List<SomePrimaryKey> results = complexPKdao.findIdsByUriQuery(new WebQuery().contains("name", "a")).getList();
assertEquals("expect 2 results", 2, results.size());
assertEquals("expect results to be of id type", SomePrimaryKey.class, results.get(0).getClass());
assertEquals("expect results to be of id type", SomePrimaryKey.class, results.get(1).getClass());
}
use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery in project stdlib by petergeneric.
the class LargeTableQueryTest method testSearchForPrimaryKeyWorks.
/**
* Test that searching works with a simple primary key
*/
@Test
@Transactional
public void testSearchForPrimaryKeyWorks() {
dao.save(new LargeTableSimplePKEntity("Alice"));
dao.save(new LargeTableSimplePKEntity("Bob"));
dao.save(new LargeTableSimplePKEntity("Carol"));
dao.save(new LargeTableSimplePKEntity("Dave"));
dao.save(new LargeTableSimplePKEntity("Eve"));
// Try a regular query
assertEquals("custom-coded count should return 2", 2, dao.countWithAInName());
// Now try a web query
final ConstrainedResultSet<Long> result = dao.findIdsByUriQuery(new WebQuery().computeSize(true).contains("name", "a"));
assertEquals("total results for generic query should be 2", Long.valueOf(2), result.getTotal());
assertEquals("generic get IDs should return 2 results", new ArrayList<>(Arrays.asList(3L, 4L)), new ArrayList<>(result.getList()));
}
use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery in project stdlib by petergeneric.
the class WebQueryTest method testParseQueryStringToWebQuery.
@Test
public void testParseQueryStringToWebQuery() {
WebQuery expected = new WebQuery().logSQL(true).eq("id", "123").offset(0).limit(200);
WebQuery actual = new WebQuery().decode(new ResteasyUriInfo(URI.create("http://example.com?_log_sql=true&id=123")));
assertEquals(expected.encode().toString(), actual.encode().toString());
}
use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery in project stdlib by petergeneric.
the class ResourceInstanceHelper method activeInstances.
/**
* Returns the number of active instances of the given template name
*
* @param service
* @param templateName
*
* @return
*/
public List<ResourceInstanceDTO> activeInstances(ServiceManagerResourceRestService service, String templateName) {
WebQuery wq = new WebQuery();
wq.eq("template.id", templateName);
wq.eq("state", ResourceInstanceState.TO_PROVISION, ResourceInstanceState.PROVISIONING, ResourceInstanceState.NOT_IN_SERVICE, ResourceInstanceState.IN_SERVICE);
List<ResourceInstanceDTO> instances = service.searchInstances(wq);
return instances;
}
Aggregations