|
| 1 | +/* |
| 2 | + * Copyright 2012-2017 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 | + * http://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 or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.actuate.autoconfigure.web.reactive; |
| 18 | + |
| 19 | +import org.junit.Test; |
| 20 | + |
| 21 | +import org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerAutoConfiguration; |
| 22 | +import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext; |
| 23 | +import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; |
| 24 | +import org.springframework.context.ApplicationContext; |
| 25 | +import org.springframework.context.annotation.Bean; |
| 26 | +import org.springframework.context.annotation.Configuration; |
| 27 | +import org.springframework.http.server.reactive.HttpHandler; |
| 28 | + |
| 29 | +import static org.assertj.core.api.Assertions.assertThat; |
| 30 | +import static org.mockito.Mockito.mock; |
| 31 | + |
| 32 | +/** |
| 33 | + * Tests for {@link ReactiveManagementContextFactory}. |
| 34 | + * |
| 35 | + * @author Madhura Bhave |
| 36 | + */ |
| 37 | +public class ReactiveManagementContextFactoryTests { |
| 38 | + |
| 39 | + private ReactiveManagementContextFactory factory = new ReactiveManagementContextFactory(); |
| 40 | + |
| 41 | + private AnnotationConfigReactiveWebServerApplicationContext parent = new AnnotationConfigReactiveWebServerApplicationContext(); |
| 42 | + |
| 43 | + @Test |
| 44 | + public void createManagementContextShouldCreateChildContextWithConfigClasses() throws Exception { |
| 45 | + this.parent.register(ParentConfiguration.class); |
| 46 | + this.parent.refresh(); |
| 47 | + AnnotationConfigReactiveWebServerApplicationContext childContext = (AnnotationConfigReactiveWebServerApplicationContext) this.factory.createManagementContext(this.parent, |
| 48 | + TestConfiguration1.class, TestConfiguration2.class); |
| 49 | + childContext.refresh(); |
| 50 | + assertThat(childContext.getBean(TestConfiguration1.class)).isNotNull(); |
| 51 | + assertThat(childContext.getBean(TestConfiguration2.class)).isNotNull(); |
| 52 | + assertThat(childContext.getBean(ReactiveWebServerAutoConfiguration.class)).isNotNull(); |
| 53 | + } |
| 54 | + |
| 55 | + @Configuration |
| 56 | + static class ParentConfiguration { |
| 57 | + |
| 58 | + @Bean |
| 59 | + public ReactiveWebServerFactory reactiveWebServerFactory() { |
| 60 | + return mock(ReactiveWebServerFactory.class); |
| 61 | + } |
| 62 | + |
| 63 | + @Bean |
| 64 | + public HttpHandler httpHandler(ApplicationContext applicationContext) { |
| 65 | + return mock(HttpHandler.class); |
| 66 | + } |
| 67 | + |
| 68 | + } |
| 69 | + |
| 70 | + @Configuration |
| 71 | + static class TestConfiguration1 { |
| 72 | + |
| 73 | + @Bean |
| 74 | + public HttpHandler httpHandler(ApplicationContext applicationContext) { |
| 75 | + return mock(HttpHandler.class); |
| 76 | + } |
| 77 | + |
| 78 | + } |
| 79 | + |
| 80 | + @Configuration |
| 81 | + static class TestConfiguration2 { |
| 82 | + |
| 83 | + } |
| 84 | + |
| 85 | +} |
0 commit comments