Search in sources :

Example 36 with MongoClient

use of com.mongodb.MongoClient in project java-design-patterns by iluwatar.

the class MongoTicketRepositoryTest method init.

@BeforeEach
public void init() {
    MongoConnectionPropertiesLoader.load();
    MongoClient mongoClient = new MongoClient(System.getProperty("mongo-host"), Integer.parseInt(System.getProperty("mongo-port")));
    mongoClient.dropDatabase(TEST_DB);
    mongoClient.close();
    repository = new MongoTicketRepository(TEST_DB, TEST_TICKETS_COLLECTION, TEST_COUNTERS_COLLECTION);
}
Also used : MongoClient(com.mongodb.MongoClient) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 37 with MongoClient

use of com.mongodb.MongoClient in project java-design-patterns by iluwatar.

the class MongoEventLogTest method init.

@BeforeEach
public void init() {
    MongoConnectionPropertiesLoader.load();
    MongoClient mongoClient = new MongoClient(System.getProperty("mongo-host"), Integer.parseInt(System.getProperty("mongo-port")));
    mongoClient.dropDatabase(TEST_DB);
    mongoClient.close();
    mongoEventLog = new MongoEventLog(TEST_DB, TEST_EVENTS_COLLECTION);
}
Also used : MongoClient(com.mongodb.MongoClient) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 38 with MongoClient

use of com.mongodb.MongoClient in project java-design-patterns by iluwatar.

the class DbManager method connect.

/**
 * Connect to DB
 */
public static void connect() throws ParseException {
    useMongoDB = true;
    mongoClient = new MongoClient();
    db = mongoClient.getDatabase("test");
}
Also used : MongoClient(com.mongodb.MongoClient)

Example 39 with MongoClient

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

the class ExecutableRemoveOperationSupportTests method setUp.

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

Example 40 with MongoClient

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

the class ExecutableUpdateOperationSupportTests method setUp.

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

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