Package com.consol.citrus.functions.core
Class RandomEnumValueFunction
- java.lang.Object
-
- com.consol.citrus.functions.core.RandomEnumValueFunction
-
- All Implemented Interfaces:
com.consol.citrus.functions.Function
public class RandomEnumValueFunction extends Object implements com.consol.citrus.functions.Function
Function to choose one random value from a list of strings. The enumeration values to choose from can either be specified as parameters or in thevalues
property of an instance of this class. These two possibilities can only be used exclusively - either empty values property and non-empty parameters or empty parameters and non-empty values property.Example custom function definition and the corresponding usage in a test:
<bean id="myCustomFunctionLibrary" class="com.consol.citrus.functions.FunctionLibrary"> <property name="name" value="myCustomFunctionLibrary" /> <property name="prefix" value="custom:" /> <property name="members"> <map> <entry key="randomHttpStatusCode"> <bean class="com.consol.citrus.functions.core.RandomEnumValueFunction"> <property name="values"> <list> <value>200</value> <value>500</value> <value>401</value> </list> </property> </bean> </entry> </map> </property> </bean>
<variable name="httpStatusCode" value="custom:randomHttpStatusCode()" />
The other usage possibility is to choose a random value from a list of values given as argument like this which achieves the same result as the previously shown custom function:
<variable name="httpStatusCode" value="citrus:randomEnumValue('200', '401', '500')" />
- Author:
- Dimo Velev ([email protected])
-
-
Constructor Summary
Constructors Constructor Description RandomEnumValueFunction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
execute(List<String> params, com.consol.citrus.context.TestContext context)
List<String>
getValues()
protected String
randomValue(List<String> values)
Pseudo-randomly choose one of the supplied values and return it.void
setValues(List<String> values)
-
-
-
Method Detail
-
execute
public String execute(List<String> params, com.consol.citrus.context.TestContext context)
- Specified by:
execute
in interfacecom.consol.citrus.functions.Function
- See Also:
Function.execute(java.util.List, com.consol.citrus.context.TestContext)
-
randomValue
protected String randomValue(List<String> values)
Pseudo-randomly choose one of the supplied values and return it.- Parameters:
values
-- Returns:
- Throws:
IllegalArgumentException
- if the values supplied arenull
or an empty list.
-
-