spring-projects / spring-projects/spring-boot

Allow @DataNeo4jTest to autoconfigure an embedded test instance

Open
#27,151 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type: enhancement
Dominant language
Java
Stars
81.5k
Forks
42.7k
Avg merge
2d 4h
Merged PRs (30d)
65

Description

https://github.com/spring-projects/spring-data-neo4j/issues/2316#issuecomment-873918857

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the linked @DataNeo4jTest reference documentation and the referenced Spring Data Neo4j issue comment. Define done as a @DataNeo4jTest test being able to autowire Neo4jClient with an embedded test instance selected from the classpath, without per-test username or password configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
databases, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.