Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<url>http://github.com/NoEnv/vertx-wiremongo</url>

<properties>
<stack.version>5.1.9-SNAPSHOT</stack.version>
<stack.version>5.2.0</stack.version>
</properties>

<dependencyManagement>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/noenv/wiremongo/WireMongoClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.noenv.wiremongo.command.Command;
import com.noenv.wiremongo.command.CountCommand;
import com.noenv.wiremongo.command.CountWithOptionsCommand;
import com.noenv.wiremongo.command.PingCommand;
import com.noenv.wiremongo.command.RunCommandCommand;
import com.noenv.wiremongo.command.aggregate.AggregateBaseCommand;
import com.noenv.wiremongo.command.aggregate.AggregateWithOptionsCommand;
Expand Down Expand Up @@ -275,6 +276,11 @@ public Future<JsonObject> runCommand(String commandName, JsonObject command) {
return call(new RunCommandCommand(commandName, command));
}

@Override
public Future<@Nullable JsonObject> ping() {
return call(new PingCommand());
}

@Override
public Future<JsonArray> distinct(String collection, String fieldName, String resultClassname) {
return call(new DistinctCommand(collection, fieldName, resultClassname));
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/noenv/wiremongo/WireMongoCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ default RunCommand runCommand() {
return addMapping(new RunCommand());
}

default Ping ping() {
return addMapping(new Ping());
}

default Aggregate aggregate() {
return addMapping(new Aggregate());
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/noenv/wiremongo/command/PingCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.noenv.wiremongo.command;

public class PingCommand extends CommandBase {
public PingCommand() {
super("ping");
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/noenv/wiremongo/mapping/Mapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ static Mapping create(JsonObject json) {
return new CreateIndexWithOptions(json);
case "runCommand":
return new RunCommand(json);
case "ping":
return new Ping(json);
case "count":
return new Count(json);
case "countWithOptions":
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/noenv/wiremongo/mapping/Ping.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.noenv.wiremongo.mapping;

import com.noenv.wiremongo.command.PingCommand;
import io.vertx.core.json.JsonObject;

public class Ping extends MappingBase<JsonObject, PingCommand, Ping> {

public Ping() {
super("ping");
}

public Ping(JsonObject json) {
super(json);
}

@Override
public Ping returns(final JsonObject response) {
return stub(c -> null == response ? null : response.copy());
}

@Override
protected JsonObject parseResponse(Object jsonValue) {
return (JsonObject) jsonValue;
}
}
65 changes: 65 additions & 0 deletions src/test/java/com/noenv/wiremongo/mapping/PingTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.noenv.wiremongo.mapping;

import com.noenv.wiremongo.TestBase;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import io.vertx.rxjava3.CompletableHelper;
import io.vertx.rxjava3.MaybeHelper;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(VertxUnitRunner.class)
public class PingTest extends TestBase {

@Test
public void testPing(TestContext ctx) {
Mapping<?, ?, ?> m = mock.ping()
.returns(new JsonObject().put("ok", 1));

db.rxPing()
.subscribe(MaybeHelper.toObserver(ctx.asyncAssertSuccess(r -> {
ctx.assertEquals(1, r.getInteger("ok"));
mock.removeMapping(m);
})));
}

@Test
public void testPingError(TestContext ctx) {
Mapping<?, ?, ?> m = mock.ping()
.returnsError(new Exception("intentional"));

db.rxPing()
.doOnError(assertIntentionalError(ctx, "intentional"))
.subscribe(MaybeHelper.toObserver(ctx.asyncAssertFailure(ex -> mock.removeMapping(m))));
}

@Test
public void testPingReturnedObjectNotModified(TestContext ctx) {
final JsonObject given = new JsonObject().put("ok", 1).put("field", "value");
final JsonObject expected = given.copy();

Mapping<?, ?, ?> m = mock.ping().returns(given);

db.rxPing()
.doOnSuccess(actual -> ctx.assertEquals(expected, actual))
.doOnSuccess(actual -> {
actual.put("ok", "replace");
actual.remove("field");
actual.put("add", "add");
})
.repeat(2)
.ignoreElements()
.subscribe(CompletableHelper.toObserver(ctx.asyncAssertSuccess(v -> mock.removeMapping(m))));
}

@Test
public void testPingMappingFromJson(TestContext ctx) {
Mapping<?, ?, ?> m = Mapping.create(new JsonObject()
.put("method", "ping")
.put("response", new JsonObject().put("ok", 1)));

ctx.assertTrue(m instanceof Ping);
ctx.assertEquals("ping", ((Ping) m).method());
}
}