Open
Description
spring-projects/spring-data-neo4j#2316 (comment)
reading https://docs.spring.io/spring-data/neo4j/docs/current/reference/html/#dataneo4jtest
and wondering, couldn't this be easier? I mean how often am I going to care about the actual username and password, couldn't I just inject, for example, a Neo4j
and have it configured by default when I use @DataNeo4jTest
depending on what's on the classpath. I don't really see why the sample test should need to do anything other than this (well, it doesn't seem as this is setting up any data, but other than that...)
@DataNeo4jTest
class MovieRepositoryTest {
@Test
public void findSomethingShouldWork(@Autowired Neo4jClient client) {
Optional<Long> result = client.query("MATCH (n) RETURN COUNT(n)")
.fetchAs(Long.class)
.one();
assertThat(result).hasValue(0L);
}
}
to contrast the examples in neo4j to reinforce my ask
@DataJpaTest
class MyRepositoryTests {
@Autowired
private TestEntityManager entityManager;
@Autowired
private UserRepository repository;
@Test
void testExample() throws Exception {
this.entityManager.persist(new User("sboot", "1234"));
User user = this.repository.findByUsername("sboot");
assertThat(user.getUsername()).isEqualTo("sboot");
assertThat(user.getEmployeeNumber()).isEqualTo("1234");
}
}
the data jpa test doesn't require you to spend time in each test configuring the entity manager.