com.noenv.wiremongo.mapping.stream.WithStream 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.stream;
import com.noenv.wiremongo.MemoryStream;
import com.noenv.wiremongo.command.stream.WithStreamCommand;
import com.noenv.wiremongo.mapping.collection.WithCollection;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.core.streams.ReadStream;
import java.util.stream.Collectors;
public abstract class WithStream> extends WithCollection, U, C> {
public WithStream(String method) {
super(method);
}
public WithStream(JsonObject json) {
super(json);
}
@Override
public C returns(final ReadStream response) {
return super.stub(c -> response instanceof MemoryStream ? ((MemoryStream) response).copy(JsonObject::copy) : response);
}
@Override
protected ReadStream parseResponse(Object jsonValue) {
return MemoryStream.fromList(((JsonArray) jsonValue).stream()
.map(o -> (JsonObject) o)
.collect(Collectors.toList()));
}
}