Skip to content

Instantly share code, notes, and snippets.

@frant-hartm
Created December 14, 2016 14:48
Show Gist options
  • Save frant-hartm/eb54c6ca346f4c5cee2636a1bbead404 to your computer and use it in GitHub Desktop.
Save frant-hartm/eb54c6ca346f4c5cee2636a1bbead404 to your computer and use it in GitHub Desktop.
SDN 4.2 issue
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {GalaxyContext.class, MyConfig.class})
@Transactional
public class MyTest {
@Autowired
WorldRepository worldRepository;
@Test(expected = DataIntegrityViolationException.class)
public void shouldTrowRollbackException() throws Exception {
worldRepository.save(new World("Tatooine", 0));
worldRepository.save(new World("Tatooine", 0));
}
@Configuration
public static class MyConfig {
@Bean
public SessionFactory sessionFactory() {
org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration();
configuration.driverConfiguration().setDriverClassName(EmbeddedDriver.class.getCanonicalName());
return new SessionFactory(configuration, "org.springframework.data.neo4j.examples.galaxy.domain");
}
@Bean
public Neo4jOperations neo4jOperations() {
Neo4jTemplate neo4jTemplate = new Neo4jTemplate(sessionFactory());
Map<String, Object> map = Collections.emptyMap();
neo4jTemplate.query("CREATE CONSTRAINT ON (w:World) ASSERT w.name IS UNIQUE", map);
return neo4jTemplate;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment