Class RandomValueGenerator
The primary entry point is generate(BeanProperty), which is
property-aware (e.g. caps String values at the column's max length).
The secondary entry point generate(Class) works on the Java type
alone and is useful when no property metadata is available.
All per-type factory methods (randomString(String, int),
randomBigDecimal(int, int), randomLong(), etc.) are
protected so that subclasses can override individual types without
replacing the full dispatch logic.
Returns null for types that are not mapped (exotic / unknown types) —
the caller is expected to set those fields manually.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongenerate(io.ebeaninternal.server.deploy.BeanProperty prop) Generate a random value for the given bean property.Generate a random value for the given Java type, without property metadata.protected BigDecimalrandomBigDecimal(int precision, int scale) Generate a randomBigDecimalthat fits within the given precision and scale.protected booleanReturn a randomboolean— defaults totrue.protected doubleReturn a randomdoublein [1, 100).protected ObjectrandomEnum(Class<?> type) Return a value for the given enum type — defaults to the first declared constant.protected floatReturn a randomfloatin [1, 100).protected InstantReturn a randomInstant— defaults to now.protected intReturn a randomintin [1, 1_000).protected LocalDateReturn a randomLocalDate— defaults to today.protected LocalDateTimeReturn a randomLocalDateTime— defaults to now.protected longReturn a randomlongin [1, 100_000).protected OffsetDateTimeReturn a randomOffsetDateTime— defaults to now.protected shortReturn a randomshortin [1, 100).protected StringrandomString(String propName, int maxLength) Generate a random string, optionally capped atmaxLength.protected UUIDReturn a randomUUID.protected ZonedDateTimeReturn a randomZonedDateTime— defaults to now.
-
Constructor Details
-
RandomValueGenerator
public RandomValueGenerator()
-
-
Method Details
-
generate
Generate a random value for the given bean property.For
Stringproperties, the value is capped at the column'sBeanProperty.dbLength()when that length is positive. ForBigDecimalproperties, precision and scale from the column definition are used. -
generate
Generate a random value for the given Java type, without property metadata.String values produced here use a fixed 8-character length. Use
generate(BeanProperty)when column-length constraints matter. -
randomLong
protected long randomLong()Return a randomlongin [1, 100_000). -
randomInt
protected int randomInt()Return a randomintin [1, 1_000). -
randomShort
protected short randomShort()Return a randomshortin [1, 100). -
randomBoolean
protected boolean randomBoolean()Return a randomboolean— defaults totrue. -
randomUUID
-
randomInstant
-
randomOffsetDateTime
Return a randomOffsetDateTime— defaults to now. -
randomZonedDateTime
Return a randomZonedDateTime— defaults to now. -
randomLocalDate
-
randomLocalDateTime
Return a randomLocalDateTime— defaults to now. -
randomDouble
protected double randomDouble()Return a randomdoublein [1, 100). -
randomFloat
protected float randomFloat()Return a randomfloatin [1, 100). -
randomEnum
-
randomString
Generate a random string, optionally capped atmaxLength.When the property name contains "email" (case-insensitive), a value of the form
<prefix>@domain.comis returned, truncated to fitmaxLength. Otherwise a UUID-derived string is returned, truncated tomaxLength(defaulting to 8 characters whenmaxLengthis 0 or negative). -
randomBigDecimal
Generate a randomBigDecimalthat fits within the given precision and scale.precisionis the total number of significant digits (dbLength);scaleis the number of decimal places (dbScale). When precision is 0 or negative (unknown), a default of 6 integer digits is used. When scale is negative (unknown), a default scale of 2 is used.
-