com.noenv.wiremongo.mapping.replace.ReplaceDocumentsWithOptions 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.replace;
import com.noenv.wiremongo.command.Command;
import com.noenv.wiremongo.command.replace.ReplaceDocumentsWithOptionsCommand;
import com.noenv.wiremongo.matching.JsonMatcher;
import com.noenv.wiremongo.matching.Matcher;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.mongo.UpdateOptions;
@SuppressWarnings("squid:MaximumInheritanceDepth")
public class ReplaceDocumentsWithOptions extends ReplaceDocumentsBase {
private Matcher options;
public ReplaceDocumentsWithOptions() {
super("replaceDocumentsWithOptions");
}
public ReplaceDocumentsWithOptions(JsonObject json) {
super(json);
options = Matcher.create(json.getJsonObject("options"), j -> new UpdateOptions((JsonObject) j), UpdateOptions::toJson);
}
@Override
public boolean matches(Command cmd) {
if (!super.matches(cmd)) {
return false;
}
if (!(cmd instanceof ReplaceDocumentsWithOptionsCommand)) {
return false;
}
ReplaceDocumentsWithOptionsCommand c = (ReplaceDocumentsWithOptionsCommand) cmd;
return options == null || options.matches(c.getOptions());
}
public ReplaceDocumentsWithOptions withOptions(UpdateOptions options) {
return withOptions(JsonMatcher.equalToJson(options.toJson(), UpdateOptions::toJson));
}
public ReplaceDocumentsWithOptions withOptions(Matcher options) {
this.options = options;
return self();
}
}