Open zigzago opened 6 years ago
can you try with driver37 branch ?
my tests pass with driver37 branch, thanks! It would be nice to have a first fongo release for 3.7 :)
@hoffrocket any plans about merging his PR or supporting 3.7 in general?
There are other issues adressing the same topic: https://github.com/fakemongo/fongo/issues/357
@twillouer any news about supporting mongodb driver 3.7+?
I am also facing this issue that prevents me from upgrading to Spring Boot 2.1.0.
I tried to test using the driver37
branch, but I could not build it with Maven. I get the following output:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Erreur : impossible de trouver ou charger la classe principale org.apache.maven.surefire.booter.ForkedBooter
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
The error message is in french, it tells that it was impossible to find the main class org.apache.maven.surefire.booter.ForkedBooter
.
I would have used the manually built jar as a workaround until the new Fongo release is published on the Maven Central repository, but this error prevents me from testing this workaround.
Same issue for me on Spring Boot 2.1.0 mongo db driver 3.8.2 and Java 8. I am on the "fongo-2.2.0-RC2" release.
Caused by: java.lang.NoClassDefFoundError: com/mongodb/OperationExecutor at com.github.fakemongo.Fongo.createMongo(Fongo.java:190)
I finally could build the driver37
branch thanks to the -DskipTests=true
Maven option š.
I tested it with Spring Boot 2.1.0 (driver 3.8.2) and it does not work. I get this error:
java.lang.AbstractMethodError: com.mongodb.client.internal.FongoOperationExecutor.execute(Lcom/mongodb/operation/ReadOperation;Lcom/mongodb/ReadPreference;Lcom/mongodb/ReadConcern;)Ljava/lang/Object;
at com.mongodb.DBCursor.initializeCursor(DBCursor.java:896)
at com.mongodb.DBCursor.hasNext(DBCursor.java:148)
at com.mongodb.DBCursor.one(DBCursor.java:697)
at com.mongodb.DBCollection.findOne(DBCollection.java:845)
at com.mongodb.DBCollection.findOne(DBCollection.java:805)
at com.mongodb.DBCollection.findOne(DBCollection.java:748)
at com.mongodb.FongoDBCollection.createIndex(FongoDBCollection.java:522)
at com.mongodb.FongoDBCollection.<init>(FongoDBCollection.java:93)
at com.mongodb.FongoDB.doGetCollection(FongoDB.java:96)
at com.mongodb.FongoDB.doGetCollection(FongoDB.java:87)
at com.mongodb.FongoDB.getCollection(FongoDB.java:82)
at com.mongodb.client.internal.FongoMongoCollection.<init>(FongoMongoCollection.java:32)
at com.mongodb.client.internal.FongoMongoDatabase.getCollection(FongoMongoDatabase.java:51)
It sounds like the driver 3.8 is different from the 3.7 one.
Same here: Caused by: java.lang.NoClassDefFoundError: com/mongodb/OperationExecutor at com.github.fakemongo.Fongo.createMongo(Fongo.java:190)
Java: 11 Spring Boot: 2.1.0.RELEASE Fongo: 2.2.0-RC2 mongodb-driver: 3.8.2
You should give a try to mongo-java-server.
I tried it recently, I encountered two blocking issues (features not yet implemented), I reported them and they were fixed very quickly. All my tests are now running with Spring Boot 2.1.0. š
Thx @bsautel - works like a charm! :+1:
A short How-To for those, running into same Problem Java Runtime: 11 Syntax: Kotlin (its easy to translate to Java with IntelliJ) Spring Boot: 2.1.0.RELEASE mongo-java-server: 1.9.7 mongodb-driver: 3.8.2
Replace "fongo" with "mongo-java-server" in your pom.xml, gradle whatever
<dependency>
<groupId>de.bwaldvogel</groupId>
<artifactId>mongo-java-server</artifactId>
<version>1.9.7</version>
<scope>test</scope>
</dependency>
Add Spring Boot Configuration
@EnableAutoConfiguration(exclude = [EmbeddedMongoAutoConfiguration::class, MongoAutoConfiguration::class, MongoDataAutoConfiguration::class, SecurityAutoConfiguration::class])
@EnableMongoRepositories(basePackages = ["my.project.repositories"])
@Configuration
@ComponentScan(basePackages = ["my.project"],
excludeFilters = [ComponentScan.Filter(classes = [SpringBootApplication::class])])
class InMemoryMongoDbConfiguration : AbstractMongoConfiguration(){
lateinit var client: MongoClient
lateinit var server: MongoServer
@Bean
fun userCascadingMongoEventListener(): CascadeSaveMongoEventListener {
return CascadeSaveMongoEventListener()
}
@Throws(Exception::class)
override fun mongoClient(): MongoClient {
server = MongoServer(MemoryBackend())
// bind on a random local port
val serverAddress = server.bind()
client = MongoClient(ServerAddress(serverAddress))
return client
}
override fun getDatabaseName(): String {
return "test"
}
@PreDestroy
fun shutdown(){
client.close()
server.shutdown()
}
}
Make a Test
@RunWith(SpringRunner::class)
@SpringBootTest(
classes = [InMemoryMongoDbConfiguration::class],
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class ApplicationsTest {
@Autowired
lateinit var testRestTemplate: TestRestTemplate
@Test
fun whenCalled_thenShouldReturnApplications() {
val _prj_base = Utils.createBasicProjectFull(UUID.randomUUID().toString())
val p = testRestTemplate.withBasicAuth("admin", "admin").postForEntity("/api/v1/projects", _prj_base, Project::class.java).body
val req = testRestTemplate.withBasicAuth("admin", "admin").getForEntity("/api/v1/projects/${p._id}", Project::class.java)
assertNotNull(req)
assertEquals(HttpStatus.OK, req?.statusCode)
Utils.assertIgnoreIdAndCreatedOn(p, req.body!!, true)
assertEquals(setOf<Application>(), req.body!!.applications.toSet())
}
}
Keep smiling! :)
Nice @leantrace , thanks for sharing the replacement example!
I just noticed noticed that you don't close the server in your InMemoryMongoDbConfiguration
(server.shutdown()
as explained in the project documentation) when the application context is destroyed. This may lead to resource leaks in your tests execution. It's not a big deal if the tests run in a dedicated JVM that stops at the ends of tests execution but it is better to free it anyway.
@leantrace @bsautel: Iām happy to hear that mongo-java-server works for you.
The Spring Boot configuration example could be something to include in the README. Do you want to submit a pull request?
Hi,
Not sure if I should double-post it or not, but you might be interested in that other comment of mine for a solution to have fongo working with mongo 3.8 : https://github.com/fakemongo/fongo/issues/357#issuecomment-458034953
MongoOperation, MongoDatabaseImpl, MongoCollectionImpl, etc. have moved to com.mongodb.client.internal package...