use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class FormComponentStateTest method shouldCopyFormEntity.
@Test
public void shouldCopyFormEntity() throws Exception {
// given
Entity copiedEntity = new DefaultEntity(dataDefinition, 14L, Collections.singletonMap("name", (Object) "text(1)"));
given(dataDefinition.copy(13L)).willReturn(Collections.singletonList(copiedEntity));
given(dataDefinition.get(14L)).willReturn(copiedEntity);
name.setFieldValue("text");
form.setFieldValue(13L);
// when
form.performEvent(viewDefinitionState, "copy", new String[0]);
// then
verify(dataDefinition).copy(13L);
verify(dataDefinition).get(14L);
assertEquals("text(1)", name.getFieldValue());
assertEquals(14L, form.getFieldValue());
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class FormComponentStateTest method shouldReturnEntityWithOnlyFormValues.
@Test
public void shouldReturnEntityWithOnlyFormValues() throws Exception {
// given
String nameFieldName = "name";
String nameFieldFormValue = "new name";
String numberFieldName = "number";
Entity formEntity = new DefaultEntity(dataDefinition, null, Maps.<String, Object>newHashMap());
formEntity.setField(nameFieldName, nameFieldFormValue);
form.setEntity(formEntity);
// when
Entity resultEntity = form.getEntity();
// then
verify(dataDefinition, never()).get(anyLong());
verify(dataDefinition, never()).get(null);
assertNull(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 FormComponentStateTest method shouldReturnPersistedEntityWithIncludedFormValues.
@Test
public void shouldReturnPersistedEntityWithIncludedFormValues() 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.getPersistedEntityWithIncludedFormValues();
// then
verify(dataDefinition).get(id);
assertEquals(id, resultEntity.getId());
assertEquals(nameFieldFormValue, resultEntity.getStringField(nameFieldName));
assertEquals(numberFieldValue, resultEntity.getStringField(numberFieldName));
assertEquals(2, resultEntity.getFields().size());
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class FormComponentStateTest method shouldSaveFormEntity.
@Test
public void shouldSaveFormEntity() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition, null, Collections.singletonMap("name", (Object) "text"));
Entity savedEntity = new DefaultEntity(dataDefinition, 13L, Collections.singletonMap("name", (Object) "text2"));
given(dataDefinition.create(null)).willReturn(new DefaultEntity(dataDefinition));
given(dataDefinition.save(eq(entity))).willReturn(savedEntity);
name.setFieldValue("text");
form.setFieldValue(null);
// when
form.performEvent(viewDefinitionState, "save", new String[0]);
// then
verify(dataDefinition).save(eq(entity));
assertEquals("text2", name.getFieldValue());
assertEquals(13L, form.getFieldValue());
assertTrue(form.isValid());
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class FormComponentStateTest method shouldReturnEntityWithFormValuesIfEntityWasDeletedByAnotherUser.
@Test
public void shouldReturnEntityWithFormValuesIfEntityWasDeletedByAnotherUser() throws Exception {
// given
Long id = 14L;
String nameFieldName = "name";
String nameFieldFormValue = "new name";
String numberFieldName = "number";
Entity formEntity = new DefaultEntity(dataDefinition, id, Maps.<String, Object>newHashMap());
formEntity.setField(nameFieldName, nameFieldFormValue);
given(dataDefinition.get(id)).willReturn(null);
form.setEntity(formEntity);
// when
Entity resultEntity = form.getPersistedEntityWithIncludedFormValues();
// then
verify(dataDefinition).get(id);
assertEquals(id, resultEntity.getId());
assertEquals(nameFieldFormValue, resultEntity.getStringField(nameFieldName));
assertNull(resultEntity.getStringField(numberFieldName));
assertEquals(1, resultEntity.getFields().size());
}
Aggregations