Search in sources :

Example 91 with DefaultEntity

use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.

the class FormComponentStateTest method shouldReturnEntityWithOnlyFormValuesEvenIfEntityIsAlreadyPersisted.

@Test
public void shouldReturnEntityWithOnlyFormValuesEvenIfEntityIsAlreadyPersisted() throws Exception {
    // given
    Long id = 14L;
    String nameFieldName = "name";
    String nameFieldFormValue = "new name";
    String numberFieldName = "number";
    String numberFieldValue = "0003";
    Entity formEntity = new DefaultEntity(dataDefinition, id, Maps.<String, Object>newHashMap());
    formEntity.setField(nameFieldName, nameFieldFormValue);
    Entity alreadyPersistedEntity = new DefaultEntity(dataDefinition, id, Maps.<String, Object>newHashMap());
    alreadyPersistedEntity.setField(nameFieldName, "old name value");
    alreadyPersistedEntity.setField(numberFieldName, numberFieldValue);
    given(dataDefinition.get(id)).willReturn(alreadyPersistedEntity);
    form.setEntity(formEntity);
    // when
    Entity resultEntity = form.getEntity();
    // then
    verify(dataDefinition, never()).get(id);
    assertEquals(id, resultEntity.getId());
    assertEquals(nameFieldFormValue, resultEntity.getStringField(nameFieldName));
    assertNull(resultEntity.getStringField(numberFieldName));
    assertEquals(1, resultEntity.getFields().size());
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) Matchers.anyLong(org.mockito.Matchers.anyLong) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Example 92 with DefaultEntity

use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.

the class GridComponentStateTest method shouldGetValueUsingField.

@Test
public void shouldGetValueUsingField() throws Exception {
    // given
    FieldDefinition field = mock(FieldDefinition.class);
    given(field.getName()).willReturn("name");
    given(field.getValue("John", Locale.ENGLISH)).willReturn("Johny");
    GridComponentColumn column = new GridComponentColumn("name");
    column.addField(field);
    Entity entity = new DefaultEntity(productDataDefinition, 13L, ImmutableMap.of("name", (Object) "John"));
    // when
    String value = column.getValue(entity, Locale.ENGLISH);
    // then
    assertEquals("Johny", value);
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) GridComponentColumn(com.qcadoo.view.internal.components.grid.GridComponentColumn) JSONObject(org.json.JSONObject) Matchers.anyString(org.mockito.Matchers.anyString) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Aggregations

DefaultEntity (com.qcadoo.model.internal.DefaultEntity)92 Test (org.junit.Test)91 Entity (com.qcadoo.model.api.Entity)90 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)66 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)53 EntityHookDefinitionImpl (com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl)16 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)12 DataDefinition (com.qcadoo.model.api.DataDefinition)10 RangeValidator (com.qcadoo.model.internal.validators.RangeValidator)9 CustomEntityService (com.qcadoo.model.beans.sample.CustomEntityService)8 LengthValidator (com.qcadoo.model.internal.validators.LengthValidator)8 UnscaledValueValidator (com.qcadoo.model.internal.validators.UnscaledValueValidator)8 JSONObject (org.json.JSONObject)8 BigDecimal (java.math.BigDecimal)7 FieldDefinition (com.qcadoo.model.api.FieldDefinition)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 ScaleValidator (com.qcadoo.model.internal.validators.ScaleValidator)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 FieldHookDefinitionImpl (com.qcadoo.model.internal.hooks.FieldHookDefinitionImpl)4 CustomEntityValidator (com.qcadoo.model.internal.validators.CustomEntityValidator)4