generator-jhipster: EntityResourceIntTest Failures with Required Relationships
Overview of the issue
There are out-of-the-box test failures when generating entities with required relationships.
Motivation for or Use Case
Tests should not fail on a fresh generated project.
JHipster Version(s)
Master, 3.2.0+ (required relationships added)
JHipster configuration, a .yo-rc.json file generated in the root folder
{
"generator-jhipster": {
"jhipsterVersion": "3.4.2",
"baseName": "test",
"packageName": "com.mycompany.myapp",
"packageFolder": "com/mycompany/myapp",
"serverPort": "8080",
"authenticationType": "session",
"hibernateCache": "ehcache",
"clusteredHttpSession": "no",
"websocket": "no",
"databaseType": "sql",
"devDatabaseType": "h2Disk",
"prodDatabaseType": "mysql",
"searchEngine": "no",
"buildTool": "maven",
"enableSocialSignIn": false,
"rememberMeKey": "8c073c30fd56d34230694bc40fb1ec253d47c7d7",
"useSass": false,
"applicationType": "monolith",
"testFrameworks": [
"gatling"
],
"jhiPrefix": "jhi",
"enableTranslation": true,
"nativeLanguage": "en",
"languages": [
"en"
]
}
}
Entity configuration(s) entityName.json files generated in the .jhipster directory
Foo
{
"relationships": [
{
"relationshipName": "foo",
"otherEntityName": "foo",
"relationshipType": "one-to-many",
"otherEntityRelationshipName": "bar"
}
],
"fields": [
{
"fieldName": "name",
"fieldType": "String"
}
],
"changelogDate": "20160624065546",
"dto": "mapstruct",
"service": "serviceClass",
"entityTableName": "bar",
"pagination": "pagination"
}
Bar
{
"relationships": [
{
"relationshipName": "bar",
"otherEntityName": "bar",
"relationshipType": "many-to-one",
"relationshipValidateRules": [
"required"
],
"otherEntityField": "name"
}
],
"fields": [
{
"fieldName": "name",
"fieldType": "String"
}
],
"changelogDate": "20160624065503",
"dto": "mapstruct",
"service": "serviceClass",
"entityTableName": "foo",
"pagination": "pagination"
}
Reproduce the error
Generate the above entities (or any with a required relationship) and run mvn test
Related issues
#1843 - talks about string length and regex validation. There is a note about validation failing is documented in the Validation section https://jhipster.github.io/creating-an-entity/:
JHipster generates unit tests that work for generic entities, without knowing your validation rules: it is possible that the generated tests do not pass the validation rules. In that case, you will need to update the sample values used in your unit tests, so that they pass the validation rules.
Suggest a Fix
Since a Bar entity is required to create/update a Foo entity, I was able to get FooResouceIntTest.java working by creating a Bar in setup(), then adding it to the initTest() and updateFoo() tests. I also needed to inject BarMapper and BarService.
The other option would be to close this issue and point at the documentation, though fixing the tests requires more work than just updating the sample values.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 19 (16 by maintainers)
Commits related to this issue
- Add required relationship tests See #3769 — committed to jhipster/generator-jhipster by jdubois 8 years ago
- Clean up code for #3769 — committed to jhipster/generator-jhipster by jdubois 8 years ago
- Fix Travis tests for #3769 — committed to jhipster/generator-jhipster by jdubois 8 years ago
Ya damn thata gonna be difficult. May be we can try to do for one level and add documentation to ask user to correct if there are nested validations
Ya we could try that
Thanks & regards, Deepu On 26 Jun 2016 22:53, “Christophe Bornet” notifications@github.com wrote: