All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.elsci.signals.mock.mongo.MongoContext Maven / Gradle / Ivy

There is a newer version: 20231025.1145-36
Show newest version
package io.elsci.signals.mock.mongo;

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * In Signals API there's search which is based on MongoDB queries. It was too hard to write a mock for that with
 * in-memory collections. So had to start a real Mongo.
 */
@Configuration
public class MongoContext {
    /**
     * @param mongoUri - should be in the form {@code mongodb://user:password@host:port/}
     */
    @Bean(destroyMethod = "close")
    MongoClient mongoClient(@Value("${mongo.url}") String mongoUri) {
        // Bean is overriden in tests as they have to rely on TestContainers which generate the port dynamically.
        return MongoClients.create(mongoUri);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy