|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2002-2022 the original author or authors.
|
|
|
|
* Copyright 2002-2023 the original author or authors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.getBean
|
|
|
|
import org.springframework.beans.factory.getBean
|
|
|
|
import org.springframework.boot.kotlinsample.TestKotlinApplication
|
|
|
|
import org.springframework.boot.kotlinsample.TestKotlinApplication
|
|
|
|
|
|
|
|
import org.springframework.boot.web.servlet.mock.MockFilter
|
|
|
|
import org.springframework.boot.web.servlet.server.MockServletWebServerFactory
|
|
|
|
import org.springframework.boot.web.servlet.server.MockServletWebServerFactory
|
|
|
|
import org.springframework.context.annotation.Bean
|
|
|
|
import org.springframework.context.annotation.Bean
|
|
|
|
import org.springframework.context.annotation.Configuration
|
|
|
|
import org.springframework.context.annotation.Configuration
|
|
|
@ -36,7 +37,7 @@ class SpringApplicationExtensionsTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun `Kotlin runApplication() top level function`() {
|
|
|
|
fun `Kotlin runApplication() top level function`() {
|
|
|
|
val context = runApplication<ExampleWebConfig>()
|
|
|
|
val context = runApplication<ExampleWebConfig>()
|
|
|
|
assertThat(context).isNotNull
|
|
|
|
assertThat(context).isNotNull()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -45,7 +46,7 @@ class SpringApplicationExtensionsTests {
|
|
|
|
val context = runApplication<ExampleWebConfig> {
|
|
|
|
val context = runApplication<ExampleWebConfig> {
|
|
|
|
setEnvironment(environment)
|
|
|
|
setEnvironment(environment)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assertThat(context).isNotNull
|
|
|
|
assertThat(context).isNotNull()
|
|
|
|
assertThat(environment).isEqualTo(context.environment)
|
|
|
|
assertThat(environment).isEqualTo(context.environment)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -54,7 +55,7 @@ class SpringApplicationExtensionsTests {
|
|
|
|
val context = runApplication<ExampleWebConfig>("--debug", "spring", "boot")
|
|
|
|
val context = runApplication<ExampleWebConfig>("--debug", "spring", "boot")
|
|
|
|
val args = context.getBean<ApplicationArguments>()
|
|
|
|
val args = context.getBean<ApplicationArguments>()
|
|
|
|
assertThat(args.nonOptionArgs.toTypedArray()).containsExactly("spring", "boot")
|
|
|
|
assertThat(args.nonOptionArgs.toTypedArray()).containsExactly("spring", "boot")
|
|
|
|
assertThat(args.containsOption("debug")).isEqualTo(true)
|
|
|
|
assertThat(args.containsOption("debug")).isTrue()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -65,14 +66,21 @@ class SpringApplicationExtensionsTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val args = context.getBean<ApplicationArguments>()
|
|
|
|
val args = context.getBean<ApplicationArguments>()
|
|
|
|
assertThat(args.nonOptionArgs.toTypedArray()).containsExactly("spring", "boot")
|
|
|
|
assertThat(args.nonOptionArgs.toTypedArray()).containsExactly("spring", "boot")
|
|
|
|
assertThat(args.containsOption("debug")).isEqualTo(true)
|
|
|
|
assertThat(args.containsOption("debug")).isTrue()
|
|
|
|
assertThat(environment).isEqualTo(context.environment)
|
|
|
|
assertThat(environment).isEqualTo(context.environment)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun `Kotlin fromApplication() top level function`() {
|
|
|
|
fun `Kotlin fromApplication() top level function`() {
|
|
|
|
val context = fromApplication<TestKotlinApplication>().with(ExampleWebConfig::class).run().applicationContext
|
|
|
|
val context = fromApplication<TestKotlinApplication>().with(ExampleWebConfig::class).run().applicationContext
|
|
|
|
assertThat(context.getBean<MockServletWebServerFactory>()).isNotNull
|
|
|
|
assertThat(context.getBean<MockServletWebServerFactory>()).isNotNull()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
fun `Kotlin fromApplication() top level function with multiple sources`() {
|
|
|
|
|
|
|
|
val context = fromApplication<TestKotlinApplication>().with(ExampleWebConfig::class, ExampleFilterConfig::class).run().applicationContext
|
|
|
|
|
|
|
|
assertThat(context.getBean<MockServletWebServerFactory>()).isNotNull()
|
|
|
|
|
|
|
|
assertThat(context.getBean<MockFilter>()).isNotNull()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -91,4 +99,14 @@ class SpringApplicationExtensionsTests {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
|
|
|
|
internal open class ExampleFilterConfig {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
|
|
|
open fun filter(): MockFilter {
|
|
|
|
|
|
|
|
return MockFilter()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|