Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
bddf624b
Commit
bddf624b
authored
Dec 17, 2013
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge EnableConfigurationPropertiesTests
Fixes gh-168
parent
bdcb94a1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
162 deletions
+99
-162
EnableConfigurationPropertiesTests.java
...ontext/properties/EnableConfigurationPropertiesTests.java
+99
-0
EnableConfigurationPropertiesTests.java
...boot/context/test/EnableConfigurationPropertiesTests.java
+0
-162
No files found.
spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java
View file @
bddf624b
...
...
@@ -290,6 +290,39 @@ public class EnableConfigurationPropertiesTests {
assertEquals
(
"foo"
,
this
.
context
.
getBean
(
TestConsumer
.
class
).
getName
());
}
@Test
public
void
testUnderscoresInPrefix
()
throws
Exception
{
TestUtils
.
addEnviroment
(
this
.
context
,
"spring_test_external_val:baz"
);
this
.
context
.
register
(
SystemExampleConfig
.
class
);
this
.
context
.
refresh
();
assertEquals
(
"baz"
,
this
.
context
.
getBean
(
SystemEnvVar
.
class
).
getVal
());
}
@Test
public
void
testSimpleAutoConfig
()
throws
Exception
{
TestUtils
.
addEnviroment
(
this
.
context
,
"external.name:foo"
);
this
.
context
.
register
(
ExampleConfig
.
class
);
this
.
context
.
refresh
();
assertEquals
(
"foo"
,
this
.
context
.
getBean
(
External
.
class
).
getName
());
}
@Test
public
void
testExplicitType
()
throws
Exception
{
TestUtils
.
addEnviroment
(
this
.
context
,
"external.name:foo"
);
this
.
context
.
register
(
AnotherExampleConfig
.
class
);
this
.
context
.
refresh
();
assertEquals
(
"foo"
,
this
.
context
.
getBean
(
External
.
class
).
getName
());
}
@Test
public
void
testMultipleExplicitTypes
()
throws
Exception
{
TestUtils
.
addEnviroment
(
this
.
context
,
"external.name:foo"
,
"another.name:bar"
);
this
.
context
.
register
(
FurtherExampleConfig
.
class
);
this
.
context
.
refresh
();
assertEquals
(
"foo"
,
this
.
context
.
getBean
(
External
.
class
).
getName
());
assertEquals
(
"bar"
,
this
.
context
.
getBean
(
Another
.
class
).
getName
());
}
/**
* Strict tests need a known set of properties so we remove system items which may be
* environment specific.
...
...
@@ -356,6 +389,72 @@ public class EnableConfigurationPropertiesTests {
protected
static
class
DefaultXmlConfiguration
{
}
@EnableConfigurationProperties
@Configuration
public
static
class
ExampleConfig
{
@Bean
public
External
external
()
{
return
new
External
();
}
}
@EnableConfigurationProperties
(
External
.
class
)
@Configuration
public
static
class
AnotherExampleConfig
{
}
@EnableConfigurationProperties
({
External
.
class
,
Another
.
class
})
@Configuration
public
static
class
FurtherExampleConfig
{
}
@EnableConfigurationProperties
({
SystemEnvVar
.
class
})
@Configuration
public
static
class
SystemExampleConfig
{
}
@ConfigurationProperties
(
name
=
"external"
)
public
static
class
External
{
private
String
name
;
public
String
getName
()
{
return
this
.
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
}
@ConfigurationProperties
(
name
=
"another"
)
public
static
class
Another
{
private
String
name
;
public
String
getName
()
{
return
this
.
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
}
@ConfigurationProperties
(
name
=
"spring_test_external"
)
public
static
class
SystemEnvVar
{
public
String
getVal
()
{
return
this
.
val
;
}
public
void
setVal
(
String
val
)
{
this
.
val
=
val
;
}
private
String
val
;
}
@Component
protected
static
class
TestConsumer
{
@Autowired
...
...
spring-boot/src/test/java/org/springframework/boot/context/test/EnableConfigurationPropertiesTests.java
deleted
100644 → 0
View file @
bdcb94a1
/*
* Copyright 2012-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
context
.
test
;
import
java.util.Properties
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.env.PropertiesPropertySource
;
import
org.springframework.core.io.ByteArrayResource
;
import
org.springframework.core.io.support.PropertiesLoaderUtils
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
/**
* Tests for {@link EnableConfigurationProperties}.
*
* @author Dave Syer
*/
public
class
EnableConfigurationPropertiesTests
{
private
AnnotationConfigApplicationContext
context
;
@Before
public
void
open
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
.
getEnvironment
()
.
getPropertySources
()
.
addFirst
(
new
PropertiesPropertySource
(
"props"
,
getProperties
(
"external.name=foo\nanother.name=bar\nspring_test_external_val=baz"
)));
}
@After
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
public
void
testUnderscoresInPrefix
()
throws
Exception
{
this
.
context
.
register
(
SystemExampleConfig
.
class
);
this
.
context
.
refresh
();
assertEquals
(
"baz"
,
this
.
context
.
getBean
(
SystemEnvVar
.
class
).
getVal
());
}
@Test
public
void
testSimpleAutoConfig
()
throws
Exception
{
this
.
context
.
register
(
ExampleConfig
.
class
);
this
.
context
.
refresh
();
assertEquals
(
"foo"
,
this
.
context
.
getBean
(
External
.
class
).
getName
());
}
@Test
public
void
testExplicitType
()
throws
Exception
{
this
.
context
.
register
(
AnotherExampleConfig
.
class
);
this
.
context
.
refresh
();
assertEquals
(
"foo"
,
this
.
context
.
getBean
(
External
.
class
).
getName
());
}
@Test
public
void
testMultipleExplicitTypes
()
throws
Exception
{
this
.
context
.
register
(
FurtherExampleConfig
.
class
);
this
.
context
.
refresh
();
assertEquals
(
"foo"
,
this
.
context
.
getBean
(
External
.
class
).
getName
());
assertEquals
(
"bar"
,
this
.
context
.
getBean
(
Another
.
class
).
getName
());
}
private
Properties
getProperties
(
String
values
)
throws
Exception
{
return
PropertiesLoaderUtils
.
loadProperties
(
new
ByteArrayResource
(
values
.
getBytes
()));
}
@EnableConfigurationProperties
@Configuration
public
static
class
ExampleConfig
{
@Bean
public
External
external
()
{
return
new
External
();
}
}
@EnableConfigurationProperties
(
External
.
class
)
@Configuration
public
static
class
AnotherExampleConfig
{
}
@EnableConfigurationProperties
({
External
.
class
,
Another
.
class
})
@Configuration
public
static
class
FurtherExampleConfig
{
}
@EnableConfigurationProperties
({
SystemEnvVar
.
class
})
@Configuration
public
static
class
SystemExampleConfig
{
}
@ConfigurationProperties
(
name
=
"external"
)
public
static
class
External
{
private
String
name
;
public
String
getName
()
{
return
this
.
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
}
@ConfigurationProperties
(
name
=
"another"
)
public
static
class
Another
{
private
String
name
;
public
String
getName
()
{
return
this
.
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
}
@ConfigurationProperties
(
name
=
"spring_test_external"
)
public
static
class
SystemEnvVar
{
public
String
getVal
()
{
return
this
.
val
;
}
public
void
setVal
(
String
val
)
{
this
.
val
=
val
;
}
private
String
val
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment