Skip to content

Commit dce046f

Browse files
authored
test(wow-spring-boot-starter): add unit tests for PrepareAutoConfiguration and ServerCommandWaitEndpoint (#1099)
- Add PrepareAutoConfigurationTest to verify the loading of PrepareProperties bean - Add ServerCommandWaitEndpointTest to test the endpoint URL construction
1 parent 56d2ce5 commit dce046f

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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.prepare
15+
16+
import me.ahoo.wow.spring.boot.starter.enableWow
17+
import org.assertj.core.api.AssertionsForInterfaceTypes
18+
import org.junit.jupiter.api.Test
19+
import org.springframework.boot.test.context.assertj.AssertableApplicationContext
20+
import org.springframework.boot.test.context.runner.ApplicationContextRunner
21+
22+
class PrepareAutoConfigurationTest {
23+
private val contextRunner = ApplicationContextRunner()
24+
25+
@Test
26+
fun contextLoads() {
27+
contextRunner
28+
.enableWow()
29+
.withUserConfiguration(PrepareAutoConfiguration::class.java)
30+
.run { context: AssertableApplicationContext ->
31+
AssertionsForInterfaceTypes.assertThat(context)
32+
.hasSingleBean(PrepareProperties::class.java)
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)