Search in sources :

Example 6 with StringType

use of com.qcadoo.model.internal.types.StringType in project qcadoo by qcadoo.

the class ValidationServiceImplTest method shouldCallFieldCustomValidatorWithNonNullOldValueOnCopy.

@Test
public final void shouldCallFieldCustomValidatorWithNonNullOldValueOnCopy() {
    // given
    final Long savedEntityId = null;
    final String someFieldName = "someField";
    final String someFieldOldValue = "someFieldValue";
    final String someFieldNewValue = "someFieldValueAfterUpdate";
    InternalFieldDefinition someFieldDefinition = mockFieldDefinition(someFieldName, new StringType());
    Map<String, FieldDefinition> fieldsMap = Maps.newHashMap();
    fieldsMap.put(someFieldName, someFieldDefinition);
    stubFieldDefinitions(dataDefinition, fieldsMap);
    when(genericEntity.getId()).thenReturn(savedEntityId);
    when(genericEntity.getField(someFieldName)).thenReturn(someFieldNewValue);
    when(genericEntity.isFieldValid(someFieldName)).thenReturn(true);
    when(existingGenericEntity.getField(someFieldName)).thenReturn(someFieldOldValue);
    // when
    validationService.validateGenericEntity(dataDefinition, genericEntity, existingGenericEntity);
    // then
    verify(someFieldDefinition, times(1)).callValidators(genericEntity, someFieldOldValue, someFieldNewValue);
}
Also used : InternalFieldDefinition(com.qcadoo.model.internal.api.InternalFieldDefinition) StringType(com.qcadoo.model.internal.types.StringType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) InternalFieldDefinition(com.qcadoo.model.internal.api.InternalFieldDefinition) Test(org.junit.Test)

Example 7 with StringType

use of com.qcadoo.model.internal.types.StringType in project qcadoo by qcadoo.

the class ValidationServiceImplTest method shouldCallFieldCustomValidatorWithNonNullOldValueOnUpdate.

@Test
public final void shouldCallFieldCustomValidatorWithNonNullOldValueOnUpdate() {
    // given
    final Long savedEntityId = 1L;
    final String someFieldName = "someField";
    final String someFieldOldValue = "someFieldValue";
    final String someFieldNewValue = "someFieldValueAfterUpdate";
    InternalFieldDefinition someFieldDefinition = mockFieldDefinition(someFieldName, new StringType());
    Map<String, FieldDefinition> fieldsMap = Maps.newHashMap();
    fieldsMap.put(someFieldName, someFieldDefinition);
    stubFieldDefinitions(dataDefinition, fieldsMap);
    when(genericEntity.getId()).thenReturn(savedEntityId);
    when(genericEntity.getField(someFieldName)).thenReturn(someFieldNewValue);
    when(genericEntity.isFieldValid(someFieldName)).thenReturn(true);
    when(existingGenericEntity.getField(someFieldName)).thenReturn(someFieldOldValue);
    // when
    validationService.validateGenericEntity(dataDefinition, genericEntity, existingGenericEntity);
    // then
    verify(someFieldDefinition, times(1)).callValidators(genericEntity, someFieldOldValue, someFieldNewValue);
}
Also used : InternalFieldDefinition(com.qcadoo.model.internal.api.InternalFieldDefinition) StringType(com.qcadoo.model.internal.types.StringType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) InternalFieldDefinition(com.qcadoo.model.internal.api.InternalFieldDefinition) Test(org.junit.Test)

Example 8 with StringType

use of com.qcadoo.model.internal.types.StringType in project qcadoo by qcadoo.

the class ValidationServiceImplTest method shouldCallFieldCustomValidatorWithNullOldValueOnCreate.

@Test
public final void shouldCallFieldCustomValidatorWithNullOldValueOnCreate() {
    // given
    final Long savedEntityId = null;
    final String someFieldName = "someField";
    final String someFieldNewValue = "someFieldValueAfterUpdate";
    InternalFieldDefinition someFieldDefinition = mockFieldDefinition(someFieldName, new StringType());
    Map<String, FieldDefinition> fieldsMap = Maps.newHashMap();
    fieldsMap.put(someFieldName, someFieldDefinition);
    stubFieldDefinitions(dataDefinition, fieldsMap);
    when(genericEntity.getId()).thenReturn(savedEntityId);
    when(genericEntity.getField(someFieldName)).thenReturn(someFieldNewValue);
    when(genericEntity.isFieldValid(someFieldName)).thenReturn(true);
    // when
    validationService.validateGenericEntity(dataDefinition, genericEntity, null);
    // then
    verify(someFieldDefinition, times(1)).callValidators(genericEntity, null, someFieldNewValue);
}
Also used : InternalFieldDefinition(com.qcadoo.model.internal.api.InternalFieldDefinition) StringType(com.qcadoo.model.internal.types.StringType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) InternalFieldDefinition(com.qcadoo.model.internal.api.InternalFieldDefinition) Test(org.junit.Test)

Example 9 with StringType

use of com.qcadoo.model.internal.types.StringType 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)

Example 10 with StringType

use of com.qcadoo.model.internal.types.StringType in project qcadoo by qcadoo.

the class GridComponentPatternTest method shouldInitializeOptions.

@Test
public void shouldInitializeOptions() throws Exception {
    // given
    DataDefinition dataDefinition = mock(DataDefinition.class);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    given(translationService.translate(Mockito.anyString(), Mockito.any(Locale.class))).willReturn("i18n");
    FieldDefinition nameFieldDefinition = mock(FieldDefinition.class);
    given(nameFieldDefinition.getType()).willReturn(new EnumType(translationService, "", true, "v1", "v2"));
    given(nameFieldDefinition.getName()).willReturn("name");
    FieldDefinition numberFieldDefinition = mock(FieldDefinition.class);
    given(numberFieldDefinition.getType()).willReturn(new IntegerType());
    given(numberFieldDefinition.getName()).willReturn("number");
    FieldDefinition productFieldDefinition = mock(FieldDefinition.class);
    given(productFieldDefinition.getType()).willReturn(new StringType());
    given(productFieldDefinition.getName()).willReturn("product");
    given(dataDefinition.getField("name")).willReturn(nameFieldDefinition);
    given(dataDefinition.getField("number")).willReturn(numberFieldDefinition);
    given(dataDefinition.getField("product")).willReturn(productFieldDefinition);
    given(dataDefinition.isPrioritizable()).willReturn(true);
    given(viewDefinition.getDataDefinition()).willReturn(dataDefinition);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    pattern.addOption(new ComponentOption("correspondingView", ImmutableMap.of("value", "plugin/details")));
    pattern.addOption(new ComponentOption("correspondingComponent", ImmutableMap.of("value", "window.form")));
    pattern.addOption(new ComponentOption("paginable", ImmutableMap.of("value", "true")));
    pattern.addOption(new ComponentOption("creatable", ImmutableMap.of("value", "true")));
    pattern.addOption(new ComponentOption("deletable", ImmutableMap.of("value", "true")));
    pattern.addOption(new ComponentOption("width", ImmutableMap.of("value", "200")));
    pattern.addOption(new ComponentOption("height", ImmutableMap.of("value", "400")));
    pattern.addOption(new ComponentOption("lookup", ImmutableMap.of("value", "true")));
    pattern.addOption(new ComponentOption("searchable", ImmutableMap.of("value", "name,number,product")));
    pattern.addOption(new ComponentOption("orderable", ImmutableMap.of("value", "name,number")));
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    pattern.addOption(new ComponentOption("column", ImmutableMap.of("name", "number", "fields", "number", "link", "true", "width", "200")));
    pattern.addOption(new ComponentOption("column", ImmutableMap.of("name", "name", "fields", "name", "hidden", "true")));
    pattern.addOption(new ComponentOption("column", ImmutableMap.of("name", "product", "expression", "#product['name']")));
    // when
    pattern.initialize();
    // then
    JSONObject options = getJsOptions(pattern);
    assertEquals("plugin/details", options.getString("correspondingView"));
    assertEquals("window.form", options.getString("correspondingComponent"));
    assertFalse(options.getBoolean("fullscreen"));
    assertTrue(options.getBoolean("paginable"));
    assertTrue(options.getBoolean("lookup"));
    assertTrue(options.getBoolean("creatable"));
    assertTrue(options.getBoolean("deletable"));
    assertTrue(options.getBoolean("prioritizable"));
    assertEquals(200, options.getInt("width"));
    assertEquals(400, options.getInt("height"));
    assertEquals(2, options.getJSONArray("orderableColumns").length());
    assertEquals("number", options.getJSONArray("orderableColumns").getString(0));
    assertEquals("name", options.getJSONArray("orderableColumns").getString(1));
    assertEquals(3, options.getJSONArray("searchableColumns").length());
    assertEquals("number", options.getJSONArray("searchableColumns").getString(0));
    assertEquals("product", options.getJSONArray("searchableColumns").getString(1));
    assertEquals("name", options.getJSONArray("searchableColumns").getString(2));
    assertFalse(options.has("belongsToFieldName"));
    assertEquals(3, options.getJSONArray("columns").length());
    JSONObject number = options.getJSONArray("columns").getJSONObject(0);
    JSONObject name = options.getJSONArray("columns").getJSONObject(1);
    JSONObject product = options.getJSONArray("columns").getJSONObject(2);
    assertEquals("number", number.getString("name"));
    assertTrue(number.getBoolean("link"));
    assertFalse(number.getBoolean("hidden"));
    assertEquals(200, number.getInt("width"));
    assertEquals("right", number.getString("align"));
    assertFalse(number.has("filterValues"));
    assertEquals("name", name.getString("name"));
    assertFalse(name.getBoolean("link"));
    assertTrue(name.getBoolean("hidden"));
    assertEquals(100, name.getInt("width"));
    assertEquals("left", name.getString("align"));
    assertEquals(2, name.getJSONArray("filterValues").length());
    assertEquals("v1", name.getJSONArray("filterValues").getJSONObject(0).getString("key"));
    assertEquals("i18n", name.getJSONArray("filterValues").getJSONObject(0).getString("value"));
    assertEquals("v2", name.getJSONArray("filterValues").getJSONObject(1).getString("key"));
    assertEquals("i18n", name.getJSONArray("filterValues").getJSONObject(1).getString("value"));
    assertEquals("product", product.getString("name"));
    assertFalse(product.getBoolean("link"));
    assertFalse(product.getBoolean("hidden"));
    assertEquals(100, product.getInt("width"));
    assertEquals("left", product.getString("align"));
    assertFalse(product.has("filterValues"));
}
Also used : Locale(java.util.Locale) IntegerType(com.qcadoo.model.internal.types.IntegerType) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) JSONObject(org.json.JSONObject) StringType(com.qcadoo.model.internal.types.StringType) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) EnumType(com.qcadoo.model.internal.types.EnumType) ComponentOption(com.qcadoo.view.internal.ComponentOption) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Aggregations

StringType (com.qcadoo.model.internal.types.StringType)10 FieldDefinition (com.qcadoo.model.api.FieldDefinition)9 Test (org.junit.Test)8 DataDefinition (com.qcadoo.model.api.DataDefinition)3 Entity (com.qcadoo.model.api.Entity)3 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)3 InternalFieldDefinition (com.qcadoo.model.internal.api.InternalFieldDefinition)3 TranslationService (com.qcadoo.localization.api.TranslationService)2 FieldDefinitionImpl (com.qcadoo.model.internal.FieldDefinitionImpl)2 IntegerType (com.qcadoo.model.internal.types.IntegerType)2 SecurityRolesService (com.qcadoo.security.api.SecurityRolesService)2 JSONObject (org.json.JSONObject)2 Before (org.junit.Before)2 ApplicationContext (org.springframework.context.ApplicationContext)2 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)1 BelongsToType (com.qcadoo.model.api.types.BelongsToType)1 FieldType (com.qcadoo.model.api.types.FieldType)1 HasManyType (com.qcadoo.model.api.types.HasManyType)1 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)1 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)1