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
ccd19ce2
Commit
ccd19ce2
authored
May 24, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.3.x'
parents
6ed63a6e
275651e8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
20 deletions
+59
-20
SampleCassandraApplicationTests.java
...ample/data/cassandra/SampleCassandraApplicationTests.java
+30
-0
SampleElasticsearchApplicationTests.java
...ta/elasticsearch/SampleElasticsearchApplicationTests.java
+29
-20
No files found.
spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java
View file @
ccd19ce2
...
...
@@ -16,11 +16,16 @@
package
sample
.
data
.
cassandra
;
import
java.io.File
;
import
org.cassandraunit.spring.CassandraDataSet
;
import
org.cassandraunit.spring.EmbeddedCassandra
;
import
org.junit.ClassRule
;
import
org.junit.Test
;
import
org.junit.rules.TestRule
;
import
org.junit.runner.Description
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.model.Statement
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.rule.OutputCapture
;
...
...
@@ -44,10 +49,35 @@ public class SampleCassandraApplicationTests {
@ClassRule
public
static
OutputCapture
outputCapture
=
new
OutputCapture
();
@ClassRule
public
static
SkipOnWindows
skipOnWindows
=
new
SkipOnWindows
();
@Test
public
void
testDefaultSettings
()
throws
Exception
{
String
output
=
SampleCassandraApplicationTests
.
outputCapture
.
toString
();
assertThat
(
output
).
contains
(
"firstName='Alice', lastName='Smith'"
);
}
static
class
SkipOnWindows
implements
TestRule
{
@Override
public
Statement
apply
(
final
Statement
base
,
Description
description
)
{
return
new
Statement
()
{
@Override
public
void
evaluate
()
throws
Throwable
{
if
(!
runningOnWindows
())
{
base
.
evaluate
();
}
}
private
boolean
runningOnWindows
()
{
return
File
.
separatorChar
==
'\\'
;
}
};
}
}
}
spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java
View file @
ccd19ce2
...
...
@@ -16,14 +16,17 @@
package
sample
.
data
.
elasticsearch
;
import
java.
net.ConnectException
;
import
java.
io.File
;
import
org.junit.ClassRule
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.TestRule
;
import
org.junit.runner.Description
;
import
org.junit.runners.model.Statement
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.test.rule.OutputCapture
;
import
org.springframework.core.NestedCheckedException
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -33,34 +36,40 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Artur Konczak
*/
public
class
SampleElasticsearchApplicationTests
{
@Rule
public
OutputCapture
outputCapture
=
new
OutputCapture
();
@ClassRule
public
static
SkipOnWindows
skipOnWindows
=
new
SkipOnWindows
();
@Test
public
void
testDefaultSettings
()
throws
Exception
{
try
{
new
SpringApplicationBuilder
(
SampleElasticsearchApplication
.
class
).
run
();
}
catch
(
IllegalStateException
ex
)
{
if
(
serverNotRunning
(
ex
))
{
return
;
}
}
new
SpringApplicationBuilder
(
SampleElasticsearchApplication
.
class
).
run
();
String
output
=
this
.
outputCapture
.
toString
();
assertThat
(
output
).
contains
(
"firstName='Alice', lastName='Smith'"
);
}
private
boolean
serverNotRunning
(
IllegalStateException
ex
)
{
@SuppressWarnings
(
"serial"
)
NestedCheckedException
nested
=
new
NestedCheckedException
(
"failed"
,
ex
)
{
};
if
(
nested
.
contains
(
ConnectException
.
class
))
{
Throwable
root
=
nested
.
getRootCause
();
if
(
root
.
getMessage
().
contains
(
"Connection refused"
))
{
return
true
;
}
static
class
SkipOnWindows
implements
TestRule
{
@Override
public
Statement
apply
(
final
Statement
base
,
Description
description
)
{
return
new
Statement
()
{
@Override
public
void
evaluate
()
throws
Throwable
{
if
(!
runningOnWindows
())
{
base
.
evaluate
();
}
}
private
boolean
runningOnWindows
()
{
return
File
.
separatorChar
==
'\\'
;
}
};
}
return
false
;
}
}
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