Search in sources :

Example 51 with DefaultEntity

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"));
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) EntityHookDefinitionImpl(com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 52 with DefaultEntity

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

Example 53 with DefaultEntity

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

Example 54 with DefaultEntity

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

Example 55 with DefaultEntity

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);
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) StringType(com.qcadoo.model.internal.types.StringType) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) FieldDefinitionImpl(com.qcadoo.model.internal.FieldDefinitionImpl) 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