Artist artist3 = artistRepository.findByName("Dolly Parton").iterator().next();
Person person = personRepository.findByName("Whitney Elisabeth Houston").iterator().next();
Person person2 = personRepository.findByName("Kenneth Brian Edmonds").iterator().next();
Person person3= personRepository.findByName("Dolly Rebecca Parton").iterator().next();
RelationEntity relation = new RelationEntity();
relation.setFromId(artist.getId());
relation.setToId(person.getId());
relation.setType("In real life");
relation.setLastUpdated(new Date());
relation.setLastUpdatedBy("JUnit");
relationRepository.create(relation);
relation = new RelationEntity();
relation.setFromId(artist2.getId());
relation.setToId(person2.getId());
relation.setType("In real life");
relation.setLastUpdated(new Date());
relation.setLastUpdatedBy("JUnit");
relationRepository.create(relation);
relation = new RelationEntity();
relation.setFromId(artist3.getId());
relation.setToId(artist.getId());
relation.setType("Composer for");
relation.setLastUpdated(new Date());
relation.setLastUpdatedBy("JUnit");
relationRepository.create(relation);
relation = new RelationEntity();
relation.setFromId(artist.getId());
relation.setToId(artist2.getId());
relation.setType("Friend to");
relation.setLastUpdated(new Date());
relation.setLastUpdatedBy("JUnit");
relationRepository.create(relation);
Collection<RelationEntity> relations = relationRepository.findRelationsFrom(SMDIdentityReferenceEntity.forEntity(artist));
assert relations != null;
assert relations .size() == 2;
relations = relationRepository.findRelationsFrom(SMDIdentityReferenceEntity.forEntity(artist), PersonEntity.class);
assert relations != null;
assert relations .size() == 1;
relation = relations.iterator().next();
assert relation != null;
assert relation.getLastUpdated() != null;
assert relation.getLastUpdatedBy() != null;
assert relation.getType().equals("In real life");
SMDIdentityReference fromReference = smdIdentityReferenceRepository.findById(relation.getFromId());
SMDIdentityReference toReference = smdIdentityReferenceRepository.findById(relation.getToId());
assert fromReference.getType().equals(ArtistEntity.class.getName());
assert toReference.getType().equals(PersonEntity.class.getName());
artist = artistRepository.findById(relation.getFromId());
assert artist != null;
assert artist.getName().equals("Whitney Houston");
person = personRepository.findById(relation.getToId());
assert person != null;
assert person.getName().equals("Whitney Elisabeth Houston");
}catch (Exception e) {
em.getTransaction().rollback();