Use the accepted profiles in BeanDefinitionDsl

Closes gh-22393
This commit is contained in:
Thomas Girard
2019-02-08 14:14:37 +01:00
committed by Sebastien Deleuze
parent ba95818b1d
commit 87c15ba9ad
2 changed files with 37 additions and 3 deletions

View File

@@ -170,6 +170,38 @@ class BeanDefinitionDslTests {
context.getBean<Baz>()
}
@Test
fun `Declare beans with accepted profiles`() {
val beans = beans {
profile("foo") { bean<Foo>() }
profile("!bar") { bean<Bar>() }
profile("bar | barbar") { bean<BarBar>() }
profile("baz & buz") { bean<Baz>() }
profile("baz & foo") { bean<FooFoo>() }
}
val context = GenericApplicationContext().apply {
environment.addActiveProfile("barbar")
environment.addActiveProfile("baz")
environment.addActiveProfile("buz")
beans.initialize(this)
refresh()
}
context.getBean<Baz>()
context.getBean<BarBar>()
context.getBean<Bar>()
try {
context.getBean<Foo>()
fail()
} catch (ignored: Exception) {
}
try {
context.getBean<FooFoo>()
fail()
} catch (ignored: Exception) {
}
}
}
class Foo