@Test public void unauthorized() { MongoTestClient testClient = new MongoTestClient(MongoUtils.URL) { private final AtomicReference<String> noException = new AtomicReference<>(); @Override public @NotNull MongoDatabase getDatabase(String databaseName) { return new MongoTestDatabase(super.getDatabase(databaseName), noException, noException, noException) { @Override public @NotNull Document runCommand(@NotNull Bson command) { unauthorizedIfServerStatus(command); return super.runCommand(command); } @Override public @NotNull Document runCommand(@NotNull Bson command, @NotNull ReadPreference readPreference) { unauthorizedIfServerStatus(command); return super.runCommand(command, readPreference); } @Override public <TResult> @NotNull TResult runCommand(@NotNull Bson command, @NotNull Class<TResult> tResultClass) { unauthorizedIfServerStatus(command); return super.runCommand(command, tResultClass); } @Override public <TResult> @NotNull TResult runCommand(@NotNull Bson command, @NotNull ReadPreference readPreference, @NotNull Class<TResult> tResultClass) { unauthorizedIfServerStatus(command); return super.runCommand(command, readPreference, tResultClass); } @Override public @NotNull Document runCommand(@NotNull ClientSession clientSession, @NotNull Bson command) { unauthorizedIfServerStatus(command); return super.runCommand(clientSession, command); } @Override public @NotNull Document runCommand(@NotNull ClientSession clientSession, @NotNull Bson command, @NotNull ReadPreference readPreference) { unauthorizedIfServerStatus(command); return super.runCommand(clientSession, command, readPreference); } @Override public <TResult> @NotNull TResult runCommand(@NotNull ClientSession clientSession, @NotNull Bson command, @NotNull Class<TResult> tResultClass) { unauthorizedIfServerStatus(command); return super.runCommand(clientSession, command, tResultClass); } @Override public <TResult> @NotNull TResult runCommand(@NotNull ClientSession clientSession, @NotNull Bson command, @NotNull ReadPreference readPreference, @NotNull Class<TResult> tResultClass) { unauthorizedIfServerStatus(command); return super.runCommand(clientSession, command, readPreference, tResultClass); } }; } private void unauthorizedIfServerStatus(Bson command) { if (command.toBsonDocument(BasicDBObject.class, getDefaultCodecRegistry()).containsKey("serverStatus")) { BsonDocument response = new BsonDocument("ok", new BsonDouble(0.0)); response.put("errmsg", new BsonString("command serverStatus requires authentication")); response.put("code", new BsonInt32(13)); response.put("codeName", new BsonString("Unauthorized")); ServerAddress address = getAddress(); if (address == null) { address = new ServerAddress(); } throw new MongoCommandException(response, address); } } }; MongoStatus status = new MongoStatus(testClient, MongoUtils.DB); assertNotNull(status.getVersion()); }
@NotNull public String getVersion() { if (version == null) { String v = getServerStatus().getString("version"); if (v == null) { v = getBuildInfo().getString("version"); } version = v; } return version; }
MongoStatus implements ServerMonitorListener { @NotNull public String getVersion() { if (version == null) { String v = getServerStatus().getString("version"); if (v == null) { v = getBuildInfo().getString("version"); } version = v; } return version; } }
MongoStatus implements ServerMonitorListener { @NotNull public String getVersion() { if (version == null) { String v = getServerStatus().getString("version"); if (v == null) { v = getBuildInfo().getString("version"); } version = v; } return version; } MongoStatus(@NotNull MongoClient client,
                       @NotNull String dbName); }
MongoStatus implements ServerMonitorListener { @NotNull public String getVersion() { if (version == null) { String v = getServerStatus().getString("version"); if (v == null) { v = getBuildInfo().getString("version"); } version = v; } return version; } MongoStatus(@NotNull MongoClient client,
                       @NotNull String dbName); void checkVersion(); boolean isMajorityReadConcernSupported(); boolean isMajorityReadConcernEnabled(); @NotNull String getServerDetails(); @NotNull String getVersion(); @Override void serverHearbeatStarted(ServerHeartbeatStartedEvent event); @Override void serverHeartbeatSucceeded(ServerHeartbeatSucceededEvent event); @Override void serverHeartbeatFailed(ServerHeartbeatFailedEvent event); }
MongoStatus implements ServerMonitorListener { @NotNull public String getVersion() { if (version == null) { String v = getServerStatus().getString("version"); if (v == null) { v = getBuildInfo().getString("version"); } version = v; } return version; } MongoStatus(@NotNull MongoClient client,
                       @NotNull String dbName); void checkVersion(); boolean isMajorityReadConcernSupported(); boolean isMajorityReadConcernEnabled(); @NotNull String getServerDetails(); @NotNull String getVersion(); @Override void serverHearbeatStarted(ServerHeartbeatStartedEvent event); @Override void serverHeartbeatSucceeded(ServerHeartbeatSucceededEvent event); @Override void serverHeartbeatFailed(ServerHeartbeatFailedEvent event);  }