Hi,
I've been struggling with trying to build a unit test that will test a repository that I've built in the application (which is working fine). Currently I have a single class (UserRepositoryTest) with a single test method. I also have a configuration file where I create SessionFactory with the embedded driver.
The error I'm getting is this:
Caused by: java.lang.AbstractMethodError: Method org/neo4j/ogm/drivers/embedded/driver/EmbeddedDriver.newTransaction(Lorg/neo4j/ogm/transaction/Transaction$Type;Ljava/lang/Iterable;)Lorg/neo4j/ogm/transaction/Transaction; is abstract
at org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver.newTransaction(EmbeddedDriver.java)
at org.neo4j.ogm.session.transaction.DefaultTransactionManager.openTransaction(DefaultTransactionManager.java:68)
at org.neo4j.ogm.session.Neo4jSession.beginTransaction(Neo4jSession.java:524)
at org.springframework.data.neo4j.transaction.Neo4jTransactionManager.doBegin(Neo4jTransactionManager.java:179)
The test code is:
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {TestConfiguration.class})
@DataNeo4jTest
@EnableTransactionManagement
public class UserRepositoryTest {
@Autowired
private UserRepository userRepository;
@Autowired
private SessionFactory sessionFactory;
Session session;
List<UserEntity> users = new ArrayList<UserEntity>();
@Before
public void setUp() {
users.add(createNewUserEntity(222222, "Moti Ben-Yosef", "moti.ben-yosef", "moti.ben-yosef@company.com"));
users.add(createNewUserEntity(222223, "David Ben-Gurion", "david.ben-gurion", "david.ben-gurion@company.com"));
users.add(createNewUserEntity(222224, "Golan Eyal", "golan.eyal", "golan.eyal@company.com"));
users.add(createNewUserEntity(222225, "Moshe Haim", "moshe.haim", "moshe.haim@company.com"));
users.add(createNewUserEntity(222226, "Haim Yavin", "haim.yavin", "haim.yavin@company.com"));
session = sessionFactory.openSession();
session.query("match (u:User) where u.Id >= 222222 and u.Id <= 222226 detach delete(u)", new HashMap<String, Object>() );
for (UserEntity u : users) {
session.save(u);
}
}
private UserEntity createNewUserEntity(long id, String name, String username, String email) {
UserEntity u = new UserEntity();
u.setUserId(id);
u.setName(name);
u.setUsername(username);
u.setEmail(email);
return u;
}
/**
* Test of findByTitle method, of class UserRepository.
*/
@Test
public void testFindUserById() {
for (UserEntity u : users) {
Optional<UserEntity> result = userRepository.findById(u.getUserId());
Assert.assertNotNull("result = null", result);
Assert.assertTrue("No User returned", result.isPresent());
UserEntity user = result.get();
Assert.assertEquals("name mismatch", u.getName(), user.getName());
}
}
}
The configuration code is:
@Configuration
@EnableNeo4jRepositories(basePackages = "com.company.someservice.repository")
@EnableTransactionManagement
public class TestConfiguration {
@Bean
public SessionFactory sessionFactory() {
EmbeddedDriver driver = new EmbeddedDriver(graphDatabaseService());
return new SessionFactory(driver, "com.company.someservice.domain");
}
@Bean
public PlatformTransactionManager transactionManager() {
return new Neo4jTransactionManager(sessionFactory());
}
@Bean
public GraphDatabaseService graphDatabaseService() {
return new GraphDatabaseFactory().newEmbeddedDatabase(new File("test_graph.db"));
}
}
Any help would be greatly appreciated!
Thanks!