{"id":20490890,"url":"https://github.com/osoco/grails-extra-runtime-validation","last_synced_at":"2025-04-13T16:40:22.727Z","repository":{"id":5727288,"uuid":"6938974","full_name":"osoco/grails-extra-runtime-validation","owner":"osoco","description":"Extra runtime validation grails plugin","archived":false,"fork":false,"pushed_at":"2012-12-09T21:29:54.000Z","size":154,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-27T07:35:47.799Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Groovy","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/osoco.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-11-30T12:56:21.000Z","updated_at":"2022-07-05T01:40:48.000Z","dependencies_parsed_at":"2022-08-24T21:40:41.489Z","dependency_job_id":null,"html_url":"https://github.com/osoco/grails-extra-runtime-validation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osoco%2Fgrails-extra-runtime-validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osoco%2Fgrails-extra-runtime-validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osoco%2Fgrails-extra-runtime-validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osoco%2Fgrails-extra-runtime-validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/osoco","download_url":"https://codeload.github.com/osoco/grails-extra-runtime-validation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248746656,"owners_count":21155306,"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":[],"created_at":"2024-11-15T17:18:54.566Z","updated_at":"2025-04-13T16:40:22.705Z","avatar_url":"https://github.com/osoco.png","language":"Groovy","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Summary\nAllows performing additional validations on Grails domain objects at runtime. Adds an overloaded ``validate(Closure extraConstraints)`` method to every domain class.\n\n# Installation\nInclude the plugin in ``BuildConfig.groovy``:\n\n```groovy\nplugins {\n    compile \":extra-runtime-validation:0.1\"\n}\n```\nor if you are somehow old school and like deprecated features:\n\n```\ngrails install-plugin extra-runtime-validation\n```\n\n# Usage\n\n## Typical scenario\n\n### Given \na domain class ``Author`` with a nullable ``firstName`` field:\n\n```groovy\nclass Author {\n    String firstName\n    String lastName\n\n    static constraints = {\n        firstName nullable: true\n        lastName blank: false\n    }\n}\n```\n\n### When\nwe want to validate that the ``firstName`` is neither null nor blank (as required by a specific use case).\n\n### Then\n\nvalidate the domain object with the standard ``validate`` method:\n\n```groovy\nanAuthor.validate()\n```\n\n#### And\nperform some additional validations with extra constraints:\n\n```groovy\nanAuthor.validate {\n\tfirstName nullable: false, blank: false\n}\n```\n\n#### And\ndo something with validation errors.\n\n# Unit testing\n\nThe plugin doesn't provide a direct support for mocking the ``validate(Closure)``. The reason behind this is that the plugin should remain compatible with both Grails 1.3 and 2.x (which implement mocking in a different way). \n\nHowever, the plugin includes a helper method ``ValidationUtils.addValidateWithExtraConstraints(Object, ApplicationContext)`` which adds the new validation method to a concrete **instance**. Dependending on the Grails version and assuming you are using Spock, you mock ``validate(Closure)`` in the following way:\n\n### Grails 1.3\n```\nimport es.osoco.grails.plugins.extraval.ValidationUtils\nimport org.codehaus.groovy.grails.support.MockApplicationContext\n\nmockDomain(Author)\ndef o = new Author(...)\n// With JUnit and a subclass of GrailsUnitTestCase, you don't have to create the MockApplicationContext. Take it from the parent class (applicationContext property)\ndef ctx = new MockApplicationContext()\nctx.registerMockBean('messageSource', null)\nValidationUtils.addValidateWithExtraConstraints(o, ctx)\n```\n\n### Grails 2.x\n```\nimport es.osoco.grails.plugins.extraval.ValidationUtils\n\n@TestMixin(DomainClassUnitTestMixin)\n\nmockDomain(Author)\ndef o = new Author(...)\nValidationUtils.addValidateWithExtraConstraints(o, applicationContext)\n```\n\n## Final notes\n\n* ``validate(Closure)`` must be called after the standard ``validate`` method so that additional errors are retained. If called before, the built-in validation cleans the error list.\n* Validation of extra constraints adds errors and doesn't replace them.\n* Extra constraints neither replace nor modify intrinsic constraints","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosoco%2Fgrails-extra-runtime-validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fosoco%2Fgrails-extra-runtime-validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosoco%2Fgrails-extra-runtime-validation/lists"}