use of org.springframework.data.mongodb.core.mapping.PersonPojoStringId in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method convertsObjectIdStringsToObjectIdCorrectly.
@Test
void convertsObjectIdStringsToObjectIdCorrectly() {
PersonPojoStringId p1 = new PersonPojoStringId("1234567890", "Text-1");
org.bson.Document doc1 = new org.bson.Document();
converter.write(p1, doc1);
assertThat(doc1.get("_id")).isInstanceOf(String.class);
PersonPojoStringId p2 = new PersonPojoStringId(new ObjectId().toString(), "Text-1");
org.bson.Document doc2 = new org.bson.Document();
converter.write(p2, doc2);
assertThat(doc2.get("_id")).isInstanceOf(ObjectId.class);
}
use of org.springframework.data.mongodb.core.mapping.PersonPojoStringId in project spring-data-mongodb by spring-projects.
the class ApplicationContextEventTests method loadEventsOnAggregation.
// DATAMONGO-1256
@Test
public void loadEventsOnAggregation() {
template.insert(new PersonPojoStringId("1", "Text"));
template.aggregate(Aggregation.newAggregation(Aggregation.project("text")), PersonPojoStringId.class, PersonPojoStringId.class);
assertThat(listener.onAfterLoadEvents).hasSize(1);
assertThat(listener.onAfterLoadEvents.get(0).getCollectionName()).isEqualTo(COLLECTION_NAME);
assertThat(listener.onBeforeConvertEvents).hasSize(1);
assertThat(listener.onBeforeConvertEvents.get(0).getCollectionName()).isEqualTo(COLLECTION_NAME);
assertThat(listener.onAfterConvertEvents).hasSize(1);
assertThat(listener.onAfterConvertEvents.get(0).getCollectionName()).isEqualTo(COLLECTION_NAME);
}
use of org.springframework.data.mongodb.core.mapping.PersonPojoStringId in project spring-data-mongodb by spring-projects.
the class ApplicationContextEventTests method loadAndConvertEvents.
// DATAMONGO-1256
@Test
public void loadAndConvertEvents() {
PersonPojoStringId entity = new PersonPojoStringId("1", "Text");
template.insert(entity);
template.findOne(query(where("id").is(entity.getId())), PersonPojoStringId.class);
assertThat(listener.onAfterLoadEvents).hasSize(1);
assertThat(listener.onAfterLoadEvents.get(0).getCollectionName()).isEqualTo(COLLECTION_NAME);
assertThat(listener.onBeforeConvertEvents).hasSize(1);
assertThat(listener.onBeforeConvertEvents.get(0).getCollectionName()).isEqualTo(COLLECTION_NAME);
assertThat(listener.onAfterConvertEvents).hasSize(1);
assertThat(listener.onAfterConvertEvents.get(0).getCollectionName()).isEqualTo(COLLECTION_NAME);
}
use of org.springframework.data.mongodb.core.mapping.PersonPojoStringId in project spring-data-mongodb by spring-projects.
the class ApplicationContextEventTests method beforeSaveEvent.
@Test
@SuppressWarnings("unchecked")
public void beforeSaveEvent() {
PersonBeforeSaveListener personBeforeSaveListener = applicationContext.getBean(PersonBeforeSaveListener.class);
AfterSaveListener afterSaveListener = applicationContext.getBean(AfterSaveListener.class);
assertThat(personBeforeSaveListener.seenEvents).isEmpty();
assertThat(afterSaveListener.seenEvents).isEmpty();
assertThat(listener.onBeforeSaveEvents).isEmpty();
assertThat(listener.onAfterSaveEvents).isEmpty();
PersonPojoStringId p = new PersonPojoStringId("1", "Text");
template.insert(p);
assertThat(personBeforeSaveListener.seenEvents).hasSize(1);
assertThat(afterSaveListener.seenEvents).hasSize(1);
assertThat(listener.onBeforeSaveEvents).hasSize(1);
assertThat(listener.onAfterSaveEvents).hasSize(1);
assertThat(listener.onBeforeSaveEvents.get(0).getCollectionName()).isEqualTo(COLLECTION_NAME);
assertThat(listener.onAfterSaveEvents.get(0).getCollectionName()).isEqualTo(COLLECTION_NAME);
assertThat(personBeforeSaveListener.seenEvents.get(0) instanceof BeforeSaveEvent<?>).isTrue();
assertThat(afterSaveListener.seenEvents.get(0) instanceof AfterSaveEvent<?>).isTrue();
BeforeSaveEvent<PersonPojoStringId> beforeSaveEvent = (BeforeSaveEvent<PersonPojoStringId>) personBeforeSaveListener.seenEvents.get(0);
PersonPojoStringId p2 = beforeSaveEvent.getSource();
org.bson.Document document = beforeSaveEvent.getDocument();
comparePersonAndDocument(p, p2, document);
AfterSaveEvent<Object> afterSaveEvent = (AfterSaveEvent<Object>) afterSaveListener.seenEvents.get(0);
assertThat(afterSaveEvent.getSource() instanceof PersonPojoStringId).isTrue();
p2 = (PersonPojoStringId) afterSaveEvent.getSource();
document = beforeSaveEvent.getDocument();
comparePersonAndDocument(p, p2, document);
}
use of org.springframework.data.mongodb.core.mapping.PersonPojoStringId in project spring-data-mongodb by spring-projects.
the class ApplicationContextEventTests method deleteEvents.
// DATAMONGO-1256
@Test
public void deleteEvents() {
PersonPojoStringId entity = new PersonPojoStringId("1", "Text");
template.insert(entity);
template.remove(entity);
assertThat(listener.onBeforeDeleteEvents).hasSize(1);
assertThat(listener.onBeforeDeleteEvents.get(0).getCollectionName()).isEqualTo(COLLECTION_NAME);
assertThat(listener.onAfterDeleteEvents).hasSize(1);
assertThat(listener.onAfterDeleteEvents.get(0).getCollectionName()).isEqualTo(COLLECTION_NAME);
}
Aggregations