Search in sources :

Example 1 with CityPopulation

use of dev.morphia.test.models.CityPopulation in project morphia by mongodb.

the class TestMapping method testBasicMapping.

@Test
public void testBasicMapping() {
    Mapper mapper = getDs().getMapper();
    mapper.map(List.of(State.class, CityPopulation.class));
    final State state = new State();
    state.state = "NY";
    state.biggest = new CityPopulation("NYC", 8336817L);
    state.smallest = new CityPopulation("Red House", 38L);
    getDs().save(state);
    Query<State> query = getDs().find(State.class).filter(eq("_id", state.id));
    State loaded = query.first();
    assertEquals(loaded, state);
    assertEquals(mapper.getEntityModel(State.class).getProperties().stream().map(PropertyModel::getMappedName).collect(toList()), List.of("_id", "state", "biggestCity", "smallestCity"));
}
Also used : Mapper(dev.morphia.mapping.Mapper) State(dev.morphia.test.models.State) PropertyModel(dev.morphia.mapping.codec.pojo.PropertyModel) CityPopulation(dev.morphia.test.models.CityPopulation) Test(org.testng.annotations.Test)

Aggregations

Mapper (dev.morphia.mapping.Mapper)1 PropertyModel (dev.morphia.mapping.codec.pojo.PropertyModel)1 CityPopulation (dev.morphia.test.models.CityPopulation)1 State (dev.morphia.test.models.State)1 Test (org.testng.annotations.Test)1