-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support authorizedCollections
option for listCollections
helpers
#1270
Conversation
import org.mockito.kotlin.verify | ||
import org.mockito.kotlin.verifyNoMoreInteractions | ||
|
||
class ListCollectionNamesFlowTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is based on com.mongodb.kotlin.client.coroutine.ListCollectionsFlowTest
.
import org.bson.BsonValue | ||
import org.bson.conversions.Bson | ||
|
||
data class SyncListCollectionNamesIterable(val wrapped: ListCollectionNamesFlow) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is based on com.mongodb.kotlin.client.coroutine.syncadapter.SyncListCollectionsIterable
.
* | ||
* @see [List collections](https://www.mongodb.com/docs/manual/reference/command/listCollections/) | ||
*/ | ||
public class ListCollectionNamesFlow(private val wrapped: ListCollectionNamesPublisher) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is based on com.mongodb.kotlin.client.coroutine.ListCollectionsFlow
.
import org.bson.BsonValue | ||
import org.bson.conversions.Bson | ||
|
||
internal class SyncListCollectionNamesIterable(val wrapped: ListCollectionNamesIterable) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is based on com.mongodb.kotlin.client.syncadapter.SyncListCollectionsIterable
.
* | ||
* @see [List collections](https://www.mongodb.com/docs/manual/reference/command/listCollections/) | ||
*/ | ||
public class ListCollectionNamesIterable(private val wrapped: JListCollectionNamesIterable) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is based on com.mongodb.kotlin.client.ListCollectionsIterable
.
import org.mockito.kotlin.verify | ||
import org.mockito.kotlin.verifyNoMoreInteractions | ||
|
||
class ListCollectionNamesIterableTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is based on com.mongodb.kotlin.client.ListCollectionsIterableTest
.
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
final class SyncListCollectionNamesIterable extends SyncMongoIterable<String> implements ListCollectionNamesIterable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is based on com.mongodb.reactivestreams.client.syncadapter.SyncListCollectionsIterable
.
import static com.mongodb.reactivestreams.client.MongoFixture.PUBLISHER_REFERENCE_CLEANUP_TIMEOUT_MILLIS; | ||
import static com.mongodb.reactivestreams.client.MongoFixture.run; | ||
|
||
public class ListCollectionNamesPublisherVerification extends PublisherVerification<String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is based on com.mongodb.reactivestreams.client.ListCollectionsPublisherVerification
.
* @param wrapped the underlying java ListCollectionNamesPublisher | ||
* @since 5.0 | ||
*/ | ||
case class ListCollectionNamesObservable(wrapped: ListCollectionNamesPublisher) extends Observable[String] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is based on org.mongodb.scala.ListCollectionsObservable
.
import java.util.concurrent.TimeUnit | ||
import scala.concurrent.duration.Duration | ||
|
||
class ListCollectionNamesObservableSpec extends BaseSpec with MockitoSugar { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is based on org.mongodb.scala.ListCollectionsObservableSpec
.
72a7033
to
619a974
Compare
import static java.util.concurrent.TimeUnit.SECONDS; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
final class ListCollectionNamesPublisherImplTest extends TestHelper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is based on com.mongodb.reactivestreams.client.internal.ListCollectionsPublisherImplTest
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Started with a review of the API, will proceed with the implementation after initial comments are resolved.
driver-sync/src/main/com/mongodb/client/CommonListCollectionsIterable.java
Outdated
Show resolved
Hide resolved
driver-sync/src/main/com/mongodb/client/ListCollectionsIterable.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting on the unit test we discussed. Otherwise LGTM.
@@ -206,6 +226,7 @@ private BsonDocument getCommand() { | |||
if (nameOnly) { | |||
command.append("nameOnly", BsonBoolean.TRUE); | |||
} | |||
putIfTrue(command, "authorizedCollections", authorizedCollections); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, add a unit test for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
The added ListCollectionsOperationTest
tests the public method ListCollectionsOperation.execute
instead of testing the (currently private) method getCommand
. This way it covers more of ListCollectionsOperation
. Since mocking is needed for this, I introduced MongoMockito.mock
(see its documentation for the detailed explanation and links to demo tests). I demonstrated it to @vbabanin and @rozza, and my understanding was that they liked this improvement over Mockito.mock
.
@Test | ||
void stubbingWithInsufficientStubbingDetector() { | ||
MongoMockito.mock(ReadBinding.class, bindingMock -> | ||
when(bindingMock.getOperationContext()).thenReturn(new OperationContext()) | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason, unused Mockito stubbing is not reported when we run tests (ideally, stubbingWithInsufficientStubbingDetector
must fail with UnnecessaryStubbingException
because the test never calls getOperationContext
). This has nothing to do with MongoMockito
, as I tried the same with Mockito
, and nothing was reported there either. Even calling Mockito.validateMockitoUsage
didn't help. If someone has any ideas, please comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the juniper extension and 💥
@ExtendWith(MockitoExtension.class)
final class InsufficientStubbingDetectorDemoTest {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, thank you! After looking at MockitoExtension
's code, I discovered that the following manually written code also enables validation:
private MockitoSession session;
@BeforeEach
void beforeEach() {
session = Mockito.mockitoSession().startMocking();
}
@AfterEach
void afterEach() {
session.finishMocking();
}
finishMocking
calls Mockito.validateMockitoUsage
, but only after notifying Mockito.framework()
that a test has finished via UniversalTestListener.testFinished
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, actually, it's the UniversalTestListener.testFinished
that checks unused stubbing, not Mockito.validateMockitoUsage
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
driver-core/src/test/unit/com/mongodb/internal/operation/ListCollectionsOperationTest.java
Show resolved
Hide resolved
driver-core/src/test/unit/com/mongodb/internal/mockito/MongoMockito.java
Outdated
Show resolved
Hide resolved
driver-core/src/test/unit/com/mongodb/internal/mockito/InsufficientStubbingDetector.java
Show resolved
Hide resolved
JAVA-4353
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
This is the 3rd incarnation of the PR. The previous are (from younger to older): #1263, #855 (the original one).
API changes
MongoDatabase.listCollectionNames
Changed the return type of a method. The change preserves source-code compatibility (existing source code that uses the changed methods does not have to be changed), breaks binary compatibility (existing source code that uses the changed methods has to be recompiled against the updated driver dependency).
com.mongodb.client
MongoDatabase
listCollectionNames
MongoIterable
ListCollectionNamesIterable
com.mongodb.reactivestreams.client
MongoDatabase
listCollectionNames
Publisher
ListCollectionNamesPublisher
org.mongodb.scala
MongoDatabase
listCollectionNames
Observable
ListCollectionNamesObservable
com.mongodb.kotlin.client
MongoDatabase
listCollectionNames
MongoIterable
ListCollectionNamesIterable
com.mongodb.kotlin.client.coroutine
MongoDatabase
listCollectionNames
Flow
ListCollectionNamesFlow
authorizedCollections
Added classes/interfaces with a new method
authorizedCollections
.com.mongodb.client
ListCollectionsIterable
ListCollectionNamesIterable
com.mongodb.reactivestreams.client
ListCollectionsPublisher
ListCollectionNamesPublisher
org.mongodb.scala
ListCollectionsObservable
ListCollectionNamesObservable
com.mongodb.kotlin.client
ListCollectionsIterable
ListCollectionNamesIterable
com.mongodb.kotlin.client.coroutine
ListCollectionsFlow
ListCollectionNamesFlow
JAVA-4353