|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2023 the original author or authors. |
| 2 | + * Copyright 2012-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.boot.actuate.autoconfigure.session;
|
18 | 18 |
|
| 19 | +import org.junit.jupiter.api.Nested; |
19 | 20 | import org.junit.jupiter.api.Test;
|
20 | 21 |
|
| 22 | +import org.springframework.boot.actuate.session.ReactiveSessionsEndpoint; |
21 | 23 | import org.springframework.boot.actuate.session.SessionsEndpoint;
|
22 | 24 | import org.springframework.boot.autoconfigure.AutoConfigurations;
|
23 |
| -import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
| 25 | +import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; |
| 26 | +import org.springframework.boot.test.context.runner.WebApplicationContextRunner; |
24 | 27 | import org.springframework.context.annotation.Bean;
|
25 | 28 | import org.springframework.context.annotation.Configuration;
|
26 | 29 | import org.springframework.session.FindByIndexNameSessionRepository;
|
| 30 | +import org.springframework.session.ReactiveFindByIndexNameSessionRepository; |
| 31 | +import org.springframework.session.ReactiveSessionRepository; |
| 32 | +import org.springframework.session.SessionRepository; |
27 | 33 |
|
28 | 34 | import static org.assertj.core.api.Assertions.assertThat;
|
29 | 35 | import static org.mockito.Mockito.mock;
|
|
32 | 38 | * Tests for {@link SessionsEndpointAutoConfiguration}.
|
33 | 39 | *
|
34 | 40 | * @author Vedran Pavic
|
| 41 | + * @author Moritz Halbritter |
35 | 42 | */
|
36 | 43 | class SessionsEndpointAutoConfigurationTests {
|
37 | 44 |
|
38 |
| - private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() |
39 |
| - .withConfiguration(AutoConfigurations.of(SessionsEndpointAutoConfiguration.class)) |
40 |
| - .withUserConfiguration(SessionConfiguration.class); |
| 45 | + @Nested |
| 46 | + class ServletSessionEndpointConfigurationTests { |
41 | 47 |
|
42 |
| - @Test |
43 |
| - void runShouldHaveEndpointBean() { |
44 |
| - this.contextRunner.withPropertyValues("management.endpoints.web.exposure.include=sessions") |
45 |
| - .run((context) -> assertThat(context).hasSingleBean(SessionsEndpoint.class)); |
46 |
| - } |
| 48 | + private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() |
| 49 | + .withConfiguration(AutoConfigurations.of(SessionsEndpointAutoConfiguration.class)) |
| 50 | + .withUserConfiguration(IndexedSessionRepositoryConfiguration.class); |
47 | 51 |
|
48 |
| - @Test |
49 |
| - void runWhenNotExposedShouldNotHaveEndpointBean() { |
50 |
| - this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(SessionsEndpoint.class)); |
51 |
| - } |
| 52 | + @Test |
| 53 | + void runShouldHaveEndpointBean() { |
| 54 | + this.contextRunner.withPropertyValues("management.endpoints.web.exposure.include=sessions") |
| 55 | + .run((context) -> assertThat(context).hasSingleBean(SessionsEndpoint.class)); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + void runWhenNoIndexedSessionRepositoryShouldHaveEndpointBean() { |
| 60 | + new WebApplicationContextRunner() |
| 61 | + .withConfiguration(AutoConfigurations.of(SessionsEndpointAutoConfiguration.class)) |
| 62 | + .withUserConfiguration(SessionRepositoryConfiguration.class) |
| 63 | + .withPropertyValues("management.endpoints.web.exposure.include=sessions") |
| 64 | + .run((context) -> assertThat(context).hasSingleBean(SessionsEndpoint.class)); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + void runWhenNotExposedShouldNotHaveEndpointBean() { |
| 69 | + this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(SessionsEndpoint.class)); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + void runWhenEnabledPropertyIsFalseShouldNotHaveEndpointBean() { |
| 74 | + this.contextRunner.withPropertyValues("management.endpoint.sessions.enabled:false") |
| 75 | + .run((context) -> assertThat(context).doesNotHaveBean(SessionsEndpoint.class)); |
| 76 | + } |
| 77 | + |
| 78 | + @Configuration(proxyBeanMethods = false) |
| 79 | + static class IndexedSessionRepositoryConfiguration { |
| 80 | + |
| 81 | + @Bean |
| 82 | + FindByIndexNameSessionRepository<?> sessionRepository() { |
| 83 | + return mock(FindByIndexNameSessionRepository.class); |
| 84 | + } |
| 85 | + |
| 86 | + } |
| 87 | + |
| 88 | + @Configuration(proxyBeanMethods = false) |
| 89 | + static class SessionRepositoryConfiguration { |
| 90 | + |
| 91 | + @Bean |
| 92 | + SessionRepository<?> sessionRepository() { |
| 93 | + return mock(SessionRepository.class); |
| 94 | + } |
| 95 | + |
| 96 | + } |
52 | 97 |
|
53 |
| - @Test |
54 |
| - void runWhenEnabledPropertyIsFalseShouldNotHaveEndpointBean() { |
55 |
| - this.contextRunner.withPropertyValues("management.endpoint.sessions.enabled:false") |
56 |
| - .run((context) -> assertThat(context).doesNotHaveBean(SessionsEndpoint.class)); |
57 | 98 | }
|
58 | 99 |
|
59 |
| - @Configuration(proxyBeanMethods = false) |
60 |
| - static class SessionConfiguration { |
| 100 | + @Nested |
| 101 | + class ReactiveSessionEndpointConfigurationTests { |
| 102 | + |
| 103 | + private final ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner() |
| 104 | + .withConfiguration(AutoConfigurations.of(SessionsEndpointAutoConfiguration.class)) |
| 105 | + .withUserConfiguration(ReactiveSessionRepositoryConfiguration.class, |
| 106 | + ReactiveIndexedSessionRepositoryConfiguration.class); |
| 107 | + |
| 108 | + @Test |
| 109 | + void runShouldHaveEndpointBean() { |
| 110 | + this.contextRunner.withPropertyValues("management.endpoints.web.exposure.include=sessions") |
| 111 | + .run((context) -> assertThat(context).hasSingleBean(ReactiveSessionsEndpoint.class)); |
| 112 | + } |
| 113 | + |
| 114 | + @Test |
| 115 | + void runWhenNoIndexedSessionRepositoryShouldHaveEndpointBean() { |
| 116 | + new ReactiveWebApplicationContextRunner() |
| 117 | + .withConfiguration(AutoConfigurations.of(SessionsEndpointAutoConfiguration.class)) |
| 118 | + .withUserConfiguration(ReactiveSessionRepositoryConfiguration.class) |
| 119 | + .withPropertyValues("management.endpoints.web.exposure.include=sessions") |
| 120 | + .run((context) -> assertThat(context).hasSingleBean(ReactiveSessionsEndpoint.class)); |
| 121 | + } |
| 122 | + |
| 123 | + @Test |
| 124 | + void runWhenNotExposedShouldNotHaveEndpointBean() { |
| 125 | + this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(ReactiveSessionsEndpoint.class)); |
| 126 | + } |
| 127 | + |
| 128 | + @Test |
| 129 | + void runWhenEnabledPropertyIsFalseShouldNotHaveEndpointBean() { |
| 130 | + this.contextRunner.withPropertyValues("management.endpoint.sessions.enabled:false") |
| 131 | + .run((context) -> assertThat(context).doesNotHaveBean(ReactiveSessionsEndpoint.class)); |
| 132 | + } |
| 133 | + |
| 134 | + @Configuration(proxyBeanMethods = false) |
| 135 | + static class ReactiveIndexedSessionRepositoryConfiguration { |
| 136 | + |
| 137 | + @Bean |
| 138 | + ReactiveFindByIndexNameSessionRepository<?> indexedSessionRepository() { |
| 139 | + return mock(ReactiveFindByIndexNameSessionRepository.class); |
| 140 | + } |
| 141 | + |
| 142 | + } |
| 143 | + |
| 144 | + @Configuration(proxyBeanMethods = false) |
| 145 | + static class ReactiveSessionRepositoryConfiguration { |
| 146 | + |
| 147 | + @Bean |
| 148 | + ReactiveSessionRepository<?> sessionRepository() { |
| 149 | + return mock(ReactiveSessionRepository.class); |
| 150 | + } |
61 | 151 |
|
62 |
| - @Bean |
63 |
| - FindByIndexNameSessionRepository<?> sessionRepository() { |
64 |
| - return mock(FindByIndexNameSessionRepository.class); |
65 | 152 | }
|
66 | 153 |
|
67 | 154 | }
|
|
0 commit comments