Search in sources :

Example 86 with DefaultEntity

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());
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) JSONObject(org.json.JSONObject) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Example 87 with DefaultEntity

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

Example 88 with DefaultEntity

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

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());
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) JSONObject(org.json.JSONObject) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Example 90 with DefaultEntity

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

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