Skip to main content

Building models for Tests

You can build a model using the TestModelBuilder class

private final TestModelBuilder modelBuilder = new TestModelBuilder();

private ComponentComposite baseModel() {
return modelBuilder.buildModel(
component("testComp",
dataElement("City")));
}

To build a Component model, you can use the buildModel(spec) method:

modelBuilder.buildModel(
component("testComp",
dataElement("City")));

You can also build a Component and select a DataElement with the buildModelAndFind(spec, selector) method:

modelBuilder.buildModelAndFind(
component("testComp",
dataElement("City")),
dataElement("testComp::City"));

Alternatively, you can pass an ApplicationSpec to build an Application model:

modelBuilder.buildModel(
application("testApp",
component("testComp",
dataElement("City"))));

The TestModelBuilder uses the Onion Spec API to define the test models.