/** @see DATAMONGO-289 */
  @Test
  public void afterLoadEffectGetsHandledCorrectly() {

    SamplePersonEventListener listener = new SamplePersonEventListener();
    listener.onApplicationEvent(new AfterLoadEvent<Person>(new BasicDBObject(), Person.class));
    assertThat(listener.invokedOnAfterLoad, is(true));
  }
  @Test
  public void invokesCallbackForEventForPerson() {

    MongoMappingEvent<Person> event =
        new BeforeConvertEvent<Person>(new Person("Dave", "Matthews"));
    SamplePersonEventListener listener = new SamplePersonEventListener();
    listener.onApplicationEvent(event);
    assertThat(listener.invokedOnBeforeConvert, is(true));
  }
  /** @see DATAMONGO-545 */
  @Test
  public void donInvokePersonCallbackForUntypedEvent() {

    MongoMappingEvent<DBObject> event = new BeforeDeleteEvent<Account>(new BasicDBObject(), null);
    SamplePersonEventListener listener = new SamplePersonEventListener();
    listener.onApplicationEvent(event);

    assertThat(listener.invokedOnBeforeDelete, is(false));
  }
  /** @see DATAMONGO-545 */
  @Test
  public void invokePersonCallbackForPersonEvent() {

    MongoMappingEvent<DBObject> event =
        new BeforeDeleteEvent<Person>(new BasicDBObject(), Person.class);
    SamplePersonEventListener listener = new SamplePersonEventListener();
    listener.onApplicationEvent(event);

    assertThat(listener.invokedOnBeforeDelete, is(true));
  }
  /** @see DATAMONGO-289 */
  @Test
  public void afterLoadEventGetsFilteredForDomainTypeWorksForSubtypes() {

    SamplePersonEventListener personListener = new SamplePersonEventListener();
    SampleContactEventListener contactListener = new SampleContactEventListener();
    personListener.onApplicationEvent(
        new AfterLoadEvent<Person>(new BasicDBObject(), Person.class));
    contactListener.onApplicationEvent(
        new AfterLoadEvent<Person>(new BasicDBObject(), Person.class));

    assertThat(personListener.invokedOnAfterLoad, is(true));
    assertThat(contactListener.invokedOnAfterLoad, is(true));
  }
  /** @see DATAMONGO-289 */
  @Test
  public void afterLoadEventGetsFilteredForDomainType() {

    SamplePersonEventListener personListener = new SamplePersonEventListener();
    SampleAccountEventListener accountListener = new SampleAccountEventListener();
    personListener.onApplicationEvent(
        new AfterLoadEvent<Person>(new BasicDBObject(), Person.class));
    accountListener.onApplicationEvent(
        new AfterLoadEvent<Person>(new BasicDBObject(), Person.class));

    assertThat(personListener.invokedOnAfterLoad, is(true));
    assertThat(accountListener.invokedOnAfterLoad, is(false));
  }
  @Test
  public void dropsEventIfNotForCorrectDomainType() {

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
    context.refresh();

    SamplePersonEventListener listener = new SamplePersonEventListener();
    context.addApplicationListener(listener);

    context.publishEvent(new BeforeConvertEvent<Person>(new Person("Dave", "Matthews")));
    assertThat(listener.invokedOnBeforeConvert, is(true));

    listener.invokedOnBeforeConvert = false;
    context.publishEvent(new BeforeConvertEvent<String>("Test"));
    assertThat(listener.invokedOnBeforeConvert, is(false));
  }