use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.
the class FormComponentStateTest method shouldRenderFormEntityId.
@Test
public void shouldRenderFormEntityId() throws Exception {
// given
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");
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
assertEquals(13L, json.getJSONObject(AbstractComponentState.JSON_CONTENT).getLong(FormComponentState.JSON_ENTITY_ID));
}
use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.
the class ViewDefinitionParserImplTest method init.
@Before
public void init() throws Exception {
applicationContext = mock(ApplicationContext.class);
dataDefinitionService = mock(DataDefinitionService.class);
translationService = mock(TranslationService.class);
RibbonParserService ribbonService = new RibbonParserService();
contextualHelpService = mock(ContextualHelpService.class);
securityRolesService = mock(SecurityRolesService.class);
viewDefinitionService = new ViewDefinitionServiceImpl();
hookFactory = new HookFactory();
setField(hookFactory, "applicationContext", applicationContext);
viewDefinitionParser = new ViewDefinitionParserImpl();
setField(viewDefinitionParser, "dataDefinitionService", dataDefinitionService);
setField(viewDefinitionParser, "viewDefinitionService", viewDefinitionService);
setField(viewDefinitionParser, "hookFactory", hookFactory);
setField(viewDefinitionParser, "translationService", translationService);
setField(viewDefinitionParser, "applicationContext", applicationContext);
setField(viewDefinitionParser, "contextualHelpService", contextualHelpService);
setField(viewDefinitionParser, "viewComponentsResolver", viewComponentsResolver);
setField(viewDefinitionParser, "ribbonService", ribbonService);
setField(viewDefinitionParser, "securityRolesService", securityRolesService);
userRoleMock = mock(SecurityRole.class);
given(securityRolesService.getRoleByIdentifier("ROLE_USER")).willReturn(userRoleMock);
adminRoleMock = mock(SecurityRole.class);
given(securityRolesService.getRoleByIdentifier("ROLE_ADMIN")).willReturn(adminRoleMock);
xml1 = "view/test1.xml";
xml2 = "view/test2.xml";
given(applicationContext.getBean(CustomViewService.class)).willReturn(new CustomViewService());
dataDefinitionA = mock(DataDefinition.class);
dataDefinitionB = mock(DataDefinition.class);
FieldDefinition nameA = mock(FieldDefinition.class, "nameA");
FieldDefinition nameB = mock(FieldDefinition.class, "nameB");
FieldDefinition hasManyB = mock(FieldDefinition.class, "hasManyB");
FieldDefinition belongToA = mock(FieldDefinition.class, "belongsToA");
HasManyType hasManyBType = mock(HasManyType.class);
BelongsToType belongToAType = mock(BelongsToType.class);
given(nameA.getDataDefinition()).willReturn(dataDefinitionA);
given(nameA.getType()).willReturn(new StringType());
given(nameB.getType()).willReturn(new StringType());
given(nameB.getDataDefinition()).willReturn(dataDefinitionA);
given(hasManyB.getType()).willReturn(hasManyBType);
given(hasManyB.getDataDefinition()).willReturn(dataDefinitionB);
given(belongToA.getType()).willReturn(belongToAType);
given(belongToA.getDataDefinition()).willReturn(dataDefinitionB);
given(hasManyBType.getDataDefinition()).willReturn(dataDefinitionB);
given(belongToAType.getDataDefinition()).willReturn(dataDefinitionA);
given(dataDefinitionA.getField("beansB")).willReturn(hasManyB);
given(dataDefinitionA.getField("name")).willReturn(nameA);
given(dataDefinitionB.getField("activeA")).willReturn(nameA);
given(dataDefinitionB.getField("activeB")).willReturn(nameA);
given(dataDefinitionB.getField("activeC")).willReturn(nameA);
given(dataDefinitionB.getField("beanA")).willReturn(belongToA);
given(dataDefinitionB.getField("beanM")).willReturn(belongToA);
given(dataDefinitionB.getField("beanB")).willReturn(belongToA);
given(dataDefinitionB.getField("name")).willReturn(nameB);
given(dataDefinitionA.getName()).willReturn("beanA");
given(dataDefinitionB.getName()).willReturn("beanB");
given(dataDefinitionA.getFields()).willReturn(ImmutableMap.of("name", nameA, "beansB", hasManyB));
given(dataDefinitionB.getFields()).willReturn(ImmutableMap.of("name", nameB, "beanA", belongToA));
given(dataDefinitionService.get("sample", "beanA")).willReturn(dataDefinitionA);
given(dataDefinitionService.get("sample", "beanB")).willReturn(dataDefinitionB);
}
use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.
the class FieldTypeFactoryTest method shouldReturnEnumType.
@Test
public void shouldReturnEnumType() throws Exception {
// given
TranslationService translationService = mock(TranslationService.class);
given(translationService.translate("path.value.val1", Locale.ENGLISH)).willReturn("i18nVal1");
given(translationService.translate("path.value.val2", Locale.ENGLISH)).willReturn("i18nVal2");
given(translationService.translate("path.value.val3", Locale.ENGLISH)).willReturn("i18nVal3");
// when
EnumeratedType fieldType = new EnumType(translationService, "path", true, "val1", "val2", "val3");
// then
assertEquals(fieldType.activeValues(Locale.ENGLISH).keySet(), Sets.newHashSet("val1", "val2", "val3"));
assertEquals(Lists.newArrayList(fieldType.activeValues(Locale.ENGLISH).values()), Lists.newArrayList("i18nVal1", "i18nVal2", "i18nVal3"));
assertEquals(String.class, fieldType.getType());
ValueAndError valueAndError1 = fieldType.toObject(fieldDefinition, "val1");
ValueAndError valueAndError2 = fieldType.toObject(fieldDefinition, "val4");
assertTrue(valueAndError1.isValid());
assertFalse(valueAndError2.isValid());
assertNotNull(valueAndError1.getValue());
assertNull(valueAndError2.getValue());
assertEquals("qcadooView.validate.field.error.invalidDictionaryItem", valueAndError2.getMessage());
assertEquals("[val1, val2, val3]", valueAndError2.getArgs()[0]);
}
use of com.qcadoo.localization.api.TranslationService in project mes by qcadoo.
the class AdvancedGenealogyPdfService method createDocumentPanelTable.
private PdfPTable createDocumentPanelTable(final Entity entity, final Locale locale) {
final PdfPTable panel = pdfHelper.createPanelTable(2);
final Entity batch = entity.getBelongsToField(GenealogyReportFields.BATCH);
final TranslationService translation = translationService;
String batchNumber = translation.translate(L_ADVANCED_GENEALOGY_BATCH_REPORT_BATCH_NUMBER_MESSAGE, locale) + AdvancedGenealogyConstants.L_SPACER + batch.getField(BatchFields.NUMBER);
final StringBuilder type = new StringBuilder(translation.translate("advancedGenealogy.batch.report.type", locale)).append(AdvancedGenealogyConstants.L_SPACER);
if (AdvancedGenealogyConstants.L_USED_TO_PRODUCE.equals(entity.getField(GenealogyReportFields.TYPE))) {
type.append(translation.translate("advancedGenealogy.genealogyReport.type.value.01usedToProduce", locale));
} else if (AdvancedGenealogyConstants.L_PRODUCED_FROM.equals(entity.getField(GenealogyReportFields.TYPE))) {
type.append(translation.translate("advancedGenealogy.genealogyReport.type.value.02producedFrom", locale));
} else {
throw new IllegalStateException("Type of genealogy table should be specified");
}
final StringBuilder includeDraft = new StringBuilder(translation.translate("advancedGenealogy.batch.report.includeDraft", locale)).append(AdvancedGenealogyConstants.L_SPACER);
if (entity.getBooleanField(GenealogyReportFields.INCLUDE_DRAFT)) {
includeDraft.append(translation.translate("qcadooView.true", locale));
} else {
includeDraft.append(translation.translate("qcadooView.false", locale));
}
final StringBuilder directRelatedOnly = new StringBuilder(translation.translate("advancedGenealogy.batch.report.directRelatedOnly", locale)).append(AdvancedGenealogyConstants.L_SPACER);
if (entity.getBooleanField(GenealogyReportFields.DIRECT_RELATED_ONLY)) {
directRelatedOnly.append(translation.translate("qcadooView.true", locale));
} else {
directRelatedOnly.append(translation.translate("qcadooView.false", locale));
}
panel.addCell(new Phrase(batchNumber, FontUtils.getDejavuBold9Dark()));
panel.addCell(new Phrase(type.toString(), FontUtils.getDejavuBold9Dark()));
panel.addCell(new Phrase(includeDraft.toString(), FontUtils.getDejavuBold9Dark()));
panel.addCell(new Phrase(directRelatedOnly.toString(), FontUtils.getDejavuBold9Dark()));
return panel;
}
use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.
the class ModelXmlToDefinitionConverterTest method init.
@BeforeClass
public static void init() throws Exception {
applicationContext = mock(ApplicationContext.class);
dataAccessService = mock(DataAccessService.class);
translationService = mock(TranslationService.class);
dataDefinitionService = new DataDefinitionServiceImpl();
modelXmlToDefinitionConverter = new ModelXmlToDefinitionConverterImpl();
setField(modelXmlToDefinitionConverter, "dataDefinitionService", dataDefinitionService);
setField(modelXmlToDefinitionConverter, "dataAccessService", dataAccessService);
setField(modelXmlToDefinitionConverter, "applicationContext", applicationContext);
setField(modelXmlToDefinitionConverter, "translationService", translationService);
given(applicationContext.getBean(CustomHook.class)).willReturn(new CustomHook());
modelXmlToClassConverter = new ModelXmlToClassConverterImpl();
((ModelXmlToClassConverterImpl) modelXmlToClassConverter).setBeanClassLoader(ClassLoader.getSystemClassLoader());
dataDefinitions = performConvert(Utils.FULL_FIRST_ENTITY_XML_RESOURCE, Utils.FULL_SECOND_ENTITY_XML_RESOURCE, Utils.FULL_THIRD_ENTITY_XML_RESOURCE, Utils.OTHER_FIRST_ENTITY_XML_RESOURCE, Utils.OTHER_SECOND_ENTITY_XML_RESOURCE);
for (DataDefinition dd : dataDefinitions.toArray(new DataDefinition[dataDefinitions.size()])) {
if (dd.getName().equals("firstEntity") && dd.getPluginIdentifier().equals("full")) {
dataDefinition = (InternalDataDefinition) dd;
}
}
}
Aggregations