/dummymaker

Create/Populate/Export Dummy Objects for you.

Primary LanguageJavaApache License 2.0Apache-2.0

DummyMaker ♨️

codecov

Library allow you to produce Dummy Objects (POJOs) by using Factories and populate their fields with random values by using Annotations. And then Export them in CSV/JSON/XML/SQL format.

Steps to do:

  1. Create Dummy (POJO).
  2. Annotate your Dummy object fields with special Gen annotations.
  3. Use Factory to populate/produce your Dummy Objects.
  4. Export your Dummy Objects by using special Exporter.

Dependency 🚀

Maven

<dependency>
    <groupId>com.github.goodforgod</groupId>
    <artifactId>dummymaker</artifactId>
    <version>1.0.3</version>
</dependency>

Gradle

dependencies {
    compile 'com.github.goodforgod:dummymaker:1.0.3'
}

Contents

Functionality

You can easily create your own annotations and generators which will be supported by Scanners and Export classes, so it is easy extendable library.

Factories

Allow to populate or produce Dummy Objects.

  • GenProduceFactory - allow you to produce new Dummies with populated fields.

  • GenPopulateFactory - allow you to populate fields of already created Dummies.

Export

Allow to export Dummy objects in specific format into file. Also allow to export Dummy objects as a string value.

BaseExporter Parameters

Constructor parameters available for all exporters.

  • ExportClass - class to export.

  • Path - set path for export file, default directory where app is started.

  • NameStrategy - naming strategy applied to all origin fields (fields which are not @GenRenameExport), default value is DEFAULT.

    NamingStrategies

    • DEFAULT - origin name, as is.
    • UPPER_CASE - name in upper case, like DummyList - DUMMYLIST
    • LOW_CASE - name in low case, like DummyList - dummylist
    • UNDERSCORED_LOW_CASE - name in upper case, with _ symbol before each capital letter, like DummyList - dummy_list
    • UNDERSCORED_UPPER_CASE - name in low case, with _ symbol before each capital letter, like DummyList - dummy_list
    • INITIAL_LOW_CASE - origin name, but first letter is low case, like DummyList - dummyList

CsvExporter Specific Parameters

  • WrapTextValues - if true will wrap String values with commas like 'this', default False.
  • GenerateHeader - if true will generate CSV header, default False.
  • Separator - set CSV format separator, default is ',' comma.

XmlExporter Specific Parameters

  • ExportClassListName - export xml list name value (example: if class is Dummy, default list name will be DummyList).

SqlExporter Specific Parameters

  • dataTypeMap - map with key as a class, and sql data type as string as map value.

DataTypeMap is used to extend your data types to export in sql format.

Annotations

Allow to declare Dummy fields with generator annotations. Factories will generate values by using their provided methods.

Generate annotations start with Gen prefix (like GenInteger, GenEmail).

Special Annotations

  • GenForceExport allow to force export object field, even if it is not generated by GenAnnotation.

  • GenIgnoreExport allow to ignore object's field during export.

  • GenRenameExport allow to rename Dummy export field name or Class Name (Annotate constructor to rename class export name).

  • GenNumerate annotation with option (from) to numerate populated/produced Dummies fields (Works on Integer/Long/String field types).

Getting Started with examples

Annotations

POJO annotate demonstration

Force and Ignore annotation demonstration

In this case, field city will be export despite that there is not generator field for it, value will be "Saint-Petersburg". And field id will NOT be export if ignore annotation will have true (default) value.

Enumerate and Field Rename demonstration

GenEnumerate annotation will enumerate Dummy field starting from 10. It means if we want to produce 10 Dummy Objects, they will have id from 10 to 19.

GenRenameExport annotation will change field export name.

Class export rename demonstration

GenRenameExport annotation will change class export name.

Factories

Available GenPopulateFactory/GenProvideFactory. Allow user populate or produce Dummy objects.

Produce 1 or more Dummy objects demonstration

Populate 1 or more Dummy objects demonstration

It will be useful in case, you have complex created objects and you want just to populate some of their fields.

Exporters

Export demonstration

Exporters options set example

Export as a string value demonstration

Is useful in save you have custom writer or need to send it over network.

Export File Structures

Examples of exported Dummy object in each format.

Dummy Object Class

public class User {

    @GenInteger
    public Integer id;

    @GenName
    public String name;
}

CSV

Can be used to import data in Cassandra, Mongo, Neo4j, etc...

Csv exporter can generate header. (Like in example below) This option is available to set during instantiating like others.

name,id
ERASMO,1746885991
HELEN,-625322461

JSON

Can be used to import data in Mongo, MySQL, etc...

{
	"User": [
		{
			"name": "GREGORY",
			"id": "-2123372253"
		},
		{
			"name": "HAROLD",
			"id": "-1637387700"
		}
	]
}

XML

Can be used to import data in MySQL, SQL Server, etc...

<UserList>
	<User>
		<name>GREGORY</name>
		<id>-2123372253</id>
	</User>
	<User>
		<name>HAROLD</name>
		<id>-1637387700</id>
	</User>
</UserList>

SQL

Don't forget about Primary Key!

Each insert query can contains max 995 rows (Due to 1000 insert row limit in SQL).

CREATE TABLE IF NOT EXISTS user(
	name	VARCHAR,
	id  INT,
	PRIMARY KEY (id)
);

INSERT INTO user (name, id) VALUES 
('GREGORY', -2123372253),
('HAROLD', -1637387700);

Version History

1.0.3 - Lots of tests for all functionality, Added DataTypeMap parameter for users in SqlExporter (expandable data type for sql), NamingStrategy for exporters, bug fixes.

1.0.2 - Added special GenRenameExport annotation, export as single string, export values order fix, minor fixes and improvements.

1.0.1 - Added new generator and annotations, special GenEnumerate annotation, other minor fixes (Like SQL export).

1.0.0 - Initial project with core functions.

License

This project is licensed under the Apache License - see the LICENCE file for details.