use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CriteriaIntegrationTest method shouldCountRestrictedEntities.
@Test
public void shouldCountRestrictedEntities() {
// given
DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
productDao.save(createProduct("asd", "asd"));
productDao.save(createProduct("asd1", "asd1"));
productDao.save(createProduct("bsd", "bsd"));
// when
long count = productDao.count(SearchRestrictions.like("name", "asd", SearchRestrictions.SearchMatchMode.START));
// then
assertEquals(2L, count);
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CriteriaIntegrationTest method shouldFindByQueryWithWhere.
@Test
public void shouldFindByQueryWithWhere() throws Exception {
// given
DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
Entity product5 = createProduct("cee", "cee");
product5.setField("quantity", 3);
productDao.save(product5);
Entity product1 = createProduct("bsd", "bsd1");
product1.setField("quantity", 1);
productDao.save(product1);
Entity product2 = createProduct("bsd", "bsd2");
product2.setField("quantity", 3);
productDao.save(product2);
Entity product3 = createProduct("abc", "abc");
product3.setField("quantity", 1);
productDao.save(product3);
Entity product4 = createProduct("bef", "bef");
product4.setField("quantity", 2);
productDao.save(product4);
// when
SearchResult searchResult = productDao.find().add(SearchRestrictions.or(SearchRestrictions.like("name", "b%"), SearchRestrictions.like("name", "c%"))).setProjection(SearchProjections.list().add(SearchProjections.groupField("name")).add(SearchProjections.alias(SearchProjections.sum("quantity"), "quantity")).add(SearchProjections.alias(SearchProjections.rowCount(), "products"))).setFirstResult(0).setMaxResults(2).addOrder(SearchOrders.asc("name")).list();
// then
assertEquals(3, searchResult.getTotalNumberOfEntities());
assertEquals(2, searchResult.getEntities().size());
assertEquals("bef", searchResult.getEntities().get(0).getField("0"));
assertEquals(Long.valueOf(2), searchResult.getEntities().get(0).getField("quantity"));
assertEquals(Long.valueOf(1), searchResult.getEntities().get(0).getField("products"));
assertEquals("bsd", searchResult.getEntities().get(1).getField("0"));
assertEquals(Long.valueOf(4), searchResult.getEntities().get(1).getField("quantity"));
assertEquals(Long.valueOf(2), searchResult.getEntities().get(1).getField("products"));
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CriteriaIntegrationTest method findByQueryWithBelongsToField.
private void findByQueryWithBelongsToField(final JoinType joinType) throws Exception {
// given
DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
DataDefinition partDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PART);
Entity product = createProduct("asd", "asd");
product.setField("quantity", 1);
product = productDao.save(product);
partDao.save(createPart("name", product));
// when
Entity result = partDao.find().add(SearchRestrictions.like("product.name", "asd")).createAlias("product", "product", joinType).setProjection(SearchProjections.list().add(SearchProjections.field("product.quantity")).add(SearchProjections.field("name")).add(SearchProjections.field("product"))).uniqueResult();
// then
assertEquals(IntegerType.class, result.getDataDefinition().getField("0").getType().getClass());
assertEquals(StringType.class, result.getDataDefinition().getField("1").getType().getClass());
assertEquals(BelongsToEntityType.class, result.getDataDefinition().getField("2").getType().getClass());
assertEquals(1, result.getField("0"));
assertEquals("name", result.getStringField("1"));
assertEquals(product.getId(), result.getBelongsToField("2").getId());
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CriteriaIntegrationTest method shouldCountAllEntities.
@Test
public void shouldCountAllEntities() {
// given
DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
productDao.save(createProduct("asd", "asd"));
productDao.save(createProduct("bsd", "bsd"));
productDao.save(createProduct("csd", "csd"));
// when
long count = productDao.count();
// then
assertEquals(3L, count);
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CriteriaIntegrationTest method shouldFindByQueryWithAlias.
@Test
public void shouldFindByQueryWithAlias() throws Exception {
// given
DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
productDao.save(createProduct("asd", "asd"));
productDao.save(createProduct("asd2", "asd2"));
// when
SearchResult result = productDao.findWithAlias("xxx").add(SearchRestrictions.eq("xxx.name", "asd")).list();
// then
assertEquals(1, result.getTotalNumberOfEntities());
assertEquals(1, result.getEntities().size());
}
Aggregations