diff --git a/module-core/src/main/java/io/goobi/vocabulary/model/jpa/FieldDefinitionEntity.java b/module-core/src/main/java/io/goobi/vocabulary/model/jpa/FieldDefinitionEntity.java index a1e6c04..1504bdb 100644 --- a/module-core/src/main/java/io/goobi/vocabulary/model/jpa/FieldDefinitionEntity.java +++ b/module-core/src/main/java/io/goobi/vocabulary/model/jpa/FieldDefinitionEntity.java @@ -90,7 +90,7 @@ public final boolean equals(Object o) { return false; } FieldDefinitionEntity that = (FieldDefinitionEntity) o; - return id != that.id; + return id == that.id; } @Override diff --git a/module-core/src/test/java/io/goobi/vocabulary/validation/RecordValidationTests.java b/module-core/src/test/java/io/goobi/vocabulary/validation/RecordValidationTests.java index 2227d2e..d1cb617 100644 --- a/module-core/src/test/java/io/goobi/vocabulary/validation/RecordValidationTests.java +++ b/module-core/src/test/java/io/goobi/vocabulary/validation/RecordValidationTests.java @@ -32,6 +32,7 @@ class RecordValidationTests { private VocabularyEntity vocabulary; private FieldTypeEntity ftText; private FieldDefinitionEntity fdName; + private FieldDefinitionEntity fdOther; @BeforeEach @@ -47,6 +48,7 @@ public void setUp() { vocabulary.setName("Test vocabulary"); fdName = new FieldDefinitionEntity(); + fdName.setId(1L); fdName.setSchema(schema); fdName.setName("Name"); fdName.setType(ftText); @@ -55,17 +57,41 @@ public void setUp() { fdName.setUnique(true); fdName.setRequired(true); - schema.setDefinitions(List.of(fdName)); + fdOther = new FieldDefinitionEntity(); + fdOther.setId(2L); + fdOther.setSchema(schema); + fdOther.setName("Other"); + fdOther.setType(ftText); + fdOther.setMainEntry(false); + fdOther.setTitleField(true); + fdOther.setUnique(false); + fdOther.setRequired(true); + + schema.setDefinitions(List.of(fdName, fdOther)); } @Test - void missingRequiredField_fails() { + void missingAllRequiredFields_fails() { VocabularyRecordEntity record = new VocabularyRecordEntity(); record.setVocabulary(vocabulary); assertThrows(VocabularyException.class, () -> validator.validate(record)); } + @Test + void missingOneRequiredField_fails() { + VocabularyRecordEntity record = new VocabularyRecordEntity(); + record.setVocabulary(vocabulary); + + FieldInstanceEntity name = new FieldInstanceEntity(); + name.setVocabularyRecord(record); + name.setDefinition(fdName); + + record.setFields(List.of(name)); + + assertThrows(VocabularyException.class, () -> validator.validate(record)); + } + @Test void insertingUnspecifiedField_fails() { VocabularyRecordEntity record = new VocabularyRecordEntity(); @@ -129,15 +155,23 @@ void hierarchicalRecordsIfEnabled_success() { parentNameField.setId(1L); parentNameField.setDefinition(fdName); parentNameField.setVocabularyRecord(parent); - parent.setFields(List.of(parentNameField)); + FieldInstanceEntity parentOtherField = new FieldInstanceEntity(); + parentOtherField.setId(2L); + parentOtherField.setDefinition(fdOther); + parentOtherField.setVocabularyRecord(parent); + parent.setFields(List.of(parentNameField, parentOtherField)); VocabularyRecordEntity child = new VocabularyRecordEntity(); child.setVocabulary(vocabulary); FieldInstanceEntity childNameField = new FieldInstanceEntity(); - childNameField.setId(2L); + childNameField.setId(3L); childNameField.setDefinition(fdName); childNameField.setVocabularyRecord(child); - child.setFields(List.of(childNameField)); + FieldInstanceEntity childOtherField = new FieldInstanceEntity(); + childOtherField.setId(4L); + childOtherField.setDefinition(fdOther); + childOtherField.setVocabularyRecord(child); + child.setFields(List.of(childNameField, childOtherField)); child.setParentRecord(parent); parent.setChildren(List.of(child));