Search in sources :

Example 1 with IndexOnValue

use of org.mongodb.morphia.entities.IndexOnValue in project morphia by mongodb.

the class TestIndexed method testIndexedEntity.

@Test
public void testIndexedEntity() throws Exception {
    getDs().ensureIndexes();
    assertThat(getDs().getCollection(IndexOnValue.class).getIndexInfo(), hasIndexNamed("value_1"));
    getDs().save(new IndexOnValue());
    getDs().ensureIndexes();
    assertThat(getDs().getCollection(IndexOnValue.class).getIndexInfo(), hasIndexNamed("value_1"));
}
Also used : NamedIndexOnValue(org.mongodb.morphia.entities.NamedIndexOnValue) IndexOnValue(org.mongodb.morphia.entities.IndexOnValue) UniqueIndexOnValue(org.mongodb.morphia.entities.UniqueIndexOnValue) Test(org.junit.Test)

Example 2 with IndexOnValue

use of org.mongodb.morphia.entities.IndexOnValue in project morphia by mongodb.

the class TestIndexed method shouldNotCreateAnIndexWhenAnIndexedEntityIsMarkedAsNotSaved.

@Test
public void shouldNotCreateAnIndexWhenAnIndexedEntityIsMarkedAsNotSaved() {
    // given
    getMorphia().map(IndexOnValue.class, NoIndexes.class);
    Datastore ds = getDs();
    // when
    ds.ensureIndexes();
    ds.save(new IndexOnValue());
    ds.save(new NoIndexes());
    // then
    List<DBObject> indexes = getDb().getCollection("NoIndexes").getIndexInfo();
    assertEquals(1, indexes.size());
}
Also used : Datastore(org.mongodb.morphia.Datastore) NamedIndexOnValue(org.mongodb.morphia.entities.NamedIndexOnValue) IndexOnValue(org.mongodb.morphia.entities.IndexOnValue) UniqueIndexOnValue(org.mongodb.morphia.entities.UniqueIndexOnValue) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 IndexOnValue (org.mongodb.morphia.entities.IndexOnValue)2 NamedIndexOnValue (org.mongodb.morphia.entities.NamedIndexOnValue)2 UniqueIndexOnValue (org.mongodb.morphia.entities.UniqueIndexOnValue)2 DBObject (com.mongodb.DBObject)1 Datastore (org.mongodb.morphia.Datastore)1