use of com.qcadoo.model.internal.types.EnumType in project qcadoo by qcadoo.
the class GridComponentPatternTest method shouldNotFilterOutColumnsVisibleForTenant.
@Test
public void shouldNotFilterOutColumnsVisibleForTenant() throws Exception {
// given
PluginStateResolver pluginStateResolver = mock(PluginStateResolver.class);
PluginUtilsService pluginUtil = new PluginUtilsService(pluginStateResolver);
pluginUtil.init();
given(pluginStateResolver.isEnabled("disabledPlugin")).willReturn(true);
InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
DataDefinition dataDefinition = mock(DataDefinition.class);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
given(viewDefinition.getDataDefinition()).willReturn(dataDefinition);
ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, viewDefinition);
componentDefinition.setTranslationService(translationService);
componentDefinition.setApplicationContext(applicationContext);
componentDefinition.setDataDefinition(dataDefinition);
GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
FieldDefinition nameFieldDefinition = mock(FieldDefinition.class);
given(nameFieldDefinition.getType()).willReturn(new EnumType(translationService, "", true, "v1", "v2"));
given(dataDefinition.getField("name")).willReturn(nameFieldDefinition);
pattern.addOption(new ComponentOption("column", ImmutableMap.of("name", "name", "fields", "name", "hidden", "true")));
pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
ViewGridColumnModuleColumnModel columnModel = new ViewGridColumnModuleColumnModel("invisible", "name");
columnModel.setWidth(100);
pattern.addColumn("disabledPlugin", columnModel);
pattern.initialize();
// when
ComponentState state = pattern.createComponentState(viewDefinitionState);
// then
assertTrue(state instanceof GridComponent);
@SuppressWarnings("unchecked") Map<String, GridComponentColumn> patternColumns = (Map<String, GridComponentColumn>) getField(pattern, "columns");
@SuppressWarnings("unchecked") Map<String, GridComponentColumn> stateColumns = (Map<String, GridComponentColumn>) getField(state, "columns");
assertEquals(2, patternColumns.size());
assertEquals(2, stateColumns.size());
assertTrue(patternColumns.keySet().contains("name"));
assertNotNull(patternColumns.get("name"));
assertTrue(patternColumns.keySet().contains("invisible"));
assertNotNull(patternColumns.get("invisible"));
assertTrue(stateColumns.keySet().contains("name"));
assertNotNull(stateColumns.get("name"));
assertTrue(stateColumns.keySet().contains("invisible"));
assertNotNull(stateColumns.get("invisible"));
}
use of com.qcadoo.model.internal.types.EnumType in project qcadoo by qcadoo.
the class FieldTypeFactoryTest method shouldReturnEnumType.
@Test
public void shouldReturnEnumType() throws Exception {
// given
TranslationService translationService = mock(TranslationService.class);
given(translationService.translate("path.value.val1", Locale.ENGLISH)).willReturn("i18nVal1");
given(translationService.translate("path.value.val2", Locale.ENGLISH)).willReturn("i18nVal2");
given(translationService.translate("path.value.val3", Locale.ENGLISH)).willReturn("i18nVal3");
// when
EnumeratedType fieldType = new EnumType(translationService, "path", true, "val1", "val2", "val3");
// then
assertEquals(fieldType.activeValues(Locale.ENGLISH).keySet(), Sets.newHashSet("val1", "val2", "val3"));
assertEquals(Lists.newArrayList(fieldType.activeValues(Locale.ENGLISH).values()), Lists.newArrayList("i18nVal1", "i18nVal2", "i18nVal3"));
assertEquals(String.class, fieldType.getType());
ValueAndError valueAndError1 = fieldType.toObject(fieldDefinition, "val1");
ValueAndError valueAndError2 = fieldType.toObject(fieldDefinition, "val4");
assertTrue(valueAndError1.isValid());
assertFalse(valueAndError2.isValid());
assertNotNull(valueAndError1.getValue());
assertNull(valueAndError2.getValue());
assertEquals("qcadooView.validate.field.error.invalidDictionaryItem", valueAndError2.getMessage());
assertEquals("[val1, val2, val3]", valueAndError2.getArgs()[0]);
}
use of com.qcadoo.model.internal.types.EnumType in project qcadoo by qcadoo.
the class GridComponentPatternTest method shouldFilterOutColumnsInvisibleForTenant.
@Test
public void shouldFilterOutColumnsInvisibleForTenant() throws Exception {
// given
PluginStateResolver pluginStateResolver = mock(PluginStateResolver.class);
PluginUtilsService pluginUtil = new PluginUtilsService(pluginStateResolver);
pluginUtil.init();
given(pluginStateResolver.isEnabled("disabledPlugin")).willReturn(false);
InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
DataDefinition dataDefinition = mock(DataDefinition.class);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
given(viewDefinition.getDataDefinition()).willReturn(dataDefinition);
ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, viewDefinition);
componentDefinition.setTranslationService(translationService);
componentDefinition.setApplicationContext(applicationContext);
componentDefinition.setDataDefinition(dataDefinition);
GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
FieldDefinition nameFieldDefinition = mock(FieldDefinition.class);
given(nameFieldDefinition.getType()).willReturn(new EnumType(translationService, "", true, "v1", "v2"));
given(dataDefinition.getField("name")).willReturn(nameFieldDefinition);
pattern.addOption(new ComponentOption("column", ImmutableMap.of("name", "name", "fields", "name", "hidden", "true")));
pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
ViewGridColumnModuleColumnModel columnModel = new ViewGridColumnModuleColumnModel("invisible", "name");
columnModel.setWidth(100);
pattern.addColumn("disabledPlugin", columnModel);
pattern.initialize();
// when
ComponentState state = pattern.createComponentState(viewDefinitionState);
// then
assertTrue(state instanceof GridComponent);
@SuppressWarnings("unchecked") Map<String, GridComponentColumn> patternColumns = (Map<String, GridComponentColumn>) getField(pattern, "columns");
@SuppressWarnings("unchecked") Map<String, GridComponentColumn> stateColumns = (Map<String, GridComponentColumn>) getField(state, "columns");
assertEquals(2, patternColumns.size());
assertEquals(1, stateColumns.size());
assertTrue(patternColumns.keySet().contains("name"));
assertNotNull(patternColumns.get("name"));
assertTrue(patternColumns.keySet().contains("invisible"));
assertNotNull(patternColumns.get("invisible"));
assertTrue(stateColumns.keySet().contains("name"));
assertNotNull(stateColumns.get("name"));
assertFalse(stateColumns.keySet().contains("invisible"));
assertNull(stateColumns.get("invisible"));
}
use of com.qcadoo.model.internal.types.EnumType 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"));
}
Aggregations