Search in sources :

Example 11 with TranslationService

use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.

the class ExpressionUtilTest method init.

@Before
public void init() {
    expressionService = new ExpressionServiceImpl();
    translationService = mock(TranslationService.class);
    setField(expressionService, "translationService", translationService);
}
Also used : TranslationService(com.qcadoo.localization.api.TranslationService) ExpressionServiceImpl(com.qcadoo.model.internal.ExpressionServiceImpl) Before(org.junit.Before)

Example 12 with TranslationService

use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.

the class SelectComponentStateTest method init.

@Before
public void init() {
    MockitoAnnotations.initMocks(this);
    DictionaryType dictionaryType = new DictionaryType(DICTIONARY_NAME, dictionaryService, false);
    TranslationService translationService = mock(TranslationService.class);
    FieldDefinition fieldDefinition = mock(FieldDefinition.class);
    when(fieldDefinition.getType()).thenReturn(dictionaryType);
    when(fieldDefinition.isRequired()).thenReturn(true);
    when(fieldDefinition.getDefaultValue()).thenReturn("asd");
    ComponentDefinition definition = new ComponentDefinition();
    definition.setName("selectComponent");
    definition.setViewDefinition(mock(InternalViewDefinition.class));
    SelectComponentPattern pattern = new SelectComponentPattern(definition);
    setField(pattern, "fieldDefinition", fieldDefinition);
    setField(pattern, "translationService", translationService);
    componentState = new SelectComponentState(pattern, Lists.newArrayList());
    setField(componentState, "locale", Locale.ENGLISH);
    setField(pattern, "defaultRequired", true);
}
Also used : TranslationService(com.qcadoo.localization.api.TranslationService) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DictionaryType(com.qcadoo.model.internal.types.DictionaryType) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) Before(org.junit.Before)

Example 13 with TranslationService

use of com.qcadoo.localization.api.TranslationService 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)

Example 14 with TranslationService

use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.

the class ViewDefinitionParserImplTest method shouldHasRibbon.

@SuppressWarnings("unchecked")
@Test
public void shouldHasRibbon() throws Exception {
    // given
    InternalViewDefinition viewDefinition = parseAndGetViewDefinition();
    TranslationService translationService = mock(TranslationService.class);
    setField(viewDefinition, "translationService", translationService);
    given(applicationContext.getBean(SecurityRolesService.class)).willReturn(securityRolesService);
    given(securityRolesService.canAccess(Mockito.any(SecurityRole.class))).willReturn(true);
    JSONObject jsOptions = (JSONObject) ((Map<String, Map<String, Object>>) viewDefinition.prepareView(new JSONObject(), Locale.ENGLISH).get("components")).get("mainWindow").get("jsOptions");
    JSONObject ribbon = jsOptions.getJSONObject("ribbon");
    // then
    assertNotNull(ribbon);
    assertEquals(2, ribbon.getJSONArray("groups").length());
    assertEquals("first", ribbon.getJSONArray("groups").getJSONObject(0).getString("name"));
    assertEquals(2, ribbon.getJSONArray("groups").getJSONObject(0).getJSONArray("items").length());
    assertEquals("second", ribbon.getJSONArray("groups").getJSONObject(1).getString("name"));
    assertEquals(2, ribbon.getJSONArray("groups").getJSONObject(1).getJSONArray("items").length());
    JSONObject item11 = ribbon.getJSONArray("groups").getJSONObject(0).getJSONArray("items").getJSONObject(0);
    assertEquals("test", item11.getString("name"));
    assertFalse(item11.has("icon"));
    assertEquals(RibbonActionItem.Type.BIG_BUTTON.toString(), item11.getString("type"));
    // assertEquals("#{mainWindow.beanBForm}.save,#{mainWindow}.back", item11.getString("clickAction"));
    JSONObject item12 = ribbon.getJSONArray("groups").getJSONObject(0).getJSONArray("items").getJSONObject(1);
    assertEquals("test2", item12.getString("name"));
    assertEquals("icon2", item12.getString("icon"));
    assertEquals(RibbonActionItem.Type.SMALL_BUTTON.toString(), item12.getString("type"));
    assertEquals("xxx", item12.getString("clickAction"));
    JSONObject item21 = ribbon.getJSONArray("groups").getJSONObject(1).getJSONArray("items").getJSONObject(0);
    assertEquals("test2", item21.getString("name"));
    assertFalse(item21.has("icon"));
    assertEquals(RibbonActionItem.Type.BIG_BUTTON.toString(), item21.getString("type"));
    assertFalse(item21.has("clickAction"));
    JSONObject item22 = ribbon.getJSONArray("groups").getJSONObject(1).getJSONArray("items").getJSONObject(1);
    assertEquals("combo1", item22.getString("name"));
    assertFalse(item22.has("icon"));
    assertEquals(RibbonActionItem.Type.BIG_BUTTON.toString(), item22.getString("type"));
    assertEquals("yyy3", item22.getString("clickAction"));
    assertEquals(2, item22.getJSONArray("items").length());
    JSONObject item221 = item22.getJSONArray("items").getJSONObject(0);
    assertEquals("test1", item221.getString("name"));
    assertFalse(item221.has("icon"));
    assertEquals(RibbonActionItem.Type.BIG_BUTTON.toString(), item221.getString("type"));
    assertEquals("yyy1", item221.getString("clickAction"));
    JSONObject item222 = item22.getJSONArray("items").getJSONObject(1);
    assertEquals("test2", item222.getString("name"));
    assertEquals("icon2", item222.getString("icon"));
    assertEquals(RibbonActionItem.Type.BIG_BUTTON.toString(), item222.getString("type"));
    assertEquals("yyy2", item222.getString("clickAction"));
}
Also used : SecurityRole(com.qcadoo.security.api.SecurityRole) JSONObject(org.json.JSONObject) TranslationService(com.qcadoo.localization.api.TranslationService) JSONObject(org.json.JSONObject) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 15 with TranslationService

use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.

the class ComponentStateTest method shouldNotHaveRequestUpdateStateIfNotValid.

@Test
public void shouldNotHaveRequestUpdateStateIfNotValid() throws Exception {
    // given
    TranslationService translationService = mock(TranslationService.class);
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn(null);
    ApplicationContext applicationContext = mock(ApplicationContext.class);
    setField(pattern, "applicationContext", applicationContext);
    AbstractComponentState componentState = new FormComponentState(pattern);
    componentState.setTranslationService(translationService);
    componentState.initialize(new JSONObject(ImmutableMap.of("components", new JSONObject())), Locale.ENGLISH);
    componentState.addMessage("test", MessageType.FAILURE);
    // when
    JSONObject json = componentState.render();
    // then
    assertFalse(json.getBoolean(AbstractComponentState.JSON_UPDATE_STATE));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) JSONObject(org.json.JSONObject) TranslationService(com.qcadoo.localization.api.TranslationService) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) Test(org.junit.Test)

Aggregations

TranslationService (com.qcadoo.localization.api.TranslationService)16 JSONObject (org.json.JSONObject)7 Test (org.junit.Test)7 ApplicationContext (org.springframework.context.ApplicationContext)7 DataDefinition (com.qcadoo.model.api.DataDefinition)6 Before (org.junit.Before)6 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)5 Entity (com.qcadoo.model.api.Entity)4 FieldDefinition (com.qcadoo.model.api.FieldDefinition)4 ExpressionServiceImpl (com.qcadoo.model.internal.ExpressionServiceImpl)4 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)4 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)4 FormComponentState (com.qcadoo.view.internal.components.form.FormComponentState)4 SecurityRolesService (com.qcadoo.security.api.SecurityRolesService)3 HasManyType (com.qcadoo.model.api.types.HasManyType)2 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)2 StringType (com.qcadoo.model.internal.types.StringType)2 SecurityRole (com.qcadoo.security.api.SecurityRole)2 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)2 Map (java.util.Map)2