@Test public void shouldntReplaceWhenReplaceCustomTranslationsIfCustomTranslationsArentNullAndNotFound() { String locale = "pl"; String replaceFrom = "replaceFrom"; String replaceTo = "replaceTo"; String translation = "translation"; given(view.getComponentByReference(LOCALE)).willReturn(localeField); given(view.getComponentByReference(L_REPLACE_FROM)).willReturn(replaceFromField); given(view.getComponentByReference(L_REPLACE_TO)).willReturn(replaceToField); given(localeField.getFieldValue()).willReturn(locale); given(replaceFromField.getFieldValue()).willReturn(replaceFrom); given(replaceToField.getFieldValue()).willReturn(replaceTo); customTranslations = mockEntityList(Arrays.asList(customTranslation)); given(customTranslationManagementService.getCustomTranslations(locale)).willReturn(customTranslations); given(customTranslation.getStringField(PROPERTIES_TRANSLATION)).willReturn(translation); given(customTranslation.getDataDefinition()).willReturn(customTranslationDD); replaceCustomTranslationsListeners.replaceCustomTranslations(view, state, null); verify(customTranslation, never()).setField(Mockito.anyString(), Mockito.any()); verify(customTranslationDD, never()).save(Mockito.any(Entity.class)); verify(replaceCustomTranslationsFrom).addMessage(Mockito.anyString(), Mockito.any(MessageType.class)); }
public void replaceCustomTranslations(final ViewDefinitionState view, final ComponentState state, final String[] args) { FormComponent replaceCustomTranslationsFrom = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM); FieldComponent localeField = (FieldComponent) view.getComponentByReference(LOCALE); FieldComponent replaceFromField = (FieldComponent) view.getComponentByReference(L_REPLACE_FROM); FieldComponent replaceToField = (FieldComponent) view.getComponentByReference(L_REPLACE_TO); String locale = (String) localeField.getFieldValue(); String replaceFrom = (String) replaceFromField.getFieldValue(); String replaceTo = (String) replaceToField.getFieldValue(); if (StringUtils.isEmpty(replaceFrom) || StringUtils.isEmpty(replaceTo)) { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsFailure", MessageType.FAILURE); } else { List<Entity> customTranslations = customTranslationManagementService.getCustomTranslations(locale); if (customTranslations.isEmpty()) { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsEmpty", MessageType.INFO); } else { int count = 0; for (Entity customTranslation : customTranslations) { String translation = customTranslation.getStringField(PROPERTIES_TRANSLATION); if (translation.contains(replaceFrom)) { count++; translation = translation.replace(replaceFrom, replaceTo); customTranslation.setField(CUSTOM_TRANSLATION, translation); customTranslation.getDataDefinition().save(customTranslation); } } if (count > 0) { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsSuccess", MessageType.SUCCESS); } else { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsInfo", MessageType.INFO); } } } }
ReplaceCustomTranslationsListeners { public void replaceCustomTranslations(final ViewDefinitionState view, final ComponentState state, final String[] args) { FormComponent replaceCustomTranslationsFrom = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM); FieldComponent localeField = (FieldComponent) view.getComponentByReference(LOCALE); FieldComponent replaceFromField = (FieldComponent) view.getComponentByReference(L_REPLACE_FROM); FieldComponent replaceToField = (FieldComponent) view.getComponentByReference(L_REPLACE_TO); String locale = (String) localeField.getFieldValue(); String replaceFrom = (String) replaceFromField.getFieldValue(); String replaceTo = (String) replaceToField.getFieldValue(); if (StringUtils.isEmpty(replaceFrom) || StringUtils.isEmpty(replaceTo)) { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsFailure", MessageType.FAILURE); } else { List<Entity> customTranslations = customTranslationManagementService.getCustomTranslations(locale); if (customTranslations.isEmpty()) { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsEmpty", MessageType.INFO); } else { int count = 0; for (Entity customTranslation : customTranslations) { String translation = customTranslation.getStringField(PROPERTIES_TRANSLATION); if (translation.contains(replaceFrom)) { count++; translation = translation.replace(replaceFrom, replaceTo); customTranslation.setField(CUSTOM_TRANSLATION, translation); customTranslation.getDataDefinition().save(customTranslation); } } if (count > 0) { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsSuccess", MessageType.SUCCESS); } else { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsInfo", MessageType.INFO); } } } } }
ReplaceCustomTranslationsListeners { public void replaceCustomTranslations(final ViewDefinitionState view, final ComponentState state, final String[] args) { FormComponent replaceCustomTranslationsFrom = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM); FieldComponent localeField = (FieldComponent) view.getComponentByReference(LOCALE); FieldComponent replaceFromField = (FieldComponent) view.getComponentByReference(L_REPLACE_FROM); FieldComponent replaceToField = (FieldComponent) view.getComponentByReference(L_REPLACE_TO); String locale = (String) localeField.getFieldValue(); String replaceFrom = (String) replaceFromField.getFieldValue(); String replaceTo = (String) replaceToField.getFieldValue(); if (StringUtils.isEmpty(replaceFrom) || StringUtils.isEmpty(replaceTo)) { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsFailure", MessageType.FAILURE); } else { List<Entity> customTranslations = customTranslationManagementService.getCustomTranslations(locale); if (customTranslations.isEmpty()) { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsEmpty", MessageType.INFO); } else { int count = 0; for (Entity customTranslation : customTranslations) { String translation = customTranslation.getStringField(PROPERTIES_TRANSLATION); if (translation.contains(replaceFrom)) { count++; translation = translation.replace(replaceFrom, replaceTo); customTranslation.setField(CUSTOM_TRANSLATION, translation); customTranslation.getDataDefinition().save(customTranslation); } } if (count > 0) { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsSuccess", MessageType.SUCCESS); } else { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsInfo", MessageType.INFO); } } } }  }
ReplaceCustomTranslationsListeners { public void replaceCustomTranslations(final ViewDefinitionState view, final ComponentState state, final String[] args) { FormComponent replaceCustomTranslationsFrom = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM); FieldComponent localeField = (FieldComponent) view.getComponentByReference(LOCALE); FieldComponent replaceFromField = (FieldComponent) view.getComponentByReference(L_REPLACE_FROM); FieldComponent replaceToField = (FieldComponent) view.getComponentByReference(L_REPLACE_TO); String locale = (String) localeField.getFieldValue(); String replaceFrom = (String) replaceFromField.getFieldValue(); String replaceTo = (String) replaceToField.getFieldValue(); if (StringUtils.isEmpty(replaceFrom) || StringUtils.isEmpty(replaceTo)) { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsFailure", MessageType.FAILURE); } else { List<Entity> customTranslations = customTranslationManagementService.getCustomTranslations(locale); if (customTranslations.isEmpty()) { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsEmpty", MessageType.INFO); } else { int count = 0; for (Entity customTranslation : customTranslations) { String translation = customTranslation.getStringField(PROPERTIES_TRANSLATION); if (translation.contains(replaceFrom)) { count++; translation = translation.replace(replaceFrom, replaceTo); customTranslation.setField(CUSTOM_TRANSLATION, translation); customTranslation.getDataDefinition().save(customTranslation); } } if (count > 0) { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsSuccess", MessageType.SUCCESS); } else { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsInfo", MessageType.INFO); } } } }  void replaceCustomTranslations(final ViewDefinitionState view, final ComponentState state, final String[] args); }
ReplaceCustomTranslationsListeners { public void replaceCustomTranslations(final ViewDefinitionState view, final ComponentState state, final String[] args) { FormComponent replaceCustomTranslationsFrom = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM); FieldComponent localeField = (FieldComponent) view.getComponentByReference(LOCALE); FieldComponent replaceFromField = (FieldComponent) view.getComponentByReference(L_REPLACE_FROM); FieldComponent replaceToField = (FieldComponent) view.getComponentByReference(L_REPLACE_TO); String locale = (String) localeField.getFieldValue(); String replaceFrom = (String) replaceFromField.getFieldValue(); String replaceTo = (String) replaceToField.getFieldValue(); if (StringUtils.isEmpty(replaceFrom) || StringUtils.isEmpty(replaceTo)) { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsFailure", MessageType.FAILURE); } else { List<Entity> customTranslations = customTranslationManagementService.getCustomTranslations(locale); if (customTranslations.isEmpty()) { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsEmpty", MessageType.INFO); } else { int count = 0; for (Entity customTranslation : customTranslations) { String translation = customTranslation.getStringField(PROPERTIES_TRANSLATION); if (translation.contains(replaceFrom)) { count++; translation = translation.replace(replaceFrom, replaceTo); customTranslation.setField(CUSTOM_TRANSLATION, translation); customTranslation.getDataDefinition().save(customTranslation); } } if (count > 0) { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsSuccess", MessageType.SUCCESS); } else { replaceCustomTranslationsFrom.addMessage( "qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsInfo", MessageType.INFO); } } } }  void replaceCustomTranslations(final ViewDefinitionState view, final ComponentState state, final String[] args);  }