Search in sources :

Example 6 with CollectionHelper

use of com.mongodb.client.test.CollectionHelper in project mongo-java-driver by mongodb.

the class AbstractChangeStreamsTest method setUp.

@Before
public void setUp() {
    assumeFalse(skipTest);
    CollectionHelper.dropDatabase(namespace.getDatabaseName(), WriteConcern.MAJORITY);
    collectionHelper = new CollectionHelper<BsonDocument>(new BsonDocumentCodec(), namespace);
    collectionHelper.drop();
    collectionHelper.create();
    if (namespace2 != null) {
        CollectionHelper.dropDatabase(namespace2.getDatabaseName(), WriteConcern.MAJORITY);
        CollectionHelper<BsonDocument> collectionHelper2 = new CollectionHelper<BsonDocument>(new BsonDocumentCodec(), namespace2);
        collectionHelper2.drop();
        collectionHelper2.create();
    }
    if (definition.containsKey("failPoint")) {
        collectionHelper.runAdminCommand(definition.getDocument("failPoint"));
    }
    commandListener = new TestCommandListener();
    mongoClient = createMongoClient(getMongoClientSettingsBuilder().addCommandListener(commandListener).build());
}
Also used : BsonDocument(org.bson.BsonDocument) TestCommandListener(com.mongodb.internal.connection.TestCommandListener) CollectionHelper(com.mongodb.client.test.CollectionHelper) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) Before(org.junit.Before)

Example 7 with CollectionHelper

use of com.mongodb.client.test.CollectionHelper in project mongo-java-driver by mongodb.

the class UnifiedTest method addInitialData.

private void addInitialData() {
    for (BsonValue cur : initialData.getValues()) {
        BsonDocument curDataSet = cur.asDocument();
        CollectionHelper<BsonDocument> helper = new CollectionHelper<>(new BsonDocumentCodec(), new MongoNamespace(curDataSet.getString("databaseName").getValue(), curDataSet.getString("collectionName").getValue()));
        helper.create(WriteConcern.MAJORITY);
        BsonArray documentsArray = curDataSet.getArray("documents", new BsonArray());
        if (!documentsArray.isEmpty()) {
            helper.insertDocuments(documentsArray.stream().map(BsonValue::asDocument).collect(toList()), WriteConcern.MAJORITY);
        }
    }
}
Also used : BsonDocument(org.bson.BsonDocument) BsonArray(org.bson.BsonArray) CollectionHelper(com.mongodb.client.test.CollectionHelper) MongoNamespace(com.mongodb.MongoNamespace) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) BsonValue(org.bson.BsonValue)

Example 8 with CollectionHelper

use of com.mongodb.client.test.CollectionHelper in project mongo-java-driver by mongodb.

the class ClientSideEncryptionSessionTest method setUp.

@Before
public void setUp() throws IOException, URISyntaxException {
    assumeTrue(serverVersionAtLeast(4, 2));
    assumeTrue(isClientSideEncryptionTest());
    assumeFalse(isStandalone());
    /* Step 1: get unencrypted client and recreate keys collection */
    client = getMongoClient();
    MongoDatabase keyvaultDatabase = client.getDatabase("keyvault");
    MongoCollection<BsonDocument> datakeys = keyvaultDatabase.getCollection("datakeys", BsonDocument.class).withWriteConcern(WriteConcern.MAJORITY);
    datakeys.drop();
    datakeys.insertOne(bsonDocumentFromPath("external-key.json"));
    /* Step 2: create encryption objects. */
    Map<String, Map<String, Object>> kmsProviders = new HashMap<>();
    Map<String, Object> localMasterkey = new HashMap<>();
    Map<String, BsonDocument> schemaMap = new HashMap<>();
    byte[] localMasterkeyBytes = Base64.getDecoder().decode("Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBM" + "UN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk");
    localMasterkey.put("key", localMasterkeyBytes);
    kmsProviders.put("local", localMasterkey);
    schemaMap.put(getDefaultDatabaseName() + "." + COLLECTION_NAME, bsonDocumentFromPath("external-schema.json"));
    AutoEncryptionSettings autoEncryptionSettings = AutoEncryptionSettings.builder().keyVaultNamespace("keyvault.datakeys").kmsProviders(kmsProviders).schemaMap(schemaMap).build();
    MongoClientSettings clientSettings = getMongoClientSettingsBuilder().autoEncryptionSettings(autoEncryptionSettings).build();
    clientEncrypted = MongoClients.create(clientSettings);
    CollectionHelper<BsonDocument> collectionHelper = new CollectionHelper<>(new BsonDocumentCodec(), new MongoNamespace(getDefaultDatabaseName(), COLLECTION_NAME));
    collectionHelper.drop();
    collectionHelper.create();
}
Also used : HashMap(java.util.HashMap) BsonString(org.bson.BsonString) MongoClientSettings(com.mongodb.MongoClientSettings) MongoNamespace(com.mongodb.MongoNamespace) BsonDocument(org.bson.BsonDocument) AutoEncryptionSettings(com.mongodb.AutoEncryptionSettings) CollectionHelper(com.mongodb.client.test.CollectionHelper) HashMap(java.util.HashMap) Map(java.util.Map) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) Before(org.junit.Before)

Aggregations

CollectionHelper (com.mongodb.client.test.CollectionHelper)8 MongoNamespace (com.mongodb.MongoNamespace)7 BsonDocument (org.bson.BsonDocument)7 BsonDocumentCodec (org.bson.codecs.BsonDocumentCodec)6 Before (org.junit.Before)6 MongoClientSettings (com.mongodb.MongoClientSettings)4 DocumentCodec (org.bson.codecs.DocumentCodec)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 BsonString (org.bson.BsonString)3 BsonValue (org.bson.BsonValue)3 Document (org.bson.Document)3 Test (org.junit.Test)3 ClusterFixture.isDataLakeTest (com.mongodb.ClusterFixture.isDataLakeTest)2 ClusterFixture.serverVersionAtLeast (com.mongodb.ClusterFixture.serverVersionAtLeast)2 MongoException (com.mongodb.MongoException)2 WriteConcern (com.mongodb.WriteConcern)2 ConnectionPoolClearedEvent (com.mongodb.event.ConnectionPoolClearedEvent)2 TestConnectionPoolListener (com.mongodb.internal.connection.TestConnectionPoolListener)2 ArrayList (java.util.ArrayList)2