Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable junit test for cyclic required relationships #24746

Merged
merged 4 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions generators/server/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,26 @@ export default class JHipsterServerGenerator extends BaseApplicationGenerator {
return this.asConfiguringEachEntityTaskGroup(this.delegateTasksToBlueprint(() => this.configuringEachEntity));
}

get postPreparingEachEntity() {
return this.asPostPreparingEachEntityTaskGroup({
checkForCircularRelationships({ entity }) {
const detectCyclicRequiredRelationship = (entity, relatedEntities) => {
if (relatedEntities.has(entity)) return true;
relatedEntities.add(entity);
return entity.relationships
?.filter(rel => rel.relationshipRequired || rel.id)
.some(rel => detectCyclicRequiredRelationship(rel.otherEntity, new Set([...relatedEntities])));
};
entity.hasCyclicRequiredRelationship = detectCyclicRequiredRelationship(entity, new Set());
entity.skipJunitTests = entity.hasCyclicRequiredRelationship ? 'Cyclic required relationships detected' : undefined;
},
});
}

get [BaseApplicationGenerator.POST_PREPARING_EACH_ENTITY]() {
return this.asPostPreparingEachEntityTaskGroup(this.delegateTasksToBlueprint(() => this.postPreparingEachEntity));
}

/** @inheritdoc */
get default() {
return this.asDefaultTaskGroup({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package <%= entityAbsolutePackage %>.web.rest;

<%_
var filterTestableRelationships = reactive ? reactiveEagerRelations : relationships;
var filterTestableRelationships = (reactive ? reactiveEagerRelations : relationships).filter(rel => rel.persistableRelationship && !rel.otherEntity.hasCyclicRequiredRelationship);
const fieldsToTest = fields.filter(field => !field.id && !field.autoGenerate && !field.transient);
let mapsIdEntity;
let mapsIdEntityInstance;
Expand Down Expand Up @@ -115,6 +115,9 @@ import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.AfterEach;
<%_ } _%>
import org.junit.jupiter.api.BeforeEach;
<%_ if (skipJunitTests) { _%>
import org.junit.jupiter.api.Disabled;
<%_ } _%>
import org.junit.jupiter.api.Test;
<%_ if (implementsEagerLoadApis || databaseTypeNeo4j) { _%>
import org.mockito.Mock;
Expand Down Expand Up @@ -246,6 +249,9 @@ import <%= entityAbsolutePackage %>.domain.enumeration.<%= field.fieldType %>;
* Integration tests for the {@link <%= entityClass %>Resource} REST controller.
*/
@IntegrationTest
<%_ if (skipJunitTests) { _%>
@Disabled("<%- skipJunitTests %>")
<%_ } _%>
<%_ if (implementsEagerLoadApis) { _%>
@ExtendWith(MockitoExtension.class)
<%_ } _%>
Expand Down Expand Up @@ -525,14 +531,14 @@ filterTestableRelationships.forEach((relationship) => { _%>
<%_ } _%>
<%_
const alreadyGeneratedEntities = [];
for (relationship of relationships) {
for (relationship of persistableRelationships) {
const relationshipValidate = relationship.relationshipValidate;
const otherEntityName = relationship.otherEntityName;
const otherEntityNameCapitalized = relationship.otherEntityNameCapitalized;
const relationshipNameCapitalizedPlural = relationship.relationshipNameCapitalizedPlural;
const relationshipNameCapitalized = relationship.relationshipNameCapitalized;
const mapsIdUse = relationship.id;
if ((relationshipValidate !== null && relationshipValidate) || mapsIdUse) { _%>
if ((relationshipValidate !== null && relationshipValidate && !relationship.otherEntity.hasCyclicRequiredRelationship) || mapsIdUse) { _%>
// Add required entity
<%_ if (alreadyGeneratedEntities.indexOf(otherEntityName) == -1) { _%>
<%_ if (relationship.otherEntityUser) { /* TODO or other entity has no unique fields */ _%>
Expand Down
13 changes: 13 additions & 0 deletions test-integration/samples/jdl-entities/cyclic.jdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@ChangelogDate(20200905000100)
entity CyclicA {
name String
}

@ChangelogDate(20200905000200)
entity CyclicB {
name String
}

relationship ManyToMany {
CyclicA{b required} to CyclicB{a required}
}