use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.
the class ComponentStateTest method shouldHaveRequestUpdateStateFlag.
@Test
public void shouldHaveRequestUpdateStateFlag() throws Exception {
// given
new ExpressionServiceImpl().init();
TranslationService translationService = mock(TranslationService.class);
DataDefinition dataDefinition = mock(DataDefinition.class);
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn("2");
ApplicationContext applicationContext = mock(ApplicationContext.class);
setField(pattern, "applicationContext", applicationContext);
AbstractComponentState componentState = new FormComponentState(pattern);
componentState.setTranslationService(translationService);
componentState.setDataDefinition(dataDefinition);
componentState.setFieldValue(13L);
componentState.initialize(new JSONObject(ImmutableMap.of("components", new JSONObject())), Locale.ENGLISH);
// when
JSONObject json = componentState.render();
// then
assertTrue(json.getBoolean(AbstractComponentState.JSON_UPDATE_STATE));
}
use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.
the class AbstractPatternTest method getComponentDefinition.
public ComponentDefinition getComponentDefinition(final String name, final String fieldPath, final String sourceFieldPath, final ContainerPattern parent, final ViewDefinition viewDefinition) {
ComponentDefinition componentDefinition = new ComponentDefinition();
componentDefinition.setName(name);
componentDefinition.setFieldPath(fieldPath);
componentDefinition.setSourceFieldPath(sourceFieldPath);
componentDefinition.setParent(parent);
TranslationService translationService = mock(TranslationService.class);
componentDefinition.setTranslationService(translationService);
ContextualHelpService contextualHelpService = mock(ContextualHelpService.class);
componentDefinition.setContextualHelpService(contextualHelpService);
if (viewDefinition != null) {
componentDefinition.setViewDefinition(viewDefinition);
} else {
componentDefinition.setViewDefinition(mock(InternalViewDefinition.class));
}
return componentDefinition;
}
use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.
the class ComponentPatternTest method shouldHaveListenersOnEmptyOptions.
@Test
public void shouldHaveListenersOnEmptyOptions() throws Exception {
// given
TranslationService translationService = mock(TranslationService.class);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
ComponentDefinition componentDefinition = getComponentDefinition("testName", null);
componentDefinition.setTranslationService(translationService);
componentDefinition.setViewDefinition(viewDefinition);
AbstractComponentPattern pattern = new TextInputComponentPattern(componentDefinition);
// when
Map<String, Object> model = pattern.prepareView(Locale.ENGLISH);
// then
JSONObject options = (JSONObject) model.get("jsOptions");
assertEquals(7, options.length());
}
use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.
the class TranslationUtilsServiceTest method init.
@Before
public final void init() {
translationService = mock(TranslationService.class);
item = mock(Entity.class);
category = mock(Entity.class);
locale = Locale.getDefault();
when(item.getStringField("pluginIdentifier")).thenReturn(PLUGIN_IDENTIFIER);
when(category.getStringField("pluginIdentifier")).thenReturn(PLUGIN_IDENTIFIER);
when(item.getStringField("name")).thenReturn(ITEM_NAME);
when(category.getStringField("name")).thenReturn(CATEGORY_NAME);
when(item.getBelongsToField("category")).thenReturn(category);
translationUtilsService = new TranslationUtilsService();
ReflectionTestUtils.setField(translationUtilsService, "translationService", translationService);
}
use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.
the class FormComponentStateTest method init.
@Before
public void init() throws Exception {
entity = mock(Entity.class);
given(entity.getField("name")).willReturn("text");
viewDefinitionState = mock(ViewDefinitionState.class);
translationService = mock(TranslationService.class);
fieldDefinition = mock(FieldDefinition.class);
given(fieldDefinition.getType()).willReturn(new StringType());
given(fieldDefinition.getName()).willReturn("name");
dataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
given(dataDefinition.get(12L)).willReturn(null);
given(dataDefinition.get(13L)).willReturn(entity);
given(dataDefinition.getPluginIdentifier()).willReturn("plugin");
given(dataDefinition.getName()).willReturn("name");
given(dataDefinition.getField("name")).willReturn(fieldDefinition);
given(dataDefinition.delete(any(Long.class))).willReturn(EntityOpResult.successfull());
given(dataDefinition.create(anyLong())).willAnswer(new Answer<Entity>() {
@Override
public Entity answer(final InvocationOnMock invocation) throws Throwable {
Long id = (Long) invocation.getArguments()[0];
return new DefaultEntity(dataDefinition, id);
}
});
FieldComponentPattern namePattern = mock(FieldComponentPattern.class);
given(namePattern.isRequired()).willReturn(false);
given(namePattern.isPersistent()).willReturn(true);
name = new FieldComponentState(namePattern);
name.setTranslationService(translationService);
name.setName("name");
name.initialize(new JSONObject(), Locale.ENGLISH);
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn("'static expression'");
applicationContext = mock(ApplicationContext.class);
setField(pattern, "applicationContext", applicationContext);
SecurityRolesService securityRolesService = mock(SecurityRolesService.class);
given(applicationContext.getBean(SecurityRolesService.class)).willReturn(securityRolesService);
form = new FormComponentState(pattern);
form.setDataDefinition(dataDefinition);
form.setTranslationService(translationService);
form.addFieldEntityIdChangeListener("name", name);
form.initialize(new JSONObject(ImmutableMap.of("components", new JSONObject())), Locale.ENGLISH);
new ExpressionServiceImpl().init();
}
Aggregations