use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class HookTest method shouldCallOnCreateHook.
@Test
public void shouldCallOnCreateHook() throws Exception {
// given
Entity entity = new DefaultEntity(dataDefinition);
entity.setField("name", null);
entity.setField("age", null);
dataDefinition.addCreateHook(new EntityHookDefinitionImpl(CustomEntityService.class.getName(), "onCreate", PLUGIN_IDENTIFIER, applicationContext));
// when
entity = dataDefinition.save(entity);
// then
assertEquals("create", entity.getField("name"));
assertEquals(null, entity.getField("age"));
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class DictionaryServiceTest method shouldReturnListOfDictionaries.
@Test
public void shouldReturnListOfDictionaries() throws Exception {
// given
Entity dict1 = new DefaultEntity(null);
dict1.setField("name", "Dict1");
dict1.setField("active", true);
Entity dict2 = new DefaultEntity(null);
dict2.setField("name", "Dict2");
dict2.setField("active", true);
Entity dict3 = new DefaultEntity(null);
dict3.setField("name", "Dict3");
dict3.setField("active", true);
given(dataDefinitionService.get("qcadooModel", "dictionary").find().addOrder(SearchOrders.asc("name")).list().getEntities()).willReturn(newArrayList(dict1, dict2, dict3));
// when
Set<String> dictionaries = dictionaryService.getDictionaries();
// then
assertThat(dictionaries.size(), equalTo(3));
assertThat(dictionaries, hasItems("Dict1", "Dict2", "Dict3"));
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class DictionaryServiceTest method shouldReturnSortedListOfDictionaryValues.
@Test
public void shouldReturnSortedListOfDictionaryValues() throws Exception {
// given
Entity item1 = new DefaultEntity(null);
item1.setField("name", "aaa");
Entity item2 = new DefaultEntity(null);
item2.setField("name", "ccc");
Entity item3 = new DefaultEntity(null);
item3.setField("name", "bbb");
given(dataDefinitionService.get("qcadooModel", "dictionaryItem").find().createAlias("dictionary", "dictionary").add(SearchRestrictions.eq("dictionary.name", "dict")).add(SearchRestrictions.eq("active", true)).addOrder(SearchOrders.asc("name")).list().getEntities()).willReturn(newArrayList(item1, item3, item2));
// when
Map<String, String> values = dictionaryService.getActiveValues("dict", Locale.ENGLISH);
// then
assertThat(values.size(), equalTo(3));
assertThat(values.get("aaa"), equalTo("aaa"));
assertThat(values.get("bbb"), equalTo("bbb"));
assertThat(values.get("ccc"), equalTo("ccc"));
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ExpressionUtilTest method shouldGenerateValueOfEmptyField.
@Test
public void shouldGenerateValueOfEmptyField() throws Exception {
// given
DataDefinition dataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
Entity entity = new DefaultEntity(dataDefinition, 1L);
entity.setField("name", null);
// when
String value = expressionService.getValue(entity, "#name", null);
// then
assertNull(value);
}
use of com.qcadoo.model.internal.DefaultEntity in project qcadoo by qcadoo.
the class ExpressionUtilTest method shouldReturnStringRepresentationOfOneFieldWithoutExpression.
@Test
public void shouldReturnStringRepresentationOfOneFieldWithoutExpression() throws Exception {
// given
Entity entity = new DefaultEntity(null, 1L);
entity.setField("name", "Mr T");
FieldDefinition fieldDefinition = new FieldDefinitionImpl(null, "name").withType(new StringType());
// when
String value = expressionService.getValue(entity, Lists.newArrayList(fieldDefinition), null);
// then
assertEquals("Mr T", value);
}
Aggregations