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
1cc1fc64
Commit
1cc1fc64
authored
Feb 06, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use AssertJ in spring-boot-samples
See gh-5083
parent
962a5985
Changes
97
Hide whitespace changes
Inline
Side-by-side
Showing
97 changed files
with
580 additions
and
733 deletions
+580
-733
SampleActiveMqTests.java
...mq/src/test/java/sample/activemq/SampleActiveMqTests.java
+2
-2
SampleActuatorApplicationTests.java
...ample/actuator/log4j2/SampleActuatorApplicationTests.java
+3
-3
SampleActuatorNoWebApplicationTests.java
...e/actuator/noweb/SampleActuatorNoWebApplicationTests.java
+2
-2
SampleActuatorUiApplicationPortTests.java
...ple/actuator/ui/SampleActuatorUiApplicationPortTests.java
+5
-5
SampleActuatorUiApplicationTests.java
.../sample/actuator/ui/SampleActuatorUiApplicationTests.java
+9
-15
EndpointsPropertiesSampleActuatorApplicationTests.java
...or/EndpointsPropertiesSampleActuatorApplicationTests.java
+7
-11
InsecureManagementPortAndPathSampleActuatorApplicationTests.java
...eManagementPortAndPathSampleActuatorApplicationTests.java
+8
-11
InsecureManagementSampleActuatorApplicationTests.java
...tor/InsecureManagementSampleActuatorApplicationTests.java
+6
-10
InsecureSampleActuatorApplicationTests.java
...mple/actuator/InsecureSampleActuatorApplicationTests.java
+4
-6
ManagementAddressActuatorApplicationTests.java
...e/actuator/ManagementAddressActuatorApplicationTests.java
+4
-6
ManagementPathSampleActuatorApplicationTests.java
...ctuator/ManagementPathSampleActuatorApplicationTests.java
+6
-10
ManagementPortAndPathSampleActuatorApplicationTests.java
.../ManagementPortAndPathSampleActuatorApplicationTests.java
+12
-16
ManagementPortSampleActuatorApplicationTests.java
...ctuator/ManagementPortSampleActuatorApplicationTests.java
+8
-10
NoManagementSampleActuatorApplicationTests.java
.../actuator/NoManagementSampleActuatorApplicationTests.java
+4
-4
NonSensitiveHealthTests.java
...rc/test/java/sample/actuator/NonSensitiveHealthTests.java
+3
-5
SampleActuatorApplicationTests.java
.../java/sample/actuator/SampleActuatorApplicationTests.java
+38
-49
ServletPathInsecureSampleActuatorApplicationTests.java
...or/ServletPathInsecureSampleActuatorApplicationTests.java
+5
-7
ServletPathSampleActuatorApplicationTests.java
...e/actuator/ServletPathSampleActuatorApplicationTests.java
+9
-13
ShutdownSampleActuatorApplicationTests.java
...mple/actuator/ShutdownSampleActuatorApplicationTests.java
+5
-7
SampleAntApplicationIT.java
...-ant/src/test/java/sample/ant/SampleAntApplicationIT.java
+4
-6
SampleAopApplicationTests.java
...p/src/test/java/sample/aop/SampleAopApplicationTests.java
+3
-3
SampleAtmosphereApplicationTests.java
...a/sample/atmosphere/SampleAtmosphereApplicationTests.java
+4
-6
SampleBatchApplicationTests.java
...c/test/java/sample/batch/SampleBatchApplicationTests.java
+4
-6
SampleCacheApplicationTests.java
...c/test/java/sample/cache/SampleCacheApplicationTests.java
+4
-7
SampleCassandraApplicationTests.java
...ample/data/cassandra/SampleCassandraApplicationTests.java
+2
-3
SampleElasticsearchApplicationTests.java
...ta/elasticsearch/SampleElasticsearchApplicationTests.java
+2
-3
SampleDataGemFireApplicationTests.java
...ample/data/gemfire/SampleDataGemFireApplicationTests.java
+35
-54
SampleDataJpaApplicationTests.java
...t/java/sample/data/jpa/SampleDataJpaApplicationTests.java
+4
-4
CityRepositoryIntegrationTests.java
...mple/data/jpa/service/CityRepositoryIntegrationTests.java
+2
-4
HotelRepositoryIntegrationTests.java
...ple/data/jpa/service/HotelRepositoryIntegrationTests.java
+6
-9
SampleMongoApplicationTests.java
...t/java/sample/data/mongo/SampleMongoApplicationTests.java
+2
-3
SampleRedisApplicationTests.java
...t/java/sample/data/redis/SampleRedisApplicationTests.java
+2
-3
CityRepositoryIntegrationTests.java
...ple/data/rest/service/CityRepositoryIntegrationTests.java
+5
-9
SampleSolrApplicationTests.java
...est/java/sample/data/solr/SampleSolrApplicationTests.java
+2
-2
SampleFlywayApplicationTests.java
...test/java/sample/flyway/SampleFlywayApplicationTests.java
+3
-3
SampleHateoasApplicationTests.java
...st/java/sample/hateoas/SampleHateoasApplicationTests.java
+8
-11
SampleHypermediaJpaApplicationIntegrationTests.java
...a/jpa/SampleHypermediaJpaApplicationIntegrationTests.java
+3
-3
SampleHypermediaUiApplicationTests.java
...ple/hypermedia/ui/SampleHypermediaUiApplicationTests.java
+5
-5
SampleHypermediaApplicationHomePageTests.java
.../hypermedia/SampleHypermediaApplicationHomePageTests.java
+4
-4
SampleIntegrationApplicationTests.java
...tegration/consumer/SampleIntegrationApplicationTests.java
+2
-2
SampleJerseyApplicationTests.java
...test/java/sample/jersey/SampleJerseyApplicationTests.java
+5
-5
SampleJersey1ApplicationTests.java
...st/java/sample/jersey1/SampleJersey1ApplicationTests.java
+4
-3
SampleJettySslApplicationTests.java
...java/sample/jetty/ssl/SampleJettySslApplicationTests.java
+3
-3
SampleJettyApplicationTests.java
...c/test/java/sample/jetty/SampleJettyApplicationTests.java
+6
-6
SampleJetty8SslApplicationTests.java
...va/sample/jetty8/ssl/SampleJetty8SslApplicationTests.java
+3
-3
SampleJetty8ApplicationTests.java
...test/java/sample/jetty8/SampleJetty8ApplicationTests.java
+6
-6
SampleJetty93ApplicationTests.java
...st/java/sample/jetty93/SampleJetty93ApplicationTests.java
+6
-6
SampleJooqApplicationTests.java
...src/test/java/sample/jooq/SampleJooqApplicationTests.java
+6
-7
JpaNoteRepositoryIntegrationTests.java
...ple/jpa/repository/JpaNoteRepositoryIntegrationTests.java
+2
-2
JpaTagRepositoryIntegrationTests.java
...mple/jpa/repository/JpaTagRepositoryIntegrationTests.java
+2
-2
SampleAtomikosApplicationTests.java
.../java/sample/atomikos/SampleAtomikosApplicationTests.java
+13
-17
SampleBitronixApplicationTests.java
.../java/sample/bitronix/SampleBitronixApplicationTests.java
+17
-24
SampleLiquibaseApplicationTests.java
...ava/sample/liquibase/SampleLiquibaseApplicationTests.java
+10
-11
SampleDropwizardMetricsApplicationTests.java
...s/dropwizard/SampleDropwizardMetricsApplicationTests.java
+2
-2
SampleProfileApplicationTests.java
...st/java/sample/profile/SampleProfileApplicationTests.java
+5
-5
SamplePropertyValidationApplicationTests.java
...yvalidation/SamplePropertyValidationApplicationTests.java
+5
-5
SampleSecureOAuth2ApplicationTests.java
...ple/secure/oauth2/SampleSecureOAuth2ApplicationTests.java
+6
-7
SampleSecureApplicationTests.java
...test/java/sample/secure/SampleSecureApplicationTests.java
+5
-5
SampleServletApplicationTests.java
...st/java/sample/servlet/SampleServletApplicationTests.java
+4
-4
SampleSessionRedisApplicationTests.java
...ple/session/redis/SampleSessionRedisApplicationTests.java
+3
-6
SampleSimpleApplicationTests.java
...test/java/sample/simple/SampleSimpleApplicationTests.java
+3
-3
SpringTestSampleSimpleApplicationTests.java
...sample/simple/SpringTestSampleSimpleApplicationTests.java
+4
-5
pom.xml
spring-boot-samples/spring-boot-sample-testng/pom.xml
+4
-0
SampleTestNGApplicationTests.java
...test/java/sample/testng/SampleTestNGApplicationTests.java
+3
-3
SampleWebJspApplicationTests.java
.../java/sample/tomcat/jsp/SampleWebJspApplicationTests.java
+3
-5
SampleTomcatTwoConnectorsApplicationTests.java
...iconnector/SampleTomcatTwoConnectorsApplicationTests.java
+5
-5
SampleTomcatSslApplicationTests.java
...t/java/sample/tomcat/SampleTomcatSslApplicationTests.java
+4
-4
NonAutoConfigurationSampleTomcatApplicationTests.java
...cat/NonAutoConfigurationSampleTomcatApplicationTests.java
+4
-4
SampleTomcatApplicationTests.java
...test/java/sample/tomcat/SampleTomcatApplicationTests.java
+6
-6
SampleWebJspApplicationTests.java
...java/sample/tomcat7/jsp/SampleWebJspApplicationTests.java
+3
-5
SampleTraditionalApplicationTests.java
...sample/traditional/SampleTraditionalApplicationTests.java
+5
-8
SampleUndertowSslApplicationTests.java
...ample/undertow/ssl/SampleUndertowSslApplicationTests.java
+3
-3
SampleUndertowApplicationTests.java
.../java/sample/undertow/SampleUndertowApplicationTests.java
+6
-6
SampleVelocityApplicationTests.java
.../java/sample/velocity/SampleVelocityApplicationTests.java
+2
-2
SampleWebFreeMarkerApplicationTests.java
...ample/freemarker/SampleWebFreeMarkerApplicationTests.java
+8
-10
SampleGroovyTemplateApplicationTests.java
...groovytemplates/SampleGroovyTemplateApplicationTests.java
+7
-12
SampleWebJspApplicationTests.java
...rc/test/java/sample/jsp/SampleWebJspApplicationTests.java
+3
-5
SampleMethodSecurityApplicationTests.java
...security/method/SampleMethodSecurityApplicationTests.java
+12
-15
SampleWebMustacheApplicationTests.java
...va/sample/mustache/SampleWebMustacheApplicationTests.java
+6
-8
SampleWebSecureCustomApplicationTests.java
...mple/ui/secure/SampleWebSecureCustomApplicationTests.java
+17
-21
SampleGithubApplicationTests.java
...ample/web/secure/github/SampleGithubApplicationTests.java
+7
-10
SampleWebSecureCustomApplicationTests.java
...eb/secure/jdbc/SampleWebSecureCustomApplicationTests.java
+16
-20
SampleSecureApplicationTests.java
.../java/sample/web/secure/SampleSecureApplicationTests.java
+16
-20
SampleWebStaticApplicationTests.java
...ava/sample/webstatic/SampleWebStaticApplicationTests.java
+8
-11
SampleWebUiApplicationTests.java
.../src/test/java/sample/ui/SampleWebUiApplicationTests.java
+8
-13
SampleWebVelocityApplicationTests.java
...ample/web/velocity/SampleWebVelocityApplicationTests.java
+6
-8
SampleWebSocketsApplicationTests.java
...les/websocket/jetty/SampleWebSocketsApplicationTests.java
+7
-6
CustomContainerWebSocketsApplicationTests.java
...jetty/echo/CustomContainerWebSocketsApplicationTests.java
+7
-6
SnakeTimerTests.java
...t/java/samples/websocket/jetty/snake/SnakeTimerTests.java
+2
-3
SampleWebSocketsApplicationTests.java
...es/websocket/tomcat/SampleWebSocketsApplicationTests.java
+7
-6
CustomContainerWebSocketsApplicationTests.java
...omcat/echo/CustomContainerWebSocketsApplicationTests.java
+7
-6
SnakeTimerTests.java
.../java/samples/websocket/tomcat/snake/SnakeTimerTests.java
+2
-3
SampleWebSocketsApplicationTests.java
.../websocket/undertow/SampleWebSocketsApplicationTests.java
+7
-6
CustomContainerWebSocketsApplicationTests.java
...ertow/echo/CustomContainerWebSocketsApplicationTests.java
+7
-6
SnakeTimerTests.java
...ava/samples/websocket/undertow/snake/SnakeTimerTests.java
+2
-3
SampleWsApplicationTests.java
...-ws/src/test/java/sample/ws/SampleWsApplicationTests.java
+2
-3
SampleSpringXmlApplicationTests.java
...test/java/sample/xml/SampleSpringXmlApplicationTests.java
+2
-2
No files found.
spring-boot-samples/spring-boot-sample-activemq/src/test/java/sample/activemq/SampleActiveMqTests.java
View file @
1cc1fc64
...
...
@@ -27,7 +27,7 @@ import org.springframework.boot.test.OutputCapture;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for demo application.
...
...
@@ -48,7 +48,7 @@ public class SampleActiveMqTests {
public
void
sendSimpleMessage
()
throws
InterruptedException
,
JMSException
{
this
.
producer
.
send
(
"Test message"
);
Thread
.
sleep
(
1000L
);
assertT
rue
(
this
.
outputCapture
.
toString
().
contains
(
"Test message"
)
);
assertT
hat
(
this
.
outputCapture
.
toString
().
contains
(
"Test message"
)).
isTrue
(
);
}
}
spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorApplicationTests.java
View file @
1cc1fc64
...
...
@@ -30,7 +30,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for service demo application.
...
...
@@ -51,10 +51,10 @@ public class SampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
port
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assert
Equals
(
"Hello Daniel"
,
body
.
get
(
"message"
)
);
assert
That
(
body
.
get
(
"message"
)).
isEqualTo
(
"Hello Daniel"
);
}
}
spring-boot-samples/spring-boot-sample-actuator-noweb/src/test/java/sample/actuator/noweb/SampleActuatorNoWebApplicationTests.java
View file @
1cc1fc64
...
...
@@ -25,7 +25,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for service demo application.
...
...
@@ -42,7 +42,7 @@ public class SampleActuatorNoWebApplicationTests {
@Test
public
void
endpointsExist
()
throws
Exception
{
assert
NotNull
(
this
.
endpoint
);
assert
That
(
this
.
endpoint
).
isNotNull
(
);
}
}
spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java
View file @
1cc1fc64
...
...
@@ -30,7 +30,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for separate management and main service ports.
...
...
@@ -53,7 +53,7 @@ public class SampleActuatorUiApplicationPortTests {
public
void
testHome
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
}
@Test
...
...
@@ -61,15 +61,15 @@ public class SampleActuatorUiApplicationPortTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/metrics"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
UNAUTHORIZED
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
}
@Test
public
void
testHealth
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/health"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
Equals
(
"{\"status\":\"UP\"}"
,
entity
.
getBody
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assert
That
(
entity
.
getBody
()).
isEqualTo
(
"{\"status\":\"UP\"}"
);
}
}
spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java
View file @
1cc1fc64
...
...
@@ -35,8 +35,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -59,17 +58,16 @@ public class SampleActuatorUiApplicationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
,
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>(
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body (title doesn't match):\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"<title>Hello"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"<title>Hello"
);
}
@Test
public
void
testCss
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/css/bootstrap.min.css"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assertT
rue
(
"Wrong body:\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"body"
)
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertT
hat
(
entity
.
getBody
()).
contains
(
"body"
);
}
@Test
...
...
@@ -77,7 +75,7 @@ public class SampleActuatorUiApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/metrics"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
UNAUTHORIZED
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
}
@Test
...
...
@@ -87,13 +85,9 @@ public class SampleActuatorUiApplicationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/error"
,
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>(
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
INTERNAL_SERVER_ERROR
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body:\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"<html>"
));
assertTrue
(
"Wrong body:\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"<body>"
));
assertTrue
(
"Wrong body:\n"
+
entity
.
getBody
(),
entity
.
getBody
()
.
contains
(
"Please contact the operator with the above information"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
assertThat
(
entity
.
getBody
()).
contains
(
"<html>"
).
contains
(
"<body>"
)
.
contains
(
"Please contact the operator with the above information"
);
}
}
spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java
View file @
1cc1fc64
...
...
@@ -33,8 +33,7 @@ import org.springframework.test.annotation.DirtiesContext;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for endpoints configuration.
...
...
@@ -59,11 +58,11 @@ public class EndpointsPropertiesSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/oops"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
INTERNAL_SERVER_ERROR
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assert
Equals
(
"None"
,
body
.
get
(
"error"
)
);
assert
Equals
(
999
,
body
.
get
(
"status"
)
);
assert
That
(
body
.
get
(
"error"
)).
isEqualTo
(
"None"
);
assert
That
(
body
.
get
(
"status"
)).
isEqualTo
(
999
);
}
@Test
...
...
@@ -71,12 +70,9 @@ public class EndpointsPropertiesSampleActuatorApplicationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/admin/health"
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"status\":\"UP\""
));
System
.
err
.
println
(
entity
.
getBody
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"hello\":\"world\""
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":\"UP\""
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"hello\":\"world\""
);
}
private
String
getPassword
()
{
...
...
spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementPortAndPathSampleActuatorApplicationTests.java
View file @
1cc1fc64
...
...
@@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for separate management and main service ports.
...
...
@@ -61,10 +60,10 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assert
Equals
(
"Hello Phil"
,
body
.
get
(
"message"
)
);
assert
That
(
body
.
get
(
"message"
)).
isEqualTo
(
"Hello Phil"
);
}
@Test
...
...
@@ -73,7 +72,7 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/admin/metrics"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
}
@Test
...
...
@@ -81,9 +80,8 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/admin/health"
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"status\":\"UP\""
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":\"UP\""
);
}
@Test
...
...
@@ -91,9 +89,8 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/admin/missing"
,
String
.
class
);
assertEquals
(
HttpStatus
.
NOT_FOUND
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"status\":404"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":404"
);
}
private
String
getPassword
()
{
...
...
spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementSampleActuatorApplicationTests.java
View file @
1cc1fc64
...
...
@@ -31,9 +31,7 @@ import org.springframework.test.annotation.DirtiesContext;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for insecured service endpoints (even with Spring Security on
...
...
@@ -56,12 +54,11 @@ public class InsecureManagementSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
UNAUTHORIZED
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertEquals
(
"Wrong body: "
+
body
,
"Unauthorized"
,
body
.
get
(
"error"
));
assertFalse
(
"Wrong headers: "
+
entity
.
getHeaders
(),
entity
.
getHeaders
().
containsKey
(
"Set-Cookie"
));
assertThat
(
body
.
get
(
"error"
)).
isEqualTo
(
"Unauthorized"
);
assertThat
(
entity
.
getHeaders
()).
doesNotContainKey
(
"Set-Cookie"
);
}
@Test
...
...
@@ -75,11 +72,10 @@ public class InsecureManagementSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/metrics"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertTrue
(
"Wrong body: "
+
body
,
body
.
containsKey
(
"counter.status.401.unmapped"
));
assertThat
(
body
).
containsKey
(
"counter.status.401.unmapped"
);
}
}
spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureSampleActuatorApplicationTests.java
View file @
1cc1fc64
...
...
@@ -30,8 +30,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for insecured service endpoints (even with Spring Security on
...
...
@@ -53,12 +52,11 @@ public class InsecureSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertEquals
(
"Hello Phil"
,
body
.
get
(
"message"
));
assertFalse
(
"Wrong headers: "
+
entity
.
getHeaders
(),
entity
.
getHeaders
().
containsKey
(
"Set-Cookie"
));
assertThat
(
body
.
get
(
"message"
)).
isEqualTo
(
"Hello Phil"
);
assertThat
(
entity
.
getHeaders
()).
doesNotContainKey
(
"Set-Cookie"
);
}
}
spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java
View file @
1cc1fc64
...
...
@@ -30,8 +30,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for separate management and main service ports.
...
...
@@ -56,7 +55,7 @@ public class ManagementAddressActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
UNAUTHORIZED
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
}
@Test
...
...
@@ -64,9 +63,8 @@ public class ManagementAddressActuatorApplicationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/admin/health"
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"status\":\"UP\""
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":\"UP\""
);
}
}
spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java
View file @
1cc1fc64
...
...
@@ -30,9 +30,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for endpoints configuration.
...
...
@@ -52,9 +50,8 @@ public class ManagementPathSampleActuatorApplicationTests {
public
void
testHealth
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/admin/health"
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"status\":\"UP\""
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":\"UP\""
);
}
@Test
...
...
@@ -62,12 +59,11 @@ public class ManagementPathSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
UNAUTHORIZED
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertEquals
(
"Wrong body: "
+
body
,
"Unauthorized"
,
body
.
get
(
"error"
));
assertFalse
(
"Wrong headers: "
+
entity
.
getHeaders
(),
entity
.
getHeaders
().
containsKey
(
"Set-Cookie"
));
assertThat
(
body
.
get
(
"error"
)).
isEqualTo
(
"Unauthorized"
);
assertThat
(
entity
.
getHeaders
()).
doesNotContainKey
(
"Set-Cookie"
);
}
}
spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java
View file @
1cc1fc64
...
...
@@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for separate management and main service ports.
...
...
@@ -61,10 +60,10 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assert
Equals
(
"Hello Phil"
,
body
.
get
(
"message"
)
);
assert
That
(
body
.
get
(
"message"
)).
isEqualTo
(
"Hello Phil"
);
}
@Test
...
...
@@ -73,7 +72,7 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/admin/metrics"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
UNAUTHORIZED
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
}
@Test
...
...
@@ -81,9 +80,8 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/admin/health"
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"status\":\"UP\""
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":\"UP\""
);
}
@Test
...
...
@@ -92,9 +90,8 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/admin/missing"
,
String
.
class
);
assertEquals
(
HttpStatus
.
NOT_FOUND
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"status\":404"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":404"
);
}
@Test
...
...
@@ -102,10 +99,10 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/error"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
INTERNAL_SERVER_ERROR
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assert
Equals
(
999
,
body
.
get
(
"status"
)
);
assert
That
(
body
.
get
(
"status"
)).
isEqualTo
(
999
);
}
@Test
...
...
@@ -113,11 +110,10 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/error"
,
Map
.
class
);
// TODO: should be 500?
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assert
Equals
(
999
,
body
.
get
(
"status"
)
);
assert
That
(
body
.
get
(
"status"
)).
isEqualTo
(
999
);
}
private
String
getPassword
()
{
...
...
spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java
View file @
1cc1fc64
...
...
@@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for separate management and main service ports.
...
...
@@ -60,10 +59,10 @@ public class ManagementPortSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assert
Equals
(
"Hello Phil"
,
body
.
get
(
"message"
)
);
assert
That
(
body
.
get
(
"message"
)).
isEqualTo
(
"Hello Phil"
);
}
@Test
...
...
@@ -72,16 +71,15 @@ public class ManagementPortSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/metrics"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
UNAUTHORIZED
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
}
@Test
public
void
testHealth
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/health"
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"status\":\"UP\""
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":\"UP\""
);
}
@Test
...
...
@@ -89,10 +87,10 @@ public class ManagementPortSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/error"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assert
Equals
(
999
,
body
.
get
(
"status"
)
);
assert
That
(
body
.
get
(
"status"
)).
isEqualTo
(
999
);
}
private
String
getPassword
()
{
...
...
spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java
View file @
1cc1fc64
...
...
@@ -32,7 +32,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for switching off management endpoints.
...
...
@@ -56,10 +56,10 @@ public class NoManagementSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assert
Equals
(
"Hello Phil"
,
body
.
get
(
"message"
)
);
assert
That
(
body
.
get
(
"message"
)).
isEqualTo
(
"Hello Phil"
);
}
@Test
...
...
@@ -68,7 +68,7 @@ public class NoManagementSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/metrics"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
NOT_FOUND
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
}
private
String
getPassword
()
{
...
...
spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NonSensitiveHealthTests.java
View file @
1cc1fc64
...
...
@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for /health with {@code endpoints.health.sensitive=false}.
...
...
@@ -49,9 +48,8 @@ public class NonSensitiveHealthTests {
public
void
testSecureHealth
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/health"
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertFalse
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"hello\":1"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
doesNotContain
(
"\"hello\":1"
);
}
}
spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java
View file @
1cc1fc64
...
...
@@ -38,10 +38,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for service demo application.
...
...
@@ -65,12 +62,11 @@ public class SampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
UNAUTHORIZED
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertEquals
(
"Wrong body: "
+
body
,
"Unauthorized"
,
body
.
get
(
"error"
));
assertFalse
(
"Wrong headers: "
+
entity
.
getHeaders
(),
entity
.
getHeaders
().
containsKey
(
"Set-Cookie"
));
assertThat
(
body
.
get
(
"error"
)).
isEqualTo
(
"Unauthorized"
);
assertThat
(
entity
.
getHeaders
()).
doesNotContainKey
(
"Set-Cookie"
);
}
@Test
...
...
@@ -78,16 +74,16 @@ public class SampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/metrics"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
UNAUTHORIZED
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/metrics/"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
UNAUTHORIZED
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/metrics/foo"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
UNAUTHORIZED
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/metrics.json"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
UNAUTHORIZED
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
}
@Test
...
...
@@ -95,10 +91,10 @@ public class SampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assert
Equals
(
"Hello Phil"
,
body
.
get
(
"message"
)
);
assert
That
(
body
.
get
(
"message"
)).
isEqualTo
(
"Hello Phil"
);
}
@Test
...
...
@@ -107,10 +103,10 @@ public class SampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/metrics"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertT
rue
(
"Wrong body: "
+
body
,
body
.
containsKey
(
"counter.status.200.root"
)
);
assertT
hat
(
body
).
containsKey
(
"counter.status.200.root"
);
}
@Test
...
...
@@ -118,49 +114,45 @@ public class SampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/env"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertT
rue
(
"Wrong body: "
+
body
,
body
.
containsKey
(
"systemProperties"
)
);
assertT
hat
(
body
).
containsKey
(
"systemProperties"
);
}
@Test
public
void
testHealth
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/health"
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"status\":\"UP\""
));
assertFalse
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"hello\":\"1\""
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":\"UP\""
);
assertThat
(
entity
.
getBody
()).
doesNotContain
(
"\"hello\":\"1\""
);
}
@Test
public
void
testSecureHealth
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/health"
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"hello\":1"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"hello\":1"
);
}
@Test
public
void
testInfo
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/info"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assertT
rue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
(
)
.
contains
(
"\"artifact\":\"spring-boot-sample-actuator\""
)
)
;
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertT
hat
(
entity
.
getBody
()
)
.
contains
(
"\"artifact\":\"spring-boot-sample-actuator\""
);
}
@Test
public
void
testErrorPage
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/foo"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
INTERNAL_SERVER_ERROR
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
String
body
=
entity
.
getBody
();
assertNotNull
(
body
);
assertTrue
(
"Wrong body: "
+
body
,
body
.
contains
(
"\"error\":"
));
assertThat
(
body
).
contains
(
"\"error\":"
);
}
@Test
...
...
@@ -171,11 +163,10 @@ public class SampleActuatorApplicationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
exchange
(
"http://localhost:"
+
this
.
port
+
"/foo"
,
HttpMethod
.
GET
,
request
,
String
.
class
);
assert
Equals
(
HttpStatus
.
INTERNAL_SERVER_ERROR
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
String
body
=
entity
.
getBody
();
assertNotNull
(
"Body was null"
,
body
);
assertTrue
(
"Wrong body: "
+
body
,
body
.
contains
(
"This application has no explicit mapping for /error"
));
assertThat
(
body
).
as
(
"Body was null"
).
isNotNull
();
assertThat
(
body
).
contains
(
"This application has no explicit mapping for /error"
);
}
@Test
...
...
@@ -185,14 +176,14 @@ public class SampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
List
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/trace"
,
List
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
List
<
Map
<
String
,
Object
>>
list
=
entity
.
getBody
();
Map
<
String
,
Object
>
trace
=
list
.
get
(
list
.
size
()
-
1
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
((
Map
<
String
,
Object
>)
((
Map
<
String
,
Object
>)
trace
.
get
(
"info"
)).
get
(
"headers"
)).
get
(
"response"
);
assert
Equals
(
"200"
,
map
.
get
(
"status"
)
);
assert
That
(
map
.
get
(
"status"
)).
isEqualTo
(
"200"
);
}
@Test
...
...
@@ -200,24 +191,23 @@ public class SampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/error"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
INTERNAL_SERVER_ERROR
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assert
Equals
(
"None"
,
body
.
get
(
"error"
)
);
assert
Equals
(
999
,
body
.
get
(
"status"
)
);
assert
That
(
body
.
get
(
"error"
)).
isEqualTo
(
"None"
);
assert
That
(
body
.
get
(
"status"
)).
isEqualTo
(
999
);
}
@Test
@SuppressWarnings
(
"unchecked"
)
public
void
testBeans
()
throws
Exception
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
List
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/beans"
,
List
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertEquals
(
1
,
entity
.
getBody
().
size
());
@SuppressWarnings
(
"unchecked"
)
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
hasSize
(
1
);
Map
<
String
,
Object
>
body
=
(
Map
<
String
,
Object
>)
entity
.
getBody
().
get
(
0
);
assertTrue
(
"Wrong body: "
+
body
,
((
String
)
body
.
get
(
"context"
)).
startsWith
(
"application"
));
assertThat
(((
String
)
body
.
get
(
"context"
))).
startsWith
(
"application"
);
}
@Test
...
...
@@ -226,11 +216,10 @@ public class SampleActuatorApplicationTests {
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/configprops"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertTrue
(
"Wrong body: "
+
body
,
body
.
containsKey
(
"spring.datasource.CONFIGURATION_PROPERTIES"
));
assertThat
(
body
).
containsKey
(
"spring.datasource.CONFIGURATION_PROPERTIES"
);
}
private
String
getPassword
()
{
...
...
spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathInsecureSampleActuatorApplicationTests.java
View file @
1cc1fc64
...
...
@@ -30,8 +30,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for insecured service endpoints (even with Spring Security on
...
...
@@ -54,12 +53,11 @@ public class ServletPathInsecureSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/spring/"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertEquals
(
"Hello Phil"
,
body
.
get
(
"message"
));
assertFalse
(
"Wrong headers: "
+
entity
.
getHeaders
(),
entity
.
getHeaders
().
containsKey
(
"Set-Cookie"
));
assertThat
(
body
.
get
(
"message"
)).
isEqualTo
(
"Hello Phil"
);
assertThat
(
entity
.
getHeaders
()).
doesNotContainKey
(
"Set-Cookie"
);
}
@Test
...
...
@@ -67,7 +65,7 @@ public class ServletPathInsecureSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/spring/metrics"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
UNAUTHORIZED
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
}
}
spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java
View file @
1cc1fc64
...
...
@@ -30,9 +30,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for endpoints configuration.
...
...
@@ -54,20 +52,19 @@ public class ServletPathSampleActuatorApplicationTests {
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
(
"user"
,
"password"
)
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/spring/error"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
INTERNAL_SERVER_ERROR
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assert
Equals
(
"None"
,
body
.
get
(
"error"
)
);
assert
Equals
(
999
,
body
.
get
(
"status"
)
);
assert
That
(
body
.
get
(
"error"
)).
isEqualTo
(
"None"
);
assert
That
(
body
.
get
(
"status"
)).
isEqualTo
(
999
);
}
@Test
public
void
testHealth
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/spring/health"
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"status\":\"UP\""
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":\"UP\""
);
}
@Test
...
...
@@ -75,12 +72,11 @@ public class ServletPathSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/spring/"
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
UNAUTHORIZED
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertEquals
(
"Wrong body: "
+
body
,
"Unauthorized"
,
body
.
get
(
"error"
));
assertFalse
(
"Wrong headers: "
+
entity
.
getHeaders
(),
entity
.
getHeaders
().
containsKey
(
"Set-Cookie"
));
assertThat
(
body
.
get
(
"error"
)).
isEqualTo
(
"Unauthorized"
);
assertThat
(
entity
.
getHeaders
()).
doesNotContainKey
(
"Set-Cookie"
);
}
}
spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java
View file @
1cc1fc64
...
...
@@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for separate management and main service ports.
...
...
@@ -57,10 +56,10 @@ public class ShutdownSampleActuatorApplicationTests {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assert
Equals
(
"Hello Phil"
,
body
.
get
(
"message"
)
);
assert
That
(
body
.
get
(
"message"
)).
isEqualTo
(
"Hello Phil"
);
}
@Test
...
...
@@ -69,11 +68,10 @@ public class ShutdownSampleActuatorApplicationTests {
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
postForEntity
(
"http://localhost:"
+
this
.
port
+
"/shutdown"
,
null
,
Map
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertTrue
(
"Wrong body: "
+
body
,
((
String
)
body
.
get
(
"message"
)).
contains
(
"Shutting down"
));
assertThat
(((
String
)
body
.
get
(
"message"
))).
contains
(
"Shutting down"
);
}
private
String
getPassword
()
{
...
...
spring-boot-samples/spring-boot-sample-ant/src/test/java/sample/ant/SampleAntApplicationIT.java
View file @
1cc1fc64
...
...
@@ -16,9 +16,7 @@
package
sample
.
ant
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
java.io.File
;
import
java.io.FileFilter
;
...
...
@@ -48,12 +46,12 @@ public class SampleAntApplicationIT {
}
});
assertThat
(
"Number of jars"
,
jarFiles
.
length
,
equalTo
(
1
)
);
assertThat
(
jarFiles
).
hasSize
(
1
);
Process
process
=
new
JavaExecutable
().
processBuilder
(
"-jar"
,
jarFiles
[
0
].
getName
()).
directory
(
target
).
start
();
process
.
waitFor
(
5
,
TimeUnit
.
MINUTES
);
assertThat
(
process
.
exitValue
()
,
equalTo
(
0
)
);
assertThat
(
process
.
exitValue
()
).
isEqualTo
(
0
);
String
output
=
FileCopyUtils
.
copyToString
(
new
InputStreamReader
(
process
.
getInputStream
()));
assertThat
(
output
,
containsString
(
"Spring Boot Ant Example"
)
);
assertThat
(
output
).
contains
(
"Spring Boot Ant Example"
);
}
}
spring-boot-samples/spring-boot-sample-aop/src/test/java/sample/aop/SampleAopApplicationTests.java
View file @
1cc1fc64
...
...
@@ -23,7 +23,7 @@ import org.junit.Test;
import
org.springframework.boot.test.OutputCapture
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link SampleAopApplication}.
...
...
@@ -57,14 +57,14 @@ public class SampleAopApplicationTests {
public
void
testDefaultSettings
()
throws
Exception
{
SampleAopApplication
.
main
(
new
String
[
0
]);
String
output
=
this
.
outputCapture
.
toString
();
assertT
rue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Hello Phil"
)
);
assertT
hat
(
output
).
contains
(
"Hello Phil"
);
}
@Test
public
void
testCommandLineOverrides
()
throws
Exception
{
SampleAopApplication
.
main
(
new
String
[]
{
"--name=Gordon"
});
String
output
=
this
.
outputCapture
.
toString
();
assertT
rue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Hello Gordon"
)
);
assertT
hat
(
output
).
contains
(
"Hello Gordon"
);
}
}
spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java
View file @
1cc1fc64
...
...
@@ -42,9 +42,7 @@ import org.springframework.web.socket.client.WebSocketConnectionManager;
import
org.springframework.web.socket.client.standard.StandardWebSocketClient
;
import
org.springframework.web.socket.handler.TextWebSocketHandler
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
SampleAtmosphereApplication
.
class
)
...
...
@@ -68,9 +66,9 @@ public class SampleAtmosphereApplicationTests {
AtomicReference
<
String
>
messagePayloadReference
=
context
.
getBean
(
ClientConfiguration
.
class
).
messagePayload
;
context
.
close
();
assertThat
(
count
,
equalTo
(
0L
)
);
assertThat
(
messagePayloadReference
.
get
()
,
containsString
(
"{\"message\":\"test\",\"author\":\"test\",\"time\":"
)
);
assertThat
(
count
).
isEqualTo
(
0L
);
assertThat
(
messagePayloadReference
.
get
()
)
.
contains
(
"{\"message\":\"test\",\"author\":\"test\",\"time\":"
);
}
@Configuration
...
...
spring-boot-samples/spring-boot-sample-batch/src/test/java/sample/batch/SampleBatchApplicationTests.java
View file @
1cc1fc64
...
...
@@ -22,8 +22,7 @@ import org.junit.Test;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.test.OutputCapture
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
SampleBatchApplicationTests
{
...
...
@@ -32,11 +31,10 @@ public class SampleBatchApplicationTests {
@Test
public
void
testDefaultSettings
()
throws
Exception
{
assert
Equals
(
0
,
SpringApplication
.
exit
(
SpringApplication
.
run
(
SampleBatchApplication
.
class
)));
assert
That
(
SpringApplication
.
exit
(
SpringApplication
.
run
(
SampleBatchApplication
.
class
)))
.
isEqualTo
(
0
)
;
String
output
=
this
.
outputCapture
.
toString
();
assertTrue
(
"Wrong output: "
+
output
,
output
.
contains
(
"completed with the following parameters"
));
assertThat
(
output
).
contains
(
"completed with the following parameters"
);
}
}
spring-boot-samples/spring-boot-sample-cache/src/test/java/sample/cache/SampleCacheApplicationTests.java
View file @
1cc1fc64
...
...
@@ -25,10 +25,7 @@ import org.springframework.cache.Cache;
import
org.springframework.cache.CacheManager
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
hamcrest
.
CoreMatchers
.
nullValue
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
core
.
IsNull
.
notNullValue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
SampleCacheApplication
.
class
)
...
...
@@ -43,11 +40,11 @@ public class SampleCacheApplicationTests {
@Test
public
void
validateCache
()
{
Cache
countries
=
this
.
cacheManager
.
getCache
(
"countries"
);
assertThat
(
countries
,
is
(
notNullValue
())
);
assertThat
(
countries
).
isNotNull
(
);
countries
.
clear
();
// Simple test assuming the cache is empty
assertThat
(
countries
.
get
(
"BE"
)
,
is
(
nullValue
())
);
assertThat
(
countries
.
get
(
"BE"
)
).
isNull
(
);
Country
be
=
this
.
countryRepository
.
findByCode
(
"BE"
);
assertThat
((
Country
)
countries
.
get
(
"BE"
).
get
()
,
is
(
be
)
);
assertThat
((
Country
)
countries
.
get
(
"BE"
).
get
()
).
isEqualTo
(
be
);
}
}
spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java
View file @
1cc1fc64
...
...
@@ -30,7 +30,7 @@ import org.springframework.test.context.TestExecutionListeners;
import
org.springframework.test.context.TestExecutionListeners.MergeMode
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link SampleCassandraApplication}.
...
...
@@ -51,8 +51,7 @@ public class SampleCassandraApplicationTests {
@Test
public
void
testDefaultSettings
()
throws
Exception
{
String
output
=
SampleCassandraApplicationTests
.
outputCapture
.
toString
();
assertTrue
(
"Wrong output: "
+
output
,
output
.
contains
(
"firstName='Alice', lastName='Smith'"
));
assertThat
(
output
).
contains
(
"firstName='Alice', lastName='Smith'"
);
}
}
spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java
View file @
1cc1fc64
...
...
@@ -25,7 +25,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import
org.springframework.boot.test.OutputCapture
;
import
org.springframework.core.NestedCheckedException
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link SampleElasticsearchApplication}.
...
...
@@ -53,8 +53,7 @@ public class SampleElasticsearchApplicationTests {
}
}
String
output
=
this
.
outputCapture
.
toString
();
assertTrue
(
"Wrong output: "
+
output
,
output
.
contains
(
"firstName='Alice', lastName='Smith'"
));
assertThat
(
output
).
contains
(
"firstName='Alice', lastName='Smith'"
);
}
private
boolean
serverNotRunning
(
IllegalStateException
ex
)
{
...
...
spring-boot-samples/spring-boot-sample-data-gemfire/src/test/java/sample/data/gemfire/SampleDataGemFireApplicationTests.java
View file @
1cc1fc64
...
...
@@ -16,8 +16,6 @@
package
sample
.
data
.
gemfire
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.atomic.AtomicLong
;
import
org.junit.Before
;
...
...
@@ -31,9 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* The SampleDataGemFireApplicationTests class is a test suite with test cases testing the
...
...
@@ -50,70 +46,38 @@ public class SampleDataGemFireApplicationTests {
private
final
AtomicLong
ID_GENERATOR
=
new
AtomicLong
(
0
l
);
protected
List
<
Gemstone
>
asList
(
final
Iterable
<
Gemstone
>
gemstones
)
{
List
<
Gemstone
>
gemstoneList
=
new
ArrayList
<
Gemstone
>();
if
(
gemstones
!=
null
)
{
for
(
Gemstone
gemstone
:
gemstones
)
{
gemstoneList
.
add
(
gemstone
);
}
}
return
gemstoneList
;
}
protected
Gemstone
createGemstone
(
final
String
name
)
{
return
createGemstone
(
this
.
ID_GENERATOR
.
incrementAndGet
(),
name
);
}
protected
Gemstone
createGemstone
(
final
Long
id
,
final
String
name
)
{
return
new
Gemstone
(
id
,
name
);
}
protected
List
<
Gemstone
>
getGemstones
(
final
String
...
names
)
{
List
<
Gemstone
>
gemstones
=
new
ArrayList
<
Gemstone
>(
names
.
length
);
for
(
String
name
:
names
)
{
gemstones
.
add
(
createGemstone
(
null
,
name
));
}
return
gemstones
;
}
@Before
public
void
setup
()
{
assertNotNull
(
"A reference to the GemstoneService was not properly configured!"
,
this
.
gemstoneService
);
assertThat
(
this
.
gemstoneService
).
isNotNull
();
}
@Test
public
void
testGemstonesApp
()
{
assert
Equals
(
0
,
this
.
gemstoneService
.
count
()
);
assertT
rue
(
asList
(
this
.
gemstoneService
.
list
()).
isEmpty
()
);
assert
That
(
this
.
gemstoneService
.
count
()).
isEqualTo
(
0
);
assertT
hat
(
this
.
gemstoneService
.
list
()).
isEmpty
(
);
this
.
gemstoneService
.
save
(
createGemstone
(
"Diamond"
));
this
.
gemstoneService
.
save
(
createGemstone
(
"Ruby"
));
assertEquals
(
2
,
this
.
gemstoneService
.
count
());
assertTrue
(
asList
(
this
.
gemstoneService
.
list
())
.
containsAll
(
getGemstones
(
"Diamond"
,
"Ruby"
)));
assertThat
(
this
.
gemstoneService
.
count
()).
isEqualTo
(
2
);
assertThat
(
this
.
gemstoneService
.
list
()).
contains
(
getGemstones
(
"Diamond"
,
"Ruby"
));
try
{
this
.
gemstoneService
.
save
(
createGemstone
(
"Coal"
));
}
catch
(
IllegalGemstoneException
expected
)
{
catch
(
IllegalGemstoneException
ex
)
{
// Expected
}
assertEquals
(
2
,
this
.
gemstoneService
.
count
());
assertTrue
(
asList
(
this
.
gemstoneService
.
list
())
.
containsAll
(
getGemstones
(
"Diamond"
,
"Ruby"
)));
assertThat
(
this
.
gemstoneService
.
count
()).
isEqualTo
(
2
);
assertThat
(
this
.
gemstoneService
.
list
()).
contains
(
getGemstones
(
"Diamond"
,
"Ruby"
));
this
.
gemstoneService
.
save
(
createGemstone
(
"Pearl"
));
this
.
gemstoneService
.
save
(
createGemstone
(
"Sapphire"
));
assert
Equals
(
4
,
this
.
gemstoneService
.
count
()
);
assertT
rue
(
asLis
t
(
this
.
gemstoneService
.
list
())
.
contains
All
(
getGemstones
(
"Diamond"
,
"Ruby"
,
"Pearl"
,
"Sapphire"
)
));
assert
That
(
this
.
gemstoneService
.
count
()).
isEqualTo
(
4
);
assertT
ha
t
(
this
.
gemstoneService
.
list
())
.
contains
(
getGemstones
(
"Diamond"
,
"Ruby"
,
"Pearl"
,
"Sapphire"
));
try
{
this
.
gemstoneService
.
save
(
createGemstone
(
"Quartz"
));
...
...
@@ -121,11 +85,28 @@ public class SampleDataGemFireApplicationTests {
catch
(
IllegalGemstoneException
expected
)
{
}
assertEquals
(
4
,
this
.
gemstoneService
.
count
());
assertTrue
(
asList
(
this
.
gemstoneService
.
list
())
.
containsAll
(
getGemstones
(
"Diamond"
,
"Ruby"
,
"Pearl"
,
"Sapphire"
)));
assertEquals
(
createGemstone
(
"Diamond"
),
this
.
gemstoneService
.
get
(
"Diamond"
));
assertEquals
(
createGemstone
(
"Pearl"
),
this
.
gemstoneService
.
get
(
"Pearl"
));
assertThat
(
this
.
gemstoneService
.
count
()).
isEqualTo
(
4
);
assertThat
(
this
.
gemstoneService
.
list
())
.
contains
(
getGemstones
(
"Diamond"
,
"Ruby"
,
"Pearl"
,
"Sapphire"
));
assertThat
(
this
.
gemstoneService
.
get
(
"Diamond"
))
.
isEqualTo
(
createGemstone
(
"Diamond"
));
assertThat
(
this
.
gemstoneService
.
get
(
"Pearl"
)).
isEqualTo
(
createGemstone
(
"Pearl"
));
}
private
Gemstone
[]
getGemstones
(
String
...
names
)
{
Gemstone
[]
gemstones
=
new
Gemstone
[
names
.
length
];
for
(
int
i
=
0
;
i
<
names
.
length
;
i
++)
{
gemstones
[
i
]
=
createGemstone
(
null
,
names
[
i
]);
}
return
gemstones
;
}
private
Gemstone
createGemstone
(
String
name
)
{
return
createGemstone
(
this
.
ID_GENERATOR
.
incrementAndGet
(),
name
);
}
private
Gemstone
createGemstone
(
Long
id
,
String
name
)
{
return
new
Gemstone
(
id
,
name
);
}
}
spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/SampleDataJpaApplicationTests.java
View file @
1cc1fc64
...
...
@@ -34,7 +34,7 @@ import org.springframework.test.web.servlet.MockMvc;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.web.context.WebApplicationContext
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
content
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
...
...
@@ -74,9 +74,9 @@ public class SampleDataJpaApplicationTests {
@Test
public
void
testJmx
()
throws
Exception
{
assert
Equals
(
1
,
ManagementFactory
.
getPlatformMBeanServer
()
.
queryMBeans
(
new
ObjectName
(
"jpa.sample:type=ConnectionPool,*"
),
null
)
.
size
()
);
assert
That
(
ManagementFactory
.
getPlatformMBeanServer
()
.
queryMBeans
(
new
ObjectName
(
"jpa.sample:type=ConnectionPool,*"
),
null
)
)
.
hasSize
(
1
);
}
}
spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java
View file @
1cc1fc64
...
...
@@ -26,9 +26,7 @@ import org.springframework.data.domain.Page;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
hamcrest
.
Matchers
.
greaterThan
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for {@link CityRepository}.
...
...
@@ -46,6 +44,6 @@ public class CityRepositoryIntegrationTests {
public
void
findsFirstPageOfCities
()
{
Page
<
City
>
cities
=
this
.
repository
.
findAll
(
new
PageRequest
(
0
,
10
));
assertThat
(
cities
.
getTotalElements
()
,
is
(
greaterThan
(
20L
))
);
assertThat
(
cities
.
getTotalElements
()
).
isGreaterThan
(
20L
);
}
}
spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/HotelRepositoryIntegrationTests.java
View file @
1cc1fc64
...
...
@@ -33,10 +33,7 @@ import org.springframework.data.domain.PageRequest;
import
org.springframework.data.domain.Sort.Direction
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
hamcrest
.
Matchers
.
greaterThan
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for {@link HotelRepository}.
...
...
@@ -57,17 +54,17 @@ public class HotelRepositoryIntegrationTests {
City
city
=
this
.
cityRepository
.
findAll
(
new
PageRequest
(
0
,
1
,
Direction
.
ASC
,
"name"
)).
getContent
()
.
get
(
0
);
assertThat
(
city
.
getName
()
,
is
(
"Atlanta"
)
);
assertThat
(
city
.
getName
()
).
isEqualTo
(
"Atlanta"
);
Page
<
HotelSummary
>
hotels
=
this
.
repository
.
findByCity
(
city
,
new
PageRequest
(
0
,
10
,
Direction
.
ASC
,
"name"
));
Hotel
hotel
=
this
.
repository
.
findByCityAndName
(
city
,
hotels
.
getContent
().
get
(
0
).
getName
());
assertThat
(
hotel
.
getName
()
,
is
(
"Doubletree"
)
);
assertThat
(
hotel
.
getName
()
).
isEqualTo
(
"Doubletree"
);
List
<
RatingCount
>
counts
=
this
.
repository
.
findRatingCounts
(
hotel
);
assertThat
(
counts
,
hasSize
(
1
)
);
assertThat
(
counts
.
get
(
0
).
getRating
()
,
is
(
Rating
.
AVERAGE
)
);
assertThat
(
counts
.
get
(
0
).
getCount
()
,
is
(
greaterThan
(
1L
))
);
assertThat
(
counts
).
hasSize
(
1
);
assertThat
(
counts
.
get
(
0
).
getRating
()
).
isEqualTo
(
Rating
.
AVERAGE
);
assertThat
(
counts
.
get
(
0
).
getCount
()
).
isGreaterThan
(
1L
);
}
}
spring-boot-samples/spring-boot-sample-data-mongodb/src/test/java/sample/data/mongo/SampleMongoApplicationTests.java
View file @
1cc1fc64
...
...
@@ -25,7 +25,7 @@ import org.springframework.boot.test.OutputCapture;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link SampleMongoApplication}.
...
...
@@ -44,8 +44,7 @@ public class SampleMongoApplicationTests {
@Test
public
void
testDefaultSettings
()
throws
Exception
{
String
output
=
SampleMongoApplicationTests
.
outputCapture
.
toString
();
assertTrue
(
"Wrong output: "
+
output
,
output
.
contains
(
"firstName='Alice', lastName='Smith'"
));
assertThat
(
output
).
contains
(
"firstName='Alice', lastName='Smith'"
);
}
}
spring-boot-samples/spring-boot-sample-data-redis/src/test/java/sample/data/redis/SampleRedisApplicationTests.java
View file @
1cc1fc64
...
...
@@ -22,7 +22,7 @@ import org.junit.Test;
import
org.springframework.boot.test.OutputCapture
;
import
org.springframework.data.redis.RedisConnectionFailureException
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link SampleRedisApplication}.
...
...
@@ -45,8 +45,7 @@ public class SampleRedisApplicationTests {
}
}
String
output
=
this
.
outputCapture
.
toString
();
assertTrue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Found key spring.boot.redis.test"
));
assertThat
(
output
).
contains
(
"Found key spring.boot.redis.test"
);
}
private
boolean
redisServerRunning
(
Throwable
ex
)
{
...
...
spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/service/CityRepositoryIntegrationTests.java
View file @
1cc1fc64
...
...
@@ -27,11 +27,7 @@ import org.springframework.data.domain.Page;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
greaterThan
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for {@link CityRepository}.
...
...
@@ -50,15 +46,15 @@ public class CityRepositoryIntegrationTests {
public
void
findsFirstPageOfCities
()
{
Page
<
City
>
cities
=
this
.
repository
.
findAll
(
new
PageRequest
(
0
,
10
));
assertThat
(
cities
.
getTotalElements
()
,
is
(
greaterThan
(
20L
))
);
assertThat
(
cities
.
getTotalElements
()
).
isGreaterThan
(
20L
);
}
@Test
public
void
findByNameAndCountry
()
{
City
city
=
this
.
repository
.
findByNameAndCountryAllIgnoringCase
(
"Melbourne"
,
"Australia"
);
assertThat
(
city
,
notNullValue
()
);
assertThat
(
city
.
getName
()
,
is
(
equalTo
(
"Melbourne"
))
);
assertThat
(
city
).
isNotNull
(
);
assertThat
(
city
.
getName
()
).
isEqualTo
(
"Melbourne"
);
}
@Test
...
...
@@ -66,6 +62,6 @@ public class CityRepositoryIntegrationTests {
Page
<
City
>
cities
=
this
.
repository
.
findByNameContainingAndCountryContainingAllIgnoringCase
(
""
,
"UK"
,
new
PageRequest
(
0
,
10
));
assertThat
(
cities
.
getTotalElements
()
,
is
(
equalTo
(
3L
))
);
assertThat
(
cities
.
getTotalElements
()
).
isEqualTo
(
3L
);
}
}
spring-boot-samples/spring-boot-sample-data-solr/src/test/java/sample/data/solr/SampleSolrApplicationTests.java
View file @
1cc1fc64
...
...
@@ -22,7 +22,7 @@ import org.junit.Test;
import
org.springframework.boot.test.OutputCapture
;
import
org.springframework.core.NestedCheckedException
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
SampleSolrApplicationTests
{
...
...
@@ -41,7 +41,7 @@ public class SampleSolrApplicationTests {
}
}
String
output
=
this
.
outputCapture
.
toString
();
assertT
rue
(
"Wrong output: "
+
output
,
output
.
contains
(
"name=Sony Playstation"
)
);
assertT
hat
(
output
).
contains
(
"name=Sony Playstation"
);
}
private
boolean
serverNotRunning
(
IllegalStateException
ex
)
{
...
...
spring-boot-samples/spring-boot-sample-flyway/src/test/java/sample/flyway/SampleFlywayApplicationTests.java
View file @
1cc1fc64
...
...
@@ -24,7 +24,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
SampleFlywayApplication
.
class
)
...
...
@@ -35,8 +35,8 @@ public class SampleFlywayApplicationTests {
@Test
public
void
testDefaultSettings
()
throws
Exception
{
assert
Equals
(
new
Integer
(
1
),
this
.
template
.
queryForObject
(
"SELECT COUNT(*) from PERSON"
,
Integer
.
class
)
);
assert
That
(
this
.
template
.
queryForObject
(
"SELECT COUNT(*) from PERSON"
,
Integer
.
class
)).
isEqualTo
(
1
);
}
}
spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java
View file @
1cc1fc64
...
...
@@ -33,10 +33,7 @@ import org.springframework.http.RequestEntity;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
startsWith
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
SampleHateoasApplication
.
class
)
...
...
@@ -50,10 +47,10 @@ public class SampleHateoasApplicationTests {
public
void
hasHalLinks
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/customers/1"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()
,
equalTo
(
HttpStatus
.
OK
)
);
assertThat
(
entity
.
getBody
()
,
startsWith
(
"{\"id\":1,\"firstName\":\"Oliver\""
+
",\"lastName\":\"Gierke\""
)
)
;
assertThat
(
entity
.
getBody
()
,
containsString
(
"_links\":{\"self\":{\"href\""
)
);
assertThat
(
entity
.
getStatusCode
()
).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()
).
startsWith
(
"{\"id\":1,\"firstName\":\"Oliver\""
+
",\"lastName\":\"Gierke\""
);
assertThat
(
entity
.
getBody
()
).
contains
(
"_links\":{\"self\":{\"href\""
);
}
@Test
...
...
@@ -64,9 +61,9 @@ public class SampleHateoasApplicationTests {
URI
.
create
(
"http://localhost:"
+
this
.
port
+
"/customers/1"
));
ResponseEntity
<
String
>
response
=
new
TestRestTemplate
().
exchange
(
request
,
String
.
class
);
assertThat
(
response
.
getStatusCode
()
,
equalTo
(
HttpStatus
.
OK
)
);
assertThat
(
response
.
getHeaders
().
getContentType
()
,
equalTo
(
MediaType
.
parseMediaType
(
"application/json;charset=UTF-8"
)
));
assertThat
(
response
.
getStatusCode
()
).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
response
.
getHeaders
().
getContentType
()
)
.
isEqualTo
(
MediaType
.
parseMediaType
(
"application/json;charset=UTF-8"
));
}
}
spring-boot-samples/spring-boot-sample-hypermedia-jpa/src/test/java/sample/hypermedia/jpa/SampleHypermediaJpaApplicationIntegrationTests.java
View file @
1cc1fc64
...
...
@@ -31,7 +31,7 @@ import org.springframework.test.web.servlet.MvcResult;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.web.context.WebApplicationContext
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
jsonPath
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
...
...
@@ -83,8 +83,8 @@ public class SampleHypermediaJpaApplicationIntegrationTests {
public
void
browser
()
throws
Exception
{
MvcResult
response
=
this
.
mockMvc
.
perform
(
get
(
"/"
).
accept
(
MediaType
.
TEXT_HTML
))
.
andExpect
(
status
().
isFound
()).
andReturn
();
assert
Equals
(
"/browser/index.html#"
,
response
.
getResponse
().
getHeaders
(
"location"
).
get
(
0
)
);
assert
That
(
response
.
getResponse
().
getHeaders
(
"location"
).
get
(
0
))
.
isEqualTo
(
"/browser/index.html#"
);
}
}
spring-boot-samples/spring-boot-sample-hypermedia-ui/src/test/java/sample/hypermedia/ui/SampleHypermediaUiApplicationTests.java
View file @
1cc1fc64
...
...
@@ -33,7 +33,7 @@ import org.springframework.http.RequestEntity;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
SampleHypermediaUiApplication
.
class
)
...
...
@@ -47,14 +47,14 @@ public class SampleHypermediaUiApplicationTests {
public
void
home
()
{
String
response
=
new
TestRestTemplate
()
.
getForObject
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assertT
rue
(
"Wrong body: "
+
response
,
response
.
contains
(
"Hello World"
)
);
assertT
hat
(
response
).
contains
(
"Hello World"
);
}
@Test
public
void
links
()
{
String
response
=
new
TestRestTemplate
().
getForObject
(
"http://localhost:"
+
this
.
port
+
"/actuator"
,
String
.
class
);
assertT
rue
(
"Wrong body: "
+
response
,
response
.
contains
(
"\"_links\":"
)
);
assertT
hat
(
response
).
contains
(
"\"_links\":"
);
}
@Test
...
...
@@ -65,7 +65,7 @@ public class SampleHypermediaUiApplicationTests {
new
RequestEntity
<
Void
>(
headers
,
HttpMethod
.
GET
,
new
URI
(
"http://localhost:"
+
this
.
port
+
"/actuator"
)),
String
.
class
);
assertT
rue
(
"Wrong body: "
+
response
,
response
.
getBody
().
contains
(
"\"_links\":"
)
);
assertT
hat
(
response
.
getBody
()).
contains
(
"\"_links\":"
);
}
@Test
...
...
@@ -75,7 +75,7 @@ public class SampleHypermediaUiApplicationTests {
ResponseEntity
<
String
>
response
=
new
TestRestTemplate
()
.
exchange
(
new
RequestEntity
<
Void
>(
headers
,
HttpMethod
.
GET
,
new
URI
(
"http://localhost:"
+
this
.
port
)),
String
.
class
);
assertT
rue
(
"Wrong body: "
+
response
,
response
.
getBody
().
contains
(
"Hello World"
)
);
assertT
hat
(
response
.
getBody
()).
contains
(
"Hello World"
);
}
}
spring-boot-samples/spring-boot-sample-hypermedia/src/test/java/sample/hypermedia/SampleHypermediaApplicationHomePageTests.java
View file @
1cc1fc64
...
...
@@ -33,7 +33,7 @@ import org.springframework.http.RequestEntity;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
SampleHypermediaApplication
.
class
)
...
...
@@ -47,7 +47,7 @@ public class SampleHypermediaApplicationHomePageTests {
public
void
home
()
{
String
response
=
new
TestRestTemplate
()
.
getForObject
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assertT
rue
(
"Wrong body: "
+
response
,
response
.
contains
(
"404"
)
);
assertT
hat
(
response
).
contains
(
"404"
);
}
@Test
...
...
@@ -58,7 +58,7 @@ public class SampleHypermediaApplicationHomePageTests {
new
RequestEntity
<
Void
>(
headers
,
HttpMethod
.
GET
,
new
URI
(
"http://localhost:"
+
this
.
port
+
"/actuator"
)),
String
.
class
);
assertT
rue
(
"Wrong body: "
+
response
,
response
.
getBody
().
contains
(
"\"_links\":"
)
);
assertT
hat
(
response
.
getBody
()).
contains
(
"\"_links\":"
);
}
@Test
...
...
@@ -69,7 +69,7 @@ public class SampleHypermediaApplicationHomePageTests {
new
RequestEntity
<
Void
>(
headers
,
HttpMethod
.
GET
,
new
URI
(
"http://localhost:"
+
this
.
port
+
"/actuator/"
)),
String
.
class
);
assertT
rue
(
"Wrong body: "
+
response
,
response
.
getBody
().
contains
(
"HAL Browser"
)
);
assertT
hat
(
response
.
getBody
()).
contains
(
"HAL Browser"
);
}
}
spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java
View file @
1cc1fc64
...
...
@@ -38,7 +38,7 @@ import org.springframework.core.io.support.ResourcePatternUtils;
import
org.springframework.util.FileSystemUtils
;
import
org.springframework.util.StreamUtils
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for service demo application.
...
...
@@ -71,7 +71,7 @@ public class SampleIntegrationApplicationTests {
public
void
testVanillaExchange
()
throws
Exception
{
SpringApplication
.
run
(
ProducerApplication
.
class
,
"World"
);
String
output
=
getOutput
();
assertT
rue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Hello World"
)
);
assertT
hat
(
output
).
contains
(
"Hello World"
);
}
private
String
getOutput
()
throws
Exception
{
...
...
spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java
View file @
1cc1fc64
...
...
@@ -28,7 +28,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.web.client.RestTemplate
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
SampleJerseyApplication
.
class
)
...
...
@@ -44,22 +44,22 @@ public class SampleJerseyApplicationTests {
public
void
contextLoads
()
{
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/hello"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
}
@Test
public
void
reverse
()
{
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/reverse?input=olleh"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
Equals
(
"hello"
,
entity
.
getBody
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assert
That
(
entity
.
getBody
()).
isEqualTo
(
"hello"
);
}
@Test
public
void
validation
()
{
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/reverse"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
BAD_REQUEST
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
BAD_REQUEST
);
}
}
spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java
View file @
1cc1fc64
...
...
@@ -25,7 +25,7 @@ import org.springframework.boot.test.TestRestTemplate;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
SampleJersey1Application
.
class
)
...
...
@@ -37,8 +37,9 @@ public class SampleJersey1ApplicationTests {
@Test
public
void
contextLoads
()
{
assertEquals
(
"Hello World"
,
new
TestRestTemplate
()
.
getForObject
(
"http://localhost:"
+
this
.
port
+
"/"
,
String
.
class
));
assertThat
(
new
TestRestTemplate
()
.
getForObject
(
"http://localhost:"
+
this
.
port
+
"/"
,
String
.
class
))
.
isEqualTo
(
"Hello World"
);
}
}
spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java
View file @
1cc1fc64
...
...
@@ -34,7 +34,7 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -64,8 +64,8 @@ public class SampleJettySslApplicationTests {
.
setHttpClient
(
httpClient
);
ResponseEntity
<
String
>
entity
=
testRestTemplate
.
getForEntity
(
"https://localhost:"
+
this
.
port
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
Equals
(
"Hello World"
,
entity
.
getBody
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assert
That
(
entity
.
getBody
()).
isEqualTo
(
"Hello World"
);
}
}
spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java
View file @
1cc1fc64
...
...
@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
org.springframework.util.StreamUtils
;
import
org.springframework.web.client.RestTemplate
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -58,8 +58,8 @@ public class SampleJettyApplicationTests {
public
void
testHome
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
Equals
(
"Hello World"
,
entity
.
getBody
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assert
That
(
entity
.
getBody
()).
isEqualTo
(
"Hello World"
);
}
@Test
...
...
@@ -74,13 +74,13 @@ public class SampleJettyApplicationTests {
"http://localhost:"
+
this
.
port
,
HttpMethod
.
GET
,
requestEntity
,
byte
[].
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
GZIPInputStream
inflater
=
new
GZIPInputStream
(
new
ByteArrayInputStream
(
entity
.
getBody
()));
try
{
assert
Equals
(
"Hello World"
,
StreamUtils
.
copyToString
(
inflater
,
Charset
.
forName
(
"UTF-8"
))
);
assert
That
(
StreamUtils
.
copyToString
(
inflater
,
Charset
.
forName
(
"UTF-8"
)))
.
isEqualTo
(
"Hello World"
);
}
finally
{
inflater
.
close
();
...
...
spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty8/ssl/SampleJetty8SslApplicationTests.java
View file @
1cc1fc64
...
...
@@ -34,7 +34,7 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -64,8 +64,8 @@ public class SampleJetty8SslApplicationTests {
.
setHttpClient
(
httpClient
);
ResponseEntity
<
String
>
entity
=
testRestTemplate
.
getForEntity
(
"https://localhost:"
+
this
.
port
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
Equals
(
"Hello World"
,
entity
.
getBody
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assert
That
(
entity
.
getBody
()).
isEqualTo
(
"Hello World"
);
}
}
spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty8/SampleJetty8ApplicationTests.java
View file @
1cc1fc64
...
...
@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
org.springframework.util.StreamUtils
;
import
org.springframework.web.client.RestTemplate
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -58,8 +58,8 @@ public class SampleJetty8ApplicationTests {
public
void
testHome
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
Equals
(
"Hello World"
,
entity
.
getBody
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assert
That
(
entity
.
getBody
()).
isEqualTo
(
"Hello World"
);
}
@Test
...
...
@@ -71,12 +71,12 @@ public class SampleJetty8ApplicationTests {
ResponseEntity
<
byte
[]>
entity
=
restTemplate
.
exchange
(
"http://localhost:"
+
this
.
port
,
HttpMethod
.
GET
,
requestEntity
,
byte
[].
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
GZIPInputStream
inflater
=
new
GZIPInputStream
(
new
ByteArrayInputStream
(
entity
.
getBody
()));
try
{
assert
Equals
(
"Hello World"
,
StreamUtils
.
copyToString
(
inflater
,
Charset
.
forName
(
"UTF-8"
))
);
assert
That
(
StreamUtils
.
copyToString
(
inflater
,
Charset
.
forName
(
"UTF-8"
)))
.
isEqualTo
(
"Hello World"
);
}
finally
{
inflater
.
close
();
...
...
spring-boot-samples/spring-boot-sample-jetty93/src/test/java/sample/jetty93/SampleJetty93ApplicationTests.java
View file @
1cc1fc64
...
...
@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
org.springframework.util.StreamUtils
;
import
org.springframework.web.client.RestTemplate
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -58,8 +58,8 @@ public class SampleJetty93ApplicationTests {
public
void
testHome
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
Equals
(
"Hello World"
,
entity
.
getBody
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assert
That
(
entity
.
getBody
()).
isEqualTo
(
"Hello World"
);
}
@Test
...
...
@@ -71,12 +71,12 @@ public class SampleJetty93ApplicationTests {
ResponseEntity
<
byte
[]>
entity
=
restTemplate
.
exchange
(
"http://localhost:"
+
this
.
port
,
HttpMethod
.
GET
,
requestEntity
,
byte
[].
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
GZIPInputStream
inflater
=
new
GZIPInputStream
(
new
ByteArrayInputStream
(
entity
.
getBody
()));
try
{
assert
Equals
(
"Hello World"
,
StreamUtils
.
copyToString
(
inflater
,
Charset
.
forName
(
"UTF-8"
))
);
assert
That
(
StreamUtils
.
copyToString
(
inflater
,
Charset
.
forName
(
"UTF-8"
)))
.
isEqualTo
(
"Hello World"
);
}
finally
{
inflater
.
close
();
...
...
spring-boot-samples/spring-boot-sample-jooq/src/test/java/sample/jooq/SampleJooqApplicationTests.java
View file @
1cc1fc64
...
...
@@ -21,8 +21,7 @@ import org.junit.Test;
import
org.springframework.boot.test.OutputCapture
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for {@link SampleJooqApplication}.
...
...
@@ -37,11 +36,11 @@ public class SampleJooqApplicationTests {
@Test
public
void
outputResults
()
throws
Exception
{
SampleJooqApplication
.
main
(
NO_ARGS
);
assertThat
(
this
.
out
.
toString
()
,
containsString
(
"jOOQ Fetch 1 Greg Turnquest"
)
);
assertThat
(
this
.
out
.
toString
()
,
containsString
(
"jOOQ Fetch 2 Craig Walls"
)
);
assertThat
(
this
.
out
.
toString
()
,
containsString
(
"jOOQ SQL "
+
"[Learning Spring Boot : Greg Turnquest, "
+
"Spring Boot in Action : Craig Walls]"
)
)
;
assertThat
(
this
.
out
.
toString
()
).
contains
(
"jOOQ Fetch 1 Greg Turnquest"
);
assertThat
(
this
.
out
.
toString
()
).
contains
(
"jOOQ Fetch 2 Craig Walls"
);
assertThat
(
this
.
out
.
toString
()
)
.
contains
(
"jOOQ SQL "
+
"[Learning Spring Boot : Greg Turnquest, "
+
"Spring Boot in Action : Craig Walls]"
);
}
}
spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaNoteRepositoryIntegrationTests.java
View file @
1cc1fc64
...
...
@@ -26,7 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for {@link JpaNoteRepository}.
...
...
@@ -43,7 +43,7 @@ public class JpaNoteRepositoryIntegrationTests {
@Test
public
void
findsAllNotes
()
{
List
<
Note
>
notes
=
this
.
repository
.
findAll
();
assert
Equals
(
4
,
notes
.
size
()
);
assert
That
(
notes
).
hasSize
(
4
);
}
}
spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaTagRepositoryIntegrationTests.java
View file @
1cc1fc64
...
...
@@ -26,7 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for {@link JpaTagRepository}.
...
...
@@ -43,7 +43,7 @@ public class JpaTagRepositoryIntegrationTests {
@Test
public
void
findsAllTags
()
{
List
<
Tag
>
tags
=
this
.
repository
.
findAll
();
assert
Equals
(
3
,
tags
.
size
()
);
assert
That
(
tags
).
hasSize
(
3
);
}
}
spring-boot-samples/spring-boot-sample-jta-atomikos/src/test/java/sample/atomikos/SampleAtomikosApplicationTests.java
View file @
1cc1fc64
...
...
@@ -16,14 +16,13 @@
package
sample
.
atomikos
;
import
org.hamcrest.Matcher
;
import
org.hamcrest.core.SubstringMatcher
;
import
org.assertj.core.api.Condition
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.springframework.boot.test.OutputCapture
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -39,25 +38,22 @@ public class SampleAtomikosApplicationTests {
public
void
testTransactionRollback
()
throws
Exception
{
SampleAtomikosApplication
.
main
(
new
String
[]
{});
String
output
=
this
.
outputCapture
.
toString
();
assertThat
(
output
,
containsS
tring
(
1
,
"---->"
));
assertThat
(
output
,
containsS
tring
(
1
,
"----> josh"
));
assertThat
(
output
,
containsS
tring
(
2
,
"Count is 1"
));
assertThat
(
output
,
containsS
tring
(
1
,
"Simulated error"
));
assertThat
(
output
).
has
(
subs
tring
(
1
,
"---->"
));
assertThat
(
output
).
has
(
subs
tring
(
1
,
"----> josh"
));
assertThat
(
output
).
has
(
subs
tring
(
2
,
"Count is 1"
));
assertThat
(
output
).
has
(
subs
tring
(
1
,
"Simulated error"
));
}
private
Matcher
<?
super
String
>
containsString
(
final
int
times
,
String
s
)
{
return
new
SubstringMatcher
(
s
)
{
private
Condition
<
String
>
substring
(
final
int
times
,
final
String
substring
)
{
return
new
Condition
<
String
>(
"containing '"
+
substring
+
"' "
+
times
+
" times"
)
{
@Override
protected
String
relationship
()
{
return
"containing "
+
times
+
" times"
;
}
@Override
protected
boolean
evalSubstringOf
(
String
s
)
{
public
boolean
matches
(
String
value
)
{
int
i
=
0
;
while
(
s
.
contains
(
this
.
substring
))
{
s
=
s
.
substring
(
s
.
indexOf
(
this
.
substring
)
+
this
.
substring
.
length
());
while
(
value
.
contains
(
substring
))
{
int
beginIndex
=
value
.
indexOf
(
substring
)
+
substring
.
length
();
value
=
value
.
substring
(
beginIndex
);
i
++;
}
return
i
==
times
;
...
...
spring-boot-samples/spring-boot-sample-jta-bitronix/src/test/java/sample/bitronix/SampleBitronixApplicationTests.java
View file @
1cc1fc64
...
...
@@ -17,8 +17,7 @@
package
sample
.
bitronix
;
import
bitronix.tm.resource.jms.PoolingConnectionFactory
;
import
org.hamcrest.Matcher
;
import
org.hamcrest.core.SubstringMatcher
;
import
org.assertj.core.api.Condition
;
import
org.junit.Rule
;
import
org.junit.Test
;
...
...
@@ -26,10 +25,7 @@ import org.springframework.boot.SpringApplication;
import
org.springframework.boot.test.OutputCapture
;
import
org.springframework.context.ApplicationContext
;
import
static
org
.
hamcrest
.
Matchers
.
instanceOf
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
hamcrest
.
Matchers
.
sameInstance
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -45,10 +41,10 @@ public class SampleBitronixApplicationTests {
public
void
testTransactionRollback
()
throws
Exception
{
SampleBitronixApplication
.
main
(
new
String
[]
{});
String
output
=
this
.
outputCapture
.
toString
();
assertThat
(
output
,
containsS
tring
(
1
,
"---->"
));
assertThat
(
output
,
containsS
tring
(
1
,
"----> josh"
));
assertThat
(
output
,
containsS
tring
(
2
,
"Count is 1"
));
assertThat
(
output
,
containsS
tring
(
1
,
"Simulated error"
));
assertThat
(
output
).
has
(
subs
tring
(
1
,
"---->"
));
assertThat
(
output
).
has
(
subs
tring
(
1
,
"----> josh"
));
assertThat
(
output
).
has
(
subs
tring
(
2
,
"Count is 1"
));
assertThat
(
output
).
has
(
subs
tring
(
1
,
"Simulated error"
));
}
@Test
...
...
@@ -58,25 +54,22 @@ public class SampleBitronixApplicationTests {
Object
jmsConnectionFactory
=
context
.
getBean
(
"jmsConnectionFactory"
);
Object
xaJmsConnectionFactory
=
context
.
getBean
(
"xaJmsConnectionFactory"
);
Object
nonXaJmsConnectionFactory
=
context
.
getBean
(
"nonXaJmsConnectionFactory"
);
assertThat
(
jmsConnectionFactory
,
sameInstance
(
xaJmsConnectionFactory
)
);
assertThat
(
jmsConnectionFactory
,
instanceOf
(
PoolingConnectionFactory
.
class
)
);
assertThat
(
nonXaJmsConnectionFactory
,
not
(
instanceOf
(
PoolingConnectionFactory
.
class
))
);
assertThat
(
jmsConnectionFactory
).
isSameAs
(
xaJmsConnectionFactory
);
assertThat
(
jmsConnectionFactory
).
isInstanceOf
(
PoolingConnectionFactory
.
class
);
assertThat
(
nonXaJmsConnectionFactory
)
.
isNotInstanceOf
(
PoolingConnectionFactory
.
class
);
}
private
Matcher
<?
super
String
>
containsString
(
final
int
times
,
String
s
)
{
return
new
SubstringMatcher
(
s
)
{
private
Condition
<
String
>
substring
(
final
int
times
,
final
String
substring
)
{
return
new
Condition
<
String
>(
"containing '"
+
substring
+
"' "
+
times
+
" times"
)
{
@Override
protected
String
relationship
()
{
return
"containing "
+
times
+
" times"
;
}
@Override
protected
boolean
evalSubstringOf
(
String
s
)
{
public
boolean
matches
(
String
value
)
{
int
i
=
0
;
while
(
s
.
contains
(
this
.
substring
))
{
s
=
s
.
substring
(
s
.
indexOf
(
this
.
substring
)
+
this
.
substring
.
length
());
while
(
value
.
contains
(
substring
))
{
int
beginIndex
=
value
.
indexOf
(
substring
)
+
substring
.
length
();
value
=
value
.
substring
(
beginIndex
);
i
++;
}
return
i
==
times
;
...
...
spring-boot-samples/spring-boot-sample-liquibase/src/test/java/sample/liquibase/SampleLiquibaseApplicationTests.java
View file @
1cc1fc64
...
...
@@ -24,7 +24,7 @@ import org.junit.Test;
import
org.springframework.boot.test.OutputCapture
;
import
org.springframework.core.NestedCheckedException
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
SampleLiquibaseApplicationTests
{
...
...
@@ -42,23 +42,22 @@ public class SampleLiquibaseApplicationTests {
}
}
String
output
=
this
.
outputCapture
.
toString
();
assertTrue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Successfully acquired change log lock"
)
&&
output
.
contains
(
"Creating database history "
+
"table with name: PUBLIC.DATABASECHANGELOG"
)
&&
output
.
contains
(
"Table person created"
)
&&
output
.
contains
(
"ChangeSet classpath:/db/"
assertThat
(
output
).
contains
(
"Successfully acquired change log lock"
)
.
contains
(
"Creating database history "
+
"table with name: PUBLIC.DATABASECHANGELOG"
)
.
contains
(
"Table person created"
)
.
contains
(
"ChangeSet classpath:/db/"
+
"changelog/db.changelog-master.yaml::1::"
+
"marceloverdijk ran successfully"
)
&&
output
.
contains
(
"New row inserted into person"
)
&&
output
.
contains
(
"ChangeSet classpath:/db/changelog/"
.
contains
(
"New row inserted into person"
)
.
contains
(
"ChangeSet classpath:/db/changelog/"
+
"db.changelog-master.yaml::2::"
+
"marceloverdijk ran successfully"
)
&&
output
.
contains
(
"Successfully released change log lock"
)
);
.
contains
(
"Successfully released change log lock"
);
}
@SuppressWarnings
(
"serial"
)
private
boolean
serverNotRunning
(
IllegalStateException
ex
)
{
@SuppressWarnings
(
"serial"
)
NestedCheckedException
nested
=
new
NestedCheckedException
(
"failed"
,
ex
)
{
};
if
(
nested
.
contains
(
ConnectException
.
class
))
{
...
...
spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/test/java/sample/metrics/dropwizard/SampleDropwizardMetricsApplicationTests.java
View file @
1cc1fc64
...
...
@@ -27,7 +27,7 @@ import org.springframework.boot.test.WebIntegrationTest;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for {@link SampleDropwizardMetricsApplication}.
...
...
@@ -49,7 +49,7 @@ public class SampleDropwizardMetricsApplicationTests {
@Test
public
void
timerCreated
()
{
this
.
gauges
.
submit
(
"timer.test"
,
1234
);
assert
Equals
(
1
,
this
.
registry
.
getTimers
().
get
(
"timer.test"
).
getCount
()
);
assert
That
(
this
.
registry
.
getTimers
().
get
(
"timer.test"
).
getCount
()).
isEqualTo
(
1
);
}
}
spring-boot-samples/spring-boot-sample-profile/src/test/java/sample/profile/SampleProfileApplicationTests.java
View file @
1cc1fc64
...
...
@@ -23,7 +23,7 @@ import org.junit.Test;
import
org.springframework.boot.test.OutputCapture
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
SampleProfileApplicationTests
{
...
...
@@ -51,7 +51,7 @@ public class SampleProfileApplicationTests {
public
void
testDefaultProfile
()
throws
Exception
{
SampleProfileApplication
.
main
(
new
String
[
0
]);
String
output
=
this
.
outputCapture
.
toString
();
assertT
rue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Hello Phil"
)
);
assertT
hat
(
output
).
contains
(
"Hello Phil"
);
}
@Test
...
...
@@ -59,7 +59,7 @@ public class SampleProfileApplicationTests {
System
.
setProperty
(
"spring.profiles.active"
,
"goodbye"
);
SampleProfileApplication
.
main
(
new
String
[
0
]);
String
output
=
this
.
outputCapture
.
toString
();
assertT
rue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Goodbye Everyone"
)
);
assertT
hat
(
output
).
contains
(
"Goodbye Everyone"
);
}
@Test
...
...
@@ -73,7 +73,7 @@ public class SampleProfileApplicationTests {
System
.
setProperty
(
"spring.profiles.active"
,
"generic"
);
SampleProfileApplication
.
main
(
new
String
[
0
]);
String
output
=
this
.
outputCapture
.
toString
();
assertT
rue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Bonjour Phil"
)
);
assertT
hat
(
output
).
contains
(
"Bonjour Phil"
);
}
@Test
...
...
@@ -81,7 +81,7 @@ public class SampleProfileApplicationTests {
SampleProfileApplication
.
main
(
new
String
[]
{
"--spring.profiles.active=goodbye"
});
String
output
=
this
.
outputCapture
.
toString
();
assertT
rue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Goodbye Everyone"
)
);
assertT
hat
(
output
).
contains
(
"Goodbye Everyone"
);
}
}
spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java
View file @
1cc1fc64
...
...
@@ -26,7 +26,7 @@ import org.springframework.boot.autoconfigure.web.ServerProperties;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link SamplePropertyValidationApplication}.
...
...
@@ -53,8 +53,8 @@ public class SamplePropertyValidationApplicationTests {
"sample.port:9090"
);
this
.
context
.
refresh
();
SampleProperties
properties
=
this
.
context
.
getBean
(
SampleProperties
.
class
);
assert
Equals
(
"192.168.0.1"
,
properties
.
getHost
()
);
assert
Equals
(
Integer
.
valueOf
(
9090
),
properties
.
getPort
(
));
assert
That
(
properties
.
getHost
()).
isEqualTo
(
"192.168.0.1"
);
assert
That
(
properties
.
getPort
()).
isEqualTo
(
Integer
.
valueOf
(
9090
));
}
@Test
...
...
@@ -84,8 +84,8 @@ public class SamplePropertyValidationApplicationTests {
"sample.port:9090"
);
this
.
context
.
refresh
();
SampleProperties
properties
=
this
.
context
.
getBean
(
SampleProperties
.
class
);
assert
Equals
(
"192.168.0.1"
,
properties
.
getHost
()
);
assert
Equals
(
Integer
.
valueOf
(
9090
),
properties
.
getPort
(
));
assert
That
(
properties
.
getHost
()).
isEqualTo
(
"192.168.0.1"
);
assert
That
(
properties
.
getPort
()).
isEqualTo
(
Integer
.
valueOf
(
9090
));
}
}
spring-boot-samples/spring-boot-sample-secure-oauth2/src/test/java/sample/secure/oauth2/SampleSecureOAuth2ApplicationTests.java
View file @
1cc1fc64
...
...
@@ -20,8 +20,7 @@ import org.springframework.test.web.servlet.MockMvc;
import
org.springframework.test.web.servlet.MvcResult
;
import
org.springframework.web.context.WebApplicationContext
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
post
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultHandlers
.
print
;
...
...
@@ -100,11 +99,11 @@ public class SampleSecureOAuth2ApplicationTests {
Flight
flight
=
this
.
objectMapper
.
readValue
(
flightsAction
.
getResponse
().
getContentAsString
(),
Flight
.
class
);
assertThat
(
flight
.
getOrigin
()
,
is
(
"Nashville"
)
);
assertThat
(
flight
.
getDestination
()
,
is
(
"Dallas"
)
);
assertThat
(
flight
.
getAirline
()
,
is
(
"Spring Ways"
)
);
assertThat
(
flight
.
getFlightNumber
()
,
is
(
"OAUTH2"
)
);
assertThat
(
flight
.
getTraveler
()
,
is
(
"Greg Turnquist"
)
);
assertThat
(
flight
.
getOrigin
()
).
isEqualTo
(
"Nashville"
);
assertThat
(
flight
.
getDestination
()
).
isEqualTo
(
"Dallas"
);
assertThat
(
flight
.
getAirline
()
).
isEqualTo
(
"Spring Ways"
);
assertThat
(
flight
.
getFlightNumber
()
).
isEqualTo
(
"OAUTH2"
);
assertThat
(
flight
.
getTraveler
()
).
isEqualTo
(
"Greg Turnquist"
);
}
}
spring-boot-samples/spring-boot-sample-secure/src/test/java/sample/secure/SampleSecureApplicationTests.java
View file @
1cc1fc64
...
...
@@ -35,7 +35,7 @@ import org.springframework.security.core.AuthenticationException;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -70,25 +70,25 @@ public class SampleSecureApplicationTests {
@Test
(
expected
=
AuthenticationException
.
class
)
public
void
secure
()
throws
Exception
{
assert
Equals
(
this
.
service
.
secure
(),
"Hello Security"
);
assert
That
(
"Hello Security"
).
isEqualTo
(
this
.
service
.
secure
()
);
}
@Test
public
void
authenticated
()
throws
Exception
{
SecurityContextHolder
.
getContext
().
setAuthentication
(
this
.
authentication
);
assert
Equals
(
this
.
service
.
secure
(),
"Hello Security"
);
assert
That
(
"Hello Security"
).
isEqualTo
(
this
.
service
.
secure
()
);
}
@Test
public
void
preauth
()
throws
Exception
{
SecurityContextHolder
.
getContext
().
setAuthentication
(
this
.
authentication
);
assert
Equals
(
this
.
service
.
authorized
(),
"Hello World"
);
assert
That
(
"Hello World"
).
isEqualTo
(
this
.
service
.
authorized
()
);
}
@Test
(
expected
=
AccessDeniedException
.
class
)
public
void
denied
()
throws
Exception
{
SecurityContextHolder
.
getContext
().
setAuthentication
(
this
.
authentication
);
assert
Equals
(
this
.
service
.
denied
(),
"Goodbye World"
);
assert
That
(
"Goodbye World"
).
isEqualTo
(
this
.
service
.
denied
()
);
}
@PropertySource
(
"classpath:test.properties"
)
...
...
spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java
View file @
1cc1fc64
...
...
@@ -30,7 +30,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -53,15 +53,15 @@ public class SampleServletApplicationTests {
public
void
testHomeIsSecure
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assert
Equals
(
HttpStatus
.
UNAUTHORIZED
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
}
@Test
public
void
testHome
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
Equals
(
"Hello World"
,
entity
.
getBody
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assert
That
(
entity
.
getBody
()).
isEqualTo
(
"Hello World"
);
}
private
String
getPassword
()
{
...
...
spring-boot-samples/spring-boot-sample-session-redis/src/test/java/sample/session/redis/SampleSessionRedisApplicationTests.java
View file @
1cc1fc64
...
...
@@ -30,10 +30,7 @@ import org.springframework.http.RequestEntity;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.client.RestTemplate
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link SampleSessionRedisApplication}.
...
...
@@ -73,12 +70,12 @@ public class SampleSessionRedisApplicationTests {
HttpMethod
.
GET
,
uri
);
String
uuid2
=
restTemplate
.
exchange
(
request
,
String
.
class
).
getBody
();
assertThat
(
uuid1
,
is
(
equalTo
(
uuid2
))
);
assertThat
(
uuid1
).
isEqualTo
(
uuid2
);
Thread
.
sleep
(
5000
);
String
uuid3
=
restTemplate
.
exchange
(
request
,
String
.
class
).
getBody
();
assertThat
(
uuid2
,
is
(
not
(
equalTo
(
uuid3
)))
);
assertThat
(
uuid2
).
isNotEqualTo
(
uuid3
);
}
private
boolean
redisServerRunning
(
Throwable
ex
)
{
...
...
spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SampleSimpleApplicationTests.java
View file @
1cc1fc64
...
...
@@ -23,7 +23,7 @@ import org.junit.Test;
import
org.springframework.boot.test.OutputCapture
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link SampleSimpleApplication}.
...
...
@@ -57,14 +57,14 @@ public class SampleSimpleApplicationTests {
public
void
testDefaultSettings
()
throws
Exception
{
SampleSimpleApplication
.
main
(
new
String
[
0
]);
String
output
=
this
.
outputCapture
.
toString
();
assertT
rue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Hello Phil"
)
);
assertT
hat
(
output
).
contains
(
"Hello Phil"
);
}
@Test
public
void
testCommandLineOverrides
()
throws
Exception
{
SampleSimpleApplication
.
main
(
new
String
[]
{
"--name=Gordon"
});
String
output
=
this
.
outputCapture
.
toString
();
assertT
rue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Hello Gordon"
)
);
assertT
hat
(
output
).
contains
(
"Hello Gordon"
);
}
}
spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SpringTestSampleSimpleApplicationTests.java
View file @
1cc1fc64
...
...
@@ -24,8 +24,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link SampleSimpleApplication}.
...
...
@@ -41,9 +40,9 @@ public class SpringTestSampleSimpleApplicationTests {
@Test
public
void
testContextLoads
()
throws
Exception
{
assert
NotNull
(
this
.
ctx
);
assertT
rue
(
this
.
ctx
.
containsBean
(
"helloWorldService"
)
);
assertT
rue
(
this
.
ctx
.
containsBean
(
"sampleSimpleApplication"
)
);
assert
That
(
this
.
ctx
).
isNotNull
(
);
assertT
hat
(
this
.
ctx
.
containsBean
(
"helloWorldService"
)).
isTrue
(
);
assertT
hat
(
this
.
ctx
.
containsBean
(
"sampleSimpleApplication"
)).
isTrue
(
);
}
}
spring-boot-samples/spring-boot-sample-testng/pom.xml
View file @
1cc1fc64
...
...
@@ -40,6 +40,10 @@
<artifactId>
testng
</artifactId>
<version>
6.8.13
</version>
</dependency>
<dependency>
<groupId>
org.assertj
</groupId>
<artifactId>
assertj-core
</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
...
...
spring-boot-samples/spring-boot-sample-testng/src/test/java/sample/testng/SampleTestNGApplicationTests.java
View file @
1cc1fc64
...
...
@@ -27,7 +27,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.testng.AbstractTestNGSpringContextTests
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -46,8 +46,8 @@ public class SampleTestNGApplicationTests extends AbstractTestNGSpringContextTes
public
void
testHome
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
Equals
(
"Hello World"
,
entity
.
getBody
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assert
That
(
entity
.
getBody
()).
isEqualTo
(
"Hello World"
);
}
}
spring-boot-samples/spring-boot-sample-tomcat-jsp/src/test/java/sample/tomcat/jsp/SampleWebJspApplicationTests.java
View file @
1cc1fc64
...
...
@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for JSP application.
...
...
@@ -49,9 +48,8 @@ public class SampleWebJspApplicationTests {
public
void
testJspWithEl
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body:\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"/resources/text.txt"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"/resources/text.txt"
);
}
}
spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java
View file @
1cc1fc64
...
...
@@ -42,7 +42,7 @@ import org.springframework.test.annotation.DirtiesContext;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.web.client.RestTemplate
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for {@link SampleTomcatTwoConnectorsApplication}.
...
...
@@ -111,13 +111,13 @@ public class SampleTomcatTwoConnectorsApplicationTests {
ResponseEntity
<
String
>
entity
=
template
.
getForEntity
(
"http://localhost:"
+
this
.
context
.
getBean
(
"port"
)
+
"/hello"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
Equals
(
"hello"
,
entity
.
getBody
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assert
That
(
entity
.
getBody
()).
isEqualTo
(
"hello"
);
ResponseEntity
<
String
>
httpsEntity
=
template
.
getForEntity
(
"https://localhost:"
+
this
.
port
+
"/hello"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
httpsEntity
.
getStatusCode
()
);
assert
Equals
(
"hello"
,
httpsEntity
.
getBody
()
);
assert
That
(
httpsEntity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assert
That
(
httpsEntity
.
getBody
()).
isEqualTo
(
"hello"
);
}
...
...
spring-boot-samples/spring-boot-sample-tomcat-ssl/src/test/java/sample/tomcat/SampleTomcatSslApplicationTests.java
View file @
1cc1fc64
...
...
@@ -23,19 +23,19 @@ import org.apache.http.impl.client.HttpClients;
import
org.apache.http.ssl.SSLContextBuilder
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
sample.tomcat.ssl.SampleTomcatSslApplication
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.client.HttpComponentsClientHttpRequestFactory
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
SampleTomcatSslApplication
.
class
)
...
...
@@ -60,8 +60,8 @@ public class SampleTomcatSslApplicationTests {
.
setHttpClient
(
httpClient
);
ResponseEntity
<
String
>
entity
=
testRestTemplate
.
getForEntity
(
"https://localhost:"
+
this
.
port
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
Equals
(
"Hello, world"
,
entity
.
getBody
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assert
That
(
entity
.
getBody
()).
isEqualTo
(
"Hello, world"
);
}
}
spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java
View file @
1cc1fc64
...
...
@@ -18,7 +18,6 @@ package sample.tomcat;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
sample.tomcat.NonAutoConfigurationSampleTomcatApplicationTests.NonAutoConfigurationSampleTomcatApplication
;
import
sample.tomcat.service.HelloWorldService
;
import
sample.tomcat.web.SampleController
;
...
...
@@ -33,6 +32,7 @@ import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfigurat
import
org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
...
...
@@ -41,7 +41,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -77,8 +77,8 @@ public class NonAutoConfigurationSampleTomcatApplicationTests {
public
void
testHome
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
Equals
(
"Hello World"
,
entity
.
getBody
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assert
That
(
entity
.
getBody
()).
isEqualTo
(
"Hello World"
);
}
}
spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java
View file @
1cc1fc64
...
...
@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
org.springframework.util.StreamUtils
;
import
org.springframework.web.client.RestTemplate
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -58,8 +58,8 @@ public class SampleTomcatApplicationTests {
public
void
testHome
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
Equals
(
"Hello World"
,
entity
.
getBody
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assert
That
(
entity
.
getBody
()).
isEqualTo
(
"Hello World"
);
}
@Test
...
...
@@ -71,12 +71,12 @@ public class SampleTomcatApplicationTests {
ResponseEntity
<
byte
[]>
entity
=
restTemplate
.
exchange
(
"http://localhost:"
+
this
.
port
,
HttpMethod
.
GET
,
requestEntity
,
byte
[].
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
GZIPInputStream
inflater
=
new
GZIPInputStream
(
new
ByteArrayInputStream
(
entity
.
getBody
()));
try
{
assert
Equals
(
"Hello World"
,
StreamUtils
.
copyToString
(
inflater
,
Charset
.
forName
(
"UTF-8"
))
);
assert
That
(
StreamUtils
.
copyToString
(
inflater
,
Charset
.
forName
(
"UTF-8"
)))
.
isEqualTo
(
"Hello World"
);
}
finally
{
inflater
.
close
();
...
...
spring-boot-samples/spring-boot-sample-tomcat7-jsp/src/test/java/sample/tomcat7/jsp/SampleWebJspApplicationTests.java
View file @
1cc1fc64
...
...
@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for JSP application.
...
...
@@ -49,9 +48,8 @@ public class SampleWebJspApplicationTests {
public
void
testJspWithEl
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body:\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"/resources/text.txt"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"/resources/text.txt"
);
}
}
spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java
View file @
1cc1fc64
...
...
@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -49,20 +48,18 @@ public class SampleTraditionalApplicationTests {
public
void
testHomeJsp
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
String
body
=
entity
.
getBody
();
assertTrue
(
"Wrong body:\n"
+
body
,
body
.
contains
(
"<html>"
));
assertTrue
(
"Wrong body:\n"
+
body
,
body
.
contains
(
"<h1>Home</h1>"
));
assertThat
(
body
).
contains
(
"<html>"
).
contains
(
"<h1>Home</h1>"
);
}
@Test
public
void
testStaticPage
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/index.html"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
String
body
=
entity
.
getBody
();
assertTrue
(
"Wrong body:\n"
+
body
,
body
.
contains
(
"<html>"
));
assertTrue
(
"Wrong body:\n"
+
body
,
body
.
contains
(
"<h1>Hello</h1>"
));
assertThat
(
body
).
contains
(
"<html>"
).
contains
(
"<h1>Hello</h1>"
);
}
}
spring-boot-samples/spring-boot-sample-undertow-ssl/src/test/java/sample/undertow/ssl/SampleUndertowSslApplicationTests.java
View file @
1cc1fc64
...
...
@@ -34,7 +34,7 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -64,8 +64,8 @@ public class SampleUndertowSslApplicationTests {
.
setHttpClient
(
httpClient
);
ResponseEntity
<
String
>
entity
=
testRestTemplate
.
getForEntity
(
"https://localhost:"
+
this
.
port
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
Equals
(
"Hello World"
,
entity
.
getBody
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assert
That
(
entity
.
getBody
()).
isEqualTo
(
"Hello World"
);
}
}
spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java
View file @
1cc1fc64
...
...
@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
org.springframework.util.StreamUtils
;
import
org.springframework.web.client.RestTemplate
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -73,12 +73,12 @@ public class SampleUndertowApplicationTests {
ResponseEntity
<
byte
[]>
entity
=
restTemplate
.
exchange
(
"http://localhost:"
+
this
.
port
,
HttpMethod
.
GET
,
requestEntity
,
byte
[].
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
GZIPInputStream
inflater
=
new
GZIPInputStream
(
new
ByteArrayInputStream
(
entity
.
getBody
()));
try
{
assert
Equals
(
"Hello World"
,
StreamUtils
.
copyToString
(
inflater
,
Charset
.
forName
(
"UTF-8"
))
);
assert
That
(
StreamUtils
.
copyToString
(
inflater
,
Charset
.
forName
(
"UTF-8"
)))
.
isEqualTo
(
"Hello World"
);
}
finally
{
inflater
.
close
();
...
...
@@ -88,8 +88,8 @@ public class SampleUndertowApplicationTests {
private
void
assertOkResponse
(
String
path
,
String
body
)
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
path
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
Equals
(
body
,
entity
.
getBody
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assert
That
(
entity
.
getBody
()).
isEqualTo
(
body
);
}
}
spring-boot-samples/spring-boot-sample-velocity/src/test/java/sample/velocity/SampleVelocityApplicationTests.java
View file @
1cc1fc64
...
...
@@ -24,7 +24,7 @@ import org.springframework.boot.test.OutputCapture;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for Velocity application with no web layer.
...
...
@@ -41,7 +41,7 @@ public class SampleVelocityApplicationTests {
@Test
public
void
testVelocityTemplate
()
throws
Exception
{
String
result
=
SampleVelocityApplicationTests
.
output
.
toString
();
assertT
rue
(
"Wrong output: "
+
result
,
result
.
contains
(
"Hello, Andy"
)
);
assertT
hat
(
result
).
contains
(
"Hello, Andy"
);
}
}
spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java
View file @
1cc1fc64
...
...
@@ -34,8 +34,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for FreeMarker application.
...
...
@@ -55,10 +54,9 @@ public class SampleWebFreeMarkerApplicationTests {
@Test
public
void
testFreeMarkerTemplate
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
port
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body:\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"Hello, Andy"
));
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"Hello, Andy"
);
}
@Test
...
...
@@ -68,12 +66,12 @@ public class SampleWebFreeMarkerApplicationTests {
HttpEntity
<
String
>
requestEntity
=
new
HttpEntity
<
String
>(
headers
);
ResponseEntity
<
String
>
responseEntity
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
port
+
"/does-not-exist"
,
HttpMethod
.
GET
,
"http://localhost:"
+
this
.
port
+
"/does-not-exist"
,
HttpMethod
.
GET
,
requestEntity
,
String
.
class
);
assert
Equals
(
HttpStatus
.
NOT_FOUND
,
responseEntity
.
getStatusCode
()
);
assertT
rue
(
"Wrong body:\n"
+
responseEntity
.
getBody
(),
responseEntity
.
getBody
().
contains
(
"Something went wrong: 404 Not Found"
)
);
assert
That
(
responseEntity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
assertT
hat
(
responseEntity
.
getBody
())
.
contains
(
"Something went wrong: 404 Not Found"
);
}
}
spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java
View file @
1cc1fc64
...
...
@@ -32,9 +32,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -54,11 +52,9 @@ public class SampleGroovyTemplateApplicationTests {
public
void
testHome
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body (title doesn't match):\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"<title>Messages"
));
assertFalse
(
"Wrong body (found layout:fragment):\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"layout:fragment"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"<title>Messages"
);
assertThat
(
entity
.
getBody
()).
doesNotContain
(
"layout:fragment"
);
}
@Test
...
...
@@ -68,16 +64,15 @@ public class SampleGroovyTemplateApplicationTests {
map
.
set
(
"summary"
,
"FOO"
);
URI
location
=
new
TestRestTemplate
()
.
postForLocation
(
"http://localhost:"
+
this
.
port
,
map
);
assertTrue
(
"Wrong location:\n"
+
location
,
location
.
toString
().
contains
(
"localhost:"
+
this
.
port
));
assertThat
(
location
.
toString
()).
contains
(
"localhost:"
+
this
.
port
);
}
@Test
public
void
testCss
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/css/bootstrap.min.css"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assertT
rue
(
"Wrong body:\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"body"
)
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertT
hat
(
entity
.
getBody
()).
contains
(
"body"
);
}
}
spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java
View file @
1cc1fc64
...
...
@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for JSP application.
...
...
@@ -49,9 +48,8 @@ public class SampleWebJspApplicationTests {
public
void
testJspWithEl
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body:\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"/resources/text.txt"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"/resources/text.txt"
);
}
}
spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java
View file @
1cc1fc64
...
...
@@ -38,8 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -62,9 +61,8 @@ public class SampleMethodSecurityApplicationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
,
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>(
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body (title doesn't match):\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"<title>Login"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"<title>Login"
);
}
@Test
...
...
@@ -79,9 +77,9 @@ public class SampleMethodSecurityApplicationTests {
"http://localhost:"
+
this
.
port
+
"/login"
,
HttpMethod
.
POST
,
new
HttpEntity
<
MultiValueMap
<
String
,
String
>>(
form
,
headers
),
String
.
class
);
assert
Equals
(
HttpStatus
.
FOUND
,
entity
.
getStatusCode
()
);
assert
Equals
(
"http://localhost:"
+
this
.
port
+
"/"
,
entity
.
getHeaders
().
getLocation
().
toString
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
FOUND
);
assert
That
(
entity
.
getHeaders
().
getLocation
().
toString
())
.
isEqualTo
(
"http://localhost:"
+
this
.
port
+
"/"
);
}
@Test
...
...
@@ -96,36 +94,35 @@ public class SampleMethodSecurityApplicationTests {
"http://localhost:"
+
this
.
port
+
"/login"
,
HttpMethod
.
POST
,
new
HttpEntity
<
MultiValueMap
<
String
,
String
>>(
form
,
headers
),
String
.
class
);
assert
Equals
(
HttpStatus
.
FOUND
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
FOUND
);
String
cookie
=
entity
.
getHeaders
().
getFirst
(
"Set-Cookie"
);
headers
.
set
(
"Cookie"
,
cookie
);
ResponseEntity
<
String
>
page
=
new
TestRestTemplate
().
exchange
(
entity
.
getHeaders
().
getLocation
(),
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>(
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
FORBIDDEN
,
page
.
getStatusCode
());
assertTrue
(
"Wrong body (message doesn't match):\n"
+
entity
.
getBody
(),
page
.
getBody
().
contains
(
"Access denied"
));
assertThat
(
page
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
FORBIDDEN
);
assertThat
(
page
.
getBody
()).
contains
(
"Access denied"
);
}
@Test
public
void
testManagementProtected
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/beans"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
UNAUTHORIZED
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
}
@Test
public
void
testManagementAuthorizedAccess
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
(
"admin"
,
"admin"
)
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/beans"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
}
@Test
public
void
testManagementUnauthorizedAccess
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
(
"user"
,
"user"
)
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/beans"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
FORBIDDEN
,
entity
.
getStatusCode
()
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
FORBIDDEN
);
}
private
void
getCsrf
(
MultiValueMap
<
String
,
String
>
form
,
HttpHeaders
headers
)
{
...
...
spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java
View file @
1cc1fc64
...
...
@@ -34,8 +34,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for Mustache application.
...
...
@@ -56,9 +55,8 @@ public class SampleWebMustacheApplicationTests {
public
void
testMustacheTemplate
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body:\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"Hello, Andy"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"Hello, Andy"
);
}
@Test
...
...
@@ -71,9 +69,9 @@ public class SampleWebMustacheApplicationTests {
"http://localhost:"
+
this
.
port
+
"/does-not-exist"
,
HttpMethod
.
GET
,
requestEntity
,
String
.
class
);
assert
Equals
(
HttpStatus
.
NOT_FOUND
,
responseEntity
.
getStatusCode
()
);
assertT
rue
(
"Wrong body:\n"
+
responseEntity
.
getBody
(),
responseEntity
.
getBody
().
contains
(
"Something went wrong: 404 Not Found"
)
);
assert
That
(
responseEntity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
assertT
hat
(
responseEntity
.
getBody
())
.
contains
(
"Something went wrong: 404 Not Found"
);
}
}
spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/ui/secure/SampleWebSecureCustomApplicationTests.java
View file @
1cc1fc64
...
...
@@ -22,12 +22,12 @@ import java.util.regex.Pattern;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
sample.web.secure.custom.SampleWebSecureCustomApplication
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
...
...
@@ -39,9 +39,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -64,9 +62,9 @@ public class SampleWebSecureCustomApplicationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
,
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>(
headers
),
String
.
class
);
assert
Equals
(
HttpStatus
.
FOUND
,
entity
.
getStatusCode
()
);
assertT
rue
(
"Wrong location:\n"
+
entity
.
getHeaders
(),
entity
.
getHeaders
().
getLocation
().
toString
().
endsWith
(
port
+
"/login"
)
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
FOUND
);
assertT
hat
(
entity
.
getHeaders
().
getLocation
().
toString
())
.
endsWith
(
this
.
port
+
"/login"
);
}
@Test
...
...
@@ -76,9 +74,8 @@ public class SampleWebSecureCustomApplicationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/login"
,
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>(
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong content:\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"_csrf"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"_csrf"
);
}
@Test
...
...
@@ -93,23 +90,22 @@ public class SampleWebSecureCustomApplicationTests {
"http://localhost:"
+
this
.
port
+
"/login"
,
HttpMethod
.
POST
,
new
HttpEntity
<
MultiValueMap
<
String
,
String
>>(
form
,
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
FOUND
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong location:\n"
+
entity
.
getHeaders
(),
entity
.
getHeaders
().
getLocation
().
toString
().
endsWith
(
port
+
"/"
));
assertNotNull
(
"Missing cookie:\n"
+
entity
.
getHeaders
(),
entity
.
getHeaders
().
get
(
"Set-Cookie"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
FOUND
);
assertThat
(
entity
.
getHeaders
().
getLocation
().
toString
())
.
endsWith
(
this
.
port
+
"/"
);
assertThat
(
entity
.
getHeaders
().
get
(
"Set-Cookie"
)).
isNotNull
();
}
private
HttpHeaders
getHeaders
()
{
HttpHeaders
headers
=
new
HttpHeaders
();
ResponseEntity
<
String
>
page
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/login"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
page
.
getStatusCode
()
);
assert
That
(
page
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
String
cookie
=
page
.
getHeaders
().
getFirst
(
"Set-Cookie"
);
headers
.
set
(
"Cookie"
,
cookie
);
Matcher
matcher
=
Pattern
.
compile
(
"(?s).*name=\"_csrf\".*?value=\"([^\"]+).*"
)
.
matcher
(
page
.
getBody
());
assertT
rue
(
"No csrf token: "
+
page
.
getBody
(),
matcher
.
matches
()
);
Pattern
pattern
=
Pattern
.
compile
(
"(?s).*name=\"_csrf\".*?value=\"([^\"]+).*"
);
Matcher
matcher
=
pattern
.
matcher
(
page
.
getBody
());
assertT
hat
(
matcher
.
matches
()).
as
(
page
.
getBody
()).
isTrue
(
);
headers
.
set
(
"X-CSRF-TOKEN"
,
matcher
.
group
(
1
));
return
headers
;
}
...
...
@@ -118,8 +114,8 @@ public class SampleWebSecureCustomApplicationTests {
public
void
testCss
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/css/bootstrap.min.css"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assertT
rue
(
"Wrong body:\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"body"
)
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertT
hat
(
entity
.
getBody
()).
contains
(
"body"
);
}
}
spring-boot-samples/spring-boot-sample-web-secure-github/src/test/java/sample/web/secure/github/SampleGithubApplicationTests.java
View file @
1cc1fc64
...
...
@@ -30,10 +30,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
startsWith
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for GitHub SSO application.
...
...
@@ -55,9 +52,9 @@ public class SampleGithubApplicationTests {
TestRestTemplate
restTemplate
=
new
TestRestTemplate
();
ResponseEntity
<
Void
>
entity
=
restTemplate
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
Void
.
class
);
assertThat
(
entity
.
getStatusCode
()
,
is
(
HttpStatus
.
FOUND
)
);
assertThat
(
entity
.
getHeaders
().
getLocation
()
,
is
(
equalTo
(
URI
.
create
(
"http://localhost:"
+
this
.
port
+
"/login"
))
));
assertThat
(
entity
.
getStatusCode
()
).
isEqualTo
(
HttpStatus
.
FOUND
);
assertThat
(
entity
.
getHeaders
().
getLocation
()
)
.
isEqualTo
(
URI
.
create
(
"http://localhost:"
+
this
.
port
+
"/login"
));
}
@Test
...
...
@@ -65,9 +62,9 @@ public class SampleGithubApplicationTests {
TestRestTemplate
restTemplate
=
new
TestRestTemplate
();
ResponseEntity
<
Void
>
entity
=
restTemplate
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/login"
,
Void
.
class
);
assertThat
(
entity
.
getStatusCode
()
,
is
(
HttpStatus
.
FOUND
)
);
assertThat
(
entity
.
getHeaders
().
getLocation
().
toString
()
,
startsWith
(
"https://github.com/login/oauth"
)
);
assertThat
(
entity
.
getStatusCode
()
).
isEqualTo
(
HttpStatus
.
FOUND
);
assertThat
(
entity
.
getHeaders
().
getLocation
().
toString
()
)
.
startsWith
(
"https://github.com/login/oauth"
);
}
}
spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureCustomApplicationTests.java
View file @
1cc1fc64
...
...
@@ -38,9 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -63,9 +61,9 @@ public class SampleWebSecureCustomApplicationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
,
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>(
headers
),
String
.
class
);
assert
Equals
(
HttpStatus
.
FOUND
,
entity
.
getStatusCode
()
);
assertT
rue
(
"Wrong location:\n"
+
entity
.
getHeaders
(),
entity
.
getHeaders
().
getLocation
().
toString
().
endsWith
(
port
+
"/login"
)
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
FOUND
);
assertT
hat
(
entity
.
getHeaders
().
getLocation
().
toString
())
.
endsWith
(
this
.
port
+
"/login"
);
}
@Test
...
...
@@ -75,9 +73,8 @@ public class SampleWebSecureCustomApplicationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/login"
,
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>(
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong content:\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"_csrf"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"_csrf"
);
}
@Test
...
...
@@ -92,23 +89,22 @@ public class SampleWebSecureCustomApplicationTests {
"http://localhost:"
+
this
.
port
+
"/login"
,
HttpMethod
.
POST
,
new
HttpEntity
<
MultiValueMap
<
String
,
String
>>(
form
,
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
FOUND
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong location:\n"
+
entity
.
getHeaders
(),
entity
.
getHeaders
().
getLocation
().
toString
().
endsWith
(
port
+
"/"
));
assertNotNull
(
"Missing cookie:\n"
+
entity
.
getHeaders
(),
entity
.
getHeaders
().
get
(
"Set-Cookie"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
FOUND
);
assertThat
(
entity
.
getHeaders
().
getLocation
().
toString
())
.
endsWith
(
this
.
port
+
"/"
);
assertThat
(
entity
.
getHeaders
().
get
(
"Set-Cookie"
)).
isNotNull
();
}
private
HttpHeaders
getHeaders
()
{
HttpHeaders
headers
=
new
HttpHeaders
();
ResponseEntity
<
String
>
page
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/login"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
page
.
getStatusCode
()
);
assert
That
(
page
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
String
cookie
=
page
.
getHeaders
().
getFirst
(
"Set-Cookie"
);
headers
.
set
(
"Cookie"
,
cookie
);
Matcher
matcher
=
Pattern
.
compile
(
"(?s).*name=\"_csrf\".*?value=\"([^\"]+).*"
)
.
matcher
(
page
.
getBody
());
assertT
rue
(
"No csrf token: "
+
page
.
getBody
(),
matcher
.
matches
()
);
Pattern
pattern
=
Pattern
.
compile
(
"(?s).*name=\"_csrf\".*?value=\"([^\"]+).*"
);
Matcher
matcher
=
pattern
.
matcher
(
page
.
getBody
());
assertT
hat
(
matcher
.
matches
()).
as
(
page
.
getBody
()).
isTrue
(
);
headers
.
set
(
"X-CSRF-TOKEN"
,
matcher
.
group
(
1
));
return
headers
;
}
...
...
@@ -117,8 +113,8 @@ public class SampleWebSecureCustomApplicationTests {
public
void
testCss
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/css/bootstrap.min.css"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assertT
rue
(
"Wrong body:\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"body"
)
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertT
hat
(
entity
.
getBody
()).
contains
(
"body"
);
}
}
spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java
View file @
1cc1fc64
...
...
@@ -38,9 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -63,9 +61,9 @@ public class SampleSecureApplicationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
,
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>(
headers
),
String
.
class
);
assert
Equals
(
HttpStatus
.
FOUND
,
entity
.
getStatusCode
()
);
assertT
rue
(
"Wrong location:\n"
+
entity
.
getHeaders
(),
entity
.
getHeaders
().
getLocation
().
toString
().
endsWith
(
port
+
"/login"
)
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
FOUND
);
assertT
hat
(
entity
.
getHeaders
().
getLocation
().
toString
())
.
endsWith
(
this
.
port
+
"/login"
);
}
@Test
...
...
@@ -75,9 +73,8 @@ public class SampleSecureApplicationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/login"
,
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>(
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong content:\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"_csrf"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"_csrf"
);
}
@Test
...
...
@@ -92,23 +89,22 @@ public class SampleSecureApplicationTests {
"http://localhost:"
+
this
.
port
+
"/login"
,
HttpMethod
.
POST
,
new
HttpEntity
<
MultiValueMap
<
String
,
String
>>(
form
,
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
FOUND
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong location:\n"
+
entity
.
getHeaders
(),
entity
.
getHeaders
().
getLocation
().
toString
().
endsWith
(
port
+
"/"
));
assertNotNull
(
"Missing cookie:\n"
+
entity
.
getHeaders
(),
entity
.
getHeaders
().
get
(
"Set-Cookie"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
FOUND
);
assertThat
(
entity
.
getHeaders
().
getLocation
().
toString
())
.
endsWith
(
this
.
port
+
"/"
);
assertThat
(
entity
.
getHeaders
().
get
(
"Set-Cookie"
)).
isNotNull
();
}
private
HttpHeaders
getHeaders
()
{
HttpHeaders
headers
=
new
HttpHeaders
();
ResponseEntity
<
String
>
page
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/login"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
page
.
getStatusCode
()
);
assert
That
(
page
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
String
cookie
=
page
.
getHeaders
().
getFirst
(
"Set-Cookie"
);
headers
.
set
(
"Cookie"
,
cookie
);
Matcher
matcher
=
Pattern
.
compile
(
"(?s).*name=\"_csrf\".*?value=\"([^\"]+).*"
)
.
matcher
(
page
.
getBody
());
assertT
rue
(
"No csrf token: "
+
page
.
getBody
(),
matcher
.
matches
()
);
Pattern
pattern
=
Pattern
.
compile
(
"(?s).*name=\"_csrf\".*?value=\"([^\"]+).*"
);
Matcher
matcher
=
pattern
.
matcher
(
page
.
getBody
());
assertT
hat
(
matcher
.
matches
()).
as
(
page
.
getBody
()).
isTrue
(
);
headers
.
set
(
"X-CSRF-TOKEN"
,
matcher
.
group
(
1
));
return
headers
;
}
...
...
@@ -117,8 +113,8 @@ public class SampleSecureApplicationTests {
public
void
testCss
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/css/bootstrap.min.css"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assertT
rue
(
"Wrong body:\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"body"
)
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertT
hat
(
entity
.
getBody
()).
contains
(
"body"
);
}
}
spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/webstatic/SampleWebStaticApplicationTests.java
View file @
1cc1fc64
...
...
@@ -18,20 +18,19 @@ package sample.webstatic;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
sample.web.staticcontent.SampleWebStaticApplication
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -51,9 +50,8 @@ public class SampleWebStaticApplicationTests {
public
void
testHome
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body (title doesn't match):\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"<title>Static"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"<title>Static"
);
}
@Test
...
...
@@ -63,11 +61,10 @@ public class SampleWebStaticApplicationTests {
"http://localhost:"
+
this
.
port
+
"/webjars/bootstrap/3.0.3/css/bootstrap.min.css"
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body:\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"body"
));
assertEquals
(
"Wrong content type:\n"
+
entity
.
getHeaders
().
getContentType
(),
MediaType
.
valueOf
(
"text/css;charset=UTF-8"
),
entity
.
getHeaders
().
getContentType
());
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"body"
);
assertThat
(
entity
.
getHeaders
().
getContentType
())
.
isEqualTo
(
MediaType
.
valueOf
(
"text/css;charset=UTF-8"
));
}
}
spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/ui/SampleWebUiApplicationTests.java
View file @
1cc1fc64
...
...
@@ -20,12 +20,12 @@ import java.net.URI;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
sample.web.ui.SampleWebUiApplication
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.annotation.DirtiesContext
;
...
...
@@ -33,9 +33,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for demo application.
...
...
@@ -55,11 +53,9 @@ public class SampleWebUiApplicationTests {
public
void
testHome
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body (title doesn't match):\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"<title>Messages"
));
assertFalse
(
"Wrong body (found layout:fragment):\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"layout:fragment"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"<title>Messages"
);
assertThat
(
entity
.
getBody
()).
doesNotContain
(
"layout:fragment"
);
}
@Test
...
...
@@ -69,16 +65,15 @@ public class SampleWebUiApplicationTests {
map
.
set
(
"summary"
,
"FOO"
);
URI
location
=
new
TestRestTemplate
()
.
postForLocation
(
"http://localhost:"
+
this
.
port
,
map
);
assertTrue
(
"Wrong location:\n"
+
location
,
location
.
toString
().
contains
(
"localhost:"
+
this
.
port
));
assertThat
(
location
.
toString
()).
contains
(
"localhost:"
+
this
.
port
);
}
@Test
public
void
testCss
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/css/bootstrap.min.css"
,
String
.
class
);
assert
Equals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
()
);
assertT
rue
(
"Wrong body:\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"body"
)
);
assert
That
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertT
hat
(
entity
.
getBody
()).
contains
(
"body"
);
}
}
spring-boot-samples/spring-boot-sample-web-velocity/src/test/java/sample/web/velocity/SampleWebVelocityApplicationTests.java
View file @
1cc1fc64
...
...
@@ -34,8 +34,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Basic integration tests for Velocity application.
...
...
@@ -56,9 +55,8 @@ public class SampleWebVelocityApplicationTests {
public
void
testVelocityTemplate
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body:\n"
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"Hello, Andy"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"Hello, Andy"
);
}
@Test
...
...
@@ -71,9 +69,9 @@ public class SampleWebVelocityApplicationTests {
"http://localhost:"
+
this
.
port
+
"/does-not-exist"
,
HttpMethod
.
GET
,
requestEntity
,
String
.
class
);
assert
Equals
(
HttpStatus
.
NOT_FOUND
,
responseEntity
.
getStatusCode
()
);
assertT
rue
(
"Wrong body:\n"
+
responseEntity
.
getBody
(),
responseEntity
.
getBody
().
contains
(
"Something went wrong: 404 Not Found"
)
);
assert
That
(
responseEntity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
assertT
hat
(
responseEntity
.
getBody
())
.
contains
(
"Something went wrong: 404 Not Found"
);
}
}
spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java
View file @
1cc1fc64
...
...
@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
samples.websocket.jetty.client.GreetingService
;
import
samples.websocket.jetty.client.SimpleClientWebSocketHandler
;
import
samples.websocket.jetty.client.SimpleGreetingService
;
...
...
@@ -34,6 +33,7 @@ import org.springframework.boot.CommandLineRunner;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -42,7 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
org.springframework.web.socket.client.WebSocketConnectionManager
;
import
org.springframework.web.socket.client.standard.StandardWebSocketClient
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
SampleJettyWebSocketsApplication
.
class
)
...
...
@@ -66,8 +66,9 @@ public class SampleWebSocketsApplicationTests {
AtomicReference
<
String
>
messagePayloadReference
=
context
.
getBean
(
ClientConfiguration
.
class
).
messagePayload
;
context
.
close
();
assertEquals
(
0
,
count
);
assertEquals
(
"Did you say \"Hello world!\"?"
,
messagePayloadReference
.
get
());
assertThat
(
count
).
isEqualTo
(
0
);
assertThat
(
messagePayloadReference
.
get
())
.
isEqualTo
(
"Did you say \"Hello world!\"?"
);
}
@Test
...
...
@@ -81,8 +82,8 @@ public class SampleWebSocketsApplicationTests {
AtomicReference
<
String
>
messagePayloadReference
=
context
.
getBean
(
ClientConfiguration
.
class
).
messagePayload
;
context
.
close
();
assert
Equals
(
0
,
count
);
assert
Equals
(
"Reversed: !dlrow olleH"
,
messagePayloadReference
.
get
()
);
assert
That
(
count
).
isEqualTo
(
0
);
assert
That
(
messagePayloadReference
.
get
()).
isEqualTo
(
"Reversed: !dlrow olleH"
);
}
@Configuration
...
...
spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java
View file @
1cc1fc64
...
...
@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
samples.websocket.jetty.SampleJettyWebSocketsApplication
;
import
samples.websocket.jetty.client.GreetingService
;
import
samples.websocket.jetty.client.SimpleClientWebSocketHandler
;
...
...
@@ -38,6 +37,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import
org.springframework.boot.context.embedded.EmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -47,7 +47,7 @@ import org.springframework.util.SocketUtils;
import
org.springframework.web.socket.client.WebSocketConnectionManager
;
import
org.springframework.web.socket.client.standard.StandardWebSocketClient
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
({
SampleJettyWebSocketsApplication
.
class
,
...
...
@@ -72,8 +72,9 @@ public class CustomContainerWebSocketsApplicationTests {
AtomicReference
<
String
>
messagePayloadReference
=
context
.
getBean
(
ClientConfiguration
.
class
).
messagePayload
;
context
.
close
();
assertEquals
(
0
,
count
);
assertEquals
(
"Did you say \"Hello world!\"?"
,
messagePayloadReference
.
get
());
assertThat
(
count
).
isEqualTo
(
0
);
assertThat
(
messagePayloadReference
.
get
())
.
isEqualTo
(
"Did you say \"Hello world!\"?"
);
}
@Test
...
...
@@ -87,8 +88,8 @@ public class CustomContainerWebSocketsApplicationTests {
AtomicReference
<
String
>
messagePayloadReference
=
context
.
getBean
(
ClientConfiguration
.
class
).
messagePayload
;
context
.
close
();
assert
Equals
(
0
,
count
);
assert
Equals
(
"Reversed: !dlrow olleH"
,
messagePayloadReference
.
get
()
);
assert
That
(
count
).
isEqualTo
(
0
);
assert
That
(
messagePayloadReference
.
get
()).
isEqualTo
(
"Reversed: !dlrow olleH"
);
}
@Configuration
...
...
spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/snake/SnakeTimerTests.java
View file @
1cc1fc64
...
...
@@ -20,8 +20,7 @@ import java.io.IOException;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
willThrow
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -35,7 +34,7 @@ public class SnakeTimerTests {
SnakeTimer
.
addSnake
(
snake
);
SnakeTimer
.
broadcast
(
""
);
assertThat
(
SnakeTimer
.
getSnakes
()
.
size
(),
is
(
0
)
);
assertThat
(
SnakeTimer
.
getSnakes
()
).
hasSize
(
0
);
}
}
spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java
View file @
1cc1fc64
...
...
@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
samples.websocket.tomcat.client.GreetingService
;
import
samples.websocket.tomcat.client.SimpleClientWebSocketHandler
;
import
samples.websocket.tomcat.client.SimpleGreetingService
;
...
...
@@ -34,6 +33,7 @@ import org.springframework.boot.CommandLineRunner;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -42,7 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
org.springframework.web.socket.client.WebSocketConnectionManager
;
import
org.springframework.web.socket.client.standard.StandardWebSocketClient
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
SampleTomcatWebSocketApplication
.
class
)
...
...
@@ -66,8 +66,9 @@ public class SampleWebSocketsApplicationTests {
AtomicReference
<
String
>
messagePayloadReference
=
context
.
getBean
(
ClientConfiguration
.
class
).
messagePayload
;
context
.
close
();
assertEquals
(
0
,
count
);
assertEquals
(
"Did you say \"Hello world!\"?"
,
messagePayloadReference
.
get
());
assertThat
(
count
).
isEqualTo
(
0
);
assertThat
(
messagePayloadReference
.
get
())
.
isEqualTo
(
"Did you say \"Hello world!\"?"
);
}
@Test
...
...
@@ -81,8 +82,8 @@ public class SampleWebSocketsApplicationTests {
AtomicReference
<
String
>
messagePayloadReference
=
context
.
getBean
(
ClientConfiguration
.
class
).
messagePayload
;
context
.
close
();
assert
Equals
(
0
,
count
);
assert
Equals
(
"Reversed: !dlrow olleH"
,
messagePayloadReference
.
get
()
);
assert
That
(
count
).
isEqualTo
(
0
);
assert
That
(
messagePayloadReference
.
get
()).
isEqualTo
(
"Reversed: !dlrow olleH"
);
}
@Configuration
...
...
spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java
View file @
1cc1fc64
...
...
@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
samples.websocket.tomcat.SampleTomcatWebSocketApplication
;
import
samples.websocket.tomcat.client.GreetingService
;
import
samples.websocket.tomcat.client.SimpleClientWebSocketHandler
;
...
...
@@ -38,6 +37,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import
org.springframework.boot.context.embedded.EmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -47,7 +47,7 @@ import org.springframework.util.SocketUtils;
import
org.springframework.web.socket.client.WebSocketConnectionManager
;
import
org.springframework.web.socket.client.standard.StandardWebSocketClient
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
({
SampleTomcatWebSocketApplication
.
class
,
...
...
@@ -72,8 +72,9 @@ public class CustomContainerWebSocketsApplicationTests {
AtomicReference
<
String
>
messagePayloadReference
=
context
.
getBean
(
ClientConfiguration
.
class
).
messagePayload
;
context
.
close
();
assertEquals
(
0
,
count
);
assertEquals
(
"Did you say \"Hello world!\"?"
,
messagePayloadReference
.
get
());
assertThat
(
count
).
isEqualTo
(
0
);
assertThat
(
messagePayloadReference
.
get
())
.
isEqualTo
(
"Did you say \"Hello world!\"?"
);
}
@Test
...
...
@@ -87,8 +88,8 @@ public class CustomContainerWebSocketsApplicationTests {
AtomicReference
<
String
>
messagePayloadReference
=
context
.
getBean
(
ClientConfiguration
.
class
).
messagePayload
;
context
.
close
();
assert
Equals
(
0
,
count
);
assert
Equals
(
"Reversed: !dlrow olleH"
,
messagePayloadReference
.
get
()
);
assert
That
(
count
).
isEqualTo
(
0
);
assert
That
(
messagePayloadReference
.
get
()).
isEqualTo
(
"Reversed: !dlrow olleH"
);
}
@Configuration
...
...
spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/snake/SnakeTimerTests.java
View file @
1cc1fc64
...
...
@@ -20,8 +20,7 @@ import java.io.IOException;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
willThrow
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -35,6 +34,6 @@ public class SnakeTimerTests {
SnakeTimer
.
addSnake
(
snake
);
SnakeTimer
.
broadcast
(
""
);
assertThat
(
SnakeTimer
.
getSnakes
()
.
size
(),
is
(
0
)
);
assertThat
(
SnakeTimer
.
getSnakes
()
).
hasSize
(
0
);
}
}
spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java
View file @
1cc1fc64
...
...
@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
samples.websocket.undertow.client.GreetingService
;
import
samples.websocket.undertow.client.SimpleClientWebSocketHandler
;
import
samples.websocket.undertow.client.SimpleGreetingService
;
...
...
@@ -34,6 +33,7 @@ import org.springframework.boot.CommandLineRunner;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -42,7 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
org.springframework.web.socket.client.WebSocketConnectionManager
;
import
org.springframework.web.socket.client.standard.StandardWebSocketClient
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
SampleUndertowWebSocketsApplication
.
class
)
...
...
@@ -66,8 +66,9 @@ public class SampleWebSocketsApplicationTests {
AtomicReference
<
String
>
messagePayloadReference
=
context
.
getBean
(
ClientConfiguration
.
class
).
messagePayload
;
context
.
close
();
assertEquals
(
0
,
count
);
assertEquals
(
"Did you say \"Hello world!\"?"
,
messagePayloadReference
.
get
());
assertThat
(
count
).
isEqualTo
(
0
);
assertThat
(
messagePayloadReference
.
get
())
.
isEqualTo
(
"Did you say \"Hello world!\"?"
);
}
@Test
...
...
@@ -81,8 +82,8 @@ public class SampleWebSocketsApplicationTests {
AtomicReference
<
String
>
messagePayloadReference
=
context
.
getBean
(
ClientConfiguration
.
class
).
messagePayload
;
context
.
close
();
assert
Equals
(
0
,
count
);
assert
Equals
(
"Reversed: !dlrow olleH"
,
messagePayloadReference
.
get
()
);
assert
That
(
count
).
isEqualTo
(
0
);
assert
That
(
messagePayloadReference
.
get
()).
isEqualTo
(
"Reversed: !dlrow olleH"
);
}
@Configuration
...
...
spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java
View file @
1cc1fc64
...
...
@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
samples.websocket.undertow.SampleUndertowWebSocketsApplication
;
import
samples.websocket.undertow.client.GreetingService
;
import
samples.websocket.undertow.client.SimpleClientWebSocketHandler
;
...
...
@@ -38,6 +37,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import
org.springframework.boot.context.embedded.EmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -47,7 +47,7 @@ import org.springframework.util.SocketUtils;
import
org.springframework.web.socket.client.WebSocketConnectionManager
;
import
org.springframework.web.socket.client.standard.StandardWebSocketClient
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
({
SampleUndertowWebSocketsApplication
.
class
,
...
...
@@ -72,8 +72,9 @@ public class CustomContainerWebSocketsApplicationTests {
AtomicReference
<
String
>
messagePayloadReference
=
context
.
getBean
(
ClientConfiguration
.
class
).
messagePayload
;
context
.
close
();
assertEquals
(
0
,
count
);
assertEquals
(
"Did you say \"Hello world!\"?"
,
messagePayloadReference
.
get
());
assertThat
(
count
).
isEqualTo
(
0
);
assertThat
(
messagePayloadReference
.
get
())
.
isEqualTo
(
"Did you say \"Hello world!\"?"
);
}
@Test
...
...
@@ -87,8 +88,8 @@ public class CustomContainerWebSocketsApplicationTests {
AtomicReference
<
String
>
messagePayloadReference
=
context
.
getBean
(
ClientConfiguration
.
class
).
messagePayload
;
context
.
close
();
assert
Equals
(
0
,
count
);
assert
Equals
(
"Reversed: !dlrow olleH"
,
messagePayloadReference
.
get
()
);
assert
That
(
count
).
isEqualTo
(
0
);
assert
That
(
messagePayloadReference
.
get
()).
isEqualTo
(
"Reversed: !dlrow olleH"
);
}
@Configuration
...
...
spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/snake/SnakeTimerTests.java
View file @
1cc1fc64
...
...
@@ -20,8 +20,7 @@ import java.io.IOException;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
willThrow
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -35,6 +34,6 @@ public class SnakeTimerTests {
SnakeTimer
.
addSnake
(
snake
);
SnakeTimer
.
broadcast
(
""
);
assertThat
(
SnakeTimer
.
getSnakes
()
.
size
(),
is
(
0
)
);
assertThat
(
SnakeTimer
.
getSnakes
()
).
hasSize
(
0
);
}
}
spring-boot-samples/spring-boot-sample-ws/src/test/java/sample/ws/SampleWsApplicationTests.java
View file @
1cc1fc64
...
...
@@ -32,8 +32,7 @@ import org.springframework.boot.test.WebIntegrationTest;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.ws.client.core.WebServiceTemplate
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
SampleWsApplication
.
class
)
...
...
@@ -68,7 +67,7 @@ public class SampleWsApplicationTests {
StreamResult
result
=
new
StreamResult
(
System
.
out
);
this
.
webServiceTemplate
.
sendSourceAndReceiveToResult
(
source
,
result
);
assertThat
(
this
.
output
.
toString
()
,
containsString
(
"Booking holiday for"
)
);
assertThat
(
this
.
output
.
toString
()
).
contains
(
"Booking holiday for"
);
}
}
spring-boot-samples/spring-boot-sample-xml/src/test/java/sample/xml/SampleSpringXmlApplicationTests.java
View file @
1cc1fc64
...
...
@@ -21,7 +21,7 @@ import org.junit.Test;
import
org.springframework.boot.test.OutputCapture
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
SampleSpringXmlApplicationTests
{
...
...
@@ -32,7 +32,7 @@ public class SampleSpringXmlApplicationTests {
public
void
testDefaultSettings
()
throws
Exception
{
SampleSpringXmlApplication
.
main
(
new
String
[
0
]);
String
output
=
this
.
outputCapture
.
toString
();
assertT
rue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Hello World"
)
);
assertT
hat
(
output
).
contains
(
"Hello World"
);
}
}
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