{"id":14983136,"url":"https://github.com/f-lopes/spring-mvc-test-utils","last_synced_at":"2025-06-29T17:37:43.810Z","repository":{"id":11174949,"uuid":"67697047","full_name":"f-lopes/spring-mvc-test-utils","owner":"f-lopes","description":"Test library aimed to ease Spring MVC form validation tests. Easily post an entire form to a given url.","archived":false,"fork":false,"pushed_at":"2025-06-02T04:58:25.000Z","size":480,"stargazers_count":19,"open_issues_count":12,"forks_count":8,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-04T23:18:49.017Z","etag":null,"topics":["spring-mvc","spring-test"],"latest_commit_sha":null,"homepage":"","language":"Java","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/f-lopes.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-09-08T11:27:58.000Z","updated_at":"2025-01-09T01:27:18.000Z","dependencies_parsed_at":"2025-05-28T21:06:19.625Z","dependency_job_id":"c3e5d58d-15b9-490b-a4b1-49d686ddf5ce","html_url":"https://github.com/f-lopes/spring-mvc-test-utils","commit_stats":{"total_commits":241,"total_committers":10,"mean_commits":24.1,"dds":0.5726141078838174,"last_synced_commit":"80c37ff838aa2d2f99e608d1521a85683e8451e0"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/f-lopes/spring-mvc-test-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-lopes%2Fspring-mvc-test-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-lopes%2Fspring-mvc-test-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-lopes%2Fspring-mvc-test-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-lopes%2Fspring-mvc-test-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/f-lopes","download_url":"https://codeload.github.com/f-lopes/spring-mvc-test-utils/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-lopes%2Fspring-mvc-test-utils/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260834903,"owners_count":23070176,"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":["spring-mvc","spring-test"],"created_at":"2024-09-24T14:06:47.322Z","updated_at":"2025-06-19T21:32:06.261Z","avatar_url":"https://github.com/f-lopes.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/f-lopes/spring-mvc-test-utils)\n\n# Spring MVC Test utils\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.florianlopes/spring-mvc-test-utils/badge.svg)](https://search.maven.org/#artifactdetails%7Cio.florianlopes%7Cspring-mvc-test-utils%7C4.0.0%7Cjar)\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/f-lopes/spring-mvc-test-utils/build.yml)\n[![codecov](https://codecov.io/gh/f-lopes/spring-mvc-test-utils/branch/main/graph/badge.svg?token=2yY70RB1tw)](https://codecov.io/gh/f-lopes/spring-mvc-test-utils)\n\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/26a17031a52941b0bc67cfacaf30c74c)](https://app.codacy.com/gh/f-lopes/spring-mvc-test-utils/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_grade)\n\nTest library aimed to ease Spring MVC form validation tests. Easily post an entire form to a given url.\n\nSee [MockMvcRequestBuilderUtils](src/main/java/io/florianlopes/spring/test/web/servlet/request/MockMvcRequestBuilderUtils.java)\n\nMore details here: [blog.florianlopes.io](https://blog.florianlopes.io/tool-for-spring-mockmvcrequestbuilder-forms-tests/)\n\n## How to use?\n\nAdd this dependency to your `pom.xml` file:\n```\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.florianlopes\u003c/groupId\u003e\n    \u003cartifactId\u003espring-mvc-test-utils\u003c/artifactId\u003e\n    \u003cversion\u003e4.0.0\u003c/version\u003e\n    \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\n**Changes for 4.0.0 version**\n* `Java 11` is no longer supported, `Java 17` is the minimum supported version._\n* \"Complex\" datatypes for Map values are now supported (see corresponding [test](https://github.com/f-lopes/spring-mvc-test-utils/blob/main/spring-mvc-test-utils/src/test/java/io/florianlopes/spring/test/web/servlet/request/MockMvcRequestBuilderUtilsTests.java#L242))\n\n_This library is tested with Spring Framework `6.1.12` along with Java `17` and `21` (\nsee [smoke-tests](https://github.com/f-lopes/spring-mvc-test-utils/tree/main/smoke-tests/src/tests/java/io/florianlopes/spring/test/web/servlet/request/MockMvcRequestBuilderUtilsSmokeTests.java)\nand [build.yml](https://github.com/f-lopes/spring-mvc-test-utils/blob/main/.github/workflows/build.yml#L15) workflow)_\n\n---\n\n```MockMvcRequestBuilderUtils.postForm(\"/url\", formObject);```\n\nExample:\n```\n@Test\npublic void testSimpleFields() throws Exception {\n    final MockHttpServletRequestBuilder mockHttpServletRequestBuilder = MockMvcRequestBuilderUtils.postForm(\"/test\",\n            new AddUserForm(\"John\", \"Doe\", null, new Address(1, \"Street\", 5222, \"New York\")));\n    final MockHttpServletRequest request = mockHttpServletRequestBuilder.buildRequest(this.servletContext);\n\n    assertEquals(\"John\", request.getParameter(\"firstName\"));\n    assertEquals(\"New York\", request.getParameter(\"address.city\"));\n}\n```\n\nUsage with `MockMvc`:\n```\nfinal AddUserForm addUserForm = new AddUserForm(\"John\", \"Doe\", null, new Address(1, \"Street\", 5222, \"New York\")));\n\nmockMvc.perform(MockMvcRequestBuilderUtils.postForm(\"/users\", addUserForm))\n\t\t.andExpect(MockMvcResultMatchers.model().hasNoErrors());\n```\n\nUsing `with()` syntax (`FormRequestPostProcessor`):\n\n```\nfinal AddUserForm addUserForm = new AddUserForm(\"John\", \"Doe\", null, new Address(1, \"Street\", 5222, \"New York\")));\n\n// POST\nmockMvc.perform(post(\"/users\").with(MockMvcRequestBuilderUtils.form(addUserForm)))\n\t\t.andExpect(MockMvcResultMatchers.model().hasNoErrors());\n\n// GET\nmockMvc.perform(get(\"/users\").with(MockMvcRequestBuilderUtils.form(addUserForm)))\n\t\t.andExpect(MockMvcResultMatchers.model().hasNoErrors());\n\t\t\n// PUT\nmockMvc.perform(put(\"/users\").with(MockMvcRequestBuilderUtils.form(addUserForm)))\n\t\t.andExpect(MockMvcResultMatchers.model().hasNoErrors());\n```\n\n### Register property editor(s)\n\nThis tool relies on default Spring's property editors (\nsee https://github.com/spring-projects/spring-framework/blob/main/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java#L200).\n\nIf you want to override one of those registered by default, simple use the `MockMvcRequestBuilderUtils.registerPropertyEditor(...)` method:\n```\nMockMvcRequestBuilderUtils.registerPropertyEditor(LocalDate.class, new CustomLocalDatePropertyEditor(\"dd/MM/yyyy\"));\n\nfinal AddUserForm addUserForm = new AddUserForm(\"John\", \"Doe\", LocalDate.now(), null);\nfinal MockHttpServletRequestBuilder mockHttpServletRequestBuilder = MockMvcRequestBuilderUtils.postForm(POST_FORM_URL, addUserForm);\n\nMockHttpServletRequest request = mockHttpServletRequestBuilder.buildRequest(this.servletContext);\nassertEquals(LocalDate.now().format(DateTimeFormatter.ofPattern(\"dd/MM/yyyy\")), request.getParameter(\"birthDate\"));\n```\n\n## Limitations and restrictions\nThis helper utility handles your form objects using the Java Reflection API. This implies\nsome restrictions in the usage within your test cases:\n\n* As long as you use simple, common Java types like `String`, etc, the mocked\n  HTTPServletRequest should not fail to be processed by data binding.\n* You can always provide a custom property editor (see above).\n\n* Converting data using classes from the Java Collection API is supported since\n  version 1.0.0. The parameters will follow the convention `name[index] = value`.\n  * Currently, no multidimensional collections (like array of arrays) are supported.\n\n* Converting data using classes from the Java Map API is supported in a simple\n  manner since version 1.1.0. The parameters will follow the convention\n  `name[key] = value`.\n  * Currently, no map of maps is supported, only simple datatypes with key and\n    value easily transformable to a `String`.\n\n* As a last resort, your properties will be converted using the `toString()`\n  method of the member object under the name of the object.\n\n## Contributing\n\nFeel free to contribute using this guide:\n\n1. Fork this project\n2. Clone your forked repository\n    ```git clone git@github.com:{your-username}/spring-mvc-test-utils.git```\n3. Add a new remote pointing to the original repository\n    ```git remote add upstream git@github.com:flopes/spring-mvc-test-utils.git```\n4. Create a new branch for your feature\n    ```git branch -b my-feature```\n5. Commit your changes (and squash them if necessary using `git rebase -i` or `git add -p`)\n6. Pull the latest changes from the original repository\n   ```git checkout main \u0026\u0026 git pull --rebase upstream main```\n7. Rebase main branch with your feature\n   ```git checkout my-feature \u0026\u0026 git rebase main```\n    Solve any existing conflicts\n8. Push your changes and create a PR on GitHub\n    ```git push -u origin my-feature```\n    Go to the original repository and create a new PR with comments.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff-lopes%2Fspring-mvc-test-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ff-lopes%2Fspring-mvc-test-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff-lopes%2Fspring-mvc-test-utils/lists"}