|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2021 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.
|
|
24 | 24 | import javax.servlet.ServletRequest;
|
25 | 25 | import javax.servlet.ServletResponse;
|
26 | 26 | import javax.servlet.http.HttpServlet;
|
| 27 | +import javax.servlet.http.HttpSessionIdListener; |
27 | 28 |
|
28 | 29 | import org.junit.jupiter.api.Test;
|
29 | 30 |
|
@@ -70,6 +71,17 @@ void looksForInitializerBeansOfSpecifiedType() {
|
70 | 71 | assertThat(initializerBeans.iterator()).toIterable().hasOnlyElementsOfType(TestServletContextInitializer.class);
|
71 | 72 | }
|
72 | 73 |
|
| 74 | + @Test |
| 75 | + void whenAnHttpSessionIdListenerBeanIsDefinedThenARegistrationBeanIsCreatedForIt() { |
| 76 | + load(HttpSessionIdListenerConfiguration.class); |
| 77 | + ServletContextInitializerBeans initializerBeans = new ServletContextInitializerBeans( |
| 78 | + this.context.getBeanFactory()); |
| 79 | + assertThat(initializerBeans).hasSize(1); |
| 80 | + assertThat(initializerBeans).first().isInstanceOf(ServletListenerRegistrationBean.class) |
| 81 | + .extracting(ServletListenerRegistrationBean.class::cast) |
| 82 | + .extracting(ServletListenerRegistrationBean::getListener).isInstanceOf(HttpSessionIdListener.class); |
| 83 | + } |
| 84 | + |
73 | 85 | private void load(Class<?>... configuration) {
|
74 | 86 | this.context = new AnnotationConfigApplicationContext(configuration);
|
75 | 87 | }
|
@@ -109,6 +121,17 @@ OtherTestServletContextInitializer otherTestServletContextInitializer() {
|
109 | 121 |
|
110 | 122 | }
|
111 | 123 |
|
| 124 | + @Configuration(proxyBeanMethods = false) |
| 125 | + static class HttpSessionIdListenerConfiguration { |
| 126 | + |
| 127 | + @Bean |
| 128 | + HttpSessionIdListener httpSessionIdListener() { |
| 129 | + return (event, oldId) -> { |
| 130 | + }; |
| 131 | + } |
| 132 | + |
| 133 | + } |
| 134 | + |
112 | 135 | static class TestServlet extends HttpServlet implements ServletContextInitializer {
|
113 | 136 |
|
114 | 137 | @Override
|
|
0 commit comments