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 ?