de.bwaldvogel.mongo.backend.TestUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mongo-java-server-test-common Show documentation
Show all versions of mongo-java-server-test-common Show documentation
Fake implementation of MongoDB in Java that speaks the wire protocol
package de.bwaldvogel.mongo.backend;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.bson.Document;
import com.mongodb.client.MongoDatabase;
public class TestUtils {
private TestUtils() {
}
public static List toArray(Iterable iterable) {
List array = new ArrayList<>();
for (T obj : iterable) {
array.add(obj);
}
return array;
}
public static Document json(String string) {
string = string.trim();
if (!string.startsWith("{")) {
string = "{" + string + "}";
}
return Document.parse(string);
}
static List jsonList(String... json) {
return Stream.of(json)
.map(TestUtils::json)
.collect(Collectors.toList());
}
public static Document getCollectionStatistics(MongoDatabase database, String collectionName) {
Document collStats = new Document("collStats", collectionName);
return database.runCommand(collStats);
}
static Instant instant(String value) {
return Instant.parse(value);
}
static Date date(String value) {
return Date.from(instant(value));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy