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
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
directoryany, 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