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