Search in sources :

Example 46 with MongoClient

use of com.mongodb.MongoClient in project spring-data-mongodb by spring-projects.

the class TailableCursorTests method setUp.

@Before
public void setUp() {
    template = new MongoTemplate(new MongoClient(), "tailable-cursor-tests");
    template.dropCollection(User.class);
    template.createCollection(User.class, CollectionOptions.empty().capped().maxDocuments(10000).size(10000));
    container = new DefaultMessageListenerContainer(template, executor);
    container.start();
    jellyBelly = new User();
    jellyBelly.id = "id-1";
    jellyBelly.userName = "jellyBelly";
    jellyBelly.age = 7;
    huffyFluffy = new User();
    huffyFluffy.id = "id-2";
    huffyFluffy.userName = "huffyFluffy";
    huffyFluffy.age = 7;
    sugarSplashy = new User();
    sugarSplashy.id = "id-3";
    sugarSplashy.userName = "sugarSplashy";
    sugarSplashy.age = 5;
}
Also used : MongoClient(com.mongodb.MongoClient) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Before(org.junit.Before)

Example 47 with MongoClient

use of com.mongodb.MongoClient in project spring-data-mongodb by spring-projects.

the class ReactiveFindOperationSupportTests method setUp.

@Before
public void setUp() {
    blocking = new MongoTemplate(new SimpleMongoDbFactory(new MongoClient(), "ExecutableFindOperationSupportTests"));
    blocking.dropCollection(STAR_WARS);
    han = new Person();
    han.firstname = "han";
    han.lastname = "solo";
    han.id = "id-1";
    luke = new Person();
    luke.firstname = "luke";
    luke.lastname = "skywalker";
    luke.id = "id-2";
    blocking.save(han);
    blocking.save(luke);
    template = new ReactiveMongoTemplate(MongoClients.create(), "ExecutableFindOperationSupportTests");
}
Also used : MongoClient(com.mongodb.MongoClient) Before(org.junit.Before)

Example 48 with MongoClient

use of com.mongodb.MongoClient in project spring-data-mongodb by spring-projects.

the class ReactiveRemoveOperationSupportTests method setUp.

@Before
public void setUp() {
    blocking = new MongoTemplate(new SimpleMongoDbFactory(new MongoClient(), "ExecutableRemoveOperationSupportTests"));
    blocking.dropCollection(STAR_WARS);
    han = new Person();
    han.firstname = "han";
    han.id = "id-1";
    luke = new Person();
    luke.firstname = "luke";
    luke.id = "id-2";
    blocking.save(han);
    blocking.save(luke);
    template = new ReactiveMongoTemplate(MongoClients.create(), "ExecutableRemoveOperationSupportTests");
}
Also used : MongoClient(com.mongodb.MongoClient) Before(org.junit.Before)

Example 49 with MongoClient

use of com.mongodb.MongoClient in project spring-data-mongodb by spring-projects.

the class MongoClientParserIntegrationTests method createsMongoClientWithDefaultsCorrectly.

// DATAMONGO-1158
@Test
public void createsMongoClientWithDefaultsCorrectly() {
    reader.loadBeanDefinitions(new ClassPathResource("namespace/mongoClient-bean.xml"));
    AbstractApplicationContext context = new GenericApplicationContext(factory);
    context.refresh();
    try {
        MongoClient client = context.getBean("mongoClient", MongoClient.class);
        assertThat(client.getAddress().getHost(), is("127.0.0.1"));
        assertThat(client.getAddress().getPort(), is(27017));
    } finally {
        context.close();
    }
}
Also used : MongoClient(com.mongodb.MongoClient) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 50 with MongoClient

use of com.mongodb.MongoClient in project spring-data-mongodb by spring-projects.

the class MongoNamespaceReplicaSetTests method testMongoWithReplicaSets.

@Test
@Ignore("CI infrastructure does not yet support replica sets")
public void testMongoWithReplicaSets() {
    MongoClient mongo = ctx.getBean(MongoClient.class);
    assertEquals(2, mongo.getAllAddress().size());
    List<ServerAddress> servers = mongo.getAllAddress();
    assertEquals("127.0.0.1", servers.get(0).getHost());
    assertEquals("localhost", servers.get(1).getHost());
    assertEquals(10001, servers.get(0).getPort());
    assertEquals(10002, servers.get(1).getPort());
    MongoTemplate template = new MongoTemplate(mongo, "admin");
    Document result = template.executeCommand("{replSetGetStatus : 1}");
    assertEquals("blort", result.get("set").toString());
}
Also used : MongoClient(com.mongodb.MongoClient) ServerAddress(com.mongodb.ServerAddress) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Document(org.bson.Document) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

MongoClient (com.mongodb.MongoClient)126 Test (org.junit.Test)31 MongoClientURI (com.mongodb.MongoClientURI)29 Document (org.bson.Document)26 ServerAddress (com.mongodb.ServerAddress)21 MongoDatabase (com.mongodb.client.MongoDatabase)21 Before (org.junit.Before)20 BasicDBObject (com.mongodb.BasicDBObject)11 ArrayList (java.util.ArrayList)11 MongoCredential (com.mongodb.MongoCredential)9 MongoException (com.mongodb.MongoException)8 DB (com.mongodb.DB)7 DBCollection (com.mongodb.DBCollection)7 UnknownHostException (java.net.UnknownHostException)7 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)7 DBObject (com.mongodb.DBObject)6 MongoClientOptions (com.mongodb.MongoClientOptions)6 IOException (java.io.IOException)5 List (java.util.List)5 MongoDbFactory (org.springframework.data.mongodb.MongoDbFactory)5