@Test public void testSimpleTranslation( ) { String translationKey = PersistenceDescriptorValidationMessageTranslator.PREFIX + originalMessage.getId( ); when( translationService.getTranslation( translationKey ) ).thenReturn( TRANSLATED_MESSAGE ); ValidationMessage expectedTranslatedMessage = new ValidationMessage( ); expectedTranslatedMessage.setId( originalMessage.getId( ) ); expectedTranslatedMessage.setLevel( originalMessage.getLevel( ) ); expectedTranslatedMessage.setText( TRANSLATED_MESSAGE ); assertEquals( expectedTranslatedMessage, translator.translate( originalMessage ) ); }
@Override public ValidationMessage translate( ValidationMessage checkMessage ) { PersistenceDescriptorValidationMessage pdValidationMessage = ( PersistenceDescriptorValidationMessage ) checkMessage; ValidationMessage result = new ValidationMessage( ); result.setId( checkMessage.getId( ) ); result.setLevel( checkMessage.getLevel( ) ); String translationKey = createTranslationKey( pdValidationMessage.getId( ) ); if ( translationService.getTranslation( translationKey ) != null ) { if ( pdValidationMessage.getParams( ) != null && !pdValidationMessage.getParams( ).isEmpty( ) ) { pdValidationMessage.getParams().toArray( new String[ pdValidationMessage.getParams().size() ] ); result.setText( translationService.format( translationKey, pdValidationMessage.getParams().toArray() ) ); } else { result.setText( translationService.getTranslation( translationKey ) ); } } else { result.setText( checkMessage.getText( ) ); } return result; }
PersistenceDescriptorValidationMessageTranslator implements ValidationMessageTranslator { @Override public ValidationMessage translate( ValidationMessage checkMessage ) { PersistenceDescriptorValidationMessage pdValidationMessage = ( PersistenceDescriptorValidationMessage ) checkMessage; ValidationMessage result = new ValidationMessage( ); result.setId( checkMessage.getId( ) ); result.setLevel( checkMessage.getLevel( ) ); String translationKey = createTranslationKey( pdValidationMessage.getId( ) ); if ( translationService.getTranslation( translationKey ) != null ) { if ( pdValidationMessage.getParams( ) != null && !pdValidationMessage.getParams( ).isEmpty( ) ) { pdValidationMessage.getParams().toArray( new String[ pdValidationMessage.getParams().size() ] ); result.setText( translationService.format( translationKey, pdValidationMessage.getParams().toArray() ) ); } else { result.setText( translationService.getTranslation( translationKey ) ); } } else { result.setText( checkMessage.getText( ) ); } return result; } }
PersistenceDescriptorValidationMessageTranslator implements ValidationMessageTranslator { @Override public ValidationMessage translate( ValidationMessage checkMessage ) { PersistenceDescriptorValidationMessage pdValidationMessage = ( PersistenceDescriptorValidationMessage ) checkMessage; ValidationMessage result = new ValidationMessage( ); result.setId( checkMessage.getId( ) ); result.setLevel( checkMessage.getLevel( ) ); String translationKey = createTranslationKey( pdValidationMessage.getId( ) ); if ( translationService.getTranslation( translationKey ) != null ) { if ( pdValidationMessage.getParams( ) != null && !pdValidationMessage.getParams( ).isEmpty( ) ) { pdValidationMessage.getParams().toArray( new String[ pdValidationMessage.getParams().size() ] ); result.setText( translationService.format( translationKey, pdValidationMessage.getParams().toArray() ) ); } else { result.setText( translationService.getTranslation( translationKey ) ); } } else { result.setText( checkMessage.getText( ) ); } return result; } @Inject  PersistenceDescriptorValidationMessageTranslator( TranslationService translationService ); }
PersistenceDescriptorValidationMessageTranslator implements ValidationMessageTranslator { @Override public ValidationMessage translate( ValidationMessage checkMessage ) { PersistenceDescriptorValidationMessage pdValidationMessage = ( PersistenceDescriptorValidationMessage ) checkMessage; ValidationMessage result = new ValidationMessage( ); result.setId( checkMessage.getId( ) ); result.setLevel( checkMessage.getLevel( ) ); String translationKey = createTranslationKey( pdValidationMessage.getId( ) ); if ( translationService.getTranslation( translationKey ) != null ) { if ( pdValidationMessage.getParams( ) != null && !pdValidationMessage.getParams( ).isEmpty( ) ) { pdValidationMessage.getParams().toArray( new String[ pdValidationMessage.getParams().size() ] ); result.setText( translationService.format( translationKey, pdValidationMessage.getParams().toArray() ) ); } else { result.setText( translationService.getTranslation( translationKey ) ); } } else { result.setText( checkMessage.getText( ) ); } return result; } @Inject  PersistenceDescriptorValidationMessageTranslator( TranslationService translationService ); @Override boolean accept( ValidationMessage checkMessage ); @Override ValidationMessage translate( ValidationMessage checkMessage ); }
PersistenceDescriptorValidationMessageTranslator implements ValidationMessageTranslator { @Override public ValidationMessage translate( ValidationMessage checkMessage ) { PersistenceDescriptorValidationMessage pdValidationMessage = ( PersistenceDescriptorValidationMessage ) checkMessage; ValidationMessage result = new ValidationMessage( ); result.setId( checkMessage.getId( ) ); result.setLevel( checkMessage.getLevel( ) ); String translationKey = createTranslationKey( pdValidationMessage.getId( ) ); if ( translationService.getTranslation( translationKey ) != null ) { if ( pdValidationMessage.getParams( ) != null && !pdValidationMessage.getParams( ).isEmpty( ) ) { pdValidationMessage.getParams().toArray( new String[ pdValidationMessage.getParams().size() ] ); result.setText( translationService.format( translationKey, pdValidationMessage.getParams().toArray() ) ); } else { result.setText( translationService.getTranslation( translationKey ) ); } } else { result.setText( checkMessage.getText( ) ); } return result; } @Inject  PersistenceDescriptorValidationMessageTranslator( TranslationService translationService ); @Override boolean accept( ValidationMessage checkMessage ); @Override ValidationMessage translate( ValidationMessage checkMessage ); static final String PREFIX; }