@Before
  public void setUp() throws Exception {
    // todo cleanup !!
    mappingContext = new Neo4jMappingContext();
    MappingInfrastructure infrastructure = createInfrastructure(mappingContext);

    template = new Neo4jTemplate(infrastructure);
    nodeEntityStateFactory = createNodeEntityStateFactory(mappingContext);
    relationshipEntityStateFactory = createRelationshipEntityStateFactory(mappingContext);
    infrastructure.setNodeEntityStateFactory(nodeEntityStateFactory);
    infrastructure.setRelationshipEntityStateFactory(relationshipEntityStateFactory);
    template.postConstruct();

    entityStateHandler = infrastructure.getEntityStateHandler();

    nodeEntityInstantiator = new NodeEntityInstantiator(entityStateHandler);
    relationshipEntityInstantiator = new RelationshipEntityInstantiator(entityStateHandler);
    nodeTypeMapper =
        new DefaultTypeMapper<Node>(
            new TRSTypeAliasAccessor<Node>(infrastructure.getNodeTypeRepresentationStrategy()),
            asList(new ClassValueTypeInformationMapper()));
    nodeStateTransmitter = new SourceStateTransmitter<Node>(nodeEntityStateFactory);
    relationshipStateTransmitter =
        new SourceStateTransmitter<Relationship>(relationshipEntityStateFactory);
    conversionService = template.getConversionService();

    fetchHandler =
        new Neo4jEntityFetchHandler(
            entityStateHandler,
            conversionService,
            nodeStateTransmitter,
            relationshipStateTransmitter);
    final EntityTools<Node> nodeEntityTools =
        new EntityTools<Node>(
            infrastructure.getNodeTypeRepresentationStrategy(),
            nodeEntityStateFactory,
            nodeEntityInstantiator);
    final EntityTools<Relationship> relationshipEntityTools =
        new EntityTools<Relationship>(
            infrastructure.getRelationshipTypeRepresentationStrategy(),
            relationshipEntityStateFactory,
            relationshipEntityInstantiator);

    entityPersister =
        new Neo4jEntityPersister(
            conversionService,
            nodeEntityTools,
            relationshipEntityTools,
            mappingContext,
            entityStateHandler);

    tx = template.beginTx();
    group = new Group();
    michael = new Person("Michael", 37);
    emil = new Person("Emil", 30);
    andres = new Person("Andrés", 36);
  }
 private MappingInfrastructure createInfrastructure(Neo4jMappingContext mappingContext)
     throws Exception {
   MappingInfrastructure infrastructure = new MappingInfrastructure();
   final GraphDatabaseService gdb = new ImpermanentGraphDatabase();
   infrastructure.setGraphDatabaseService(gdb);
   final DelegatingGraphDatabase graphDatabase = new DelegatingGraphDatabase(gdb);
   infrastructure.setGraphDatabase(graphDatabase);
   infrastructure.setMappingContext(mappingContext);
   final EntityStateHandler entityStateHandler =
       new EntityStateHandler(mappingContext, graphDatabase);
   infrastructure.setNodeTypeRepresentationStrategy(new NoopNodeTypeRepresentationStrategy());
   infrastructure.setRelationshipTypeRepresentationStrategy(
       new NoopRelationshipTypeRepresentationStrategy());
   infrastructure.setConversionService(new Neo4jConversionServiceFactoryBean().getObject());
   infrastructure.setEntityStateHandler(entityStateHandler);
   return infrastructure;
 }