com.noenv.wiremongo.mapping.index.CreateIndexes 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.index;
import com.noenv.wiremongo.command.Command;
import com.noenv.wiremongo.command.index.CreateIndexesCommand;
import com.noenv.wiremongo.mapping.collection.WithCollection;
import com.noenv.wiremongo.matching.JsonMatcher;
import com.noenv.wiremongo.matching.Matcher;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.mongo.IndexModel;
import java.util.List;
import java.util.stream.Collectors;
public class CreateIndexes extends WithCollection {
private Matcher> indexModels;
public CreateIndexes() {
this("createIndexes");
}
public CreateIndexes(String method) {
super(method);
}
public CreateIndexes(JsonObject json) {
super(json);
indexModels = Matcher.create(json.getJsonObject("indexModels"),
j -> ((JsonArray) j).stream().map(v -> new IndexModel((JsonObject) v)).collect(Collectors.toList()),
l -> new JsonArray(l.stream().map(IndexModel::toJson).collect(Collectors.toList())));
}
@Override
protected Void parseResponse(Object jsonValue) {
return null;
}
@Override
public boolean matches(Command cmd) {
if (!super.matches(cmd)) {
return false;
}
if (!(cmd instanceof CreateIndexesCommand)) {
return false;
}
CreateIndexesCommand c = (CreateIndexesCommand) cmd;
return indexModels == null || indexModels.matches(c.getIndexModels());
}
public CreateIndexes withIndexModels(List indexModels) {
JsonArray array = new JsonArray(indexModels.stream().map(IndexModel::toJson).collect(Collectors.toList()));
return withIndexModels(JsonMatcher.equalToJson(array,l -> new JsonArray(l.stream().map(IndexModel::toJson).collect(Collectors.toList()))));
}
public CreateIndexes withIndexModels(Matcher> indexModels) {
this.indexModels = indexModels;
return self();
}
}