Class TestEntityBuilder
java.lang.Object
io.ebean.test.TestEntityBuilder
Builds entity bean instances with randomly populated scalar fields for use in tests.
@Id and @Version properties are left at their defaults (zero/null).
@ManyToOne and @OneToOne relationships that have cascade persist are
recursively built and set. Collection relationships (@OneToMany,
@ManyToMany) are left empty — the caller can populate them if needed.
TestEntityBuilder builder = TestEntityBuilder.builder(DB.getDefault()).build();
// build in-memory (not saved to database)
MyEntity entity = builder.build(MyEntity.class);
// build and insert to the database
MyEntity entity = builder.save(MyEntity.class);
// supply a custom value generator for domain-specific values
TestEntityBuilder builder = TestEntityBuilder.builder(DB.getDefault())
.valueGenerator(myGenerator)
.build();
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescription<T> TBuild and return an instance of the entity class with scalar fields populated with random values.static TestEntityBuilder.Builderbuilder(io.ebean.Database database) Returns a newTestEntityBuilder.Builderfor the given database.<T> TBuild an instance of the entity class, insert it to the database, and return it.
-
Method Details
-
builder
Returns a newTestEntityBuilder.Builderfor the given database. -
build
Build and return an instance of the entity class with scalar fields populated with random values. The entity is not saved to the database.- Parameters:
beanClass- the entity class to build- Throws:
IllegalArgumentException- if the class is not a known Ebean entity
-
save
Build an instance of the entity class, insert it to the database, and return it.- Parameters:
beanClass- the entity class to build and save- Throws:
IllegalArgumentException- if the class is not a known Ebean entity
-