Search in sources :

Example 1 with GridComponentState

use of com.qcadoo.view.internal.components.grid.GridComponentState 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)

Example 2 with GridComponentState

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

the class GridComponentStateTest method init.

@Before
public void init() throws Exception {
    JSONObject jsonContent = new JSONObject();
    jsonContent.put(GridComponentState.JSON_SELECTED_ENTITY_ID, 13L);
    jsonContent.put(GridComponentState.JSON_MULTISELECT_MODE, false);
    JSONObject jsonSelected = new JSONObject();
    jsonSelected.put("13", true);
    jsonContent.put(GridComponentState.JSON_SELECTED_ENTITIES, jsonSelected);
    jsonContent.put(GridComponentState.JSON_BELONGS_TO_ENTITY_ID, 1L);
    jsonContent.put(GridComponentState.JSON_FIRST_ENTITY, 60);
    jsonContent.put(GridComponentState.JSON_MAX_ENTITIES, 30);
    jsonContent.put(GridComponentState.JSON_FILTERS_ENABLED, true);
    JSONArray jsonOrder = new JSONArray();
    jsonOrder.put(ImmutableMap.of("column", "asd", "direction", "asc"));
    jsonContent.put(GridComponentState.JSON_ORDER, jsonOrder);
    JSONObject jsonFilters = new JSONObject();
    jsonFilters.put("asd", "test");
    jsonFilters.put("qwe", "test2");
    jsonContent.put(GridComponentState.JSON_FILTERS, jsonFilters);
    json = new JSONObject(Collections.singletonMap(AbstractComponentState.JSON_CONTENT, jsonContent));
    Entity entity = mock(Entity.class);
    given(entity.getField("name")).willReturn("text");
    viewDefinitionState = mock(ViewDefinitionState.class);
    productDataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
    substituteDataDefinition = mock(DataDefinition.class, "substituteDataDefinition");
    HasManyType substitutesFieldType = mock(HasManyType.class);
    given(substitutesFieldType.getDataDefinition()).willReturn(substituteDataDefinition);
    given(substitutesFieldType.getJoinFieldName()).willReturn("product");
    substitutesFieldDefinition = mock(FieldDefinition.class);
    given(substitutesFieldDefinition.getType()).willReturn(substitutesFieldType);
    given(substitutesFieldDefinition.getName()).willReturn("substitutes");
    given(substitutesFieldDefinition.getDataDefinition()).willReturn(substituteDataDefinition);
    substituteCriteria = mock(SearchCriteriaBuilder.class);
    given(substituteDataDefinition.getPluginIdentifier()).willReturn("plugin");
    given(substituteDataDefinition.getName()).willReturn("substitute");
    given(substituteDataDefinition.find()).willReturn(substituteCriteria);
    given(productDataDefinition.getPluginIdentifier()).willReturn("plugin");
    given(productDataDefinition.getName()).willReturn("product");
    given(productDataDefinition.getField("substitutes")).willReturn(substitutesFieldDefinition);
    columns = new LinkedHashMap<String, GridComponentColumn>();
    TranslationService translationService = mock(TranslationService.class);
    given(translationService.translate(Mockito.anyString(), Mockito.any(Locale.class))).willReturn("i18n");
    given(translationService.translate(Mockito.anyString(), Mockito.anyString(), Mockito.any(Locale.class))).willReturn("i18n");
    given(translationService.translate(Mockito.anyString(), Mockito.any(Locale.class))).willReturn("i18n");
    GridComponentPattern pattern = mock(GridComponentPattern.class);
    given(pattern.getColumns()).willReturn(columns);
    given(pattern.getBelongsToFieldDefinition()).willReturn(substitutesFieldDefinition);
    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);
    grid.setTranslationService(translationService);
    new ExpressionServiceImpl().init();
}
Also used : Locale(java.util.Locale) Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) JSONArray(org.json.JSONArray) GridComponentColumn(com.qcadoo.view.internal.components.grid.GridComponentColumn) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Matchers.anyString(org.mockito.Matchers.anyString) DataDefinition(com.qcadoo.model.api.DataDefinition) HasManyType(com.qcadoo.model.api.types.HasManyType) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) ApplicationContext(org.springframework.context.ApplicationContext) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) JSONObject(org.json.JSONObject) TranslationService(com.qcadoo.localization.api.TranslationService) GridComponentState(com.qcadoo.view.internal.components.grid.GridComponentState) SecurityRolesService(com.qcadoo.security.api.SecurityRolesService) ExpressionServiceImpl(com.qcadoo.model.internal.ExpressionServiceImpl) Before(org.junit.Before)

Aggregations

SecurityRolesService (com.qcadoo.security.api.SecurityRolesService)2 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)2 GridComponentState (com.qcadoo.view.internal.components.grid.GridComponentState)2 JSONObject (org.json.JSONObject)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ApplicationContext (org.springframework.context.ApplicationContext)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 TranslationService (com.qcadoo.localization.api.TranslationService)1 DataDefinition (com.qcadoo.model.api.DataDefinition)1 Entity (com.qcadoo.model.api.Entity)1 FieldDefinition (com.qcadoo.model.api.FieldDefinition)1 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)1 HasManyType (com.qcadoo.model.api.types.HasManyType)1 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)1 ExpressionServiceImpl (com.qcadoo.model.internal.ExpressionServiceImpl)1 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)1 GridComponentColumn (com.qcadoo.view.internal.components.grid.GridComponentColumn)1 GridComponentOrderColumn (com.qcadoo.view.internal.components.grid.GridComponentOrderColumn)1 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)1 LinkedHashMap (java.util.LinkedHashMap)1