DATAGRAPH-1420 - Check for TargetNode in RelationshipProperties.
This commit is contained in:
@@ -154,8 +154,12 @@ final class DefaultNeo4jPersistentProperty extends AnnotationBasedPersistentProp
|
||||
|
||||
@NonNull
|
||||
private Class<?> getRelationshipPropertiesTargetType(Class<?> relationshipPropertiesType) {
|
||||
return this.mappingContext.getPersistentEntity(relationshipPropertiesType)
|
||||
.getPersistentProperty(TargetNode.class).getType();
|
||||
Neo4jPersistentProperty persistentProperty = this.mappingContext.getPersistentEntity(relationshipPropertiesType)
|
||||
.getPersistentProperty(TargetNode.class);
|
||||
if (persistentProperty == null) {
|
||||
throw new MappingException("Missing @TargetNode declaration in " + relationshipPropertiesType);
|
||||
}
|
||||
return persistentProperty.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.neo4j.core.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -28,12 +29,15 @@ import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.neo4j.core.schema.DynamicLabels;
|
||||
import org.springframework.data.neo4j.core.schema.GeneratedValue;
|
||||
import org.springframework.data.neo4j.core.schema.Id;
|
||||
import org.springframework.data.neo4j.core.schema.Node;
|
||||
import org.springframework.data.neo4j.core.schema.Property;
|
||||
import org.springframework.data.neo4j.core.schema.Relationship;
|
||||
import org.springframework.data.neo4j.core.schema.RelationshipProperties;
|
||||
import org.springframework.data.neo4j.core.schema.TargetNode;
|
||||
|
||||
/**
|
||||
* @author Gerrit Meier
|
||||
@@ -89,6 +93,23 @@ class DefaultNeo4jPersistentEntityTest {
|
||||
schema.setInitialEntitySet(new HashSet<>(Arrays.asList(entityToTest)));
|
||||
assertThatIllegalStateException().isThrownBy(() -> schema.initialize()).withMessageMatching(expectedMessage);
|
||||
}
|
||||
|
||||
@Test // DATAGRAPH-1420
|
||||
void doesNotFailOnCorrectRelationshipProperties() {
|
||||
Neo4jPersistentEntity<?> persistentEntity = new Neo4jMappingContext()
|
||||
.getPersistentEntity(EntityWithCorrectRelationshipProperties.class);
|
||||
|
||||
assertThat(persistentEntity).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAGRAPH-1420
|
||||
void doesFailOnRelationshipPropertiesWithMissingTargetNode() {
|
||||
|
||||
assertThatExceptionOfType(MappingException.class)
|
||||
.isThrownBy(() -> new Neo4jMappingContext()
|
||||
.getPersistentEntity(EntityWithInCorrectRelationshipProperties.class))
|
||||
.withMessageContaining("Missing @TargetNode declaration in");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@@ -391,4 +412,26 @@ class DefaultNeo4jPersistentEntityTest {
|
||||
|
||||
private Map<String, List<Neo4jMappingContextTest.BikeNode>> bikes2;
|
||||
}
|
||||
|
||||
static class EntityWithCorrectRelationshipProperties {
|
||||
@Id private String id;
|
||||
@Relationship HasTargetNodeRelationshipProperties rel;
|
||||
}
|
||||
|
||||
static class EntityWithInCorrectRelationshipProperties {
|
||||
@Id private String id;
|
||||
@Relationship HasNoTargetNodeRelationshipProperties rel;
|
||||
}
|
||||
|
||||
@RelationshipProperties
|
||||
static class HasTargetNodeRelationshipProperties {
|
||||
|
||||
@TargetNode
|
||||
EntityWithExplicitPrimaryLabel entity;
|
||||
}
|
||||
|
||||
@RelationshipProperties
|
||||
static class HasNoTargetNodeRelationshipProperties {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user