Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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