use of com.mongodb.MongoNamespace in project mongo-java-driver by mongodb.
the class AbstractCrudTest method setUp.
@Before
public void setUp() {
assumeFalse(skipTest);
collectionHelper = new CollectionHelper<>(new DocumentCodec(), new MongoNamespace(databaseName, collectionName));
collectionHelper.create(collectionName, new CreateCollectionOptions(), WriteConcern.ACKNOWLEDGED);
createMongoClient(commandListener);
database = getDatabase(databaseName);
collection = database.getCollection(collectionName, BsonDocument.class);
helper = new JsonPoweredCrudTestHelper(description, database, collection);
if (!data.isEmpty()) {
List<BsonDocument> documents = new ArrayList<>();
for (BsonValue document : data) {
documents.add(document.asDocument());
}
if (documents.size() > 0) {
collectionHelper.insertDocuments(documents, WriteConcern.MAJORITY);
}
}
commandListener.reset();
}
use of com.mongodb.MongoNamespace in project mongo-java-driver by mongodb.
the class AbstractUnifiedTest method shouldPassAllOutcomes.
@Test
public void shouldPassAllOutcomes() {
try {
executeOperations(definition.getArray("operations"), false);
} finally {
closeAllSessions();
shutdownAllExecutors();
}
if (definition.containsKey("expectations")) {
List<CommandEvent> expectedEvents = getExpectedEvents(definition.getArray("expectations"), databaseName, null);
List<CommandEvent> events = commandListener.getCommandStartedEvents();
assertTrue("Actual number of events is less than expected number of events", events.size() >= expectedEvents.size());
assertEventsEquality(expectedEvents, events.subList(0, expectedEvents.size()), lsidMap);
}
BsonDocument expectedOutcome = definition.getDocument("outcome", new BsonDocument());
if (expectedOutcome.containsKey("collection")) {
BsonDocument collectionDocument = expectedOutcome.getDocument("collection");
List<BsonDocument> collectionData;
if (collectionDocument.containsKey("name")) {
collectionData = new CollectionHelper<Document>(new DocumentCodec(), new MongoNamespace(databaseName, collectionDocument.getString("name").getValue())).find(new BsonDocumentCodec());
} else {
collectionData = collectionHelper.find(new BsonDocumentCodec());
}
assertEquals(expectedOutcome.getDocument("collection").getArray("data").getValues(), collectionData);
}
}
use of com.mongodb.MongoNamespace in project mongo-java-driver by mongodb.
the class ClientSideEncryptionBypassAutoEncryptionTest method setUp.
@Before
public void setUp() {
assumeTrue(serverVersionAtLeast(4, 2));
MongoClient mongoClient = getMongoClient();
final byte[] localMasterKey = new byte[96];
new SecureRandom().nextBytes(localMasterKey);
Map<String, Map<String, Object>> kmsProviders = new HashMap<String, Map<String, Object>>() {
{
put("local", new HashMap<String, Object>() {
{
put("key", localMasterKey);
}
});
}
};
// Set up the key vault for this example
MongoNamespace keyVaultNamespace = new MongoNamespace("encryption.testKeyVault");
MongoCollection<Document> keyVaultCollection = mongoClient.getDatabase(keyVaultNamespace.getDatabaseName()).getCollection(keyVaultNamespace.getCollectionName());
keyVaultCollection.drop();
// Ensure that two data keys cannot share the same keyAltName.
keyVaultCollection.createIndex(Indexes.ascending("keyAltNames"), new IndexOptions().unique(true).partialFilterExpression(Filters.exists("keyAltNames")));
MongoDatabase db = mongoClient.getDatabase(Fixture.getDefaultDatabaseName());
db.getCollection("test").drop();
// Create the ClientEncryption instance
ClientEncryptionSettings clientEncryptionSettings = ClientEncryptionSettings.builder().keyVaultMongoClientSettings(getMongoClientSettings()).keyVaultNamespace(keyVaultNamespace.getFullName()).kmsProviders(kmsProviders).build();
clientEncryption = ClientEncryptions.create(clientEncryptionSettings);
AutoEncryptionSettings autoEncryptionSettings = AutoEncryptionSettings.builder().keyVaultNamespace(keyVaultNamespace.getFullName()).kmsProviders(kmsProviders).bypassAutoEncryption(true).build();
MongoClientSettings clientSettings = getMongoClientSettingsBuilder().autoEncryptionSettings(autoEncryptionSettings).build();
clientEncrypted = MongoClients.create(clientSettings);
}
use of com.mongodb.MongoNamespace in project mongo-java-driver by mongodb.
the class AbstractChangeStreamsTest method checkStreamValues.
private void checkStreamValues(final BsonDocument result, final MongoCursor<ChangeStreamDocument<BsonDocument>> cursor) {
for (BsonValue success : result.getArray("success", new BsonArray())) {
BsonDocument expected = success.asDocument();
ChangeStreamDocument<BsonDocument> actual = cursor.next();
MongoNamespace expectedNamespace = null;
if (expected.containsKey("ns")) {
BsonDocument nsDocument = expected.getDocument("ns");
expectedNamespace = nsDocument != null ? new MongoNamespace(nsDocument.getString("db").getValue(), nsDocument.getString("coll").getValue()) : null;
}
assertEquals(expectedNamespace, actual.getNamespace());
assertEquals(OperationType.fromString(expected.getString("operationType").getValue()), actual.getOperationType());
if (actual.getFullDocument() != null) {
actual.getFullDocument().remove("_id");
}
assertEquals(expected.get("fullDocument"), actual.getFullDocument());
}
if (result.containsKey("error")) {
BsonDocument error = result.getDocument("error");
try {
cursor.next();
} catch (MongoException e) {
assertTrue(e.getCode() == error.getInt32("code").intValue() || !Collections.disjoint(e.getErrorLabels(), error.getArray("errorLabels", new BsonArray())));
}
}
}
use of com.mongodb.MongoNamespace in project mongo-java-driver by mongodb.
the class AbstractChangeStreamsTest method handleOperations.
private void handleOperations() {
for (BsonValue operations : definition.getArray("operations")) {
BsonDocument op = operations.asDocument();
MongoNamespace opNamespace = new MongoNamespace(op.getString("database").getValue(), op.getString("collection").getValue());
createJsonPoweredCrudTestHelper(Fixture.getMongoClient(), opNamespace).getOperationResults(op);
}
}
Aggregations