Search in sources :

Example 61 with DataDefinition

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());
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 62 with DataDefinition

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);
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 63 with DataDefinition

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());
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 64 with DataDefinition

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));
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 65 with DataDefinition

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));
}
Also used : Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Aggregations

DataDefinition (com.qcadoo.model.api.DataDefinition)415 Entity (com.qcadoo.model.api.Entity)285 Test (org.junit.Test)165 BigDecimal (java.math.BigDecimal)53 FieldDefinition (com.qcadoo.model.api.FieldDefinition)48 List (java.util.List)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)32 Service (org.springframework.stereotype.Service)31 Autowired (org.springframework.beans.factory.annotation.Autowired)27 Date (java.util.Date)26 Map (java.util.Map)26 Collectors (java.util.stream.Collectors)26 FormComponent (com.qcadoo.view.api.components.FormComponent)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)22 IOException (java.io.IOException)21 Objects (java.util.Objects)21 GridComponent (com.qcadoo.view.api.components.GridComponent)20 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)20 Lists (com.google.common.collect.Lists)16