Search in sources :

Example 1 with GridComponentOrderColumn

use of com.qcadoo.view.internal.components.grid.GridComponentOrderColumn in project qcadoo by qcadoo.

the class GridComponentStateTest method shouldInitializeWithoutData.

@Test
@SuppressWarnings("unchecked")
public void shouldInitializeWithoutData() throws Exception {
    // given
    GridComponentPattern pattern = mock(GridComponentPattern.class);
    given(pattern.getColumns()).willReturn(columns);
    given(pattern.getBelongsToFieldDefinition()).willReturn(null);
    given(pattern.isActivable()).willReturn(false);
    given(pattern.isWeakRelation()).willReturn(false);
    ApplicationContext applicationContext = mock(ApplicationContext.class);
    setField(pattern, "applicationContext", applicationContext);
    SecurityRolesService securityRolesService = mock(SecurityRolesService.class);
    given(applicationContext.getBean(SecurityRolesService.class)).willReturn(securityRolesService);
    grid = new GridComponentState(productDataDefinition, pattern);
    grid.setDataDefinition(substituteDataDefinition);
    JSONObject json = new JSONObject(Collections.singletonMap(AbstractComponentState.JSON_CONTENT, new JSONObject()));
    // when
    grid.initialize(json, Locale.ENGLISH);
    // then
    assertNull(getField(grid, "belongsToFieldDefinition"));
    assertNull(getField(grid, "selectedEntityId"));
    assertNull(getField(grid, "belongsToEntityId"));
    assertNull(getField(grid, "entities"));
    assertEquals(0, getField(grid, "totalEntities"));
    assertEquals(0, getField(grid, "firstResult"));
    assertEquals(Integer.MAX_VALUE, getField(grid, "maxResults"));
    assertTrue((Boolean) getField(grid, "filtersEnabled"));
    List<GridComponentOrderColumn> orderColumns = (List<GridComponentOrderColumn>) getField(grid, "orderColumns");
    assertEquals(0, orderColumns.size());
    Map<String, String> filters = (Map<String, String>) getField(grid, "filters");
    assertEquals(0, filters.size());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) GridComponentOrderColumn(com.qcadoo.view.internal.components.grid.GridComponentOrderColumn) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) JSONObject(org.json.JSONObject) GridComponentState(com.qcadoo.view.internal.components.grid.GridComponentState) SecurityRolesService(com.qcadoo.security.api.SecurityRolesService) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 SecurityRolesService (com.qcadoo.security.api.SecurityRolesService)1 GridComponentOrderColumn (com.qcadoo.view.internal.components.grid.GridComponentOrderColumn)1 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)1 GridComponentState (com.qcadoo.view.internal.components.grid.GridComponentState)1 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 ApplicationContext (org.springframework.context.ApplicationContext)1