Search in sources :

Example 51 with DataDefinition

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

Example 52 with DataDefinition

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

Example 53 with DataDefinition

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

Example 54 with DataDefinition

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

Example 55 with DataDefinition

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());
}
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