Nebula is a generation tool written in java. Nebula provides simple tools for easy data generation.
The central element in Nebula is the model. The model consists on
-
Entities that describes data structure and the generation behaviours for properties.
-
Generation rules that describe how generated data will be format and write
package com.nebula.examples.csv;
import com.nebula.core.Model;
import com.nebula.Nebula;
import com.nebula.core.Entity;
import com.nebula.core.types.NebulaTypes;
import com.nebula.core.generators.NebulaGenerators;
import com.nebula.core.formatter.NebulaFormatters;
import com.nebula.core.generationconstraint.NebulaConstraints;
import com.nebula.core.output.NebulaOutputs;
import org.joda.time.DateTime;
import static com.nebula.Nebula.*;
public class CsvUsers {
private static DateTime MIN_BIRTH_DATE = new DateTime(1950, 1, 1, 0, 0);
private static DateTime MAX_BIRTH_DATE = new DateTime(2000, 1, 1, 0, 0);
public static void main(String[] args) {
System.out.println("Generate 10 Users");
Model model = Nebula.newModel();
model.setSeed("a seed");
model.setDateFormat("dd/MM/yyyy");
Entity users = newEntity("users", Long.MAX_VALUE);
users.addProperty("firstName", NebulaGenerators.random(), NebulaGenerationTypes.string().withPattern("[A-Z]{1}[a-z]{3,25}"));
users.addProperty("lastName", NebulaGenerators.random(), NebulaGenerationTypes.string().withPattern("[A-Z]{1}[a-z]{3,25}"));
users.addProperty("dayOfBirth", NebulaGenerators.random(), NebulaGenerationTypes.dateTime().range().withMin(MIN_BIRTH_DATE).withMax(MAX_BIRTH_DATE));
model.addEntity(users);
model.addGenerationRule(Nebula.newGenerationRule()
.withEntity(users)
.withFormatter(NebulaFormatters.csv().withSeparator(";").withColumns("lastName", "firstName", "dayOfBirth"))
.addOutput(NebulaOutputs.stdout())
.addGenerationConstraint(NebulaConstraints.amount(10)));
model.generate();
System.out.println("Done");
}
}
The concept behind Nebula is data generation based on two elements :
-
a seed
-
an index
The most important thing is when an entity is declared, Nubula works like an array which all items is a generated object that match entity declaration. All object can be accessible with an index (from 0 to 9223372036854775807). All objects are generated on demand when access via index is perform.
Seed concept is very important. For a same seed nebula will generate the same dataset.
-
Model : a model contains the data structure to generate (entities) and all generation behavior for data generation.
-
Entity : represent a hierarchical data structure. An entity consist on a set of properties that describe name, type and generation rule for a property.
-
Formatter : a formatter transform entities to String for outputs
-
Output : Example : file, http, stdout, jdbc, …
Model settings are apply on all operations that use these setting in the model.
Parameter | Usage | Description | Default Value |
---|---|---|---|
seed |
|
Sepcify the seed to use for all random operations in the model. If you sepecify a |
A random Long |
date format |
|
Specify the date format to use for all date format operations in the model. See java formats for all possibls formats |
"MM/dd/yyyy" |
decimal separator |
model.setNumberDecimalSeparator(<char>) |
Specify the decimal separator for number format |
"." |
thousand separator |
model.setNumberThousandSeparator(<char>) |
Specify the thousand separator for number format |
"," |
Types are accessible in NebulaTypes class
Type |
Description |
Default behavior |
amongItems() |
Provide a list of items and pick one of these |
|
bool() |
Generate a boolean (true or false) |
|
constant() |
Always generate the same thing |
|
custom() |
A custom type implementation can be specify with this type |
|
datetime() |
Generate a date time according rule |
|
entity() |
Generate an another entity |
|
list() |
Generate à list |
|
number() |
Generate a number |
|
string() |
Generate a string |
All generators are accessible in NebulaGenerators
Generator |
Description |
Default behavior |
custom() |
A custom implementation can be specify with this generator |
|
random() |
Generate a random type |
|
randomUnique() |
Generate a random type uniquely. After all types are generated, the generator cycle again |
|
sequence() |
Generate sequentially the type |
By default, the sequence cycle if reach the maximum |