Class MapValueFunction

java.lang.Object
org.citrusframework.functions.core.MapValueFunction
All Implemented Interfaces:
org.citrusframework.common.InitializingPhase, org.citrusframework.functions.Function, org.citrusframework.functions.ParameterizedFunction<StringParameter>, StringFunction

public class MapValueFunction extends Object implements StringFunction, org.citrusframework.common.InitializingPhase
Function to map the function's argument to a corresponding value configured using a map.

Example of the function definition and its usage:

 <bean id="myCustomFunctionLibrary" class="org.citrusframework.functions.FunctionLibrary">
  <property name="name" value="myCustomFunctionLibrary" />
  <property name="prefix" value="custom:" />
  <property name="members">
    <map>
      <entry key="mapHttpStatusCodeToMessage">
        <bean class="org.citrusframework.functions.core.MapValueFunction">
          <property name="values">
            <map>
              <entry key="200" value="OK" />
              <entry key="401" value="Unauthorized" />
              <entry key="500" value="Internal Server Error" />
            </map>
          </property>
        </bean>
      </entry>
    </map>
  </property>
 </bean>
 
and the corresponding usage in a test which maps the HTTP status code 500 to its message 'Internal Server Error':
 <variable name="httpStatusCodeMessage" value="custom:mapHttpStatusCodeToMessage('500')" />
 
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.citrusframework.functions.ParameterizedFunction

    org.citrusframework.functions.ParameterizedFunction.FunctionParameters
  • Field Summary

    Fields inherited from interface org.citrusframework.functions.Function

    functions, logger, RESOURCE_PATH
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    execute(String key, org.citrusframework.context.TestContext context)
    Execute function with the single String parameter.
    Gets the mappings for this function.
    void
     
    void
    Sets the mappings for this function.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.citrusframework.functions.ParameterizedFunction

    execute

    Methods inherited from interface org.citrusframework.functions.StringFunction

    execute, getParameters
  • Constructor Details

    • MapValueFunction

      public MapValueFunction()
  • Method Details

    • execute

      public String execute(String key, org.citrusframework.context.TestContext context)
      Description copied from interface: StringFunction
      Execute function with the single String parameter.
      Specified by:
      execute in interface StringFunction
    • initialize

      public void initialize()
      Specified by:
      initialize in interface org.citrusframework.common.InitializingPhase
    • getMap

      public Map<String,String> getMap()
      Gets the mappings for this function.
    • setMap

      public void setMap(Map<String,String> map)
      Sets the mappings for this function.