Skip to content

Commit

Permalink
Merge pull request #18067 from emilpaw/nested-derived-identifier-fail…
Browse files Browse the repository at this point in the history
…ing-tests

fix test when nested jpaDerivedIdentifier is used
  • Loading branch information
mshima authored Mar 18, 2022
2 parents 4637dab + bb8e267 commit 21a538e
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const otherEntities = _.uniq(Object.values(differentRelationships).filter(rels =
const skipCreateTest =
(
!cypressBootstrapEntities ||
requiredRelationships.some(rel => rel.otherEntity.primaryKey && rel.otherEntity.primaryKey.derived) ||
requiredRelationships.some(rel => rel.otherEntity.builtInUser || rel.otherEntity === this.entity) ||
requiredRelationships.map(rel => rel.otherEntity.relationships).flat().some(rel => rel.relationshipRequired) ||
!entityFakeData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,17 @@ if (field.fieldTypeString || field.blobContentTypeText) {
<%_ } else { _%>
<%= asEntity(otherEntityNameCapitalized) %> <%= otherEntityName %>;
<%_ if (databaseTypeSql && !reactive) { _%>
<%_ if (!isUsingMapsId || fieldStatus !== "UPDATED_") { _%>
if (TestUtil.findAll(em, <%= asEntity(otherEntityNameCapitalized) %>.class).isEmpty()) {
<%_ } _%>
<%= otherEntityName %> = <%= createEntityPrefix %><%= otherEntityNameCapitalized %>ResourceIT.create<% if (fieldStatus === 'UPDATED_') { %>Updated<% } %>Entity(em)<%= createEntityPostfix %>;
em.persist(<%= otherEntityName %>);
em.flush();
<%_ if (!isUsingMapsId || fieldStatus !== "UPDATED_") { _%>
} else {
<%= otherEntityName %> = TestUtil.findAll(em, <%= asEntity(otherEntityNameCapitalized) %>.class).get(0);
}
<%_ } _%>
<%_ } else { _%>
<%= otherEntityName %> = <%= createEntityPrefix %><%= otherEntityNameCapitalized %>ResourceIT.create<% if (fieldStatus === 'UPDATED_') { %>Updated<% } %>Entity(<% if (databaseType === 'sql') { %>em<% } %>)<%= createEntityPostfix %>;
<%_ } _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"clientRootFolder": "",
"databaseType": "sql",
"dto": "mapstruct",
"entityTableName": "maps_id_child_entity_withdto",
"entityTableName": "maps_id_child_with_dto",
"fields": [{ "fieldName": "date", "fieldType": "Instant" }],
"fluentMethods": true,
"jpaMetamodelFiltering": false,
Expand All @@ -17,6 +17,13 @@
"ownerSide": true,
"relationshipName": "mapsIdParentEntityWithDTO",
"relationshipType": "one-to-one"
},
{
"otherEntityName": "mapsIdGrandchildEntityWithDTO",
"otherEntityRelationshipName": "mapsIdChildEntityWithDTO",
"ownerSide": false,
"relationshipName": "mapsIdGrandchildEntityWithDTO",
"relationshipType": "one-to-one"
}
],
"searchEngine": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"clientRootFolder": "",
"databaseType": "sql",
"dto": "no",
"entityTableName": "child_entity_wo_dto",
"entityTableName": "maps_id_child_wo_dto",
"fields": [{ "fieldName": "date", "fieldType": "Instant" }],
"fluentMethods": true,
"jpaMetamodelFiltering": false,
Expand All @@ -17,6 +17,13 @@
"ownerSide": true,
"relationshipName": "mapsIdParentEntityWithoutDTO",
"relationshipType": "one-to-one"
},
{
"otherEntityName": "mapsIdGrandchildEntityWithoutDTO",
"otherEntityRelationshipName": "mapsIdChildEntityWithoutDTO",
"ownerSide": false,
"relationshipName": "mapsIdGrandchildEntityWithoutDTO",
"relationshipType": "one-to-one"
}
],
"searchEngine": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"changelogDate": "20220313234025",
"clientRootFolder": "",
"databaseType": "sql",
"dto": "mapstruct",
"entityTableName": "maps_id_grandchild_with_dto",
"fields": [{ "fieldName": "date", "fieldType": "Instant" }],
"fluentMethods": true,
"jpaMetamodelFiltering": false,
"pagination": "no",
"relationships": [
{
"id": true,
"otherEntityField": "id",
"otherEntityName": "mapsIdChildEntityWithDTO",
"otherEntityRelationshipName": "mapsIdGrandchildEntityWithDTO",
"ownerSide": true,
"relationshipName": "mapsIdChildEntityWithDTO",
"relationshipType": "one-to-one"
}
],
"searchEngine": false,
"service": "serviceImpl"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"changelogDate": "20220313234416",
"clientRootFolder": "",
"databaseType": "sql",
"dto": "no",
"entityTableName": "maps_id_grandchild_wo_dto",
"fields": [{ "fieldName": "date", "fieldType": "Instant" }],
"fluentMethods": true,
"jpaMetamodelFiltering": false,
"pagination": "no",
"relationships": [
{
"id": true,
"otherEntityField": "id",
"otherEntityName": "mapsIdChildEntityWithoutDTO",
"otherEntityRelationshipName": "mapsIdGrandchildEntityWithoutDTO",
"ownerSide": true,
"relationshipName": "mapsIdChildEntityWithoutDTO",
"relationshipType": "one-to-one"
}
],
"searchEngine": false,
"service": "no"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"clientRootFolder": "",
"databaseType": "sql",
"dto": "mapstruct",
"entityTableName": "maps_id_parent_entity_withdto",
"entityTableName": "maps_id_parent_with_dto",
"fields": [{ "fieldName": "name", "fieldType": "String" }],
"fluentMethods": true,
"jpaMetamodelFiltering": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"clientRootFolder": "",
"databaseType": "sql",
"dto": "no",
"entityTableName": "parent_entity_wo_dto",
"entityTableName": "maps_id_parent_wo_dto",
"fields": [{ "fieldName": "name", "fieldType": "String" }],
"fluentMethods": true,
"jpaMetamodelFiltering": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"clientRootFolder": "",
"databaseType": "sql",
"dto": "mapstruct",
"entityTableName": "maps_id_user_profile_withdto",
"entityTableName": "maps_id_user_profile_with_dto",
"fields": [{ "fieldName": "dateOfBirth", "fieldType": "Instant" }],
"fluentMethods": true,
"jpaMetamodelFiltering": false,
Expand Down
2 changes: 2 additions & 0 deletions test-integration/scripts/11-generate-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ elif [[ "$JHI_ENTITY" == "sqlfull" ]]; then

moveEntity MapsIdParentEntityWithoutDTO
moveEntity MapsIdChildEntityWithoutDTO
moveEntity MapsIdGrandchildEntityWithoutDTO
moveEntity MapsIdParentEntityWithDTO
moveEntity MapsIdChildEntityWithDTO
moveEntity MapsIdGrandchildEntityWithDTO
moveEntity MapsIdUserProfileWithDTO

moveEntity JpaFilteringRelationship
Expand Down
2 changes: 2 additions & 0 deletions test-integration/scripts/11-generate-entities.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ elif [[ "$JHI_ENTITY" == "sqlfull" ]]; then

moveEntity MapsIdParentEntityWithoutDTO
moveEntity MapsIdChildEntityWithoutDTO
moveEntity MapsIdGrandchildEntityWithoutDTO
moveEntity MapsIdParentEntityWithDTO
moveEntity MapsIdChildEntityWithDTO
moveEntity MapsIdGrandchildEntityWithDTO
moveEntity MapsIdUserProfileWithDTO

moveEntity JpaFilteringRelationship
Expand Down
7 changes: 6 additions & 1 deletion utils/relationship.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ function prepareRelationshipForTemplates(entityWithConfig, relationship, generat
}
return otherSideRelationship.relationshipName === relationship.otherEntityRelationshipName;
});
if (
if (!otherRelationship) {
// TODO throw error at v8.
generator.warning(
`Error at '${entityName}' definitions: 'otherEntityRelationshipName' is set with value '${relationship.otherEntityRelationshipName}' at relationship '${relationship.relationshipName}' but no back-reference was found at '${otherEntityName}'`
);
} else if (
otherRelationship &&
otherRelationship.otherEntityRelationshipName &&
otherRelationship.otherEntityRelationshipName !== relationship.relationshipName
Expand Down

0 comments on commit 21a538e

Please sign in to comment.