@Test public void testNoResourceFound() throws EvaluationException { when( parameters.getValue( eq( 0 ) ) ).thenReturn( "not found" ); ResourceLookupFunction function = new ResourceLookupFunction(); TypeValuePair result = function.evaluate( context, parameters ); String actual = String.valueOf( result.getValue() ); assertEquals( "key", actual ); }
@Override public TypeValuePair evaluate( FormulaContext context, ParameterCallback parameters ) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if ( parameterCount < 2 ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE ); } Type textType = parameters.getType( 0 ); Object textValue = parameters.getValue( 0 ); final String bundleId = context.getTypeRegistry().convertToText( textType, textValue ); if ( bundleId == null || bundleId.isEmpty() ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE ); } textType = parameters.getType( 1 ); textValue = parameters.getValue( 1 ); String key = context.getTypeRegistry().convertToText( textType, textValue ); if ( key == null || key.isEmpty() ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE ); } if ( context instanceof ReportFormulaContext ) { ReportFormulaContext fc = ReportFormulaContext.class.cast( context ); try { ResourceBundleFactory factory = fc.getProcessingContext().getResourceBundleFactory(); ResourceBundle bundle = factory.getResourceBundle( bundleId ); if ( bundle != null && bundle.containsKey( key ) ) { key = bundle.getString( key ); } } catch ( MissingResourceException | ClassCastException e ) { } } return new TypeValuePair( TextType.TYPE, key ); }
ResourceLookupFunction implements Function { @Override public TypeValuePair evaluate( FormulaContext context, ParameterCallback parameters ) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if ( parameterCount < 2 ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE ); } Type textType = parameters.getType( 0 ); Object textValue = parameters.getValue( 0 ); final String bundleId = context.getTypeRegistry().convertToText( textType, textValue ); if ( bundleId == null || bundleId.isEmpty() ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE ); } textType = parameters.getType( 1 ); textValue = parameters.getValue( 1 ); String key = context.getTypeRegistry().convertToText( textType, textValue ); if ( key == null || key.isEmpty() ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE ); } if ( context instanceof ReportFormulaContext ) { ReportFormulaContext fc = ReportFormulaContext.class.cast( context ); try { ResourceBundleFactory factory = fc.getProcessingContext().getResourceBundleFactory(); ResourceBundle bundle = factory.getResourceBundle( bundleId ); if ( bundle != null && bundle.containsKey( key ) ) { key = bundle.getString( key ); } } catch ( MissingResourceException | ClassCastException e ) { } } return new TypeValuePair( TextType.TYPE, key ); } }
ResourceLookupFunction implements Function { @Override public TypeValuePair evaluate( FormulaContext context, ParameterCallback parameters ) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if ( parameterCount < 2 ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE ); } Type textType = parameters.getType( 0 ); Object textValue = parameters.getValue( 0 ); final String bundleId = context.getTypeRegistry().convertToText( textType, textValue ); if ( bundleId == null || bundleId.isEmpty() ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE ); } textType = parameters.getType( 1 ); textValue = parameters.getValue( 1 ); String key = context.getTypeRegistry().convertToText( textType, textValue ); if ( key == null || key.isEmpty() ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE ); } if ( context instanceof ReportFormulaContext ) { ReportFormulaContext fc = ReportFormulaContext.class.cast( context ); try { ResourceBundleFactory factory = fc.getProcessingContext().getResourceBundleFactory(); ResourceBundle bundle = factory.getResourceBundle( bundleId ); if ( bundle != null && bundle.containsKey( key ) ) { key = bundle.getString( key ); } } catch ( MissingResourceException | ClassCastException e ) { } } return new TypeValuePair( TextType.TYPE, key ); }  }
ResourceLookupFunction implements Function { @Override public TypeValuePair evaluate( FormulaContext context, ParameterCallback parameters ) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if ( parameterCount < 2 ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE ); } Type textType = parameters.getType( 0 ); Object textValue = parameters.getValue( 0 ); final String bundleId = context.getTypeRegistry().convertToText( textType, textValue ); if ( bundleId == null || bundleId.isEmpty() ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE ); } textType = parameters.getType( 1 ); textValue = parameters.getValue( 1 ); String key = context.getTypeRegistry().convertToText( textType, textValue ); if ( key == null || key.isEmpty() ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE ); } if ( context instanceof ReportFormulaContext ) { ReportFormulaContext fc = ReportFormulaContext.class.cast( context ); try { ResourceBundleFactory factory = fc.getProcessingContext().getResourceBundleFactory(); ResourceBundle bundle = factory.getResourceBundle( bundleId ); if ( bundle != null && bundle.containsKey( key ) ) { key = bundle.getString( key ); } } catch ( MissingResourceException | ClassCastException e ) { } } return new TypeValuePair( TextType.TYPE, key ); }  @Override String getCanonicalName(); @Override TypeValuePair evaluate( FormulaContext context, ParameterCallback parameters ); }
ResourceLookupFunction implements Function { @Override public TypeValuePair evaluate( FormulaContext context, ParameterCallback parameters ) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if ( parameterCount < 2 ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE ); } Type textType = parameters.getType( 0 ); Object textValue = parameters.getValue( 0 ); final String bundleId = context.getTypeRegistry().convertToText( textType, textValue ); if ( bundleId == null || bundleId.isEmpty() ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE ); } textType = parameters.getType( 1 ); textValue = parameters.getValue( 1 ); String key = context.getTypeRegistry().convertToText( textType, textValue ); if ( key == null || key.isEmpty() ) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE ); } if ( context instanceof ReportFormulaContext ) { ReportFormulaContext fc = ReportFormulaContext.class.cast( context ); try { ResourceBundleFactory factory = fc.getProcessingContext().getResourceBundleFactory(); ResourceBundle bundle = factory.getResourceBundle( bundleId ); if ( bundle != null && bundle.containsKey( key ) ) { key = bundle.getString( key ); } } catch ( MissingResourceException | ClassCastException e ) { } } return new TypeValuePair( TextType.TYPE, key ); }  @Override String getCanonicalName(); @Override TypeValuePair evaluate( FormulaContext context, ParameterCallback parameters ); static final String NAME; }