Example usage for org.springframework.session.data.gemfire AbstractGemFireOperationsSessionRepository setApplicationEventPublisher

List of usage examples for org.springframework.session.data.gemfire AbstractGemFireOperationsSessionRepository setApplicationEventPublisher

Introduction

In this page you can find the example usage for org.springframework.session.data.gemfire AbstractGemFireOperationsSessionRepository setApplicationEventPublisher.

Prototype

@Override
public void setApplicationEventPublisher(@NonNull ApplicationEventPublisher applicationEventPublisher) 

Source Link

Document

Sets the configured ApplicationEventPublisher used to publish Session AbstractSessionEvent events corresponding to Apache Geode/Pivotal GemFire cache events.

Usage

From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java

@Test
@SuppressWarnings("unchecked")
public void gemfireOperationsSessionRepositoryIsProperlyConstructedAndInitialized() throws Exception {
    ApplicationEventPublisher mockApplicationEventPublisher = mock(ApplicationEventPublisher.class);
    AttributesMutator<Object, ExpiringSession> mockAttributesMutator = mock(AttributesMutator.class);
    Region<Object, ExpiringSession> mockRegion = mock(Region.class);

    given(mockRegion.getFullPath()).willReturn("/Example");
    given(mockRegion.getAttributesMutator()).willReturn(mockAttributesMutator);

    GemfireTemplate template = new GemfireTemplate(mockRegion);

    AbstractGemFireOperationsSessionRepository sessionRepository = new TestGemFireOperationsSessionRepository(
            template);//from  w w w.  j a  v a2 s .  c  o m

    ApplicationEventPublisher applicationEventPublisher = sessionRepository.getApplicationEventPublisher();

    assertThat(applicationEventPublisher).isNotNull();
    assertThat(sessionRepository.getFullyQualifiedRegionName()).isNull();
    assertThat(sessionRepository.getMaxInactiveIntervalInSeconds())
            .isEqualTo(GemFireHttpSessionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL_IN_SECONDS);
    assertThat(sessionRepository.getTemplate()).isSameAs(template);

    sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
    sessionRepository.setMaxInactiveIntervalInSeconds(300);
    sessionRepository.afterPropertiesSet();

    assertThat(sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
    assertThat(sessionRepository.getFullyQualifiedRegionName()).isEqualTo("/Example");
    assertThat(sessionRepository.getMaxInactiveIntervalInSeconds()).isEqualTo(300);
    assertThat(sessionRepository.getTemplate()).isSameAs(template);

    verify(mockRegion, times(1)).getAttributesMutator();
    verify(mockRegion, times(1)).getFullPath();
    verify(mockAttributesMutator, times(1)).addCacheListener(same(sessionRepository));
}