I'm trying to follow the Cineasts example and have created some nodes, a relationship between them and a test case.
I currently have two node types Event and Tag and an EventTagRelationship RelationshipEntity.
Within these I have the following (removed a lot of the code for brevity, tell me if you need more).
EventNode:
@RelatedToVia(type="EVENT_TAG")
Collection<EventTagRelationship> tagRelationships;
@RelatedTo(type="EVENT_TAG")
Set<TagNode> tags;
public EventTagRelationship addTag(TagNode tag) {
final EventTagRelationship tagRel = new EventTagRelationship(tag, this);
tagRelationships.add(tagRel);
return tagRel;
}
public Set<TagNode> getTags() {
return tags;
}
TagNode:
@RelatedTo(type = "EVENT_TAG", direction = Direction.INCOMING)
Set<EventNode> events;
EventTagRelationship:
@GraphId Long id;
@EndNode TagNode tag;
@StartNode EventNode event;
And here's my test:
@Test
public void eventCanHaveTags() {
EventNode event = template.save(new EventNode("1", "Super Duper Test Event"));
TagNode concertTag = template.save(new TagNode("1", "concert"));
TagNode bandTag = template.save(new TagNode("2", "band"));
EventTagRelationship eventBandTag = event.addTag(bandTag);
assertNotNull(eventBandTag);
template.save(eventBandTag);
EventTagRelationship eventConcertTag = event.addTag(concertTag);
assertNotNull(eventConcertTag);
template.save(eventConcertTag);
EventNode foundEvent = this.eventRepository.findById("1");
assertEquals(event, foundEvent);
assertEquals(event.getTitle(), foundEvent.getTitle());
assertEquals(2, foundEvent.getTags().size());
//now let's make sure we can find the tags themselves first
TagNode foundTag = this.tagRepository.findById("1");
assertEquals(concertTag.getName(), foundTag.getName());
System.out.println("number of tags in the event: " + foundEvent.getTags().size());
//now let's test out our relationships to ensure they are created properly
TagNode tag1 = foundEvent.getTags().iterator().next();
<--- where it starts breaking down
System.out.println("found tag relationship:" + tag1);
<---
assertEquals(eventConcertTag, tag1);
assertEquals(eventConcertTag.getTag().getName(), tag1.getName());
}
I can retrieve the event, I can retrieve the tags, but when I try and retrieve the tags related to an event I get a null object. Looking at the size of the tags set it returns 2 as expected, but the first object returns null. Here's the test output:
number of tags in the event: 2
found tag relationship:null [null]
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 11.147 sec <<< FAILURE!
Results :
Failed tests: eventCanHaveTags(com.clearboxmedia.srs.it.graph.Do mainTest): expected:<null [1], concert [1] [1]> but was:<null [null]>
Like the cineast example I have changed the toString method to output pertinent information like title, name and the [id] of the object.
Any help is greatly appreciated, thanks!
-warner


Reply With Quote
. Here's my latest output from the test:
