use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CrudIntegrationTest method shouldOffsetEntities.
@Test
public void shouldOffsetEntities() throws Exception {
// given
DataDefinition machineDataDefinition = dataDefinitionService.get(PLUGIN_MACHINES_NAME, ENTITY_NAME_MACHINE);
machineDataDefinition.save(createMachine("asd"));
Entity machine2 = machineDataDefinition.save(createMachine("def"));
// when
List<Entity> machines = machineDataDefinition.find().setFirstResult(1).setMaxResults(1).list().getEntities();
// then
assertNotNull(machines);
assertEquals(1, machines.size());
assertEquals(machine2.getId(), machines.get(0).getId());
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CrudIntegrationTest method shouldReturnNullForGettingNotExistedEntity.
@Test
public void shouldReturnNullForGettingNotExistedEntity() throws Exception {
// given
DataDefinition machineDataDefinition = dataDefinitionService.get(PLUGIN_MACHINES_NAME, ENTITY_NAME_MACHINE);
// then
Entity machine = machineDataDefinition.get(1L);
// then
assertNull(machine);
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CrudIntegrationTest method shouldOrderEntitiesByMultipleFields.
@Test
public void shouldOrderEntitiesByMultipleFields() throws Exception {
// given
DataDefinition productDataDefinition = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
Entity product1 = productDataDefinition.save(createProduct("asd", "asd"));
Entity product2 = productDataDefinition.save(createProduct("def", "asd"));
Entity product3 = productDataDefinition.save(createProduct("def", "def"));
// when
List<Entity> products = productDataDefinition.find().addOrder(SearchOrders.desc("name")).addOrder(SearchOrders.asc("number")).list().getEntities();
// then
assertNotNull(products);
assertEquals(2, products.size());
assertFalse(product2.isValid());
assertEquals(product3.getId(), products.get(0).getId());
assertEquals(product1.getId(), products.get(1).getId());
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CrudIntegrationTest method shouldNotUpdateInvalidEntity.
@Test
public void shouldNotUpdateInvalidEntity() throws Exception {
// given
DataDefinition productDataDefinition = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
Entity product = createProduct("asd", "asd");
product.setField("quantity", "2");
product = productDataDefinition.save(product);
product.setField("quantity", "0");
verifyHooks.clear();
// when
product = productDataDefinition.save(product);
// then
assertEquals(Integer.valueOf(0), Integer.valueOf(product.getField("quantity").toString()));
assertFalse(product.isValid());
assertFalse(product.isFieldValid("quantity"));
Map<String, Object> result = jdbcTemplate.queryForMap("select * from " + TABLE_NAME_PRODUCT);
assertNotNull(result);
assertEquals(2, result.get("quantity"));
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.SAVE));
assertEquals(0, 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 shouldOnDeleteHookRejectHardDeleteEntity.
@Test
public void shouldOnDeleteHookRejectHardDeleteEntity() throws Exception {
// given
DataDefinition componentDataDefinition = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_COMPONENT);
Entity component = createComponent("name", null, null);
component.setField("deletionIsAllowed", false);
component = componentDataDefinition.save(component);
verifyHooks.clear();
// when
componentDataDefinition.delete(component.getId());
// then
int total = jdbcTemplate.queryForInt("select count(*) from " + TABLE_NAME_COMPONENT);
assertEquals(1, total);
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.SAVE));
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.CREATE));
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.COPY));
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.UPDATE));
assertEquals(1, verifyHooks.getNumOfInvocations(HookType.DELETE));
}
Aggregations