@Test public void listing3_9_add_properties_to_relationships() { usersAndMovies.addPropertiesToRelationships(); try (Transaction tx = graphDb.beginTx()) { Relationship hasSeen = usersAndMovies.user1.getSingleRelationship( MyRelationshipTypes.HAS_SEEN, Direction.OUTGOING); assertEquals(5, hasSeen.getProperty("stars")); tx.success(); } }
@Test @Transactional public void shouldCreateRelationshipWithProperty() throws Exception { Relationship relationship = neo4jTemplate.createRelationshipBetween(referenceNode, node1, "has", map("name", "rel2")); assertNotNull(relationship); assertEquals(referenceNode, relationship.getStartNode()); assertEquals(node1, relationship.getEndNode()); assertEquals(HAS.name(), relationship.getType().name()); assertEquals("rel2", relationship.getProperty("name", "not set")); }
// ----- protected methods ----- protected boolean hasPropertyValue( Relationship rel, PropertyKey propertyKey, Object propertyValue) { if (rel != null && rel.hasProperty(propertyKey.dbName())) { Object value = rel.getProperty(propertyKey.dbName()); return value.equals(propertyValue); } return false; }
@Override public String convert(Relationship value, Class<String> type) { return (String) value.getProperty("name"); }