/driver-reactive-streams/src/test/unit/com/mongodb/reactivestreams/client/internal/ListCollectionsPublisherImplTest.java

https://github.com/jyemin/mongo-java-driver · Java · 72 lines · 42 code · 13 blank · 17 comment · 0 complexity · 2692a853b76b96305c65db5e9377792d MD5 · raw file

  1. /*
  2. * Copyright 2008-present MongoDB, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.mongodb.reactivestreams.client.internal;
  17. import com.mongodb.ReadPreference;
  18. import com.mongodb.internal.operation.ListCollectionsOperation;
  19. import com.mongodb.reactivestreams.client.ListCollectionsPublisher;
  20. import org.bson.BsonDocument;
  21. import org.bson.BsonInt32;
  22. import org.bson.Document;
  23. import org.junit.jupiter.api.DisplayName;
  24. import org.junit.jupiter.api.Test;
  25. import reactor.core.publisher.Flux;
  26. import static com.mongodb.reactivestreams.client.MongoClients.getDefaultCodecRegistry;
  27. import static java.util.Arrays.asList;
  28. import static java.util.concurrent.TimeUnit.SECONDS;
  29. import static org.junit.jupiter.api.Assertions.assertEquals;
  30. public class ListCollectionsPublisherImplTest extends TestHelper {
  31. private static final String DATABASE_NAME = NAMESPACE.getDatabaseName();
  32. @DisplayName("Should build the expected ListCollectionsOperation")
  33. @Test
  34. void shouldBuildTheExpectedOperation() {
  35. TestOperationExecutor executor = createOperationExecutor(asList(getBatchCursor(), getBatchCursor()));
  36. ListCollectionsPublisher<String> publisher = new ListCollectionsPublisherImpl<>(null, createMongoOperationPublisher(executor)
  37. .withDocumentClass(String.class), true);
  38. ListCollectionsOperation<String> expectedOperation = new ListCollectionsOperation<>(DATABASE_NAME,
  39. getDefaultCodecRegistry().get(String.class))
  40. .batchSize(Integer.MAX_VALUE)
  41. .nameOnly(true).retryReads(true);
  42. // default input should be as expected
  43. Flux.from(publisher).blockFirst();
  44. assertOperationIsTheSameAs(expectedOperation, executor.getReadOperation());
  45. assertEquals(ReadPreference.primary(), executor.getReadPreference());
  46. // Should apply settings
  47. publisher
  48. .filter(new Document("filter", 1))
  49. .maxTime(10, SECONDS)
  50. .batchSize(100);
  51. expectedOperation
  52. .filter(new BsonDocument("filter", new BsonInt32(1)))
  53. .maxTime(10, SECONDS)
  54. .batchSize(100);
  55. Flux.from(publisher).blockFirst();
  56. assertOperationIsTheSameAs(expectedOperation, executor.getReadOperation());
  57. assertEquals(ReadPreference.primary(), executor.getReadPreference());
  58. }
  59. }