I've been trying to create an embedded Mongodb database for the test, so far I wasn't able to make it work.
I've looked at https://github.com/quarkusio/quarkus/tree/main/test-framework/mongodb
I've also read this https://quarkus.io/guides/getting-started-testing#quarkus-test-resource but it doesn't seem updated
EDIT1:
application.properties (in my test package)
quarkus.mongodb.connection-string=${MONGO_URI:mongodb://localhost:19345/db-test}`
When I run my test I get the following error: Cluster description not yet available. Waiting for 30000 ms before timing out and then Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:19345, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]
EDIT2:
application.properties
%prod.quarkus.mongodb.connection-string=...
%prod.quarkus.mongodb.database=prod-db
test
@QuarkusTest
@TestMethodOrder(MethodOrderer.OrderAnnotation::class)
class ControllerTest {
@Inject lateinit var accountRepository: MockAccountRepository
@Test
@Order(1)
fun `badRequest`() {
given()
.`when`().get(endPoint)
.then()
.assertThat().statusCode(HttpResponseStatus.BAD_REQUEST.code())
}
}
MockAccount
@Mock
@ApplicationScoped
class MockAccountRepository(mongoClient: MongoClient) {
private val collection = mongoClient.getDatabase("db-test")
.getCollection("account", MockAccount::class.java)
....
}