jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.55k stars 4.02k forks source link

JHipster generates unit test code that can't ever pass, especially when using oracle or any other relational database that uses sequences #19799

Closed naris closed 2 years ago

naris commented 2 years ago
Overview of the issue

Jhipster generates test code that expects that a new entity's id is the size of the table as this code shows. // Validate the Category in the database List<Category> categoryList = categoryRepository.findAll(); assertThat(categoryList).hasSize(databaseSizeBeforeCreate + 1); Category testCategory = categoryList.get(categoryList.size() - 1); However, when the id is assigned from a sequence that will almost never be the case. This is especially true since JHipster uses the same sequence for every entity (table) it generates.

This causes most of the following test cases to fail as the get() call will either fail or read a different record from the one expected.

Motivation for or Use Case

It causes most of the unit test cases, and hence ./mvnw verify and hence any build pipelines to fail.

Reproduce the error

Generate a JHipster project using oracle, or any other database that uses sequences, and several entities. then run ./mvnw verify

Suggest a Fix

Change the get() call to use the value from the sequence, not list.size() + 1.

JHipster Version(s)

any

JHipster configuration

any

Entity configuration(s) entityName.json files generated in the .jhipster directory

any, but this is the 1 entity (Category) mentioned above. { "applications": "*", "changelogDate": "20220525172747", "dto": "no", "embedded": false, "entityTableName": "category", "fields": [ { "fieldName": "name", "fieldType": "String", "fieldValidateRules": ["maxlength", "required"], "fieldValidateRulesMaxlength": "128" }, { "fieldName": "createUser", "fieldType": "String", "fieldValidateRules": ["required"] }, { "fieldName": "createDate", "fieldType": "Instant", "fieldValidateRules": ["required"] }, { "fieldName": "modifyUser", "fieldType": "String" }, { "fieldName": "modifyDate", "fieldType": "Instant" } ], "fluentMethods": true, "incrementalChangelog": false, "jpaMetamodelFiltering": true, "name": "Category", "pagination": "pagination", "readOnly": false, "relationships": [ { "relationshipType": "many-to-one", "otherEntityName": "dimension", "otherEntityRelationshipName": "categories", "relationshipName": "dimension" }, { "relationshipType": "one-to-many", "otherEntityName": "platform", "otherEntityRelationshipName": "category", "relationshipName": "platform" } ], "service": "serviceClass", "skipCheckLengthOfIdentifier": true }

Browsers and Operating System

N/A

naris commented 2 years ago

This is actually a different issue. I shouldn't add issues before coffee and further investigation :(