Class RandomEnumValueFunction
java.lang.Object
org.citrusframework.functions.core.RandomEnumValueFunction
- All Implemented Interfaces:
org.citrusframework.functions.Function,org.citrusframework.functions.ParameterizedFunction<StringParameters>
public class RandomEnumValueFunction
extends Object
implements org.citrusframework.functions.ParameterizedFunction<StringParameters>
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 the
values 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="org.citrusframework.functions.FunctionLibrary">
<property name="name" value="myCustomFunctionLibrary" />
<property name="prefix" value="custom:" />
<property name="members">
<map>
<entry key="randomHttpStatusCode">
<bean class="org.citrusframework.functions.core.RandomEnumValueFunction">
<property name="values">
<list>
<value>200</value>
<value>500</value>
<value>401</value>
</list>
</property>
</bean>
</entry>
</map>
</property>
</bean>
and the corresponding usage which sets the httpStatusCode to one of the configured values - 200, 500 or 401:
<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')" />
You should choose which one of the two flavours to use based on the number of times you use this function - if you need it in
only one special case you may go with specifying the list as arguments otherwise you should define a custom function and reuse it.-
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 -
Method Summary
Modifier and TypeMethodDescriptionexecute(StringParameters params, org.citrusframework.context.TestContext context) protected StringrandomValue(List<String> values) Pseudo-randomly choose one of the supplied values and return it.voidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.citrusframework.functions.ParameterizedFunction
execute
-
Constructor Details
-
RandomEnumValueFunction
public RandomEnumValueFunction()
-
-
Method Details
-
execute
- Specified by:
executein interfaceorg.citrusframework.functions.ParameterizedFunction<StringParameters>
-
getParameters
- Specified by:
getParametersin interfaceorg.citrusframework.functions.ParameterizedFunction<StringParameters>
-
randomValue
Pseudo-randomly choose one of the supplied values and return it.- Throws:
IllegalArgumentException- if the values supplied arenullor an empty list.
-
getValues
-
setValues
-