Search in sources :

Example 31 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition in project qcadoo by qcadoo.

the class GridComponentPatternTest method shouldReturnState.

@Test
public void shouldReturnState() throws Exception {
    // given
    InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
    DataDefinition dataDefinition = mock(DataDefinition.class);
    BelongsToType belongsToFieldType = mock(BelongsToType.class);
    FieldDefinition belongsToFieldDefinition = mock(FieldDefinition.class);
    given(belongsToFieldDefinition.getName()).willReturn("joinName");
    given(belongsToFieldDefinition.getType()).willReturn(belongsToFieldType);
    HasManyType hasManyFieldType = mock(HasManyType.class);
    given(hasManyFieldType.getJoinFieldName()).willReturn("joinName");
    given(hasManyFieldType.getDataDefinition()).willReturn(dataDefinition);
    FieldDefinition hasManyFieldDefinition = mock(FieldDefinition.class);
    given(hasManyFieldDefinition.getName()).willReturn("fieldName");
    given(hasManyFieldDefinition.getType()).willReturn(hasManyFieldType);
    given(dataDefinition.getField("field")).willReturn(hasManyFieldDefinition);
    given(dataDefinition.getField("joinName")).willReturn(belongsToFieldDefinition);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractComponentPattern sourceComponent = new TextInputComponentPattern(getComponentDefinition("component", viewDefinition));
    setField(sourceComponent, "dataDefinition", dataDefinition);
    setField(sourceComponent, "initialized", true);
    given(viewDefinition.getComponentByReference("component")).willReturn(sourceComponent);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, null, "#{component}.field", null, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    pattern.initialize();
    // when
    ComponentState state = pattern.createComponentState(viewDefinitionState);
    // then
    assertTrue(state instanceof GridComponent);
    assertEquals(belongsToFieldDefinition, getField(state, "belongsToFieldDefinition"));
    assertEquals(getField(pattern, "columns"), getField(state, "columns"));
}
Also used : InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) GridComponent(com.qcadoo.view.api.components.GridComponent) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) HasManyType(com.qcadoo.model.api.types.HasManyType) BelongsToType(com.qcadoo.model.api.types.BelongsToType) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) ComponentState(com.qcadoo.view.api.ComponentState) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Example 32 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition 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"));
}
Also used : PluginUtilsService(com.qcadoo.plugin.internal.PluginUtilsService) ViewGridColumnModuleColumnModel(com.qcadoo.view.internal.module.gridColumn.ViewGridColumnModuleColumnModel) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) GridComponent(com.qcadoo.view.api.components.GridComponent) FieldDefinition(com.qcadoo.model.api.FieldDefinition) GridComponentColumn(com.qcadoo.view.internal.components.grid.GridComponentColumn) DataDefinition(com.qcadoo.model.api.DataDefinition) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) PluginStateResolver(com.qcadoo.plugin.api.PluginStateResolver) EnumType(com.qcadoo.model.internal.types.EnumType) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) ComponentState(com.qcadoo.view.api.ComponentState) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Example 33 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition 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)

Example 34 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition in project qcadoo by qcadoo.

the class ComponentPatternTest method shouldAddItselfToParentOnInitialize.

@Test
public void shouldAddItselfToParentOnInitialize() throws Exception {
    // given
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("test", viewDefinition));
    ComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("testName", "testField", null, parent, viewDefinition));
    // when
    pattern.initialize();
    // then
    assertEquals(pattern, parent.getFieldEntityIdChangeListeners().get("testField"));
}
Also used : WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 35 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition in project qcadoo by qcadoo.

the class ComponentPatternTest method shouldHaveValidInstance.

@Test
@SuppressWarnings("unchecked")
public void shouldHaveValidInstance() throws Exception {
    // given
    InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
    TranslationService translationService = mock(TranslationService.class);
    ApplicationContext applicationContext = mock(ApplicationContext.class);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    ComponentDefinition componentDefinition = getComponentDefinition("testName", null);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    componentDefinition.setViewDefinition(viewDefinition);
    AbstractComponentPattern pattern = new FormComponentPattern(componentDefinition);
    ViewEventListenerHook viewEventListenerHook = mock(ViewEventListenerHook.class);
    given(viewEventListenerHook.getEventName()).willReturn("save");
    pattern.addCustomEvent(viewEventListenerHook);
    // when
    ComponentState state = pattern.createComponentState(viewDefinitionState);
    // then
    assertTrue(state instanceof FormComponent);
    EventHandlerHolder eventHandlerHolder = (EventHandlerHolder) getField(state, "eventHandlerHolder");
    Map<String, List<EventHandlerHolder.EventHandler>> eventHandlers = (Map<String, List<EventHandlerHolder.EventHandler>>) getField(eventHandlerHolder, "eventHandlers");
    List<EventHandlerHolder.EventHandler> handlers = eventHandlers.get("save");
    assertNotNull(handlers);
    assertEquals(2, handlers.size());
    assertEquals(viewEventListenerHook, handlers.get(1));
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) EventHandlerHolder(com.qcadoo.view.internal.internal.EventHandlerHolder) ApplicationContext(org.springframework.context.ApplicationContext) ViewEventListenerHook(com.qcadoo.view.internal.hooks.ViewEventListenerHook) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) TranslationService(com.qcadoo.localization.api.TranslationService) List(java.util.List) Map(java.util.Map) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) ComponentState(com.qcadoo.view.api.ComponentState) Test(org.junit.Test)

Aggregations

InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)49 Test (org.junit.Test)40 DataDefinition (com.qcadoo.model.api.DataDefinition)25 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)21 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)15 FieldDefinition (com.qcadoo.model.api.FieldDefinition)14 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)14 ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)13 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)11 JSONObject (org.json.JSONObject)10 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)9 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)9 ComponentOption (com.qcadoo.view.internal.ComponentOption)8 ComponentState (com.qcadoo.view.api.ComponentState)7 ViewDefinitionImpl (com.qcadoo.view.internal.internal.ViewDefinitionImpl)7 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)6 BelongsToType (com.qcadoo.model.api.types.BelongsToType)5 HasManyType (com.qcadoo.model.api.types.HasManyType)5 ModuleException (com.qcadoo.plugin.api.ModuleException)4 EnumType (com.qcadoo.model.internal.types.EnumType)3