Search in sources :

Example 56 with DefaultEntity

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

the class ExpressionUtilTest method shouldGenerateValueOfTheBelongsToColumn.

@Test
public void shouldGenerateValueOfTheBelongsToColumn() throws Exception {
    // given
    DataDefinition dataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
    Entity product = new DefaultEntity(dataDefinition, 1L);
    product.setField("name", "P1");
    BelongsToType belongsToType = mock(BelongsToType.class);
    given(dataDefinition.getField(eq("name")).getType().toString(eq("P1"), eq(Locale.ENGLISH))).willReturn("P1");
    given(dataDefinition.getField(eq("product")).getType()).willReturn(belongsToType);
    given(dataDefinition.getField(eq("product")).getType()).willReturn(belongsToType);
    given(belongsToType.getDataDefinition()).willReturn(dataDefinition);
    Entity entity = new DefaultEntity(dataDefinition, 1L);
    entity.setField("product", product);
    // when
    String value = expressionService.getValue(entity, "#product['name']", Locale.ENGLISH);
    // then
    assertEquals("P1", value);
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) BelongsToType(com.qcadoo.model.api.types.BelongsToType) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 57 with DefaultEntity

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

the class ValidatorTest method shouldHasNoCheckLenghtOfBoolean.

@Test
public void shouldHasNoCheckLenghtOfBoolean() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("retired", false);
    fieldDefinitionRetired.withValidator(new LengthValidator(null, null, 0));
    // when
    entity = dataDefinition.save(entity);
    // then
    verify(session).save(any(SampleSimpleDatabaseObject.class));
    assertTrue(entity.isValid());
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) LengthValidator(com.qcadoo.model.internal.validators.LengthValidator) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 58 with DefaultEntity

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

the class ValidatorTest method shouldHasErrorsIfStringLengthIsNotEqual.

@Test
public void shouldHasErrorsIfStringLengthIsNotEqual() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("name", "Qcadoo Framework RLZ!");
    fieldDefinitionName.withValidator(new LengthValidator(null, 4, null));
    // when
    entity = dataDefinition.save(entity);
    // then
    verify(session, never()).save(any(SampleSimpleDatabaseObject.class));
    assertFalse(entity.isValid());
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) LengthValidator(com.qcadoo.model.internal.validators.LengthValidator) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 59 with DefaultEntity

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

the class ValidatorTest method shouldNotCallFieldValidatorIfSourcePluginIsNotEnabled.

@Test
public final void shouldNotCallFieldValidatorIfSourcePluginIsNotEnabled() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("name", "EverythingButNotQWERTY :)");
    fieldDefinitionName.withValidator(new CustomValidator(new FieldHookDefinitionImpl(CustomEntityService.class.getName(), "isEqualToQwerty", PLUGIN_IDENTIFIER, applicationContext)));
    stubPluginIsEnabled(false);
    // when
    Entity savedEntity = dataDefinition.save(entity);
    // then
    assertTrue(savedEntity.isValid());
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) CustomEntityService(com.qcadoo.model.beans.sample.CustomEntityService) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) FieldHookDefinitionImpl(com.qcadoo.model.internal.hooks.FieldHookDefinitionImpl) CustomValidator(com.qcadoo.model.internal.validators.CustomValidator) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 60 with DefaultEntity

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

the class ValidatorTest method shouldHasNoErrorsIfStringValueLenghtIsOk.

@Test
public void shouldHasNoErrorsIfStringValueLenghtIsOk() throws Exception {
    // given
    Entity entity = new DefaultEntity(dataDefinition);
    entity.setField("name", "qwert");
    fieldDefinitionName.withValidator(new LengthValidator(null, null, 5));
    // when
    entity = dataDefinition.save(entity);
    // then
    verify(session).save(any(SampleSimpleDatabaseObject.class));
    assertTrue(entity.isValid());
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) LengthValidator(com.qcadoo.model.internal.validators.LengthValidator) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) 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