|
| 1 | +/* |
| 2 | + * Copyright 2017-present the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 13 | + * or implied. See the License for the specific language governing |
| 14 | + * permissions and limitations under the License. |
| 15 | + */ |
| 16 | +package org.springframework.geode.boot.autoconfigure.session; |
| 17 | + |
| 18 | +import static org.assertj.core.api.Assertions.assertThat; |
| 19 | + |
| 20 | +import org.junit.Test; |
| 21 | + |
| 22 | +import org.springframework.beans.factory.annotation.Autowired; |
| 23 | +import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 24 | +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; |
| 25 | +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; |
| 26 | +import org.springframework.session.Session; |
| 27 | +import org.springframework.session.SessionRepository; |
| 28 | +import org.springframework.session.data.gemfire.GemFireOperationsSessionRepository; |
| 29 | +import org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration; |
| 30 | + |
| 31 | +/** |
| 32 | + * Abstract base test class for {@link Session} {@literal} in the configured {@literal time unit}, |
| 33 | + * for example: seconds, minutes, etc. |
| 34 | + * |
| 35 | + * @author John Blum |
| 36 | + * @see org.junit.Test |
| 37 | + * @see org.springframework.boot.autoconfigure.SpringBootApplication |
| 38 | + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport |
| 39 | + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects |
| 40 | + * @see org.springframework.session.Session |
| 41 | + * @see org.springframework.session.SessionRepository |
| 42 | + * @see org.springframework.session.data.gemfire.GemFireOperationsSessionRepository |
| 43 | + * @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration |
| 44 | + * @since 2.0.0 |
| 45 | + */ |
| 46 | +@SuppressWarnings("unused") |
| 47 | +public abstract class AbstractSessionExpirationTimeoutInTimeUnitIntegrationTests extends IntegrationTestsSupport { |
| 48 | + |
| 49 | + @Autowired |
| 50 | + private GemFireHttpSessionConfiguration configuration; |
| 51 | + |
| 52 | + @Autowired |
| 53 | + private SessionRepository<Session> repository; |
| 54 | + |
| 55 | + protected int getExpectedMaxInactiveIntervalInSeconds() { |
| 56 | + return GemFireHttpSessionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL_IN_SECONDS; |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void sessionTimeoutConfigurationIsCorrect() { |
| 61 | + |
| 62 | + int expectedMaxInactiveIntervalInSeconds = getExpectedMaxInactiveIntervalInSeconds(); |
| 63 | + |
| 64 | + assertThat(this.configuration).isNotNull(); |
| 65 | + assertThat(this.configuration.getMaxInactiveIntervalInSeconds()).isEqualTo(expectedMaxInactiveIntervalInSeconds); |
| 66 | + assertThat(this.repository).isInstanceOf(GemFireOperationsSessionRepository.class); |
| 67 | + |
| 68 | + Session session = this.repository.createSession(); |
| 69 | + |
| 70 | + assertThat(session).isNotNull(); |
| 71 | + assertThat(session.getMaxInactiveInterval().getSeconds()).isEqualTo(expectedMaxInactiveIntervalInSeconds); |
| 72 | + } |
| 73 | + |
| 74 | + @SpringBootApplication |
| 75 | + @EnableGemFireMockObjects |
| 76 | + static class TestConfiguration { } |
| 77 | + |
| 78 | +} |
0 commit comments