public static String resolveFunction ( String functionString , TestContext context ) { String functionExpression = VariableUtils . cutOffVariablesPrefix ( functionString ) ; if ( ! functionExpression . contains ( "(" ) || ! functionExpression . endsWith ( ")" ) || ! functionExpression . contains ( ":" ) ) { throw new InvalidFunctionUsageException ( "Unable to resolve function: " + functionExpression ) ; } String functionPrefix = functionExpression . substring ( 0 , functionExpression . indexOf ( ' ' ) + 1 ) ; String parameterString = functionExpression . substring ( functionExpression . indexOf ( ' ' ) + 1 , functionExpression . length ( ) - 1 ) ; String function = functionExpression . substring ( functionPrefix . length ( ) , functionExpression . indexOf ( ' ' ) ) ; FunctionLibrary library = context . getFunctionRegistry ( ) . getLibraryForPrefix ( functionPrefix ) ; parameterString = VariableUtils . replaceVariablesInString ( parameterString , context , false ) ; parameterString = replaceFunctionsInString ( parameterString , context ) ; String value = library . getFunction ( function ) . execute ( FunctionParameterHelper . getParameterList ( parameterString ) , context ) ; if ( value == null ) { return "" ; } else { return value ; } }
This method resolves a custom function to its respective result .