use of com.mongodb.client.model.CreateIndexOptions in project mongo-java-driver by mongodb.
the class MongoCollectionImplTest method testCreateIndexes.
@Test
public void testCreateIndexes() {
Bson key = BsonDocument.parse("{key: 1}");
CreateIndexOptions createIndexOptions = new CreateIndexOptions();
CreateIndexOptions customCreateIndexOptions = new CreateIndexOptions().commitQuorum(CreateIndexCommitQuorum.VOTING_MEMBERS);
List<IndexModel> indexes = singletonList(new IndexModel(key, new IndexOptions().background(true).bits(9)));
assertAll("createIndexes", () -> assertAll("check validation", () -> assertThrows(IllegalArgumentException.class, () -> collection.createIndexes(null)), () -> assertThrows(IllegalArgumentException.class, () -> collection.createIndexes(indexes, null)), () -> assertThrows(IllegalArgumentException.class, () -> collection.createIndexes(clientSession, null)), () -> assertThrows(IllegalArgumentException.class, () -> collection.createIndexes(clientSession, indexes, null)), () -> assertThrows(IllegalArgumentException.class, () -> collection.createIndexes(null, indexes)), () -> assertThrows(IllegalArgumentException.class, () -> collection.createIndexes(null, indexes, createIndexOptions))), () -> {
Publisher<String> expected = mongoOperationPublisher.createIndexes(null, indexes, createIndexOptions);
assertPublisherIsTheSameAs(expected, collection.createIndexes(indexes), "Default");
}, () -> {
Publisher<String> expected = mongoOperationPublisher.createIndexes(null, indexes, customCreateIndexOptions);
assertPublisherIsTheSameAs(expected, collection.createIndexes(indexes, customCreateIndexOptions), "With custom options");
}, () -> {
Publisher<String> expected = mongoOperationPublisher.createIndexes(clientSession, indexes, createIndexOptions);
assertPublisherIsTheSameAs(expected, collection.createIndexes(clientSession, indexes), "With client session");
}, () -> {
Publisher<String> expected = mongoOperationPublisher.createIndexes(clientSession, indexes, customCreateIndexOptions);
assertPublisherIsTheSameAs(expected, collection.createIndexes(clientSession, indexes, customCreateIndexOptions), "With client session, & custom options");
});
}
Aggregations