Fake-O-Matic is a utility tool for creating fake data.
Fake-O-Matic is configured through a set of yaml
files that forms a hierarchy. If some configuration is not found on
one file, then the next file is used. That also means that you can override configurations by leaving the default values
as the last in the hierarchy.
A Fake-O-Matic configuration has:
samples: # (1)
sample_name:
# configuration
placeholders: # (2)
"PLACEHOLDER_CHARACTER": sample_name
-
Ideally as many samples as needed
-
Optional placeholders for creating expressions
The configuration for each part is covered through this document.
Some configuration values can be externalized by different ways additionally to the normal String value:
- env
-
Fetches the value from an Environment Variable.
param:
env: PARAM # reads the value from the PARAM environment variable (export PARAM=foo)
- property
-
Fetches the value from a System Property.
param:
property: my.parameter # reads the value from the my.parameter system property (-Dmy.parameter=foo)
- file
-
Reads the value from a
file
.
param:
file: /tmp/myfile # reads the value from the /tmp/myfile content
- resource
-
Reads the value using a
class.getResourceAsStream
.
param:
resource: /com/example/configuration.yaml # reads the value from the configuration.yaml
# file inside the com.example package
- url
-
Reads the value from the given URL by using GET
url
.
param:
url: https://something.example.com/some-param
- value
-
Supplies a raw value.
param:
value: bar # uses "bar" as the value if the PARAM environment variable is not present
It is also possible to combine different approaches for getting the value by passing all the desired options. The first one that holds a value will be used (see the priority bellow):
param:
env: PARAM
property: my.parameter
value: bar
The priority for getting the value is:
-
env
-
property
-
file
-
resource
-
url
-
value
It’s also possible to supply a raw value without specifying the type value
if it’s the only value:
param: some value # implies a configuration of type "value"
Some samples take other samples as configuration. In most cases, there are two ways of passing a sample as configuration:
-
Referring through a
ref
property. -
Directly through a
sample
property.
The rules for generating data can contain sample
and placeholders
. Samples are a set of data that Fake-O-Matic can
randomly pick and placeholders are characters that can be associated with the samples for to allow the use of
expressions for generating data.
This sample can pick any character from a given string. Useful for defining a set of characters that can be used to produce IDs or any other information that is not meant to be read.
This sample can pick any item from a given list of objects.
- type
-
list
- values
-
List of raw values to use.
- samples
-
List of Samples to use.
- source
-
A configuration pointing to where to locate the list of values.
Note
|
You need to supply only one way of loading the values (values , sample or source ).
|
samples:
cause:
type: list
values:
- "clock speed"
- "solar flares"
- "electromagnetic radiation from satellite debris"
- "static from nylon underwear"
- "static from plastic slide rules"
- "global warming"
- "poor power conditioning"
- "static buildup"
- "doppler effect"
first_name:
type: list
samples:
- man_name
- woman_name
story:
type: list
source:
env: STORIES
property: stories
default: stories.txt
This sample actually calls a given API to get data to use every time it’s asked for a data.
Warning
|
Due to the nature of this sample, it’s not possible to reproduce the same payloads without relying on the dependent API. |
This sample extracts a value from a JSON object. Useful when used in combination with the API Sample.
- type
-
json
- path
-
A JSON Pointer to specify which value to take from the JSON object.
- source
-
Which sample sample should be used to obtain the JSON object.
This sample will produce a universally unique identifier.
This sample will gather other samples and join them into one data.
- type
-
join
- samples
-
Which samples to join
- separator
-
Which separator to use (defaults to an empty string).
A sample that allows you to define specific weights to each element.
- type
-
weight
- values
-
The list of values.
- weight
-
The weight of the value.
- value
-
The value to use.
- source
-
Which sample sample should be used instead of the
value
.
samples:
color:
type: weight
values:
- weight: 30
value: blue
- weight: 45
value: yellow
- weight: 10
value: red
- weight: 20
value: brown
- weight: 25
value: cyan
Note
|
The sum of the weights don’t necessary need to be 100 , but using a total weight of 100 helps to see the
weights as percentage.
|
This sample generates numbers from a given interval.
A sample that generates data based on expressions.
- type
-
expression
- sample
-
The sample to use as an expression.
- expression
-
The expression to use.
Note
|
You need to supply a sample or an expression .
|
A sample that can generate dates based on a given interval.
- type
-
date
- from
-
Defines the start date.
- to
-
Defines the end date.
- period
-
Defines a period instead of an end date. See the docs for
java.time.Period#parse
. - format
-
The format to parse the supplied dates. Defaults to
dd-MM-yyyy
. See the docs forjava.time.format.DateTimeFormatter#ofPatter
. - inclusive
-
Sets if the end date is part of the interval or not.
Note
|
It is possible to use today , yesterday or tomorrow instead of the actual date values.
|
A sample that caches the value. Useful when used with an API sample that posts data in order to create a data dependency.
- type
-
cache
- source
-
Which sample sample should be used to obtain the value to cache.
- ttl
-
How many hits the value should last until the cache gets another one. This is a configuration value.
The placeholders are a single character that can be associated with any of the configured sample. Bellow is an example of a configuration file:
placeholders:
"#": digit (1)
"%": letter (2)
samples:
letter:
type: chars
value: "abcdefghijklmnopqrstuvwxyz"
digit:
type: chars
value: "0123456789"
-
Associated with the
digit
sample -
Associated with the
letter
sample
Fake-O-Matic uses Qute templates to produce the payloads. A couple of methods can be used to get a fake data, the main one are:
- some(sampleName)
-
Gets a random sample from the given sample name.
- expression(placeholders)
-
Gets a random data produced by replacing each placeholder by a random sample associated with it.
The following properties can be configured as a JVM argument (prefix -D
), environment variable (with upper cases
and underscores), or a command line parameter:
- generator.total|GENERATOR_TOTAL|--total
-
The number of generated payloads. Defaults to
10
. - generator.config|GENERATOR_CONFIG|--config
-
Which configuration files should be used. Fake-O-Matic allows you to define parent configurations, so you can reuse them in the way it suits you better. The configurations should be comma separated from the most specific to the least specific (so the last configuration file becomes the parent one). The built-in configuration can be included with a simple
fakeomatic
name. The built-in configuration can be found atsrc/main/resources/META-INF/config/fakeomatic.yaml
.
Note
|
The --config param can be also used once for each file to include.
|
- generator.seed|GENERATOR_SEED|--seed
-
The seed to use for the random functions. Fake-O-Matic will generate one if empty.
- fakeomatic.events.log.level|FAKEOMATIC_EVENTS_LOG_LEVEL|--events-log-level
-
Sets the log level for the events. To see all the payloads and responses, set the log level to DEBUG.