Search in sources :

Example 11 with FindOptions

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);
}
Also used : FindOptions(dev.morphia.query.FindOptions) Test(org.testng.annotations.Test)

Example 12 with FindOptions

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"));
}
Also used : FindOptions(dev.morphia.query.FindOptions) ContainsMapLike(dev.morphia.test.models.errors.ContainsMapLike) Test(org.testng.annotations.Test)

Example 13 with FindOptions

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);
}
Also used : FindOptions(dev.morphia.query.FindOptions) Test(org.testng.annotations.Test)

Example 14 with FindOptions

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);
}
Also used : FindOptions(dev.morphia.query.FindOptions) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 15 with FindOptions

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);
}
Also used : FindOptions(dev.morphia.query.FindOptions) Test(org.testng.annotations.Test)

Aggregations

FindOptions (dev.morphia.query.FindOptions)118 Test (org.testng.annotations.Test)114 Point (com.mongodb.client.model.geojson.Point)16 Position (com.mongodb.client.model.geojson.Position)16 Document (org.bson.Document)16 Rectangle (dev.morphia.test.models.Rectangle)13 Datastore (dev.morphia.Datastore)12 UpdateResult (com.mongodb.client.result.UpdateResult)8 UpdateOptions (dev.morphia.UpdateOptions)8 ObjectId (org.bson.types.ObjectId)7 ValidationException (dev.morphia.query.ValidationException)6 User (dev.morphia.test.models.User)5 ContainsPic (dev.morphia.test.query.TestQuery.ContainsPic)5 Pic (dev.morphia.test.query.TestQuery.Pic)5 LocalDate (java.time.LocalDate)5 Date (java.util.Date)5 DeleteOptions (dev.morphia.DeleteOptions)4 Query (dev.morphia.query.Query)4 DocumentValidation (dev.morphia.test.models.DocumentValidation)4 ContainsPic (dev.morphia.test.query.TestLegacyQuery.ContainsPic)4