|
|
|
|
@ -1,5 +1,5 @@
@@ -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"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test
@@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.getBean |
|
|
|
|
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.context.annotation.Bean |
|
|
|
|
import org.springframework.context.annotation.Configuration |
|
|
|
|
@ -36,7 +37,7 @@ class SpringApplicationExtensionsTests {
@@ -36,7 +37,7 @@ class SpringApplicationExtensionsTests {
|
|
|
|
|
@Test |
|
|
|
|
fun `Kotlin runApplication() top level function`() { |
|
|
|
|
val context = runApplication<ExampleWebConfig>() |
|
|
|
|
assertThat(context).isNotNull |
|
|
|
|
assertThat(context).isNotNull() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -45,7 +46,7 @@ class SpringApplicationExtensionsTests {
@@ -45,7 +46,7 @@ class SpringApplicationExtensionsTests {
|
|
|
|
|
val context = runApplication<ExampleWebConfig> { |
|
|
|
|
setEnvironment(environment) |
|
|
|
|
} |
|
|
|
|
assertThat(context).isNotNull |
|
|
|
|
assertThat(context).isNotNull() |
|
|
|
|
assertThat(environment).isEqualTo(context.environment) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -54,7 +55,7 @@ class SpringApplicationExtensionsTests {
@@ -54,7 +55,7 @@ class SpringApplicationExtensionsTests {
|
|
|
|
|
val context = runApplication<ExampleWebConfig>("--debug", "spring", "boot") |
|
|
|
|
val args = context.getBean<ApplicationArguments>() |
|
|
|
|
assertThat(args.nonOptionArgs.toTypedArray()).containsExactly("spring", "boot") |
|
|
|
|
assertThat(args.containsOption("debug")).isEqualTo(true) |
|
|
|
|
assertThat(args.containsOption("debug")).isTrue() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -65,14 +66,21 @@ class SpringApplicationExtensionsTests {
@@ -65,14 +66,21 @@ class SpringApplicationExtensionsTests {
|
|
|
|
|
} |
|
|
|
|
val args = context.getBean<ApplicationArguments>() |
|
|
|
|
assertThat(args.nonOptionArgs.toTypedArray()).containsExactly("spring", "boot") |
|
|
|
|
assertThat(args.containsOption("debug")).isEqualTo(true) |
|
|
|
|
assertThat(args.containsOption("debug")).isTrue() |
|
|
|
|
assertThat(environment).isEqualTo(context.environment) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
fun `Kotlin fromApplication() top level function`() { |
|
|
|
|
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 |
|
|
|
|
@ -91,4 +99,14 @@ class SpringApplicationExtensionsTests {
@@ -91,4 +99,14 @@ class SpringApplicationExtensionsTests {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false) |
|
|
|
|
internal open class ExampleFilterConfig { |
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
open fun filter(): MockFilter { |
|
|
|
|
return MockFilter() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|