@Test
@Transactional
public void testLabels() {
String[] labelNames = {"Person", "Developer", "Father","_Person"};
Person p = new Person("Michael",39).persist();
// assertThat(p.getLabels(), hasItems(labelNames[0],labelNames[3]));
p = neo4jTemplate.findOne(p.getId(), Person.class);
assertThat(p.getLabels(), hasItems(labelNames[0],labelNames[3]));
p.addLabel(labelNames[1]);
p.addLabel(labelNames[2]);
neo4jTemplate.save(p);
System.out.println("p.getLabels() = " + p.getLabels());
assertEquals(4, IteratorUtil.count(getNodeState(p).getLabels()));
for (Label l : getNodeState(p).getLabels()) {
assertEquals("Wrong label "+l.name(),true, asList(labelNames).contains(l.name()));
}
assertThat(p.getLabels(), hasItems(labelNames));
Person loaded = neo4jTemplate.findOne(p.getId(), Person.class);
assertThat(loaded.getLabels(), hasItems(labelNames));
loaded.removeLabel(labelNames[2]);
assertThat(p.getLabels(), hasItems(labelNames[0], labelNames[1]));
assertThat(loaded.getLabels(), hasItems(labelNames[0], labelNames[1]));
loaded = neo4jTemplate.findOne(p.getId(), Person.class);
assertThat(loaded.getLabels(), hasItems(labelNames[0],labelNames[1]));
}