{"id":19982060,"url":"https://github.com/triologygmbh/test-data-loader","last_synced_at":"2025-05-04T05:32:14.385Z","repository":{"id":44859049,"uuid":"64739217","full_name":"triologygmbh/test-data-loader","owner":"triologygmbh","description":"A Groovy DSL for creating test data via JPA","archived":false,"fork":false,"pushed_at":"2022-01-21T23:09:25.000Z","size":147,"stargazers_count":11,"open_issues_count":5,"forks_count":8,"subscribers_count":7,"default_branch":"develop","last_synced_at":"2025-04-08T04:22:11.204Z","etag":null,"topics":["database","dsl","entity","groovy","h2","h2-database","java","jpa","test-data","test-data-generator","test-data-loader","testdata","wildfly","wildfly-swarm"],"latest_commit_sha":null,"homepage":null,"language":"Groovy","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/triologygmbh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-02T08:31:43.000Z","updated_at":"2025-03-12T12:02:49.000Z","dependencies_parsed_at":"2022-08-30T10:51:34.680Z","dependency_job_id":null,"html_url":"https://github.com/triologygmbh/test-data-loader","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triologygmbh%2Ftest-data-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triologygmbh%2Ftest-data-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triologygmbh%2Ftest-data-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triologygmbh%2Ftest-data-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/triologygmbh","download_url":"https://codeload.github.com/triologygmbh/test-data-loader/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252293082,"owners_count":21724960,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","dsl","entity","groovy","h2","h2-database","java","jpa","test-data","test-data-generator","test-data-loader","testdata","wildfly","wildfly-swarm"],"created_at":"2024-11-13T04:08:56.492Z","updated_at":"2025-05-04T05:32:14.056Z","avatar_url":"https://github.com/triologygmbh.png","language":"Groovy","funding_links":[],"categories":[],"sub_categories":[],"readme":"# test-data-loader \n[![Build Status](https://opensource.triology.de/jenkins/buildStatus/icon?job=triologygmbh-github/test-data-loader/master)](https://opensource.triology.de/jenkins/blue/organizations/jenkins/triologygmbh-github%2Ftest-data-loader/branches)\n[![Maven Central](https://img.shields.io/maven-central/v/de.triology.test-data-loader/test-data-loader.svg)](http://search.maven.org/#search|gav|1|g%3A%22de.triology.test-data-loader%22%20AND%20a%3A%22test-data-loader%22)\n\n## Overview\nThis project implements a Groovy DSL that can be used to populate a database using JPA entities. Its indented use is testing but it could be used in other scenarios as well.\nThe DSL is implemented in Groovy but can be used from pure Java. Entities are modularly defined in separate .groovy files using the DSL syntax. Those entity definition files can then be loaded as needed using the `de.triology.blog.testdata.loader.TestDataLoader`, which also provides access to loaded entities. Thus, the client code does not need to deal with any database or JPA specific concerns other than providing an initialized EntityManager.\n\nThis project was started while working on an article published in [Java aktuell](http://www.ijug.eu/java-aktuell/das-magazin.html) 03/2017: \n[A Groovy DSL for the Creation of Test Data using JPA](https://www.triology.de/en/blog-entries/groovy-dsl-test-data).  \nThe original article (🇩🇪) can be found here: [Eine Groovy-DSL zum Erzeugen von Testdaten über JPA](https://www.triology.de/wp-content/uploads/2017/09/Eine-Groovy-DSL-zum-Erzeugen-von-Testdaten-ueber-JPA.pdf).\n\nPlease note that from version 1.x the implementation as described in the article referenced above has changed. For more information about the changes, please refer to the release notes of each [release](https://github.com/triologygmbh/test-data-loader/releases).\n\n## Configuration\n\nAdd the [latest stable version of test-data-loader](http://search.maven.org/#search|gav|1|g%3A%22de.triology.test-data-loader%22%20AND%20a%3A%22test-data-loader%22) to the dependency management tool of your choice.\n\nE.g. for maven\n\n```XML\n\u003cdependency\u003e\n    \u003cgroupId\u003ede.triology.test-data-loader\u003c/groupId\u003e\n    \u003cartifactId\u003etest-data-loader\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\nCurrent version is [![Maven Central](https://img.shields.io/maven-central/v/de.triology.test-data-loader/test-data-loader.svg)](http://search.maven.org/#search|gav|1|g%3A%22de.triology.test-data-loader%22%20AND%20a%3A%22test-data-loader%22)\n\nYou can get snapshot versions from maven central (for the most recent commit on develop branch) or via [JitPack](https://jitpack.io/#triologygmbh/test-data-loader) (note that JitPack uses different maven coordinates).  \n\n## Usage\nAn example entity definition Groovy script file can be found here: https://github.com/triologygmbh/test-data-loader/blob/master/src/test/resources/tests/itTestData.groovy\n\nThe [`de.triology.blog.testdata.loader.TestDataLoaderIT`](https://github.com/triologygmbh/test-data-loader/blob/master/src/test/java/de/triology/blog/testdata/loader/TestDataLoaderIT.java) integration test shows how to load that file.\n\n### Entity Definitions\nUse the following syntax in a separate .groovy file to define a `User` entity. The entity will be created, persisted and registered under the name \"Peter\" when the definition file is loaded. _**Note:** Entity definition files are expected to be UTF-8 encoded._\n```Groovy\nimport de.triology.blog.testdata.loader.testentities.User\n\ncreate User, 'Peter', {\n    id = 123\n    firstName = 'Peter'\n    lastName = 'Pan'\n    login = 'pete'\n    email = 'peter.pan@example.com'\n}\n```\nCreate nested entities by simply nesting their definitions:\n```Groovy\nimport de.triology.blog.testdata.loader.testentities.User\nimport de.triology.blog.testdata.loader.testentities.Department\n\ncreate User, 'Peter', {\n    // ...\n    department = create Department, 'lostBoys', {\n        id = 999\n        name = 'The Lost Boys'\n    }\n}\n```\nAnd reference previously created entities by their name like so: \n```Groovy\nimport de.triology.blog.testdata.loader.testentities.User\nimport de.triology.blog.testdata.loader.testentities.Department\n\ncreate User, 'Peter', {\n    // ...\n    department = create Department, 'lostBoys', {\n        // ...\n        head = Peter\n    }\n}\n\ncreate User, 'Tinker', {\n    id = 555\n    firstName = 'Tinker'\n    lastName = 'Bell'\n    department = lostBoys\n}\n```\nSince entity definition files are just plain Groovy scripts, you are free to use any control structures, like loops and conditions, e.g.:\n```Groovy\nimport de.triology.blog.testdata.loader.testentities.User\n\n5.times { count -\u003e\n    create User, \"user_$count\", {\n        id = 1000 + count\n        if(count % 2 == 0) {\n            firstName = \"even_$count\"\n        } else {\n            firstName = \"odd_$count\"\n        }\n    }\n}\n```\n\n**Private fields from superclasses**\n\nFor now, we must work around this, by setting the field to `protected` or creating a `protected` setter method.\nSee [this issue](https://github.com/triologygmbh/test-data-loader/issues/7).\n\n### Loading entity definitions\nUse the `de.triology.blog.testdata.loader.TestDataLoader` to load entity definition files (from classpath or file system) and persist the defined entities. \nThe `TestDataLoader` requires a fully initialized, ready-to-use `EntityManager` and can then be used to load entity definition files and access the persisted entities.\n```Java\nEntityManager entityManager = // ... init EntityManager\nTestDataLoader testDataLoader = new TestDataLoader(entityManager);\ntestDataLoader.loadTestData(Collections.singletonList(\"demo/testData.groovy\"));\n\nUser peter = entityManager.find(User.class, 123L);\nassert \"Pan\".equals(peter.getLastName());\n\nUser tinker = testDataLoader.getEntityByName(\"Tinker\", User.class);\nassert \"Bell\".equals(tinker.getLastName());\n```\n\n### Clean up afterwards\nTo reset the database as well as the TestDataLoader to a clean state after a test case simply call `testDataLoader.clear()`. That will delete all created entities from the database and from TestDataLoader's entity cache.\n\n## Tested with...\n\nWe have approved TestDataLoader in multiple projects and use cases including\n\n* \"unit\" tests with H2 and JUnit\n* Integration test with arquillian, WildFly (Swarm) and Postgresql\n* Integration tests with arquillian, IBM WebSphere Liberty Profile and IBM DB2\n\n## Contributions\nThe test-data-loader has been derived and generalized from real world development projects but has yet to prove itself as stand-alone library. **Any feedback or contributions are highly welcome!**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftriologygmbh%2Ftest-data-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftriologygmbh%2Ftest-data-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftriologygmbh%2Ftest-data-loader/lists"}