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