How to use RandomEnumValueFunction class of com.consol.citrus.functions.core package

Best Citrus code snippet using com.consol.citrus.functions.core.RandomEnumValueFunction

Source:DefaultFunctionLibrary.java Github

copy

Full Screen

...13import com.consol.citrus.functions.core.LocalHostAddressFunction;14import com.consol.citrus.functions.core.LowerCaseFunction;15import com.consol.citrus.functions.core.MaxFunction;16import com.consol.citrus.functions.core.MinFunction;17import com.consol.citrus.functions.core.RandomEnumValueFunction;18import com.consol.citrus.functions.core.RandomNumberFunction;19import com.consol.citrus.functions.core.RandomStringFunction;20import com.consol.citrus.functions.core.RandomUUIDFunction;21import com.consol.citrus.functions.core.ReadFileResourceFunction;22import com.consol.citrus.functions.core.RoundFunction;23import com.consol.citrus.functions.core.StringLengthFunction;24import com.consol.citrus.functions.core.SubstringAfterFunction;25import com.consol.citrus.functions.core.SubstringBeforeFunction;26import com.consol.citrus.functions.core.SubstringFunction;27import com.consol.citrus.functions.core.SumFunction;28import com.consol.citrus.functions.core.SystemPropertyFunction;29import com.consol.citrus.functions.core.TranslateFunction;30import com.consol.citrus.functions.core.UpperCaseFunction;31import com.consol.citrus.functions.core.UrlDecodeFunction;32import com.consol.citrus.functions.core.UrlEncodeFunction;33import com.consol.citrus.functions.core.UnixTimestampFunction;34import org.slf4j.Logger;35import org.slf4j.LoggerFactory;36/**37 * @author Christoph Deppisch38 */39public class DefaultFunctionLibrary extends FunctionLibrary {40 /** Logger */41 private static final Logger LOG = LoggerFactory.getLogger(DefaultFunctionLibrary.class);42 /**43 * Default constructor adding default function implementations.44 */45 public DefaultFunctionLibrary() {46 setName("citrusFunctionLibrary");47 getMembers().put("randomNumber", new RandomNumberFunction());48 getMembers().put("randomString", new RandomStringFunction());49 getMembers().put("concat", new ConcatFunction());50 getMembers().put("currentDate", new CurrentDateFunction());51 getMembers().put("substring", new SubstringFunction());52 getMembers().put("stringLength", new StringLengthFunction());53 getMembers().put("translate", new TranslateFunction());54 getMembers().put("substringBefore", new SubstringBeforeFunction());55 getMembers().put("substringAfter", new SubstringAfterFunction());56 getMembers().put("round", new RoundFunction());57 getMembers().put("floor", new FloorFunction());58 getMembers().put("ceiling", new CeilingFunction());59 getMembers().put("upperCase", new UpperCaseFunction());60 getMembers().put("lowerCase", new LowerCaseFunction());61 getMembers().put("average", new AvgFunction());62 getMembers().put("minimum", new MinFunction());63 getMembers().put("maximum", new MaxFunction());64 getMembers().put("sum", new SumFunction());65 getMembers().put("absolute", new AbsoluteFunction());66 getMembers().put("randomEnumValue", new RandomEnumValueFunction());67 getMembers().put("randomUUID", new RandomUUIDFunction());68 getMembers().put("encodeBase64", new EncodeBase64Function());69 getMembers().put("decodeBase64", new DecodeBase64Function());70 getMembers().put("urlEncode", new UrlEncodeFunction());71 getMembers().put("urlDecode", new UrlDecodeFunction());72 getMembers().put("digestAuthHeader", new DigestAuthHeaderFunction());73 getMembers().put("localHostAddress", new LocalHostAddressFunction());74 getMembers().put("changeDate", new ChangeDateFunction());75 getMembers().put("readFile", new ReadFileResourceFunction());76 getMembers().put("message", new LoadMessageFunction());77 getMembers().put("systemProperty", new SystemPropertyFunction());78 getMembers().put("unixTimestamp", new UnixTimestampFunction());79 lookupFunctions();80 }...

Full Screen

Full Screen

Source:RandomEnumValueFunction.java Github

copy

Full Screen

...20import java.util.List;21import java.util.Random;22/**23 * Function to choose one random value from a list of strings. The enumeration values to choose from24 * can either be specified as parameters or in the {@link RandomEnumValueFunction#values} property of 25 * an instance of this class. These two possibilities can only be used exclusively - either empty values26 * property and non-empty parameters or empty parameters and non-empty values property.27 * <p>Example custom function definition and the corresponding usage in a test:</p>28 * 29 * <code>30 * <pre>31 * &lt;bean id="myCustomFunctionLibrary" class="com.consol.citrus.functions.FunctionLibrary"&gt;32 * &lt;property name="name" value="myCustomFunctionLibrary" /&gt;33 * &lt;property name="prefix" value="custom:" /&gt;34 * &lt;property name="members"&gt;35 * &lt;map&gt;36 * &lt;entry key="randomHttpStatusCode"&gt;37 * &lt;bean class="com.consol.citrus.functions.core.RandomEnumValueFunction"&gt;38 * &lt;property name="values"&gt;39 * &lt;list&gt;40 * &lt;value&gt;200&lt;/value&gt;41 * &lt;value&gt;500&lt;/value&gt;42 * &lt;value&gt;401&lt;/value&gt;43 * &lt;/list&gt;44 * &lt;/property&gt;45 * &lt;/bean&gt;46 * &lt;/entry&gt;47 * &lt;/map&gt;48 * &lt;/property&gt;49 * &lt;/bean&gt;50 * </pre>51 * </code>52 * and the corresponding usage which sets the httpStatusCode to one of the configured values - 200, 500 or 401:53 * <code>54 * <pre>55 * &lt;variable name="httpStatusCode" value="custom:randomHttpStatusCode()" /&gt;56 * </pre>57 * </code>58 * <p>The other usage possibility is to choose a random value from a list of values given as argument 59 * like this which achieves the same result as the previously shown custom function:</p>60 * <code>61 * <pre>62 * &lt;variable name="httpStatusCode" value="citrus:randomEnumValue('200', '401', '500')" /&gt;63 * </pre>64 * </code>65 * 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 in66 * only one special case you may go with specifying the list as arguments otherwise you should define a custom function and reuse it. 67 * 68 * @author Dimo Velev (dimo.velev@gmail.com)69 */70public class RandomEnumValueFunction implements Function {71 private Random random = new Random(System.currentTimeMillis());72 private List<String> values = null;73 74 /**75 * @see Function#execute(java.util.List, com.consol.citrus.context.TestContext)76 */77 public String execute(List<String> params, TestContext context) {78 if (values == null) {79 return randomValue(params);80 } else {81 if (!params.isEmpty()) {82 throw new InvalidFunctionUsageException("The enumeration values have already been set");83 }84 return randomValue(values);...

Full Screen

Full Screen

Source:RandomEnumValueFunctionTest.java Github

copy

Full Screen

...20import java.util.*;21import static org.testng.Assert.assertNotNull;22import static org.testng.Assert.assertTrue;23/**24 * Test the {@link RandomEnumValueFunction} function.25 * 26 * @author Dimo Velev (dimo.velev@gmail.com)27 *28 */29public class RandomEnumValueFunctionTest extends AbstractTestNGUnitTest {30 private Random random = new Random(System.currentTimeMillis());31 32 private List<String> generateRandomValues() {33 final int valueCount = random.nextInt(15) + 5;34 final List<String> values = new ArrayList<String>(valueCount);35 for (int i=0; i<valueCount; i++) {36 values.add("value" + i);37 }38 return values;39 }40 41 @Test42 public void testWithParameters() {43 RandomEnumValueFunction testee = new RandomEnumValueFunction();44 final List<String> values = generateRandomValues();45 for (int i=0; i<100; i++) {46 final String value = testee.execute(values, context);47 assertNotNull(value);48 assertTrue(values.contains(value));49 }50 }51 52 @Test53 public void testWithValues() {54 RandomEnumValueFunction testee = new RandomEnumValueFunction();55 testee.setValues(generateRandomValues());56 final List<String> noParameters = Collections.emptyList();57 58 for (int i=0; i<100; i++) {59 final String value = testee.execute(noParameters, context);60 assertNotNull(value);61 assertTrue(testee.getValues().contains(value));62 }63 }64 65 @Test(expectedExceptions = {InvalidFunctionUsageException.class})66 public void testWithBoth() {67 RandomEnumValueFunction testee = new RandomEnumValueFunction();68 testee.setValues(generateRandomValues());69 final List<String> params = generateRandomValues();70 testee.execute(params, context);71 }72 73 @Test(expectedExceptions = {InvalidFunctionUsageException.class})74 public void testWithNone() {75 RandomEnumValueFunction testee = new RandomEnumValueFunction();76 final List<String> noParameters = Collections.emptyList();77 testee.execute(noParameters, context);78 }79}...

Full Screen

Full Screen

RandomEnumValueFunction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.functions.core;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.functions.core.RandomEnumValueFunction;4import com.consol.citrus.testng.AbstractTestNGUnitTest;5import org.testng.Assert;6import org.testng.annotations.Test;7public class RandomEnumValueFunctionTest extends AbstractTestNGUnitTest {8 public void testRandomEnumValueFunction() {9 RandomEnumValueFunction randomEnumValueFunction = new RandomEnumValueFunction();10 TestContext context = new TestContext();11 Assert.assertEquals(randomEnumValueFunction.execute(context, "com.consol.citrus.functions.core.RandomEnumValueFunctionTest$TestEnum"), TestEnum.VALUE1);12 Assert.assertEquals(randomEnumValueFunction.execute(context, "com.consol.citrus.functions.core.RandomEnumValueFunctionTest$TestEnum"), TestEnum.VALUE2);13 }14 public enum TestEnum {15 }16}17package com.consol.citrus.functions.core;18import com.consol.citrus.context.TestContext;19import com.consol.citrus.functions.core.RandomStringFunction;20import com.consol.citrus.testng.AbstractTestNGUnitTest;21import org.testng.annotations.Test;22public class RandomStringFunctionTest extends AbstractTestNGUnitTest {23 public void testRandomStringFunction() {24 RandomStringFunction randomStringFunction = new RandomStringFunction();25 TestContext context = new TestContext();26 for (int i = 0; i < 100; i++) {27 String result = randomStringFunction.execute(context, "10");28 Assert.assertEquals(result.length(), 10);29 }30 }31}32package com.consol.citrus.functions.core;33import com.consol.citrus.context.TestContext;34import com.consol.citrus.functions.core.RandomNumberFunction;35import com.consol.citrus.testng.AbstractTestNGUnitTest;36import org.testng.Assert;37import org.testng.annotations.Test;38public class RandomNumberFunctionTest extends AbstractTestNGUnitTest {39 public void testRandomNumberFunction() {40 RandomNumberFunction randomNumberFunction = new RandomNumberFunction();41 TestContext context = new TestContext();

Full Screen

Full Screen

RandomEnumValueFunction

Using AI Code Generation

copy

Full Screen

1public class RandomEnumValueFunctionTest extends TestNGCitrusTestDesigner {2 public void randomEnumValueFunctionTest() {3 variable("fruit", RandomEnumValueFunction.class, "com.consol.citrus.functions.core.Fruit");4 echo("Random fruit: ${fruit}");5 }6}7public class RandomEnumValueFunctionTest extends TestNGCitrusTestDesigner {8 public void randomEnumValueFunctionTest() {9 variable("fruit", RandomEnumValueFunction.class, "com.consol.citrus.functions.core.Fruit");10 echo("Random fruit: ${fruit}");11 }12}13public class RandomEnumValueFunctionTest extends TestNGCitrusTestDesigner {14 public void randomEnumValueFunctionTest() {15 variable("fruit", RandomEnumValueFunction.class, "com.consol.citrus.functions.core.Fruit");16 echo("Random fruit: ${fruit}");17 }18}19public class RandomEnumValueFunctionTest extends TestNGCitrusTestDesigner {20 public void randomEnumValueFunctionTest() {21 variable("fruit", RandomEnumValueFunction.class, "com.consol.citrus.functions.core.Fruit");22 echo("Random fruit: ${fruit}");23 }24}25public class RandomEnumValueFunctionTest extends TestNGCitrusTestDesigner {26 public void randomEnumValueFunctionTest() {27 variable("fruit", RandomEnumValueFunction.class, "com.consol.citrus.functions.core.Fruit");28 echo("Random fruit: ${fruit}");29 }30}31public class RandomEnumValueFunctionTest extends TestNGCitrusTestDesigner {32 public void randomEnumValueFunctionTest() {

Full Screen

Full Screen

RandomEnumValueFunction

Using AI Code Generation

copy

Full Screen

1public class RandomEnumValueFunctionTest {2 public void testRandomEnumValueFunction() {3 RandomEnumValueFunction function = new RandomEnumValueFunction();4 function.setEnumClassName("com.consol.citrus.functions.core.RandomEnumValueFunctionTest$TestEnum");5 function.setSeparator(",");6 function.setEnumValues("VALUE1,VALUE2,VALUE3,VALUE4");7 function.setRandom(new Random());8 function.execute();9 }10 public enum TestEnum {11 }12}

Full Screen

Full Screen

RandomEnumValueFunction

Using AI Code Generation

copy

Full Screen

1import org.springframework.context.annotation.Bean;2import org.springframework.context.annotation.Configuration;3import com.consol.citrus.dsl.builder.Builder;4import com.consol.citrus.dsl.builder.HttpClientActionBuilder;5import com.consol.citrus.dsl.builder.HttpServerActionBuilder;6import com.consol.citrus.dsl.builder.SendMessageActionBuilder;7import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;8import com.consol.citrus.dsl.builder.SendSoapMessageActionBuilder;9import com.consol.citrus.dsl.builder.ReceiveSoapMessageActionBuilder;10import com.consol.citrus.dsl.builder.HttpActionBuilder;11import com.consol.citrus.dsl.builder.AbstractTestBehaviorBuilder;12import com.consol.citrus.dsl.builder.TestBehaviorBuilder;13import com.consol.citrus.dsl.builder.TestActionBuilder;14import com.consol.citrus.dsl.builder.TestActionContainerBuilder;15import com.consol.citrus.dsl.builder.EchoActionBuilder;16import com.consol.citrus.dsl.builder.FailActionBuilder;17import com.consol.citrus.dsl.builder.PurgeEndpointActionBuilder;18import com.consol.citrus.dsl.builder.StopTimerActionBuilder;19import com.consol.citrus.dsl.builder.StartTimerActionBuilder;20import com.consol.citrus.dsl.builder.CreateVariablesActionBuilder;21import com.consol.citrus.dsl.builder.PurgeJmsQueuesActionBuilder;22import com.consol.citrus.dsl.builder.PurgeJmsTopicsActionBuilder;23import com.consol.citrus.dsl.builder.PurgeMessageChannelActionBuilder;24import com.consol.citrus.dsl.builder.PurgeMessageStoreActionBuilder;25import com.consol.citrus.dsl.builder.PurgeMongoDbCollectionsActionBuilder;26import com.consol.citrus.dsl.builder.PurgeRedisChannelsActionBuilder;27import com.consol.citrus.dsl.builder.PurgeRedisKeysActionBuilder;28import com.consol.citrus.dsl.builder.AssertExceptionBuilder;29import com.consol.citrus.dsl.builder.PurgeEndpointActionBuilder.PurgeEndpointActionBuilderSupport;30import com.consol.citrus.dsl.builder.PurgeJmsQueuesActionBuilder.PurgeJmsQueuesActionBuilderSupport;31import com.consol.citrus.dsl.builder.PurgeJmsTopicsActionBuilder.PurgeJmsTopicsActionBuilderSupport;32import

Full Screen

Full Screen

RandomEnumValueFunction

Using AI Code Generation

copy

Full Screen

1public class RandomEnumValueFunctionTest extends TestCase {2 private RandomEnumValueFunction function = new RandomEnumValueFunction();3 public void testRandomEnumValueFunction() {4 assertEquals("testEnumValue", function.execute("com.consol.citrus.functions.core.testEnum", null));5 }6}7public class RandomNumberFunctionTest extends TestCase {8 private RandomNumberFunction function = new RandomNumberFunction();9 public void testRandomNumberFunction() {10 assertEquals("5", function.execute("5", null));11 }12}13public class RandomStringFunctionTest extends TestCase {14 private RandomStringFunction function = new RandomStringFunction();15 public void testRandomStringFunction() {16 assertEquals("testString", function.execute("10", null));17 }18}19public class ReplaceVariablesFunctionTest extends TestCase {20 private ReplaceVariablesFunction function = new ReplaceVariablesFunction();21 public void testReplaceVariablesFunction() {22 assertEquals("testString", function.execute("testString", null));23 }24}25public class SystemPropertyFunctionTest extends TestCase {26 private SystemPropertyFunction function = new SystemPropertyFunction();27 public void testSystemPropertyFunction() {28 assertEquals("testString", function.execute("testString", null));29 }30}31public class TimeStampFunctionTest extends TestCase {32 private TimeStampFunction function = new TimeStampFunction();33 public void testTimeStampFunction() {34 assertEquals("testString", function.execute("testString", null));35 }36}37public class UuidFunctionTest extends TestCase {38 private UuidFunction function = new UuidFunction();39 public void testUuidFunction() {40 assertEquals("testString", function.execute("testString", null));41 }42}

Full Screen

Full Screen

RandomEnumValueFunction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.functions.core;2import com.consol.citrus.functions.Function;3import org.springframework.stereotype.Component;4import java.util.Random;5public class RandomEnumValueFunction implements Function {6 public Object execute(Object... objects) {7 Random random = new Random();8 Object[] enumValues = objects[0].getClass().getEnumConstants();9 return enumValues[random.nextInt(enumValues.length)];10 }11}12package com.consol.citrus.functions.core;13import com.consol.citrus.functions.Function;14import java.util.Random;15public class RandomStringFunction implements Function {16 public Object execute(Object... objects) {17 int length = (Integer) objects[0];18 Random random = new Random();19 StringBuilder builder = new StringBuilder();20 for (int i = 0; i < length; i++) {21 builder.append((char) (random.nextInt(26) + 'a'));22 }23 return builder.toString();24 }25}26package com.consol.citrus.functions.core;27import com.consol.citrus.functions.Function;28import java.util.Random;29public class RandomNumberFunction implements Function {30 public Object execute(Object... objects) {31 int length = (Integer) objects[0];32 Random random = new Random();33 StringBuilder builder = new StringBuilder();34 for (int i = 0; i < length; i++) {35 builder.append(random.nextInt(10));36 }37 return builder.toString();38 }39}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in RandomEnumValueFunction

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful