use of com.mongodb.client.MongoClient in project spring-data-mongodb by spring-projects.
the class MongoTestUtils method serverVersion.
/**
* @return the server version extracted from buildInfo.
* @since 3.0
*/
public static Version serverVersion() {
try (MongoClient client = client()) {
MongoDatabase database = client.getDatabase("test");
Document result = database.runCommand(new Document("buildInfo", 1));
return Version.parse(result.get("version", String.class));
} catch (Exception e) {
return ANY;
}
}
use of com.mongodb.client.MongoClient in project rocketmq-externals by apache.
the class ReplicaContextTest method testCreateMongoClient.
@Test
public void testCreateMongoClient() {
MongoClient mongoClient = context.createMongoClient(new ReplicaSetConfig("shardName1", "", "127.0.0.1:27027"));
MongoIterable<String> collectionNames = mongoClient.getDatabase("local").listCollectionNames();
MongoCursor<String> iterator = collectionNames.iterator();
while (iterator.hasNext()) {
Assert.assertTrue(StringUtils.isNoneBlank(iterator.next()));
}
}
use of com.mongodb.client.MongoClient in project iaf by ibissource.
the class MongoDbSenderTest method setUp.
@Override
public void setUp() throws Exception {
String url = "mongodb://" + user + ":" + password + "@" + host;
MongoClient mongoClient = MongoClients.create(url);
mongoClientFactory = new JndiMongoClientFactory();
mongoClientFactory.add(mongoClient, JndiMongoClientFactory.GLOBAL_DEFAULT_DATASOURCE_NAME);
super.setUp();
}
use of com.mongodb.client.MongoClient in project logging-log4j2 by apache.
the class MongoDb4AuthFailureTest method test.
@Test
public void test() {
final Logger logger = LogManager.getLogger();
logger.info("Hello log");
try (final MongoClient mongoClient = mongoDbTestRule.getMongoClient()) {
final MongoDatabase database = mongoClient.getDatabase("testDb");
Assert.assertNotNull(database);
final MongoCollection<Document> collection = database.getCollection("testCollection");
Assert.assertNotNull(collection);
final Document first = collection.find().first();
Assert.assertNull(first);
}
}
use of com.mongodb.client.MongoClient in project logging-log4j2 by apache.
the class MongoDb4MapMessageTest method test.
@Test
public void test() {
final Logger logger = LogManager.getLogger();
final MapMessage<?, Object> mapMessage = new MapMessage<>();
mapMessage.with("SomeName", "SomeValue");
mapMessage.with("SomeInt", 1);
logger.info(mapMessage);
//
try (final MongoClient mongoClient = mongoDbTestRule.getMongoClient()) {
final MongoDatabase database = mongoClient.getDatabase("testDb");
Assert.assertNotNull(database);
final MongoCollection<Document> collection = database.getCollection("testCollection");
Assert.assertNotNull(collection);
final Document first = collection.find().first();
Assert.assertNotNull(first);
final String firstJson = first.toJson();
Assert.assertEquals(firstJson, "SomeValue", first.getString("SomeName"));
Assert.assertEquals(firstJson, Integer.valueOf(1), first.getInteger("SomeInt"));
}
}
Aggregations