use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CriteriaIntegrationTest method shouldFindByQueryWithEntityIdParameters.
@Test
public void shouldFindByQueryWithEntityIdParameters() throws Exception {
// given
DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
DataDefinition partDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PART);
Entity expectedProduct = productDao.save(createProduct("asd", "asd"));
Entity expectedPart = partDao.save(createPart("name", expectedProduct));
// when
Entity part = partDao.find().add(SearchRestrictions.belongsTo("product", PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT, expectedProduct.getId())).uniqueResult();
// then
assertEquals(expectedPart.getId(), part.getId());
assertEquals(expectedPart.getDataDefinition(), part.getDataDefinition());
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CriteriaIntegrationTest method shouldFindByQueryWithInlineEntityId.
@Test
public void shouldFindByQueryWithInlineEntityId() throws Exception {
// given
DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
DataDefinition partDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PART);
Entity expectedProduct = productDao.save(createProduct("asd", "asd"));
Entity expectedPart = partDao.save(createPart("name", expectedProduct));
// when
Entity part = partDao.find().add(SearchRestrictions.eq("product.id", expectedProduct.getId())).uniqueResult();
// then
assertEquals(expectedPart.getId(), part.getId());
assertEquals(expectedPart.getDataDefinition(), part.getDataDefinition());
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CrudIntegrationTest method shouldNotSaveEntityWithHasManyRelationToInvalidEntity.
@Test
public void shouldNotSaveEntityWithHasManyRelationToInvalidEntity() throws Exception {
// given
final DataDefinition productDataDefinition = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
Entity product = createProduct("product", "asd");
Entity part1 = createPart("part1", product);
Entity part2 = createPart(null, product);
product.setField("parts", Lists.newArrayList(part1, part2));
// when
product = productDataDefinition.save(product);
// then
final List<Entity> productParts = product.getHasManyField("parts");
part1 = productParts.get(0);
part2 = productParts.get(1);
assertNotNull(product.getField("name"));
assertNull(product.getId());
assertFalse(product.isValid());
assertTrue(product.isFieldValid("name"));
assertNotNull(part1.getField("name"));
assertTrue(part1.isValid());
assertNull(part2.getField("name"));
assertFalse(part2.isValid());
int total = jdbcTemplate.queryForInt("select count(*) from " + TABLE_NAME_PRODUCT);
assertEquals(0, total);
assertEquals(1, verifyHooks.getNumOfInvocations(HookType.SAVE));
assertEquals(1, verifyHooks.getNumOfInvocations(HookType.CREATE));
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.COPY));
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.UPDATE));
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.DELETE));
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CrudIntegrationTest method shouldHookUpdateReadOnlyFieldOnUpdate.
@Test
public void shouldHookUpdateReadOnlyFieldOnUpdate() throws Exception {
// given
DataDefinition productDataDefinition = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
Entity product = createProduct("product", "18");
product = productDataDefinition.save(product);
// when
product.setField("readOnly", "someValue");
product = productDataDefinition.save(product);
// then
assertTrue(product.isValid());
assertEquals("changedByHook", product.getField("readOnly"));
Map<String, Object> result = jdbcTemplate.queryForMap("select * from " + TABLE_NAME_PRODUCT);
assertNotNull(result);
assertEquals("changedByHook", result.get("readOnly"));
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CrudIntegrationTest method shouldLimitEntities.
@Test
public void shouldLimitEntities() throws Exception {
// given
DataDefinition machineDataDefinition = dataDefinitionService.get(PLUGIN_MACHINES_NAME, ENTITY_NAME_MACHINE);
Entity machine1 = machineDataDefinition.save(createMachine("asd"));
machineDataDefinition.save(createMachine("def"));
// when
List<Entity> machines = machineDataDefinition.find().setMaxResults(1).list().getEntities();
// then
assertNotNull(machines);
assertEquals(1, machines.size());
assertEquals(machine1.getId(), machines.get(0).getId());
}
Aggregations