|
| 1 | +/* |
| 2 | + * Copyright [2021-present] [ahoo wang <[email protected]> (https://github.com/Ahoo-Wang)]. |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * Unless required by applicable law or agreed to in writing, software |
| 8 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | + * See the License for the specific language governing permissions and |
| 11 | + * limitations under the License. |
| 12 | + */ |
| 13 | + |
| 14 | +package me.ahoo.wow.spring.boot.starter.command |
| 15 | + |
| 16 | +import io.mockk.every |
| 17 | +import io.mockk.mockk |
| 18 | +import me.ahoo.cosid.machine.HostAddressSupplier |
| 19 | +import me.ahoo.wow.openapi.command.CommandWaitRouteSpecFactory |
| 20 | +import org.hamcrest.CoreMatchers.equalTo |
| 21 | +import org.hamcrest.MatcherAssert.* |
| 22 | +import org.junit.jupiter.api.Test |
| 23 | +import org.springframework.boot.web.context.WebServerInitializedEvent |
| 24 | + |
| 25 | +class ServerCommandWaitEndpointTest { |
| 26 | + |
| 27 | + @Test |
| 28 | + fun endpoint() { |
| 29 | + val hostAddress = "127.0.0.1" |
| 30 | + val serverCommandWaitEndpoint = ServerCommandWaitEndpoint(object : HostAddressSupplier { |
| 31 | + override fun getHostAddress(): String? { |
| 32 | + return hostAddress |
| 33 | + } |
| 34 | + }) |
| 35 | + val event = mockk<WebServerInitializedEvent> { |
| 36 | + every { webServer.port } returns 8080 |
| 37 | + } |
| 38 | + serverCommandWaitEndpoint.onApplicationEvent(event) |
| 39 | + assertThat( |
| 40 | + serverCommandWaitEndpoint.endpoint, |
| 41 | + equalTo("http://$hostAddress:8080${CommandWaitRouteSpecFactory.PATH}") |
| 42 | + ) |
| 43 | + } |
| 44 | +} |
0 commit comments