Table of Contents |
---|
...
StubFactory
...
StubFactory is used to create temporary mocks for front-end and back-end developers before real models and real data is applied.
The feature of the class is ability to generate different instances of simple or complex types.
...
StubFactory can generate:
primitives (boolean, short, int and so on)
string
list
map
complex object e.g. Person (name, age, birthday...)
StubFactory works recursively, so it can generate collections with other nested types e.g. List<Map<List<Integer>, String>> and so on.
...
Just replace 'YOUR_CLASS' with an appropriate DTO (usually *Response or *Request classes)Usually code above is generated automatically during api generation through JBT (see api-generate) but such behavior can be changed. To turn off stub generation <strong>#TODO end this paragraph</strong>
Usage in JBT
Usually StubFactory is used during API generation through JBT. It produces interfaces in com.knubisoft.api.spec with or without default implementation with StubFactory.
To generate API layer without StubFactory (usual interfaces) use the following command from the project's root directory:
Info |
---|
cmd/app generate api |
To generate API layer with StubFactory usage (default method with StubFactory in interfaces) use the following command from the project's root directory:
Info |
---|
cmd/app generate api-stub |
MockDataGenerator
...
Overview
Basically, StubFactory generates random appropriate data, but it also is able to generate meaningful data using MockDataGenerator.
Meaningful data provided by MockDataGenerator is listed below:
name (first name + last name) / last name
phone number
email
address
date
datetime
text (like Lorem Ipsum)
Also, MockDataGenerator supports different locales.
...
Code Block | ||||
---|---|---|---|---|
| ||||
{ "body": { "fullName": "Lon Wyman", "birthday": "Fri Apr 09 12:15:47 EEST 1993", }, "errors": null, "debugInfo": null } |
If you have any questions/suggestions/remarks feel free to contact Diakonov Serhii. Hope you'll find it useful =)