Search in sources :

Example 1 with CreateIndexOptions

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");
    });
}
Also used : CreateIndexOptions(com.mongodb.client.model.CreateIndexOptions) DropIndexOptions(com.mongodb.client.model.DropIndexOptions) IndexOptions(com.mongodb.client.model.IndexOptions) CreateIndexOptions(com.mongodb.client.model.CreateIndexOptions) IndexModel(com.mongodb.client.model.IndexModel) Bson(org.bson.conversions.Bson) Test(org.junit.jupiter.api.Test)

Aggregations

CreateIndexOptions (com.mongodb.client.model.CreateIndexOptions)1 DropIndexOptions (com.mongodb.client.model.DropIndexOptions)1 IndexModel (com.mongodb.client.model.IndexModel)1 IndexOptions (com.mongodb.client.model.IndexOptions)1 Bson (org.bson.conversions.Bson)1 Test (org.junit.jupiter.api.Test)1