Search in sources :

Example 1 with ConventionModel

use of org.bson.codecs.pojo.entities.ConventionModel in project mongo-java-driver by mongodb.

the class PojoCodecCyclicalLookupTest method testConventionModel.

@Test
void testConventionModel() {
    ConventionModel model = getConventionModel();
    String json = "{'_id': 'id', '_cls': 'AnnotatedConventionModel', 'myFinalField': 10, 'myIntField': 10," + "'child': {'_id': 'child', 'myFinalField': 10, 'myIntField': 10," + "'model': {'integerField': 42, 'stringField': 'myString'}}}";
    LookupCountingCodecRegistry registry = createRegistry(ConventionModel.class, SimpleModel.class);
    roundTrip(registry, model, json);
    // Looked up in encodesTo & decodesTo
    assertEquals(2, registry.counters.get(ConventionModel.class).get());
    // Lookup on encode then cached (PropertyCodecRegistry)
    assertEquals(1, registry.counters.get(SimpleModel.class).get());
    // Once for ConventionModel & once for SimpleModel
    assertEquals(2, registry.counters.get(String.class).get());
    // Once for ConventionModel & once for SimpleModel
    assertEquals(2, registry.counters.get(Integer.class).get());
}
Also used : ConventionModel(org.bson.codecs.pojo.entities.ConventionModel) Test(org.junit.jupiter.api.Test)

Example 2 with ConventionModel

use of org.bson.codecs.pojo.entities.ConventionModel in project mongo-java-driver by mongodb.

the class PojoTestCase method getConventionModel.

static ConventionModel getConventionModel() {
    SimpleModel simpleModel = getSimpleModel();
    ConventionModel child = new ConventionModel("child", null, simpleModel);
    return new ConventionModel("id", child, null);
}
Also used : SimpleModel(org.bson.codecs.pojo.entities.SimpleModel) ConventionModel(org.bson.codecs.pojo.entities.ConventionModel)

Aggregations

ConventionModel (org.bson.codecs.pojo.entities.ConventionModel)2 SimpleModel (org.bson.codecs.pojo.entities.SimpleModel)1 Test (org.junit.jupiter.api.Test)1