use of dev.morphia.mapping.codec.writer.DocumentWriter in project morphia by mongodb.
the class CodecStructureTest method evaluate.
private void evaluate(Document expected, Expression value) {
DocumentWriter writer = new DocumentWriter(getMapper());
document(writer, () -> {
value.encode(getDs(), writer, EncoderContext.builder().build());
});
Document actual = writer.getDocument();
assertDocumentEquals(actual, expected);
}
use of dev.morphia.mapping.codec.writer.DocumentWriter in project morphia by mongodb.
the class TestBase method toDocument.
protected Document toDocument(Object entity) {
final Class<?> type = getMapper().getEntityModel(entity.getClass()).getType();
DocumentWriter writer = new DocumentWriter(getMapper());
((Codec) getDs().getCodecRegistry().get(type)).encode(writer, entity, EncoderContext.builder().build());
return writer.getDocument();
}
use of dev.morphia.mapping.codec.writer.DocumentWriter in project morphia by mongodb.
the class ExpressionsTestBase method assertAndCheckDocShape.
@SuppressWarnings("unchecked")
protected void assertAndCheckDocShape(String expectedString, Expression value, Object expectedValue) {
Document expected = Document.parse(expectedString);
DocumentWriter writer = new DocumentWriter(getMapper());
document(writer, () -> {
value.encode(getDs(), writer, EncoderContext.builder().build());
});
Document actual = writer.getDocument();
assertDocumentEquals(actual, expected);
Document test = getDs().aggregate(User.class).project(Projection.project().include("test", value)).execute(Document.class).next();
assertEquals(test.get("test"), expectedValue);
}
Aggregations