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
e7675a06
Commit
e7675a06
authored
Jan 18, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests for YAML parsing errors
Test for gh-235
parent
0a6074be
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
YamlProcessorTests.java
...a/org/springframework/boot/config/YamlProcessorTests.java
+19
-0
YamlPropertiesFactoryBeanTests.java
...framework/boot/config/YamlPropertiesFactoryBeanTests.java
+16
-0
No files found.
spring-boot/src/test/java/org/springframework/boot/config/YamlProcessorTests.java
View file @
e7675a06
...
...
@@ -18,10 +18,13 @@ package org.springframework.boot.config;
import
java.util.Map
;
import
java.util.Properties
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.springframework.boot.config.YamlProcessor.MatchCallback
;
import
org.springframework.core.io.ByteArrayResource
;
import
org.springframework.core.io.Resource
;
import
org.yaml.snakeyaml.scanner.ScannerException
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
...
...
@@ -34,6 +37,9 @@ public class YamlProcessorTests {
private
YamlProcessor
processor
=
new
YamlProcessor
();
@Rule
public
ExpectedException
exception
=
ExpectedException
.
none
();
@Test
public
void
arrayConvertedToIndexedBeanReference
()
{
this
.
processor
.
setResources
(
new
Resource
[]
{
new
ByteArrayResource
(
...
...
@@ -49,6 +55,19 @@ public class YamlProcessorTests {
});
}
@Test
public
void
testBadResource
()
throws
Exception
{
this
.
processor
.
setResources
(
new
Resource
[]
{
new
ByteArrayResource
(
"foo: bar\ncd\nspam:\n foo: baz"
.
getBytes
())
});
this
.
exception
.
expect
(
ScannerException
.
class
);
this
.
exception
.
expectMessage
(
"line 3, column 1"
);
this
.
processor
.
process
(
new
MatchCallback
()
{
@Override
public
void
process
(
Properties
properties
,
Map
<
String
,
Object
>
map
)
{
}
});
}
@Test
public
void
mapConvertedToIndexedBeanReference
()
{
this
.
processor
.
setResources
(
new
Resource
[]
{
new
ByteArrayResource
(
...
...
spring-boot/src/test/java/org/springframework/boot/config/YamlPropertiesFactoryBeanTests.java
View file @
e7675a06
...
...
@@ -21,7 +21,9 @@ import java.util.Map;
import
java.util.Properties
;
import
org.junit.Ignore
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.springframework.boot.config.YamlProcessor.DocumentMatcher
;
import
org.springframework.boot.config.YamlProcessor.MatchStatus
;
import
org.springframework.boot.config.YamlProcessor.ResolutionMethod
;
...
...
@@ -29,6 +31,7 @@ import org.springframework.core.io.ByteArrayResource;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.core.io.Resource
;
import
org.yaml.snakeyaml.Yaml
;
import
org.yaml.snakeyaml.scanner.ScannerException
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
...
...
@@ -39,6 +42,9 @@ import static org.junit.Assert.assertEquals;
*/
public
class
YamlPropertiesFactoryBeanTests
{
@Rule
public
ExpectedException
exception
=
ExpectedException
.
none
();
@Test
public
void
testLoadResource
()
throws
Exception
{
YamlPropertiesFactoryBean
factory
=
new
YamlPropertiesFactoryBean
();
...
...
@@ -49,6 +55,16 @@ public class YamlPropertiesFactoryBeanTests {
assertEquals
(
"baz"
,
properties
.
get
(
"spam.foo"
));
}
@Test
public
void
testBadResource
()
throws
Exception
{
YamlPropertiesFactoryBean
factory
=
new
YamlPropertiesFactoryBean
();
factory
.
setResources
(
new
Resource
[]
{
new
ByteArrayResource
(
"foo: bar\ncd\nspam:\n foo: baz"
.
getBytes
())
});
this
.
exception
.
expect
(
ScannerException
.
class
);
this
.
exception
.
expectMessage
(
"line 3, column 1"
);
factory
.
getObject
();
}
@Test
public
void
testLoadResourcesWithOverride
()
throws
Exception
{
YamlPropertiesFactoryBean
factory
=
new
YamlPropertiesFactoryBean
();
...
...
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