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);
}
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);
}
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();
}
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"));
}
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));
}
Aggregations