com.noenv.wiremongo.mapping.RunCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vertx-wiremongo Show documentation
Show all versions of vertx-wiremongo Show documentation
Lightweight mongo mocking for Vert.x
package com.noenv.wiremongo.mapping;
import com.noenv.wiremongo.command.Command;
import com.noenv.wiremongo.command.RunCommandCommand;
import com.noenv.wiremongo.matching.Matcher;
import io.vertx.core.json.JsonObject;
import static com.noenv.wiremongo.matching.EqualsMatcher.equalTo;
public class RunCommand extends MappingBase {
private Matcher commandName;
private Matcher command;
public RunCommand() {
super("runCommand");
}
public RunCommand(JsonObject json) {
super(json);
commandName = Matcher.create(json.getJsonObject("commandName"));
command = Matcher.create(json.getJsonObject("command"));
}
@Override
public RunCommand returns(final JsonObject response) {
return stub(c -> null == response ? null : response.copy());
}
@Override
protected JsonObject parseResponse(Object jsonValue) {
return (JsonObject) jsonValue;
}
@Override
public boolean matches(Command cmd) {
if (!(cmd instanceof RunCommandCommand)) {
return false;
}
RunCommandCommand c = (RunCommandCommand) cmd;
return (commandName == null || commandName.matches(c.getCommandName()))
&& (command == null || command.matches(c.getCommand()));
}
public RunCommand withCommand(String commandName, JsonObject command) {
return withCommand(equalTo(commandName), equalTo(command));
}
public RunCommand withCommand(Matcher commandName, Matcher command) {
this.commandName = commandName;
this.command = command;
return self();
}
}