All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.noenv.wiremongo.mapping.RunCommand Maven / Gradle / Ivy

There is a newer version: 4.5.10
Show newest version
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();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy