com.noenv.wiremongo.mapping.WithDocument 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.WithDocumentCommand;
import com.noenv.wiremongo.mapping.collection.WithCollection;
import com.noenv.wiremongo.matching.Matcher;
import io.vertx.core.json.JsonObject;
import org.bson.types.ObjectId;
import static com.noenv.wiremongo.matching.EqualsMatcher.equalTo;
public abstract class WithDocument> extends WithCollection {
private Matcher document;
public WithDocument(String method) {
super(method);
}
public WithDocument(JsonObject json) {
super(json);
document = Matcher.create(json.getJsonObject("document"));
}
public C withDocument(JsonObject document) {
return withDocument(equalTo(document));
}
public C withDocument(Matcher document) {
this.document = document;
return self();
}
public C returnsObjectId() {
return returns(ObjectId.get().toHexString());
}
@Override
public boolean matches(Command cmd) {
if (!super.matches(cmd)) {
return false;
}
if (!(cmd instanceof WithDocumentCommand)) {
return false;
}
WithDocumentCommand c = (WithDocumentCommand) cmd;
return document == null || document.matches(c.getDocument());
}
@Override
protected String parseResponse(Object jsonValue) {
return (String) jsonValue;
}
}