use of dev.morphia.query.FindOptions in project morphia by mongodb.
the class TestMapping method testMapWithEmbeddedInterface.
@Test
public void testMapWithEmbeddedInterface() {
final ContainsMapWithEmbeddedInterface aMap = new ContainsMapWithEmbeddedInterface();
final Foo f1 = new Foo1();
final Foo f2 = new Foo2();
aMap.embeddedValues.put("first", f1);
aMap.embeddedValues.put("second", f2);
getDs().save(aMap);
final ContainsMapWithEmbeddedInterface mapLoaded = getDs().find(ContainsMapWithEmbeddedInterface.class).iterator(new FindOptions().limit(1)).next();
assertNotNull(mapLoaded);
assertEquals(mapLoaded.embeddedValues.size(), 2);
assertTrue(mapLoaded.embeddedValues.get("first") instanceof Foo1);
assertTrue(mapLoaded.embeddedValues.get("second") instanceof Foo2);
}
use of dev.morphia.query.FindOptions in project morphia by mongodb.
the class TestMapping method testMapLike.
@Test
public void testMapLike() {
final ContainsMapLike ml = new ContainsMapLike();
ml.m.put("first", "test");
getDs().save(ml);
final ContainsMapLike mlLoaded = getDs().find(ContainsMapLike.class).iterator(new FindOptions().limit(1)).next();
assertNotNull(mlLoaded);
assertNotNull(mlLoaded.m);
assertTrue(mlLoaded.m.containsKey("first"));
}
use of dev.morphia.query.FindOptions in project morphia by mongodb.
the class TestMapping method testLongArrayMapping.
@Test
public void testLongArrayMapping() {
getMapper().map(ContainsLongAndStringArray.class);
getDs().save(new ContainsLongAndStringArray());
ContainsLongAndStringArray loaded = getDs().find(ContainsLongAndStringArray.class).iterator(new FindOptions().limit(1)).next();
assertEquals((new ContainsLongAndStringArray()).longs, loaded.longs);
assertEquals((new ContainsLongAndStringArray()).strings, loaded.strings);
final ContainsLongAndStringArray array = new ContainsLongAndStringArray();
array.strings = new String[] { "a", "B", "c" };
array.longs = new Long[] { 4L, 5L, 4L };
getDs().save(array);
loaded = getDs().find(ContainsLongAndStringArray.class).filter(eq("_id", array.id)).first();
assertEquals(loaded.longs, array.longs);
assertEquals(loaded.strings, array.strings);
assertNotNull(loaded.id);
}
use of dev.morphia.query.FindOptions in project morphia by mongodb.
the class TestUUIDs method testUUID.
@Test
public void testUUID() {
getMapper().map(ContainsUUID.class);
final ContainsUUID uuid = new ContainsUUID();
final UUID before = uuid.uuid;
getDs().save(uuid);
final ContainsUUID loaded = getDs().find(ContainsUUID.class).iterator(new FindOptions().limit(1)).next();
assertNotNull(loaded);
assertNotNull(loaded.id);
assertNotNull(loaded.uuid);
assertEquals(before, loaded.uuid);
}
use of dev.morphia.query.FindOptions in project morphia by mongodb.
the class TestGenerics method testIt.
@Test
public void testIt() {
getMapper().map(HoldsAnInteger.class, HoldsAString.class, ContainsThings.class);
final ContainsThings ct = new ContainsThings();
final HoldsAnInteger hai = new HoldsAnInteger();
hai.setThing(7);
final HoldsAString has = new HoldsAString();
has.setThing("tr");
ct.stringThing = has;
ct.integerThing = hai;
getDs().save(ct);
assertNotNull(ct.id);
assertEquals(getDs().find(ContainsThings.class).count(), 1);
final ContainsThings ctLoaded = getDs().find(ContainsThings.class).iterator(new FindOptions().limit(1)).next();
assertNotNull(ctLoaded);
assertNotNull(ctLoaded.id);
assertNotNull(ctLoaded.stringThing);
assertNotNull(ctLoaded.integerThing);
}
Aggregations