use of dev.morphia.annotations.IndexOptions in project morphia by mongodb.
the class IndexHelperTest method indexOptionsConversion.
@Test
public void indexOptionsConversion() {
IndexOptions indexOptions = buildOptions(true);
com.mongodb.client.model.IndexOptions options = getIndexHelper().convert(indexOptions);
assertEquals(options.getName(), "index_name");
assertTrue(options.isBackground());
assertTrue(options.isUnique());
assertTrue(options.isSparse());
assertEquals(options.getExpireAfter(TimeUnit.SECONDS), Long.valueOf(42));
assertEquals(options.getDefaultLanguage(), "en");
assertEquals(options.getLanguageOverride(), "de");
assertEquals(getIndexHelper().convert(indexOptions.collation()), options.getCollation());
assertTrue(getIndexHelper().convert(indexOptions).isBackground());
assertTrue(getIndexHelper().convert(indexOptions).isBackground());
assertFalse(getIndexHelper().convert(buildOptions(false)).isBackground());
}
use of dev.morphia.annotations.IndexOptions in project morphia by mongodb.
the class IndexHelperTest method index.
@Test
public void index() {
MongoCollection<Document> collection = getDatabase().getCollection("indexes");
EntityModel model = getMapper().getEntityModel(IndexedClass.class);
IndexOptions options = indexOptionsBuilder().name("index_name").background(true).collation(collation().build()).disableValidation(true).language("en").languageOverride("de").sparse(true).unique(true).build();
Index index = indexBuilder().fields(fieldBuilder().value("indexName").build(), fieldBuilder().value("text").type(IndexType.DESC).build()).options(options).build();
getIndexHelper().createIndex(collection, model, index);
List<Document> indexInfo = getIndexInfo(IndexedClass.class);
for (Document document : indexInfo) {
if (document.get("name").equals("indexName")) {
checkIndex(document);
assertEquals(document.get("default_language"), "en");
assertEquals(document.get("language_override"), "de");
assertEquals(document.get("collation"), new Document().append("locale", "en").append("caseLevel", true).append("caseFirst", "upper").append("strength", 5).append("numericOrdering", true).append("alternate", "shifted").append("maxVariable", "space").append("backwards", true).append("normalization", true).append("version", "57.1"));
}
}
}
use of dev.morphia.annotations.IndexOptions in project morphia by mongodb.
the class IndexHelperTest method findField.
@Test
public void findField() {
getMapper().map(MappedInterface.class, MappedInterfaceImpl.class, AbstractParent.class, IndexedClass.class);
EntityModel model = getMapper().getEntityModel(IndexedClass.class);
IndexOptions options = indexOptionsBuilder().build();
assertEquals(getIndexHelper().findField(model, options, "indexName"), "indexName");
assertEquals(getIndexHelper().findField(model, options, "nested.name"), "nest.name");
assertEquals(getIndexHelper().findField(model, options, "nest.name"), "nest.name");
try {
assertEquals(getIndexHelper().findField(model, options, "nest.whatsit"), "nest.whatsit");
fail("Should have failed on the bad index path");
} catch (ValidationException e) {
// alles ist gut
}
assertEquals(getIndexHelper().findField(model, indexOptionsBuilder().disableValidation(true).build(), "nest.whatsit.nested.more.deeply.than.the.object.model"), "nest.whatsit.nested.more.deeply.than.the.object.model");
}
Aggregations