0

I have spring app which uses mongoRepository. I want to have an integration to test my repository by using @DataMongoTest. For some reason my test tries to connect localhost for mongo and gets timeout. I am using this as a dependency:

<dependency>
  <groupId>de.flapdoodle.embed</groupId>
  <artifactId>de.flapdoodle.embed.mongo</artifactId>
  <scope>test</scope>
</dependency>

org.springframework.dao.DataAccessResourceFailureException: Timed out while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused}}]

My test is as below:

@DataMongoTest
class MarketRepositorySpecIT extends Specification {

    @Autowired
    EmployeeRepository myRepository

    def "findByIdWillReturnData"() {
        given:
        def data = testData()
        myRepository.save(data)

        when:
        def result = myRepository.findById("id", EmployeeDocument.class)

        then:
        result.isPresent()
    }

and the repository is :

@Repository
public interface EmployeeRepository extends MongoRepository<EmployeeDocument, String> {}

Why it tries to connect mongoDb in localhost instead of using embedded mongo db ?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.