use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MongoConfigurationSupport method scanForEntities.
/**
* Scans the given base package for entities, i.e. MongoDB specific types annotated with {@link Document}.
*
* @param basePackage must not be {@literal null}.
* @return
* @throws ClassNotFoundException
* @since 1.10
*/
protected Set<Class<?>> scanForEntities(String basePackage) throws ClassNotFoundException {
if (!StringUtils.hasText(basePackage)) {
return Collections.emptySet();
}
Set<Class<?>> initialEntitySet = new HashSet<Class<?>>();
if (StringUtils.hasText(basePackage)) {
ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(false);
componentProvider.addIncludeFilter(new AnnotationTypeFilter(Document.class));
for (BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) {
initialEntitySet.add(ClassUtils.forName(candidate.getBeanClassName(), MongoConfigurationSupport.class.getClassLoader()));
}
}
return initialEntitySet;
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method convertsLocalesOutOfTheBox.
@Test
void convertsLocalesOutOfTheBox() {
LocaleWrapper wrapper = new LocaleWrapper();
wrapper.locale = Locale.US;
org.bson.Document document = new org.bson.Document();
converter.write(wrapper, document);
Object localeField = document.get("locale");
assertThat(localeField).isInstanceOf(String.class);
assertThat(localeField).isEqualTo("en_US");
LocaleWrapper read = converter.read(LocaleWrapper.class, document);
assertThat(read.locale).isEqualTo(Locale.US);
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method readsClassWithBigDecimal.
// DATACMNS-42, DATAMONGO-171
@Test
void readsClassWithBigDecimal() {
org.bson.Document document = new org.bson.Document("value", "2.5");
document.put("map", new org.bson.Document("foo", "2.5"));
BasicDBList list = new BasicDBList();
list.add("2.5");
document.put("collection", list);
BigDecimalContainer result = converter.read(BigDecimalContainer.class, document);
assertThat(result.value).isEqualTo(BigDecimal.valueOf(2.5d));
assertThat(result.map.get("foo")).isEqualTo(BigDecimal.valueOf(2.5d));
assertThat(result.collection.get(0)).isEqualTo(BigDecimal.valueOf(2.5d));
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method shouldReadEntityWithGeoBoxCorrectly.
// DATAMONGO-858
@Test
void shouldReadEntityWithGeoBoxCorrectly() {
ClassWithGeoBox object = new ClassWithGeoBox();
object.box = new Box(new Point(1, 2), new Point(3, 4));
org.bson.Document document = new org.bson.Document();
converter.write(object, document);
ClassWithGeoBox result = converter.read(ClassWithGeoBox.class, document);
assertThat(result).isNotNull();
assertThat(result.box).isEqualTo(object.box);
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method readsDBRefMap.
// DATAMONGO-424
@Test
void readsDBRefMap() {
DBRef dbRef = mock(DBRef.class);
org.bson.Document refMap = new org.bson.Document("foo", dbRef);
org.bson.Document document = new org.bson.Document("refMap", refMap);
DBRefWrapper result = converter.read(DBRefWrapper.class, document);
assertThat(result.refMap.entrySet()).hasSize(1);
assertThat(result.refMap.values()).contains(dbRef);
}
Aggregations