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
94677b35
Commit
94677b35
authored
Feb 06, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use AssertJ in spring-boot-actuator
See gh-5083
parent
a5ae81c1
Changes
103
Hide whitespace changes
Inline
Side-by-side
Showing
103 changed files
with
1197 additions
and
1405 deletions
+1197
-1405
AuditEventTests.java
...g/springframework/boot/actuate/audit/AuditEventTests.java
+7
-8
InMemoryAuditEventRepositoryTests.java
...boot/actuate/audit/InMemoryAuditEventRepositoryTests.java
+15
-16
AuditAutoConfigurationTests.java
...ot/actuate/autoconfigure/AuditAutoConfigurationTests.java
+10
-12
CacheStatisticsAutoConfigurationTests.java
.../autoconfigure/CacheStatisticsAutoConfigurationTests.java
+6
-6
CrshAutoConfigurationTests.java
...oot/actuate/autoconfigure/CrshAutoConfigurationTests.java
+48
-76
EndpointAutoConfigurationTests.java
...actuate/autoconfigure/EndpointAutoConfigurationTests.java
+31
-33
EndpointMBeanExportAutoConfigurationTests.java
...oconfigure/EndpointMBeanExportAutoConfigurationTests.java
+15
-30
EndpointMvcIntegrationTests.java
...ot/actuate/autoconfigure/EndpointMvcIntegrationTests.java
+5
-8
EndpointWebMvcAutoConfigurationTests.java
...e/autoconfigure/EndpointWebMvcAutoConfigurationTests.java
+32
-37
HealthIndicatorAutoConfigurationTests.java
.../autoconfigure/HealthIndicatorAutoConfigurationTests.java
+71
-72
HealthMvcEndpointAutoConfigurationTests.java
...utoconfigure/HealthMvcEndpointAutoConfigurationTests.java
+5
-5
JolokiaAutoConfigurationTests.java
.../actuate/autoconfigure/JolokiaAutoConfigurationTests.java
+5
-9
ManagementServerPropertiesAutoConfigurationTests.java
...ure/ManagementServerPropertiesAutoConfigurationTests.java
+7
-9
ManagementWebSecurityAutoConfigurationTests.java
...onfigure/ManagementWebSecurityAutoConfigurationTests.java
+23
-24
MetricExportAutoConfigurationTests.java
...ate/autoconfigure/MetricExportAutoConfigurationTests.java
+4
-6
MetricFilterAutoConfigurationTests.java
...ate/autoconfigure/MetricFilterAutoConfigurationTests.java
+4
-5
MetricRepositoryAutoConfigurationTests.java
...autoconfigure/MetricRepositoryAutoConfigurationTests.java
+11
-16
PublicMetricsAutoConfigurationTests.java
...te/autoconfigure/PublicMetricsAutoConfigurationTests.java
+12
-16
ShellPropertiesTests.java
...work/boot/actuate/autoconfigure/ShellPropertiesTests.java
+42
-49
TraceRepositoryAutoConfigurationTests.java
.../autoconfigure/TraceRepositoryAutoConfigurationTests.java
+4
-7
TraceWebFilterAutoConfigurationTests.java
...e/autoconfigure/TraceWebFilterAutoConfigurationTests.java
+2
-2
AbstractEndpointTests.java
...ramework/boot/actuate/endpoint/AbstractEndpointTests.java
+12
-13
AutoConfigurationReportEndpointTests.java
...ctuate/endpoint/AutoConfigurationReportEndpointTests.java
+4
-4
BeansEndpointTests.java
...ngframework/boot/actuate/endpoint/BeansEndpointTests.java
+4
-4
ConfigurationPropertiesReportEndpointMethodAnnotationsTests.java
...rationPropertiesReportEndpointMethodAnnotationsTests.java
+7
-8
ConfigurationPropertiesReportEndpointParentTests.java
...int/ConfigurationPropertiesReportEndpointParentTests.java
+5
-6
ConfigurationPropertiesReportEndpointProxyTests.java
...oint/ConfigurationPropertiesReportEndpointProxyTests.java
+2
-3
ConfigurationPropertiesReportEndpointSerializationTests.java
...figurationPropertiesReportEndpointSerializationTests.java
+35
-36
ConfigurationPropertiesReportEndpointTests.java
.../endpoint/ConfigurationPropertiesReportEndpointTests.java
+28
-32
DumpEndpointTests.java
...ingframework/boot/actuate/endpoint/DumpEndpointTests.java
+2
-3
EnvironmentEndpointTests.java
...ework/boot/actuate/endpoint/EnvironmentEndpointTests.java
+39
-43
FlywayEndpointTests.java
...gframework/boot/actuate/endpoint/FlywayEndpointTests.java
+2
-3
HealthEndpointTests.java
...gframework/boot/actuate/endpoint/HealthEndpointTests.java
+2
-3
InfoEndpointTests.java
...ingframework/boot/actuate/endpoint/InfoEndpointTests.java
+2
-3
LiquibaseEndpointTests.java
...amework/boot/actuate/endpoint/LiquibaseEndpointTests.java
+2
-3
MetricReaderPublicMetricsTests.java
...boot/actuate/endpoint/MetricReaderPublicMetricsTests.java
+2
-2
MetricsEndpointTests.java
...framework/boot/actuate/endpoint/MetricsEndpointTests.java
+6
-9
RequestMappingEndpointTests.java
...rk/boot/actuate/endpoint/RequestMappingEndpointTests.java
+13
-14
RichGaugeReaderPublicMetricsTests.java
...t/actuate/endpoint/RichGaugeReaderPublicMetricsTests.java
+13
-15
SanitizerTests.java
...springframework/boot/actuate/endpoint/SanitizerTests.java
+11
-12
ShutdownEndpointTests.java
...ramework/boot/actuate/endpoint/ShutdownEndpointTests.java
+6
-9
ShutdownParentEndpointTests.java
...rk/boot/actuate/endpoint/ShutdownParentEndpointTests.java
+9
-11
SystemPublicMetricsTests.java
...ework/boot/actuate/endpoint/SystemPublicMetricsTests.java
+21
-25
TomcatPublicMetricsTests.java
...ework/boot/actuate/endpoint/TomcatPublicMetricsTests.java
+4
-5
TraceEndpointTests.java
...ngframework/boot/actuate/endpoint/TraceEndpointTests.java
+2
-3
EndpointMBeanExporterTests.java
...boot/actuate/endpoint/jmx/EndpointMBeanExporterTests.java
+27
-33
EndpointHandlerMappingTests.java
...oot/actuate/endpoint/mvc/EndpointHandlerMappingTests.java
+23
-34
HalBrowserMvcEndpointBrowserPathIntegrationTests.java
...mvc/HalBrowserMvcEndpointBrowserPathIntegrationTests.java
+3
-2
HalBrowserMvcEndpointDisabledIntegrationTests.java
...nt/mvc/HalBrowserMvcEndpointDisabledIntegrationTests.java
+3
-2
HalBrowserMvcEndpointEndpointsDisabledIntegrationTests.java
...lBrowserMvcEndpointEndpointsDisabledIntegrationTests.java
+2
-3
HalBrowserMvcEndpointServerContextPathIntegrationTests.java
...lBrowserMvcEndpointServerContextPathIntegrationTests.java
+9
-14
HalBrowserMvcEndpointServerPortIntegrationTests.java
.../mvc/HalBrowserMvcEndpointServerPortIntegrationTests.java
+9
-15
HalBrowserMvcEndpointVanillaIntegrationTests.java
...int/mvc/HalBrowserMvcEndpointVanillaIntegrationTests.java
+3
-2
HealthMvcEndpointTests.java
...ork/boot/actuate/endpoint/mvc/HealthMvcEndpointTests.java
+40
-45
JolokiaMvcEndpointTests.java
...rk/boot/actuate/endpoint/mvc/JolokiaMvcEndpointTests.java
+2
-6
LogFileMvcEndpointTests.java
...rk/boot/actuate/endpoint/mvc/LogFileMvcEndpointTests.java
+7
-9
MvcEndpointsTests.java
...ramework/boot/actuate/endpoint/mvc/MvcEndpointsTests.java
+7
-7
NamePatternFilterTests.java
...ork/boot/actuate/endpoint/mvc/NamePatternFilterTests.java
+19
-23
ShutdownMvcEndpointTests.java
...k/boot/actuate/endpoint/mvc/ShutdownMvcEndpointTests.java
+2
-2
ApplicationHealthIndicatorTests.java
.../boot/actuate/health/ApplicationHealthIndicatorTests.java
+2
-2
CompositeHealthIndicatorTests.java
...rk/boot/actuate/health/CompositeHealthIndicatorTests.java
+21
-27
DataSourceHealthIndicatorTests.java
...k/boot/actuate/health/DataSourceHealthIndicatorTests.java
+21
-26
DiskSpaceHealthIndicatorTests.java
...rk/boot/actuate/health/DiskSpaceHealthIndicatorTests.java
+9
-9
ElasticsearchHealthIndicatorTests.java
...oot/actuate/health/ElasticsearchHealthIndicatorTests.java
+15
-19
HealthTests.java
.../org/springframework/boot/actuate/health/HealthTests.java
+35
-37
JmsHealthIndicatorTests.java
...ramework/boot/actuate/health/JmsHealthIndicatorTests.java
+7
-7
MailHealthIndicatorTests.java
...amework/boot/actuate/health/MailHealthIndicatorTests.java
+7
-9
MongoHealthIndicatorTests.java
...mework/boot/actuate/health/MongoHealthIndicatorTests.java
+9
-13
OrderedHealthAggregatorTests.java
...ork/boot/actuate/health/OrderedHealthAggregatorTests.java
+9
-6
RabbitHealthIndicatorTests.java
...ework/boot/actuate/health/RabbitHealthIndicatorTests.java
+4
-4
RedisHealthIndicatorTests.java
...mework/boot/actuate/health/RedisHealthIndicatorTests.java
+9
-15
SolrHealthIndicatorTests.java
...amework/boot/actuate/health/SolrHealthIndicatorTests.java
+9
-11
AggregateMetricReaderTests.java
...actuate/metrics/aggregate/AggregateMetricReaderTests.java
+14
-13
BufferGaugeServiceSpeedTests.java
.../actuate/metrics/buffer/BufferGaugeServiceSpeedTests.java
+3
-3
BufferMetricReaderTests.java
.../boot/actuate/metrics/buffer/BufferMetricReaderTests.java
+6
-7
CounterBuffersTests.java
...work/boot/actuate/metrics/buffer/CounterBuffersTests.java
+4
-5
CounterServiceSpeedTests.java
...boot/actuate/metrics/buffer/CounterServiceSpeedTests.java
+3
-3
DefaultCounterServiceSpeedTests.java
...tuate/metrics/buffer/DefaultCounterServiceSpeedTests.java
+2
-2
DefaultGaugeServiceSpeedTests.java
...actuate/metrics/buffer/DefaultGaugeServiceSpeedTests.java
+2
-2
DropwizardCounterServiceSpeedTests.java
...te/metrics/buffer/DropwizardCounterServiceSpeedTests.java
+2
-2
DropwizardMetricServicesTests.java
...ate/metrics/dropwizard/DropwizardMetricServicesTests.java
+10
-10
MetricCopyExporterTests.java
.../boot/actuate/metrics/export/MetricCopyExporterTests.java
+10
-10
MetricExportersTests.java
...ork/boot/actuate/metrics/export/MetricExportersTests.java
+7
-8
PrefixMetricGroupExporterTests.java
...ctuate/metrics/export/PrefixMetricGroupExporterTests.java
+6
-6
RichGaugeExporterTests.java
...k/boot/actuate/metrics/export/RichGaugeExporterTests.java
+2
-2
SpringIntegrationMetricReaderTests.java
...trics/integration/SpringIntegrationMetricReaderTests.java
+2
-2
DefaultMetricNamingStrategyTests.java
...actuate/metrics/jmx/DefaultMetricNamingStrategyTests.java
+14
-14
MetricRegistryMetricReaderTests.java
...tuate/metrics/reader/MetricRegistryMetricReaderTests.java
+5
-8
InMemoryMetricRepositoryTests.java
...ate/metrics/repository/InMemoryMetricRepositoryTests.java
+6
-3
InMemoryPrefixMetricRepositoryTests.java
...trics/repository/InMemoryPrefixMetricRepositoryTests.java
+12
-13
RedisMetricRepositoryTests.java
.../metrics/repository/redis/RedisMetricRepositoryTests.java
+14
-15
RedisMultiMetricRepositoryTests.java
...ics/repository/redis/RedisMultiMetricRepositoryTests.java
+14
-18
InMemoryRichGaugeRepositoryTests.java
...ctuate/metrics/rich/InMemoryRichGaugeRepositoryTests.java
+4
-3
MultiMetricRichGaugeReaderTests.java
...actuate/metrics/rich/MultiMetricRichGaugeReaderTests.java
+8
-9
StatsdMetricWriterTests.java
.../boot/actuate/metrics/statsd/StatsdMetricWriterTests.java
+24
-26
SimpleInMemoryRepositoryTests.java
...t/actuate/metrics/util/SimpleInMemoryRepositoryTests.java
+44
-44
DefaultCounterServiceTests.java
...ot/actuate/metrics/writer/DefaultCounterServiceTests.java
+12
-9
DefaultGaugeServiceTests.java
...boot/actuate/metrics/writer/DefaultGaugeServiceTests.java
+5
-3
AuthenticationAuditListenerTests.java
...ot/actuate/security/AuthenticationAuditListenerTests.java
+3
-4
ApplicationPidFileWriterTests.java
...rk/boot/actuate/system/ApplicationPidFileWriterTests.java
+10
-16
EmbeddedServerPortFileWriterTests.java
...oot/actuate/system/EmbeddedServerPortFileWriterTests.java
+15
-19
InMemoryTraceRepositoryTests.java
...work/boot/actuate/trace/InMemoryTraceRepositoryTests.java
+7
-7
WebRequestTraceFilterTests.java
...mework/boot/actuate/trace/WebRequestTraceFilterTests.java
+22
-22
No files found.
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventTests.java
View file @
94677b35
...
...
@@ -20,8 +20,7 @@ import java.util.Collections;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link AuditEvent}.
...
...
@@ -34,17 +33,17 @@ public class AuditEventTests {
public
void
testNowEvent
()
throws
Exception
{
AuditEvent
event
=
new
AuditEvent
(
"phil"
,
"UNKNOWN"
,
Collections
.
singletonMap
(
"a"
,
(
Object
)
"b"
));
assert
Equals
(
"b"
,
event
.
getData
().
get
(
"a"
)
);
assert
Equals
(
"UNKNOWN"
,
event
.
getType
()
);
assert
Equals
(
"phil"
,
event
.
getPrincipal
()
);
assert
NotNull
(
event
.
getTimestamp
()
);
assert
That
(
event
.
getData
().
get
(
"a"
)).
isEqualTo
(
"b"
);
assert
That
(
event
.
getType
()).
isEqualTo
(
"UNKNOWN"
);
assert
That
(
event
.
getPrincipal
()).
isEqualTo
(
"phil"
);
assert
That
(
event
.
getTimestamp
()).
isNotNull
(
);
}
@Test
public
void
testConvertStringsToData
()
throws
Exception
{
AuditEvent
event
=
new
AuditEvent
(
"phil"
,
"UNKNOWN"
,
"a=b"
,
"c=d"
);
assert
Equals
(
"b"
,
event
.
getData
().
get
(
"a"
)
);
assert
Equals
(
"d"
,
event
.
getData
().
get
(
"c"
)
);
assert
That
(
event
.
getData
().
get
(
"a"
)).
isEqualTo
(
"b"
);
assert
That
(
event
.
getData
().
get
(
"c"
)).
isEqualTo
(
"d"
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/InMemoryAuditEventRepositoryTests.java
View file @
94677b35
...
...
@@ -24,8 +24,7 @@ import java.util.Map;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link InMemoryAuditEventRepository}.
...
...
@@ -41,9 +40,9 @@ public class InMemoryAuditEventRepositoryTests {
repository
.
add
(
new
AuditEvent
(
"dave"
,
"a"
));
repository
.
add
(
new
AuditEvent
(
"dave"
,
"b"
));
List
<
AuditEvent
>
events
=
repository
.
find
(
"dave"
,
null
);
assertThat
(
events
.
size
()
,
equalTo
(
2
)
);
assertThat
(
events
.
get
(
0
).
getType
()
,
equalTo
(
"a"
)
);
assertThat
(
events
.
get
(
1
).
getType
()
,
equalTo
(
"b"
)
);
assertThat
(
events
.
size
()
).
isEqualTo
(
2
);
assertThat
(
events
.
get
(
0
).
getType
()
).
isEqualTo
(
"a"
);
assertThat
(
events
.
get
(
1
).
getType
()
).
isEqualTo
(
"b"
);
}
...
...
@@ -54,9 +53,9 @@ public class InMemoryAuditEventRepositoryTests {
repository
.
add
(
new
AuditEvent
(
"dave"
,
"b"
));
repository
.
add
(
new
AuditEvent
(
"dave"
,
"c"
));
List
<
AuditEvent
>
events
=
repository
.
find
(
"dave"
,
null
);
assertThat
(
events
.
size
()
,
equalTo
(
2
)
);
assertThat
(
events
.
get
(
0
).
getType
()
,
equalTo
(
"b"
)
);
assertThat
(
events
.
get
(
1
).
getType
()
,
equalTo
(
"c"
)
);
assertThat
(
events
.
size
()
).
isEqualTo
(
2
);
assertThat
(
events
.
get
(
0
).
getType
()
).
isEqualTo
(
"b"
);
assertThat
(
events
.
get
(
1
).
getType
()
).
isEqualTo
(
"c"
);
}
@Test
...
...
@@ -67,9 +66,9 @@ public class InMemoryAuditEventRepositoryTests {
repository
.
add
(
new
AuditEvent
(
"dave"
,
"c"
));
repository
.
add
(
new
AuditEvent
(
"phil"
,
"d"
));
List
<
AuditEvent
>
events
=
repository
.
find
(
"dave"
,
null
);
assertThat
(
events
.
size
()
,
equalTo
(
2
)
);
assertThat
(
events
.
get
(
0
).
getType
()
,
equalTo
(
"a"
)
);
assertThat
(
events
.
get
(
1
).
getType
()
,
equalTo
(
"c"
)
);
assertThat
(
events
.
size
()
).
isEqualTo
(
2
);
assertThat
(
events
.
get
(
0
).
getType
()
).
isEqualTo
(
"a"
);
assertThat
(
events
.
get
(
1
).
getType
()
).
isEqualTo
(
"c"
);
}
@Test
...
...
@@ -89,12 +88,12 @@ public class InMemoryAuditEventRepositoryTests {
repository
.
add
(
new
AuditEvent
(
calendar
.
getTime
(),
"phil"
,
"d"
,
data
));
calendar
.
add
(
Calendar
.
DAY_OF_YEAR
,
1
);
List
<
AuditEvent
>
events
=
repository
.
find
(
null
,
after
);
assertThat
(
events
.
size
()
,
equalTo
(
2
)
);
assertThat
(
events
.
get
(
0
).
getType
()
,
equalTo
(
"c"
)
);
assertThat
(
events
.
get
(
1
).
getType
()
,
equalTo
(
"d"
)
);
assertThat
(
events
.
size
()
).
isEqualTo
(
2
);
assertThat
(
events
.
get
(
0
).
getType
()
).
isEqualTo
(
"c"
);
assertThat
(
events
.
get
(
1
).
getType
()
).
isEqualTo
(
"d"
);
events
=
repository
.
find
(
"dave"
,
after
);
assertThat
(
events
.
size
()
,
equalTo
(
1
)
);
assertThat
(
events
.
get
(
0
).
getType
()
,
equalTo
(
"c"
)
);
assertThat
(
events
.
size
()
).
isEqualTo
(
1
);
assertThat
(
events
.
get
(
0
).
getType
()
).
isEqualTo
(
"c"
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/AuditAutoConfigurationTests.java
View file @
94677b35
...
...
@@ -31,9 +31,7 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.security.access.event.AbstractAuthorizationEvent
;
import
org.springframework.security.authentication.event.AbstractAuthenticationEvent
;
import
static
org
.
hamcrest
.
Matchers
.
instanceOf
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link AuditAutoConfiguration}.
...
...
@@ -48,33 +46,33 @@ public class AuditAutoConfigurationTests {
@Test
public
void
testTraceConfiguration
()
throws
Exception
{
registerAndRefresh
(
AuditAutoConfiguration
.
class
);
assert
NotNull
(
this
.
context
.
getBean
(
AuditEventRepository
.
class
)
);
assert
NotNull
(
this
.
context
.
getBean
(
AuthenticationAuditListener
.
class
)
);
assert
NotNull
(
this
.
context
.
getBean
(
AuthorizationAuditListener
.
class
)
);
assert
That
(
this
.
context
.
getBean
(
AuditEventRepository
.
class
)).
isNotNull
(
);
assert
That
(
this
.
context
.
getBean
(
AuthenticationAuditListener
.
class
)).
isNotNull
(
);
assert
That
(
this
.
context
.
getBean
(
AuthorizationAuditListener
.
class
)).
isNotNull
(
);
}
@Test
public
void
ownAutoRepository
()
throws
Exception
{
registerAndRefresh
(
CustomAuditEventRepositoryConfiguration
.
class
,
AuditAutoConfiguration
.
class
);
assertThat
(
this
.
context
.
getBean
(
AuditEventRepository
.
class
)
,
instanceOf
(
TestAuditEventRepository
.
class
)
);
assertThat
(
this
.
context
.
getBean
(
AuditEventRepository
.
class
)
)
.
isInstanceOf
(
TestAuditEventRepository
.
class
);
}
@Test
public
void
ownAuthenticationAuditListener
()
throws
Exception
{
registerAndRefresh
(
CustomAuthenticationAuditListenerConfiguration
.
class
,
AuditAutoConfiguration
.
class
);
assertThat
(
this
.
context
.
getBean
(
AbstractAuthenticationAuditListener
.
class
)
,
instanceOf
(
TestAuthenticationAuditListener
.
class
)
);
assertThat
(
this
.
context
.
getBean
(
AbstractAuthenticationAuditListener
.
class
)
)
.
isInstanceOf
(
TestAuthenticationAuditListener
.
class
);
}
@Test
public
void
ownAuthorizationAuditListener
()
throws
Exception
{
registerAndRefresh
(
CustomAuthorizationAuditListenerConfiguration
.
class
,
AuditAutoConfiguration
.
class
);
assertThat
(
this
.
context
.
getBean
(
AbstractAuthorizationAuditListener
.
class
)
,
instanceOf
(
TestAuthorizationAuditListener
.
class
)
);
assertThat
(
this
.
context
.
getBean
(
AbstractAuthorizationAuditListener
.
class
)
)
.
isInstanceOf
(
TestAuthorizationAuditListener
.
class
);
}
private
void
registerAndRefresh
(
Class
<?>...
annotatedClasses
)
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CacheStatisticsAutoConfigurationTests.java
View file @
94677b35
...
...
@@ -53,8 +53,8 @@ import org.springframework.core.io.ClassPathResource;
import
org.springframework.core.io.Resource
;
import
org.springframework.util.Assert
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
offset
;
/**
* Tests for {@link CacheStatisticsAutoConfiguration}.
...
...
@@ -160,8 +160,8 @@ public class CacheStatisticsAutoConfigurationTests {
private
void
assertCoreStatistics
(
CacheStatistics
metrics
,
Long
size
,
Double
hitRatio
,
Double
missRatio
)
{
assert
NotNull
(
"Cache metrics must not be null"
,
metrics
);
assert
Equals
(
"Wrong size for metrics "
+
metrics
,
size
,
metrics
.
getSize
()
);
assert
That
(
metrics
).
isNotNull
(
);
assert
That
(
metrics
.
getSize
()).
isEqualTo
(
size
);
checkRatio
(
"Wrong hit ratio for metrics "
+
metrics
,
hitRatio
,
metrics
.
getHitRatio
());
checkRatio
(
"Wrong miss ratio for metrics "
+
metrics
,
missRatio
,
...
...
@@ -170,10 +170,10 @@ public class CacheStatisticsAutoConfigurationTests {
private
void
checkRatio
(
String
message
,
Double
expected
,
Double
actual
)
{
if
(
expected
==
null
||
actual
==
null
)
{
assert
Equals
(
message
,
expected
,
actual
);
assert
That
(
actual
).
as
(
message
).
isEqualTo
(
expected
);
}
else
{
assert
Equals
(
message
,
expected
,
actual
,
0.01
D
);
assert
That
(
actual
).
as
(
message
).
isEqualTo
(
expected
,
offset
(
0.01
D
)
);
}
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java
View file @
94677b35
...
...
@@ -51,11 +51,7 @@ import org.springframework.security.core.AuthenticationException;
import
org.springframework.security.core.authority.SimpleGrantedAuthority
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link CrshAutoConfiguration}.
...
...
@@ -82,13 +78,12 @@ public class CrshAutoConfigurationTests {
env
.
setProperty
(
"shell.disabled_plugins"
,
"GroovyREPL, termIOHandler, org.crsh.auth.AuthenticationPlugin"
);
load
(
env
);
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
assert
NotNull
(
lifeCycle
);
assert
Null
(
lifeCycle
.
getContext
().
getPlugin
(
GroovyRepl
.
class
)
);
assert
Null
(
lifeCycle
.
getContext
().
getPlugin
(
ProcessorIOHandler
.
class
));
assertNull
(
lifeCycle
.
getContext
().
getPlugin
(
JaasAuthenticationPlugin
.
class
)
);
assert
That
(
lifeCycle
).
isNotNull
(
);
assertThat
(
lifeCycle
.
getContext
().
getPlugin
(
GroovyRepl
.
class
)).
isNull
();
assert
That
(
lifeCycle
.
getContext
().
getPlugin
(
ProcessorIOHandler
.
class
)).
isNull
(
);
assert
That
(
lifeCycle
.
getContext
().
getPlugin
(
JaasAuthenticationPlugin
.
class
))
.
isNull
(
);
}
@Test
...
...
@@ -96,13 +91,12 @@ public class CrshAutoConfigurationTests {
this
.
context
=
new
AnnotationConfigWebApplicationContext
();
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
refresh
();
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
Map
<
String
,
Object
>
attributes
=
lifeCycle
.
getContext
().
getAttributes
();
assertTrue
(
attributes
.
containsKey
(
"spring.version"
));
assertTrue
(
attributes
.
containsKey
(
"spring.beanfactory"
));
assertEquals
(
this
.
context
.
getBeanFactory
(),
attributes
.
get
(
"spring.beanfactory"
));
assertThat
(
attributes
.
containsKey
(
"spring.version"
)).
isTrue
();
assertThat
(
attributes
.
containsKey
(
"spring.beanfactory"
)).
isTrue
();
assertThat
(
attributes
.
get
(
"spring.beanfactory"
))
.
isEqualTo
(
this
.
context
.
getBeanFactory
());
}
@Test
...
...
@@ -113,12 +107,11 @@ public class CrshAutoConfigurationTests {
load
(
env
);
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
assertEquals
(
"3333"
,
lifeCycle
.
getConfig
().
getProperty
(
"crash.ssh.port"
));
assertEquals
(
"600000"
,
lifeCycle
.
getConfig
().
getProperty
(
"crash.ssh.auth_timeout"
));
assertEquals
(
"600000"
,
lifeCycle
.
getConfig
().
getProperty
(
"crash.ssh.idle_timeout"
));
assertThat
(
lifeCycle
.
getConfig
().
getProperty
(
"crash.ssh.port"
)).
isEqualTo
(
"3333"
);
assertThat
(
lifeCycle
.
getConfig
().
getProperty
(
"crash.ssh.auth_timeout"
))
.
isEqualTo
(
"600000"
);
assertThat
(
lifeCycle
.
getConfig
().
getProperty
(
"crash.ssh.idle_timeout"
))
.
isEqualTo
(
"600000"
);
}
@Test
...
...
@@ -127,11 +120,9 @@ public class CrshAutoConfigurationTests {
env
.
setProperty
(
"shell.ssh.enabled"
,
"true"
);
env
.
setProperty
(
"shell.ssh.key_path"
,
"~/.ssh/id.pem"
);
load
(
env
);
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
assertEquals
(
"~/.ssh/id.pem"
,
lifeCycle
.
getConfig
().
getProperty
(
"crash.ssh.keypath"
));
assertThat
(
lifeCycle
.
getConfig
().
getProperty
(
"crash.ssh.keypath"
))
.
isEqualTo
(
"~/.ssh/id.pem"
);
}
@Test
...
...
@@ -141,13 +132,11 @@ public class CrshAutoConfigurationTests {
env
.
setProperty
(
"shell.ssh.auth-timeout"
,
"300000"
);
env
.
setProperty
(
"shell.ssh.idle-timeout"
,
"400000"
);
load
(
env
);
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
assertEquals
(
"300000"
,
lifeCycle
.
getConfig
().
getProperty
(
"crash.ssh.auth_timeout"
));
assertEquals
(
"400000"
,
lifeCycle
.
getConfig
().
getProperty
(
"crash.ssh.idle_timeout"
));
assertThat
(
lifeCycle
.
getConfig
().
getProperty
(
"crash.ssh.auth_timeout"
))
.
isEqualTo
(
"300000"
);
assertThat
(
lifeCycle
.
getConfig
().
getProperty
(
"crash.ssh.idle_timeout"
))
.
isEqualTo
(
"400000"
);
}
private
void
load
(
MockEnvironment
env
)
{
...
...
@@ -162,9 +151,7 @@ public class CrshAutoConfigurationTests {
this
.
context
=
new
AnnotationConfigWebApplicationContext
();
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
refresh
();
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
int
count
=
0
;
Iterator
<
Resource
>
resources
=
lifeCycle
.
getContext
()
.
loadResources
(
"login"
,
ResourceKind
.
LIFECYCLE
).
iterator
();
...
...
@@ -172,8 +159,7 @@ public class CrshAutoConfigurationTests {
count
++;
resources
.
next
();
}
assertEquals
(
1
,
count
);
assertThat
(
count
).
isEqualTo
(
1
);
count
=
0
;
resources
=
lifeCycle
.
getContext
()
.
loadResources
(
"sleep.groovy"
,
ResourceKind
.
COMMAND
).
iterator
();
...
...
@@ -181,7 +167,7 @@ public class CrshAutoConfigurationTests {
count
++;
resources
.
next
();
}
assert
Equals
(
1
,
count
);
assert
That
(
count
).
isEqualTo
(
1
);
}
@Test
...
...
@@ -189,9 +175,7 @@ public class CrshAutoConfigurationTests {
this
.
context
=
new
AnnotationConfigWebApplicationContext
();
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
refresh
();
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
int
count
=
0
;
Iterator
<
Resource
>
resources
=
lifeCycle
.
getContext
()
.
loadResources
(
"jdbc.groovy"
,
ResourceKind
.
COMMAND
).
iterator
();
...
...
@@ -199,7 +183,7 @@ public class CrshAutoConfigurationTests {
count
++;
resources
.
next
();
}
assert
Equals
(
0
,
count
);
assert
That
(
count
).
isEqualTo
(
0
);
}
@Test
...
...
@@ -209,10 +193,8 @@ public class CrshAutoConfigurationTests {
this
.
context
.
register
(
SecurityConfiguration
.
class
);
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
refresh
();
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
PluginContext
pluginContext
=
lifeCycle
.
getContext
();
int
count
=
0
;
Iterator
<
AuthenticationPlugin
>
plugins
=
pluginContext
.
getPlugins
(
AuthenticationPlugin
.
class
).
iterator
();
...
...
@@ -220,7 +202,7 @@ public class CrshAutoConfigurationTests {
count
++;
plugins
.
next
();
}
assert
Equals
(
3
,
count
);
assert
That
(
count
).
isEqualTo
(
3
);
}
@Test
...
...
@@ -231,9 +213,8 @@ public class CrshAutoConfigurationTests {
this
.
context
.
setServletContext
(
new
MockServletContext
());
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
refresh
();
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
assert
Equals
(
"simple"
,
lifeCycle
.
getConfig
().
get
(
"crash.auth"
)
);
assert
That
(
lifeCycle
.
getConfig
().
get
(
"crash.auth"
)).
isEqualTo
(
"simple"
);
}
@Test
...
...
@@ -247,11 +228,10 @@ public class CrshAutoConfigurationTests {
this
.
context
.
register
(
SecurityConfiguration
.
class
);
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
refresh
();
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
assert
Equals
(
"jaas"
,
lifeCycle
.
getConfig
().
get
(
"crash.auth"
)
);
assert
Equals
(
"my-test-domain"
,
lifeCycle
.
getConfig
().
get
(
"crash.auth.jaas.domain"
)
);
assert
That
(
lifeCycle
.
getConfig
().
get
(
"crash.auth"
)).
isEqualTo
(
"jaas"
);
assert
That
(
lifeCycle
.
getConfig
().
get
(
"crash.auth.jaas.domain"
))
.
isEqualTo
(
"my-test-domain"
);
}
@Test
...
...
@@ -265,10 +245,10 @@ public class CrshAutoConfigurationTests {
this
.
context
.
register
(
SecurityConfiguration
.
class
);
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
refresh
();
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
assertEquals
(
"key"
,
lifeCycle
.
getConfig
().
get
(
"crash.auth"
));
assertEquals
(
"~/test.pem"
,
lifeCycle
.
getConfig
().
get
(
"crash.auth.key.path"
));
assertThat
(
lifeCycle
.
getConfig
().
get
(
"crash.auth"
)).
isEqualTo
(
"key"
);
assertThat
(
lifeCycle
.
getConfig
().
get
(
"crash.auth.key.path"
))
.
isEqualTo
(
"~/test.pem"
);
}
@Test
...
...
@@ -283,13 +263,11 @@ public class CrshAutoConfigurationTests {
this
.
context
.
register
(
SecurityConfiguration
.
class
);
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
refresh
();
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
assertEquals
(
"simple"
,
lifeCycle
.
getConfig
().
get
(
"crash.auth"
));
assertThat
(
lifeCycle
.
getConfig
().
get
(
"crash.auth"
)).
isEqualTo
(
"simple"
);
AuthenticationPlugin
<
String
>
authenticationPlugin
=
null
;
String
authentication
=
lifeCycle
.
getConfig
().
getProperty
(
"crash.auth"
);
assert
NotNull
(
authentication
);
assert
That
(
authentication
).
isNotNull
(
);
for
(
AuthenticationPlugin
plugin
:
lifeCycle
.
getContext
()
.
getPlugins
(
AuthenticationPlugin
.
class
))
{
if
(
authentication
.
equals
(
plugin
.
getName
()))
{
...
...
@@ -297,10 +275,10 @@ public class CrshAutoConfigurationTests {
break
;
}
}
assert
NotNull
(
authenticationPlugin
);
assertT
rue
(
authenticationPlugin
.
authenticate
(
"user"
,
"password"
)
);
assert
False
(
authenticationPlugin
.
authenticate
(
UUID
.
randomUUID
().
toString
(),
"password"
));
assert
That
(
authenticationPlugin
).
isNotNull
(
);
assertT
hat
(
authenticationPlugin
.
authenticate
(
"user"
,
"password"
)).
isTrue
(
);
assert
That
(
authenticationPlugin
.
authenticate
(
UUID
.
randomUUID
().
toString
(),
"password"
))
.
isFalse
()
;
}
@Test
...
...
@@ -313,12 +291,10 @@ public class CrshAutoConfigurationTests {
this
.
context
.
register
(
SecurityConfiguration
.
class
);
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
refresh
();
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
AuthenticationPlugin
<
String
>
authenticationPlugin
=
null
;
String
authentication
=
lifeCycle
.
getConfig
().
getProperty
(
"crash.auth"
);
assert
NotNull
(
authentication
);
assert
That
(
authentication
).
isNotNull
(
);
for
(
AuthenticationPlugin
plugin
:
lifeCycle
.
getContext
()
.
getPlugins
(
AuthenticationPlugin
.
class
))
{
if
(
authentication
.
equals
(
plugin
.
getName
()))
{
...
...
@@ -326,11 +302,10 @@ public class CrshAutoConfigurationTests {
break
;
}
}
assertTrue
(
authenticationPlugin
.
authenticate
(
SecurityConfiguration
.
USERNAME
,
SecurityConfiguration
.
PASSWORD
));
assertFalse
(
authenticationPlugin
.
authenticate
(
UUID
.
randomUUID
().
toString
(),
SecurityConfiguration
.
PASSWORD
));
assertThat
(
authenticationPlugin
.
authenticate
(
SecurityConfiguration
.
USERNAME
,
SecurityConfiguration
.
PASSWORD
)).
isTrue
();
assertThat
(
authenticationPlugin
.
authenticate
(
UUID
.
randomUUID
().
toString
(),
SecurityConfiguration
.
PASSWORD
)).
isFalse
();
}
@Test
...
...
@@ -343,12 +318,10 @@ public class CrshAutoConfigurationTests {
this
.
context
.
register
(
SecurityConfiguration
.
class
);
this
.
context
.
register
(
CrshAutoConfiguration
.
class
);
this
.
context
.
refresh
();
PluginLifeCycle
lifeCycle
=
this
.
context
.
getBean
(
PluginLifeCycle
.
class
);
AuthenticationPlugin
<
String
>
authenticationPlugin
=
null
;
String
authentication
=
lifeCycle
.
getConfig
().
getProperty
(
"crash.auth"
);
assert
NotNull
(
authentication
);
assert
That
(
authentication
).
isNotNull
(
);
for
(
AuthenticationPlugin
plugin
:
lifeCycle
.
getContext
()
.
getPlugins
(
AuthenticationPlugin
.
class
))
{
if
(
authentication
.
equals
(
plugin
.
getName
()))
{
...
...
@@ -356,11 +329,10 @@ public class CrshAutoConfigurationTests {
break
;
}
}
assertTrue
(
authenticationPlugin
.
authenticate
(
SecurityConfiguration
.
USERNAME
,
SecurityConfiguration
.
PASSWORD
));
assertFalse
(
authenticationPlugin
.
authenticate
(
UUID
.
randomUUID
().
toString
(),
SecurityConfiguration
.
PASSWORD
));
assertThat
(
authenticationPlugin
.
authenticate
(
SecurityConfiguration
.
USERNAME
,
SecurityConfiguration
.
PASSWORD
)).
isTrue
();
assertThat
(
authenticationPlugin
.
authenticate
(
UUID
.
randomUUID
().
toString
(),
SecurityConfiguration
.
PASSWORD
)).
isFalse
();
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java
View file @
94677b35
...
...
@@ -47,10 +47,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link EndpointAutoConfiguration}.
...
...
@@ -76,15 +73,15 @@ public class EndpointAutoConfigurationTests {
@Test
public
void
endpoints
()
throws
Exception
{
load
(
EndpointAutoConfiguration
.
class
);
assert
NotNull
(
this
.
context
.
getBean
(
BeansEndpoint
.
class
)
);
assert
NotNull
(
this
.
context
.
getBean
(
DumpEndpoint
.
class
)
);
assert
NotNull
(
this
.
context
.
getBean
(
EnvironmentEndpoint
.
class
)
);
assert
NotNull
(
this
.
context
.
getBean
(
HealthEndpoint
.
class
)
);
assert
NotNull
(
this
.
context
.
getBean
(
InfoEndpoint
.
class
)
);
assert
NotNull
(
this
.
context
.
getBean
(
MetricsEndpoint
.
class
)
);
assert
NotNull
(
this
.
context
.
getBean
(
ShutdownEndpoint
.
class
)
);
assert
NotNull
(
this
.
context
.
getBean
(
TraceEndpoint
.
class
)
);
assert
NotNull
(
this
.
context
.
getBean
(
RequestMappingEndpoint
.
class
)
);
assert
That
(
this
.
context
.
getBean
(
BeansEndpoint
.
class
)).
isNotNull
(
);
assert
That
(
this
.
context
.
getBean
(
DumpEndpoint
.
class
)).
isNotNull
(
);
assert
That
(
this
.
context
.
getBean
(
EnvironmentEndpoint
.
class
)).
isNotNull
(
);
assert
That
(
this
.
context
.
getBean
(
HealthEndpoint
.
class
)).
isNotNull
(
);
assert
That
(
this
.
context
.
getBean
(
InfoEndpoint
.
class
)).
isNotNull
(
);
assert
That
(
this
.
context
.
getBean
(
MetricsEndpoint
.
class
)).
isNotNull
(
);
assert
That
(
this
.
context
.
getBean
(
ShutdownEndpoint
.
class
)).
isNotNull
(
);
assert
That
(
this
.
context
.
getBean
(
TraceEndpoint
.
class
)).
isNotNull
(
);
assert
That
(
this
.
context
.
getBean
(
RequestMappingEndpoint
.
class
)).
isNotNull
(
);
}
@Test
...
...
@@ -92,19 +89,19 @@ public class EndpointAutoConfigurationTests {
load
(
EmbeddedDataSourceConfiguration
.
class
,
EndpointAutoConfiguration
.
class
,
HealthIndicatorAutoConfiguration
.
class
);
HealthEndpoint
bean
=
this
.
context
.
getBean
(
HealthEndpoint
.
class
);
assert
NotNull
(
bean
);
assert
That
(
bean
).
isNotNull
(
);
Health
result
=
bean
.
invoke
();
assert
NotNull
(
result
);
assertT
rue
(
"Wrong result: "
+
result
,
result
.
getDetails
().
containsKey
(
"db"
)
);
assert
That
(
result
).
isNotNull
(
);
assertT
hat
(
result
.
getDetails
().
containsKey
(
"db"
)).
isTrue
(
);
}
@Test
public
void
healthEndpointWithDefaultHealthIndicator
()
{
load
(
EndpointAutoConfiguration
.
class
,
HealthIndicatorAutoConfiguration
.
class
);
HealthEndpoint
bean
=
this
.
context
.
getBean
(
HealthEndpoint
.
class
);
assert
NotNull
(
bean
);
assert
That
(
bean
).
isNotNull
(
);
Health
result
=
bean
.
invoke
();
assert
NotNull
(
result
);
assert
That
(
result
).
isNotNull
(
);
}
@Test
...
...
@@ -112,8 +109,8 @@ public class EndpointAutoConfigurationTests {
load
(
PublicMetricsAutoConfiguration
.
class
,
EndpointAutoConfiguration
.
class
);
MetricsEndpoint
endpoint
=
this
.
context
.
getBean
(
MetricsEndpoint
.
class
);
Map
<
String
,
Object
>
metrics
=
endpoint
.
invoke
();
assertT
rue
(
metrics
.
containsKey
(
"mem"
)
);
assertT
rue
(
metrics
.
containsKey
(
"heap.used"
)
);
assertT
hat
(
metrics
.
containsKey
(
"mem"
)).
isTrue
(
);
assertT
hat
(
metrics
.
containsKey
(
"heap.used"
)).
isTrue
(
);
}
@Test
...
...
@@ -124,18 +121,19 @@ public class EndpointAutoConfigurationTests {
Map
<
String
,
Object
>
metrics
=
endpoint
.
invoke
();
// Custom metrics
assertT
rue
(
metrics
.
containsKey
(
"foo"
)
);
assertT
hat
(
metrics
.
containsKey
(
"foo"
)).
isTrue
(
);
// System metrics still available
assertT
rue
(
metrics
.
containsKey
(
"mem"
)
);
assertT
rue
(
metrics
.
containsKey
(
"heap.used"
)
);
assertT
hat
(
metrics
.
containsKey
(
"mem"
)).
isTrue
(
);
assertT
hat
(
metrics
.
containsKey
(
"heap.used"
)).
isTrue
(
);
}
@Test
public
void
autoConfigurationAuditEndpoints
()
{
load
(
EndpointAutoConfiguration
.
class
,
ConditionEvaluationReport
.
class
);
assertNotNull
(
this
.
context
.
getBean
(
AutoConfigurationReportEndpoint
.
class
));
assertThat
(
this
.
context
.
getBean
(
AutoConfigurationReportEndpoint
.
class
))
.
isNotNull
();
}
@Test
...
...
@@ -145,9 +143,9 @@ public class EndpointAutoConfigurationTests {
this
.
context
.
register
(
EndpointAutoConfiguration
.
class
);
this
.
context
.
refresh
();
InfoEndpoint
endpoint
=
this
.
context
.
getBean
(
InfoEndpoint
.
class
);
assert
NotNull
(
endpoint
);
assert
NotNull
(
endpoint
.
invoke
().
get
(
"git"
)
);
assert
Equals
(
"bar"
,
endpoint
.
invoke
().
get
(
"foo"
)
);
assert
That
(
endpoint
).
isNotNull
(
);
assert
That
(
endpoint
.
invoke
().
get
(
"git"
)).
isNotNull
(
);
assert
That
(
endpoint
.
invoke
().
get
(
"foo"
)).
isEqualTo
(
"bar"
);
}
@Test
...
...
@@ -158,8 +156,8 @@ public class EndpointAutoConfigurationTests {
this
.
context
.
register
(
EndpointAutoConfiguration
.
class
);
this
.
context
.
refresh
();
InfoEndpoint
endpoint
=
this
.
context
.
getBean
(
InfoEndpoint
.
class
);
assert
NotNull
(
endpoint
);
assert
Null
(
endpoint
.
invoke
().
get
(
"git"
)
);
assert
That
(
endpoint
).
isNotNull
(
);
assert
That
(
endpoint
.
invoke
().
get
(
"git"
)).
isNull
(
);
}
@Test
...
...
@@ -169,8 +167,8 @@ public class EndpointAutoConfigurationTests {
FlywayAutoConfiguration
.
class
,
EndpointAutoConfiguration
.
class
);
this
.
context
.
refresh
();
FlywayEndpoint
endpoint
=
this
.
context
.
getBean
(
FlywayEndpoint
.
class
);
assert
NotNull
(
endpoint
);
assert
Equals
(
1
,
endpoint
.
invoke
().
size
()
);
assert
That
(
endpoint
).
isNotNull
(
);
assert
That
(
endpoint
.
invoke
()).
hasSize
(
1
);
}
@Test
...
...
@@ -180,8 +178,8 @@ public class EndpointAutoConfigurationTests {
LiquibaseAutoConfiguration
.
class
,
EndpointAutoConfiguration
.
class
);
this
.
context
.
refresh
();
LiquibaseEndpoint
endpoint
=
this
.
context
.
getBean
(
LiquibaseEndpoint
.
class
);
assert
NotNull
(
endpoint
);
assert
Equals
(
1
,
endpoint
.
invoke
().
size
()
);
assert
That
(
endpoint
).
isNotNull
(
);
assert
That
(
endpoint
.
invoke
()).
hasSize
(
1
);
}
private
void
load
(
Class
<?>...
config
)
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMBeanExportAutoConfigurationTests.java
View file @
94677b35
...
...
@@ -43,10 +43,7 @@ import org.springframework.mock.env.MockEnvironment;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.ObjectUtils
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link EndpointMBeanExportAutoConfiguration}.
...
...
@@ -71,11 +68,10 @@ public class EndpointMBeanExportAutoConfigurationTests {
EndpointMBeanExportAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
assert
NotNull
(
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
)
);
assert
That
(
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
)).
isNotNull
(
);
MBeanExporter
mbeanExporter
=
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
);
assertFalse
(
mbeanExporter
.
getServer
()
.
queryNames
(
getObjectName
(
"*"
,
"*,*"
,
this
.
context
),
null
).
isEmpty
());
assertThat
(
mbeanExporter
.
getServer
()
.
queryNames
(
getObjectName
(
"*"
,
"*,*"
,
this
.
context
),
null
)).
isNotEmpty
();
}
@Test
...
...
@@ -86,12 +82,10 @@ public class EndpointMBeanExportAutoConfigurationTests {
ManagedEndpoint
.
class
,
EndpointMBeanExportAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
assertNotNull
(
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
));
assertThat
(
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
)).
isNotNull
();
MBeanExporter
mbeanExporter
=
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
);
assertTrue
(
mbeanExporter
.
getServer
()
.
queryNames
(
getObjectName
(
"*"
,
"*,*"
,
this
.
context
),
null
).
isEmpty
());
assertThat
(
mbeanExporter
.
getServer
()
.
queryNames
(
getObjectName
(
"*"
,
"*,*"
,
this
.
context
),
null
)).
isEmpty
();
}
@Test
...
...
@@ -102,12 +96,10 @@ public class EndpointMBeanExportAutoConfigurationTests {
NestedInManagedEndpoint
.
class
,
EndpointMBeanExportAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
assertNotNull
(
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
));
assertThat
(
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
)).
isNotNull
();
MBeanExporter
mbeanExporter
=
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
);
assertTrue
(
mbeanExporter
.
getServer
()
.
queryNames
(
getObjectName
(
"*"
,
"*,*"
,
this
.
context
),
null
).
isEmpty
());
assertThat
(
mbeanExporter
.
getServer
()
.
queryNames
(
getObjectName
(
"*"
,
"*,*"
,
this
.
context
),
null
)).
isEmpty
();
}
@Test
(
expected
=
NoSuchBeanDefinitionException
.
class
)
...
...
@@ -120,7 +112,6 @@ public class EndpointMBeanExportAutoConfigurationTests {
EndpointMBeanExportAutoConfiguration
.
class
);
this
.
context
.
refresh
();
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
);
fail
();
}
@Test
...
...
@@ -138,11 +129,9 @@ public class EndpointMBeanExportAutoConfigurationTests {
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
);
MBeanExporter
mbeanExporter
=
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
);
assertNotNull
(
mbeanExporter
.
getServer
()
.
getMBeanInfo
(
ObjectNameManager
.
getInstance
(
getObjectName
(
"test-domain"
,
"healthEndpoint"
,
this
.
context
)
.
toString
()
+
",key1=value1,key2=value2"
)));
assertThat
(
mbeanExporter
.
getServer
().
getMBeanInfo
(
ObjectNameManager
.
getInstance
(
getObjectName
(
"test-domain"
,
"healthEndpoint"
,
this
.
context
).
toString
()
+
",key1=value1,key2=value2"
))).
isNotNull
();
}
@Test
...
...
@@ -151,15 +140,12 @@ public class EndpointMBeanExportAutoConfigurationTests {
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
.
register
(
JmxAutoConfiguration
.
class
,
EndpointAutoConfiguration
.
class
,
EndpointMBeanExportAutoConfiguration
.
class
);
AnnotationConfigApplicationContext
parent
=
new
AnnotationConfigApplicationContext
();
parent
.
register
(
JmxAutoConfiguration
.
class
,
EndpointAutoConfiguration
.
class
,
EndpointMBeanExportAutoConfiguration
.
class
);
this
.
context
.
setParent
(
parent
);
parent
.
refresh
();
this
.
context
.
refresh
();
parent
.
close
();
}
...
...
@@ -178,9 +164,7 @@ public class EndpointMBeanExportAutoConfigurationTests {
return
ObjectNameManager
.
getInstance
(
String
.
format
(
name
,
domain
,
beanKey
,
ObjectUtils
.
getIdentityHexString
(
applicationContext
)));
}
else
{
return
ObjectNameManager
.
getInstance
(
String
.
format
(
name
,
domain
,
beanKey
));
}
return
ObjectNameManager
.
getInstance
(
String
.
format
(
name
,
domain
,
beanKey
));
}
@Configuration
...
...
@@ -223,6 +207,7 @@ public class EndpointMBeanExportAutoConfigurationTests {
public
Boolean
invoke
()
{
return
true
;
}
}
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java
View file @
94677b35
...
...
@@ -64,8 +64,7 @@ import org.springframework.web.bind.annotation.RestController;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for MVC {@link Endpoint}s.
...
...
@@ -89,18 +88,16 @@ public class EndpointMvcIntegrationTests {
public
void
envEndpointHidden
()
throws
InterruptedException
{
String
body
=
new
TestRestTemplate
().
getForObject
(
"http://localhost:"
+
this
.
port
+
"/env/user.dir"
,
String
.
class
);
assertNotNull
(
body
);
assertTrue
(
"Wrong body: \n"
+
body
,
body
.
contains
(
"spring-boot-actuator"
));
assertTrue
(
this
.
interceptor
.
invoked
());
assertThat
(
body
).
isNotNull
().
contains
(
"spring-boot-actuator"
);
assertThat
(
this
.
interceptor
.
invoked
()).
isTrue
();
}
@Test
public
void
healthEndpointNotHidden
()
throws
InterruptedException
{
String
body
=
new
TestRestTemplate
()
.
getForObject
(
"http://localhost:"
+
this
.
port
+
"/health"
,
String
.
class
);
assertNotNull
(
body
);
assertTrue
(
"Wrong body: \n"
+
body
,
body
.
contains
(
"status"
));
assertTrue
(
this
.
interceptor
.
invoked
());
assertThat
(
body
).
isNotNull
().
contains
(
"status"
);
assertThat
(
this
.
interceptor
.
invoked
()).
isTrue
();
}
@Target
(
ElementType
.
TYPE
)
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java
View file @
94677b35
...
...
@@ -60,6 +60,7 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerExcepti
import
org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent
;
import
org.springframework.boot.context.web.ServerPortInfoApplicationContextInitializer
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.boot.test.assertj.Matched
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.annotation.Bean
;
...
...
@@ -79,16 +80,9 @@ import org.springframework.web.servlet.ModelAndView;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
instanceOf
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
hamcrest
.
Matchers
.
startsWith
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -136,8 +130,10 @@ public class EndpointWebMvcAutoConfigurationTests {
assertContent
(
"/endpoint"
,
ports
.
get
().
server
,
"endpointoutput"
);
assertContent
(
"/controller"
,
ports
.
get
().
management
,
null
);
assertContent
(
"/endpoint"
,
ports
.
get
().
management
,
null
);
assertTrue
(
hasHeader
(
"/endpoint"
,
ports
.
get
().
server
,
"X-Application-Context"
));
assertTrue
(
this
.
applicationContext
.
containsBean
(
"applicationContextIdFilter"
));
assertThat
(
hasHeader
(
"/endpoint"
,
ports
.
get
().
server
,
"X-Application-Context"
))
.
isTrue
();
assertThat
(
this
.
applicationContext
.
containsBean
(
"applicationContextIdFilter"
))
.
isTrue
();
this
.
applicationContext
.
close
();
assertAllClosed
();
}
...
...
@@ -150,8 +146,10 @@ public class EndpointWebMvcAutoConfigurationTests {
BaseConfiguration
.
class
,
ServerPortConfig
.
class
,
EndpointWebMvcAutoConfiguration
.
class
);
this
.
applicationContext
.
refresh
();
assertFalse
(
hasHeader
(
"/endpoint"
,
ports
.
get
().
server
,
"X-Application-Context"
));
assertFalse
(
this
.
applicationContext
.
containsBean
(
"applicationContextIdFilter"
));
assertThat
(
hasHeader
(
"/endpoint"
,
ports
.
get
().
server
,
"X-Application-Context"
))
.
isFalse
();
assertThat
(
this
.
applicationContext
.
containsBean
(
"applicationContextIdFilter"
))
.
isFalse
();
this
.
applicationContext
.
close
();
assertAllClosed
();
}
...
...
@@ -171,7 +169,7 @@ public class EndpointWebMvcAutoConfigurationTests {
.
getBean
(
ManagementContextResolver
.
class
).
getApplicationContext
();
List
<?>
interceptors
=
(
List
<?>)
ReflectionTestUtils
.
getField
(
managementContext
.
getBean
(
EndpointHandlerMapping
.
class
),
"interceptors"
);
assert
Equals
(
1
,
interceptors
.
size
()
);
assert
That
(
interceptors
).
hasSize
(
1
);
this
.
applicationContext
.
close
();
assertAllClosed
();
}
...
...
@@ -244,7 +242,7 @@ public class EndpointWebMvcAutoConfigurationTests {
this
.
applicationContext
.
addApplicationListener
(
grabManagementPort
);
this
.
applicationContext
.
refresh
();
int
managementPort
=
grabManagementPort
.
getServletContainer
().
getPort
();
assertThat
(
managementPort
,
not
(
equalTo
(
ports
.
get
().
server
))
);
assertThat
(
managementPort
).
isNotEqualTo
(
ports
.
get
().
server
);
assertContent
(
"/controller"
,
ports
.
get
().
server
,
"controlleroutput"
);
assertContent
(
"/endpoint"
,
ports
.
get
().
server
,
null
);
assertContent
(
"/controller"
,
managementPort
,
null
);
...
...
@@ -337,8 +335,9 @@ public class EndpointWebMvcAutoConfigurationTests {
EndpointWebMvcAutoConfiguration
.
class
);
this
.
applicationContext
.
refresh
();
assertContent
(
"/controller"
,
ports
.
get
().
server
,
"controlleroutput"
);
assertEquals
(
"foo"
,
this
.
applicationContext
.
getBean
(
ServerProperties
.
class
).
getDisplayName
());
ServerProperties
serverProperties
=
this
.
applicationContext
.
getBean
(
ServerProperties
.
class
);
assertThat
(
serverProperties
.
getDisplayName
()).
isEqualTo
(
"foo"
);
this
.
applicationContext
.
close
();
assertAllClosed
();
}
...
...
@@ -354,9 +353,9 @@ public class EndpointWebMvcAutoConfigurationTests {
.
getProperty
(
"local.server.port"
,
Integer
.
class
);
Integer
localManagementPort
=
this
.
applicationContext
.
getEnvironment
()
.
getProperty
(
"local.management.port"
,
Integer
.
class
);
assertThat
(
localServerPort
,
notNullValue
()
);
assertThat
(
localManagementPort
,
notNullValue
()
);
assertThat
(
localServerPort
,
equalTo
(
localManagementPort
)
);
assertThat
(
localServerPort
).
isNotNull
(
);
assertThat
(
localManagementPort
).
isNotNull
(
);
assertThat
(
localServerPort
).
isEqualTo
(
localManagementPort
);
this
.
applicationContext
.
close
();
assertAllClosed
();
}
...
...
@@ -373,11 +372,11 @@ public class EndpointWebMvcAutoConfigurationTests {
.
getProperty
(
"local.server.port"
,
Integer
.
class
);
Integer
localManagementPort
=
this
.
applicationContext
.
getEnvironment
()
.
getProperty
(
"local.management.port"
,
Integer
.
class
);
assertThat
(
localServerPort
,
notNullValue
()
);
assertThat
(
localManagementPort
,
notNullValue
()
);
assertThat
(
localServerPort
,
not
(
equalTo
(
localManagementPort
))
);
assertThat
(
this
.
applicationContext
.
getBean
(
ServerPortConfig
.
class
).
getCount
()
,
equalTo
(
2
)
);
assertThat
(
localServerPort
).
isNotNull
(
);
assertThat
(
localManagementPort
).
isNotNull
(
);
assertThat
(
localServerPort
).
isNotEqualTo
(
localManagementPort
);
assertThat
(
this
.
applicationContext
.
getBean
(
ServerPortConfig
.
class
).
getCount
()
)
.
isEqualTo
(
2
);
this
.
applicationContext
.
close
();
assertAllClosed
();
}
...
...
@@ -389,7 +388,7 @@ public class EndpointWebMvcAutoConfigurationTests {
this
.
applicationContext
.
refresh
();
RequestMappingInfoHandlerMapping
mapping
=
this
.
applicationContext
.
getBean
(
RequestMappingInfoHandlerMapping
.
class
);
assertThat
(
mapping
,
not
(
instanceOf
(
EndpointHandlerMapping
.
class
)
));
assertThat
(
mapping
).
isNotEqualTo
(
instanceOf
(
EndpointHandlerMapping
.
class
));
}
@Test
...
...
@@ -398,8 +397,7 @@ public class EndpointWebMvcAutoConfigurationTests {
ServerPortConfig
.
class
,
EndpointWebMvcAutoConfiguration
.
class
);
this
.
applicationContext
.
refresh
();
// /health, /metrics, /env, /actuator (/shutdown is disabled by default)
assertThat
(
this
.
applicationContext
.
getBeansOfType
(
MvcEndpoint
.
class
).
size
(),
is
(
equalTo
(
4
)));
assertThat
(
this
.
applicationContext
.
getBeansOfType
(
MvcEndpoint
.
class
)).
hasSize
(
4
);
}
@Test
...
...
@@ -409,8 +407,7 @@ public class EndpointWebMvcAutoConfigurationTests {
EnvironmentTestUtils
.
addEnvironment
(
this
.
applicationContext
,
"ENDPOINTS_ENABLED:false"
);
this
.
applicationContext
.
refresh
();
assertThat
(
this
.
applicationContext
.
getBeansOfType
(
MvcEndpoint
.
class
).
size
(),
is
(
equalTo
(
0
)));
assertThat
(
this
.
applicationContext
.
getBeansOfType
(
MvcEndpoint
.
class
)).
isEmpty
();
}
@Test
...
...
@@ -450,9 +447,8 @@ public class EndpointWebMvcAutoConfigurationTests {
EnvironmentTestUtils
.
addEnvironment
(
this
.
applicationContext
,
"endpoints.shutdown.enabled:true"
);
this
.
applicationContext
.
refresh
();
assertThat
(
this
.
applicationContext
.
getBeansOfType
(
ShutdownMvcEndpoint
.
class
).
size
(),
is
(
equalTo
(
1
)));
assertThat
(
this
.
applicationContext
.
getBeansOfType
(
ShutdownMvcEndpoint
.
class
))
.
hasSize
(
1
);
}
private
void
endpointDisabled
(
String
name
,
Class
<?
extends
MvcEndpoint
>
type
)
{
...
...
@@ -461,7 +457,7 @@ public class EndpointWebMvcAutoConfigurationTests {
EnvironmentTestUtils
.
addEnvironment
(
this
.
applicationContext
,
String
.
format
(
"endpoints.%s.enabled:false"
,
name
));
this
.
applicationContext
.
refresh
();
assertThat
(
this
.
applicationContext
.
getBeansOfType
(
type
)
.
size
(),
is
(
equalTo
(
0
))
);
assertThat
(
this
.
applicationContext
.
getBeansOfType
(
type
)
).
isEmpty
(
);
}
private
void
endpointEnabledOverride
(
String
name
,
Class
<?
extends
MvcEndpoint
>
type
)
...
...
@@ -472,7 +468,7 @@ public class EndpointWebMvcAutoConfigurationTests {
"endpoints.enabled:false"
,
String
.
format
(
"endpoints_%s_enabled:true"
,
name
));
this
.
applicationContext
.
refresh
();
assertThat
(
this
.
applicationContext
.
getBeansOfType
(
type
)
.
size
(),
is
(
equalTo
(
1
))
);
assertThat
(
this
.
applicationContext
.
getBeansOfType
(
type
)
).
hasSize
(
1
);
}
private
void
assertAllClosed
()
throws
Exception
{
...
...
@@ -482,7 +478,6 @@ public class EndpointWebMvcAutoConfigurationTests {
assertContent
(
"/endpoint"
,
ports
.
get
().
management
,
null
);
}
@SuppressWarnings
(
"unchecked"
)
public
void
assertContent
(
String
url
,
int
port
,
Object
expected
)
throws
Exception
{
SimpleClientHttpRequestFactory
clientHttpRequestFactory
=
new
SimpleClientHttpRequestFactory
();
ClientHttpRequest
request
=
clientHttpRequestFactory
...
...
@@ -493,10 +488,10 @@ public class EndpointWebMvcAutoConfigurationTests {
String
actual
=
StreamUtils
.
copyToString
(
response
.
getBody
(),
Charset
.
forName
(
"UTF-8"
));
if
(
expected
instanceof
Matcher
)
{
assertThat
(
actual
,
is
((
Matcher
<
String
>)
expected
));
assertThat
(
actual
).
is
(
Matched
.
by
((
Matcher
<?
>)
expected
));
}
else
{
assertThat
(
actual
,
equalTo
(
expected
)
);
assertThat
(
actual
).
isEqualTo
(
expected
);
}
}
finally
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java
View file @
94677b35
...
...
@@ -57,8 +57,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.cassandra.core.CassandraOperations
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertSame
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
...
...
@@ -88,9 +87,9 @@ public class HealthIndicatorAutoConfigurationTests {
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
ApplicationHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
ApplicationHealthIndicator
.
class
);
}
@Test
...
...
@@ -102,9 +101,9 @@ public class HealthIndicatorAutoConfigurationTests {
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
ApplicationHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
ApplicationHealthIndicator
.
class
);
}
@Test
...
...
@@ -116,9 +115,9 @@ public class HealthIndicatorAutoConfigurationTests {
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Same
(
this
.
context
.
getBean
(
"customHealthIndicator"
),
beans
.
values
().
iterator
().
next
());
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
this
.
context
.
getBean
(
"customHealthIndicator"
))
.
isSameAs
(
beans
.
values
().
iterator
().
next
());
}
@Test
...
...
@@ -131,9 +130,9 @@ public class HealthIndicatorAutoConfigurationTests {
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
DiskSpaceHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
DiskSpaceHealthIndicator
.
class
);
}
@Test
...
...
@@ -145,9 +144,9 @@ public class HealthIndicatorAutoConfigurationTests {
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
RedisHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
RedisHealthIndicator
.
class
);
}
@Test
...
...
@@ -160,9 +159,9 @@ public class HealthIndicatorAutoConfigurationTests {
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
ApplicationHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
ApplicationHealthIndicator
.
class
);
}
@Test
...
...
@@ -175,9 +174,9 @@ public class HealthIndicatorAutoConfigurationTests {
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
MongoHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
MongoHealthIndicator
.
class
);
}
@Test
...
...
@@ -191,9 +190,9 @@ public class HealthIndicatorAutoConfigurationTests {
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
ApplicationHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
ApplicationHealthIndicator
.
class
);
}
@Test
...
...
@@ -204,7 +203,7 @@ public class HealthIndicatorAutoConfigurationTests {
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
4
,
beans
.
size
()
);
assert
That
(
beans
).
hasSize
(
4
);
}
@Test
...
...
@@ -216,9 +215,9 @@ public class HealthIndicatorAutoConfigurationTests {
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
DataSourceHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
DataSourceHealthIndicator
.
class
);
}
@Test
...
...
@@ -234,11 +233,11 @@ public class HealthIndicatorAutoConfigurationTests {
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
That
(
beans
).
hasSize
(
1
);
HealthIndicator
healthIndicator
=
beans
.
values
().
iterator
().
next
();
assert
Equals
(
DataSourceHealthIndicator
.
class
,
healthIndicator
.
getClass
()
);
assert
That
(
healthIndicator
.
getClass
()).
isEqualTo
(
DataSourceHealthIndicator
.
class
);
DataSourceHealthIndicator
dataSourceHealthIndicator
=
(
DataSourceHealthIndicator
)
healthIndicator
;
assert
Equals
(
"SELECT from FOOBAR"
,
dataSourceHealthIndicator
.
getQuery
()
);
assert
That
(
dataSourceHealthIndicator
.
getQuery
()).
isEqualTo
(
"SELECT from FOOBAR"
);
}
@Test
...
...
@@ -251,9 +250,9 @@ public class HealthIndicatorAutoConfigurationTests {
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
ApplicationHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
ApplicationHealthIndicator
.
class
);
}
@Test
...
...
@@ -265,9 +264,9 @@ public class HealthIndicatorAutoConfigurationTests {
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
RabbitHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
RabbitHealthIndicator
.
class
);
}
@Test
...
...
@@ -280,9 +279,9 @@ public class HealthIndicatorAutoConfigurationTests {
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
ApplicationHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
ApplicationHealthIndicator
.
class
);
}
@Test
...
...
@@ -294,9 +293,9 @@ public class HealthIndicatorAutoConfigurationTests {
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
SolrHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
SolrHealthIndicator
.
class
);
}
@Test
...
...
@@ -309,9 +308,9 @@ public class HealthIndicatorAutoConfigurationTests {
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
ApplicationHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
ApplicationHealthIndicator
.
class
);
}
@Test
...
...
@@ -320,9 +319,9 @@ public class HealthIndicatorAutoConfigurationTests {
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
DiskSpaceHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
DiskSpaceHealthIndicator
.
class
);
}
@Test
...
...
@@ -336,9 +335,9 @@ public class HealthIndicatorAutoConfigurationTests {
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
MailHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
MailHealthIndicator
.
class
);
}
@Test
...
...
@@ -352,9 +351,9 @@ public class HealthIndicatorAutoConfigurationTests {
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
ApplicationHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
ApplicationHealthIndicator
.
class
);
}
@Test
...
...
@@ -367,9 +366,9 @@ public class HealthIndicatorAutoConfigurationTests {
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
JmsHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
JmsHealthIndicator
.
class
);
}
@Test
...
...
@@ -383,9 +382,9 @@ public class HealthIndicatorAutoConfigurationTests {
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
ApplicationHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
ApplicationHealthIndicator
.
class
);
}
@Test
...
...
@@ -400,9 +399,9 @@ public class HealthIndicatorAutoConfigurationTests {
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
ElasticsearchHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
ElasticsearchHealthIndicator
.
class
);
}
@Test
...
...
@@ -418,9 +417,9 @@ public class HealthIndicatorAutoConfigurationTests {
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
ApplicationHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
ApplicationHealthIndicator
.
class
);
}
@Test
...
...
@@ -432,9 +431,9 @@ public class HealthIndicatorAutoConfigurationTests {
this
.
context
.
refresh
();
Map
<
String
,
HealthIndicator
>
beans
=
this
.
context
.
getBeansOfType
(
HealthIndicator
.
class
);
assert
Equals
(
1
,
beans
.
size
()
);
assert
Equals
(
CassandraHealthIndicator
.
class
,
beans
.
values
().
iterator
().
next
().
getClass
()
);
assert
That
(
beans
).
hasSize
(
1
);
assert
That
(
beans
.
values
().
iterator
().
next
().
getClass
())
.
isEqualTo
(
CassandraHealthIndicator
.
class
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthMvcEndpointAutoConfigurationTests.java
View file @
94677b35
...
...
@@ -35,7 +35,7 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.mock.web.MockServletContext
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link EndpointWebMvcAutoConfiguration} of the {@link HealthMvcEndpoint}.
...
...
@@ -62,8 +62,8 @@ public class HealthMvcEndpointAutoConfigurationTests {
this
.
context
.
refresh
();
Health
health
=
(
Health
)
this
.
context
.
getBean
(
HealthMvcEndpoint
.
class
)
.
invoke
(
null
);
assert
Equals
(
Status
.
UP
,
health
.
getStatus
()
);
assert
Equals
(
null
,
health
.
getDetails
().
get
(
"foo"
)
);
assert
That
(
health
.
getStatus
()).
isEqualTo
(
Status
.
UP
);
assert
That
(
health
.
getDetails
().
get
(
"foo"
)).
isNull
(
);
}
@Test
...
...
@@ -76,9 +76,9 @@ public class HealthMvcEndpointAutoConfigurationTests {
this
.
context
.
refresh
();
Health
health
=
(
Health
)
this
.
context
.
getBean
(
HealthMvcEndpoint
.
class
)
.
invoke
(
null
);
assert
Equals
(
Status
.
UP
,
health
.
getStatus
()
);
assert
That
(
health
.
getStatus
()).
isEqualTo
(
Status
.
UP
);
Health
map
=
(
Health
)
health
.
getDetails
().
get
(
"test"
);
assert
Equals
(
"bar"
,
map
.
getDetails
().
get
(
"foo"
)
);
assert
That
(
map
.
getDetails
().
get
(
"foo"
)).
isEqualTo
(
"bar"
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java
View file @
94677b35
...
...
@@ -41,7 +41,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import
org.springframework.test.web.servlet.result.MockMvcResultMatchers
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link JolokiaAutoConfiguration}.
...
...
@@ -74,8 +74,7 @@ public class JolokiaAutoConfigurationTests {
HttpMessageConvertersAutoConfiguration
.
class
,
JolokiaAutoConfiguration
.
class
);
this
.
context
.
refresh
();
assertEquals
(
1
,
this
.
context
.
getBeanNamesForType
(
JolokiaMvcEndpoint
.
class
).
length
);
assertThat
(
this
.
context
.
getBeanNamesForType
(
JolokiaMvcEndpoint
.
class
)).
hasSize
(
1
);
}
@Test
...
...
@@ -89,8 +88,7 @@ public class JolokiaAutoConfigurationTests {
HttpMessageConvertersAutoConfiguration
.
class
,
JolokiaAutoConfiguration
.
class
);
this
.
context
.
refresh
();
assertEquals
(
1
,
this
.
context
.
getBeanNamesForType
(
JolokiaMvcEndpoint
.
class
).
length
);
assertThat
(
this
.
context
.
getBeanNamesForType
(
JolokiaMvcEndpoint
.
class
)).
hasSize
(
1
);
MockMvc
mockMvc
=
MockMvcBuilders
.
webAppContextSetup
(
this
.
context
).
build
();
mockMvc
.
perform
(
MockMvcRequestBuilders
.
get
(
"/foo/bar"
))
.
andExpect
(
MockMvcResultMatchers
.
content
()
...
...
@@ -122,8 +120,7 @@ public class JolokiaAutoConfigurationTests {
HttpMessageConvertersAutoConfiguration
.
class
,
JolokiaAutoConfiguration
.
class
);
this
.
context
.
refresh
();
assertEquals
(
0
,
this
.
context
.
getBeanNamesForType
(
JolokiaMvcEndpoint
.
class
).
length
);
assertThat
(
this
.
context
.
getBeanNamesForType
(
JolokiaMvcEndpoint
.
class
)).
isEmpty
();
}
private
void
assertEndpointEnabled
(
String
...
pairs
)
{
...
...
@@ -135,8 +132,7 @@ public class JolokiaAutoConfigurationTests {
HttpMessageConvertersAutoConfiguration
.
class
,
JolokiaAutoConfiguration
.
class
);
this
.
context
.
refresh
();
assertEquals
(
1
,
this
.
context
.
getBeanNamesForType
(
JolokiaMvcEndpoint
.
class
).
length
);
assertThat
(
this
.
context
.
getBeanNamesForType
(
JolokiaMvcEndpoint
.
class
)).
hasSize
(
1
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementServerPropertiesAutoConfigurationTests.java
View file @
94677b35
...
...
@@ -18,9 +18,7 @@ package org.springframework.boot.actuate.autoconfigure;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ManagementServerPropertiesAutoConfiguration}.
...
...
@@ -33,8 +31,8 @@ public class ManagementServerPropertiesAutoConfigurationTests {
@Test
public
void
defaultManagementServerProperties
()
{
ManagementServerProperties
properties
=
new
ManagementServerProperties
();
assertThat
(
properties
.
getPort
()
,
nullValue
()
);
assertThat
(
properties
.
getContextPath
()
,
equalTo
(
""
)
);
assertThat
(
properties
.
getPort
()
).
isNull
(
);
assertThat
(
properties
.
getContextPath
()
).
isEqualTo
(
""
);
}
@Test
...
...
@@ -42,22 +40,22 @@ public class ManagementServerPropertiesAutoConfigurationTests {
ManagementServerProperties
properties
=
new
ManagementServerProperties
();
properties
.
setPort
(
123
);
properties
.
setContextPath
(
"/foo"
);
assertThat
(
properties
.
getPort
()
,
equalTo
(
123
)
);
assertThat
(
properties
.
getContextPath
()
,
equalTo
(
"/foo"
)
);
assertThat
(
properties
.
getPort
()
).
isEqualTo
(
123
);
assertThat
(
properties
.
getContextPath
()
).
isEqualTo
(
"/foo"
);
}
@Test
public
void
trailingSlashOfContextPathIsRemoved
()
{
ManagementServerProperties
properties
=
new
ManagementServerProperties
();
properties
.
setContextPath
(
"/foo/"
);
assertThat
(
properties
.
getContextPath
()
,
equalTo
(
"/foo"
)
);
assertThat
(
properties
.
getContextPath
()
).
isEqualTo
(
"/foo"
);
}
@Test
public
void
slashOfContextPathIsDefaultValue
()
{
ManagementServerProperties
properties
=
new
ManagementServerProperties
();
properties
.
setContextPath
(
"/"
);
assertThat
(
properties
.
getContextPath
()
,
equalTo
(
""
)
);
assertThat
(
properties
.
getContextPath
()
).
isEqualTo
(
""
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementWebSecurityAutoConfigurationTests.java
View file @
94677b35
...
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
;
import
java.util.ArrayList
;
import
javax.servlet.Filter
;
import
org.hamcrest.Matchers
;
...
...
@@ -42,6 +44,7 @@ import org.springframework.security.config.annotation.authentication.builders.Au
import
org.springframework.security.config.annotation.authentication.configuration.EnableGlobalAuthentication
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.authority.AuthorityUtils
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
...
...
@@ -55,12 +58,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
static
org
.
hamcrest
.
Matchers
.
greaterThan
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
springframework
.
security
.
test
.
web
.
servlet
.
setup
.
SecurityMockMvcConfigurers
.
springSecurity
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
...
...
@@ -96,21 +94,20 @@ public class ManagementWebSecurityAutoConfigurationTests {
PropertyPlaceholderAutoConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"security.basic.enabled:false"
);
this
.
context
.
refresh
();
assert
NotNull
(
this
.
context
.
getBean
(
AuthenticationManagerBuilder
.
class
)
);
assert
That
(
this
.
context
.
getBean
(
AuthenticationManagerBuilder
.
class
)).
isNotNull
(
);
FilterChainProxy
filterChainProxy
=
this
.
context
.
getBean
(
FilterChainProxy
.
class
);
// 1 for static resources, one for management endpoints and one for the rest
assertThat
(
filterChainProxy
.
getFilterChains
(),
hasSize
(
3
));
assertThat
(
filterChainProxy
.
getFilters
(
"/beans"
),
hasSize
(
greaterThan
(
0
)));
assertThat
(
filterChainProxy
.
getFilters
(
"/beans/"
),
hasSize
(
greaterThan
(
0
)));
assertThat
(
filterChainProxy
.
getFilters
(
"/beans.foo"
),
hasSize
(
greaterThan
(
0
)));
assertThat
(
filterChainProxy
.
getFilters
(
"/beans/foo/bar"
),
hasSize
(
greaterThan
(
0
)));
assertThat
(
filterChainProxy
.
getFilterChains
()).
hasSize
(
3
);
assertThat
(
filterChainProxy
.
getFilters
(
"/beans"
)).
isNotEmpty
();
assertThat
(
filterChainProxy
.
getFilters
(
"/beans/"
)).
isNotEmpty
();
assertThat
(
filterChainProxy
.
getFilters
(
"/beans.foo"
)).
isNotEmpty
();
assertThat
(
filterChainProxy
.
getFilters
(
"/beans/foo/bar"
)).
isNotEmpty
();
}
@Test
public
void
testPathNormalization
()
throws
Exception
{
String
path
=
"admin/./error"
;
assert
Equals
(
"admin/error"
,
StringUtils
.
cleanPath
(
path
)
);
assert
That
(
StringUtils
.
cleanPath
(
path
)).
isEqualTo
(
"admin/error"
);
}
@Test
...
...
@@ -120,8 +117,10 @@ public class ManagementWebSecurityAutoConfigurationTests {
this
.
context
.
register
(
WebConfiguration
.
class
);
this
.
context
.
refresh
();
UserDetails
user
=
getUser
();
assertTrue
(
user
.
getAuthorities
().
containsAll
(
AuthorityUtils
.
commaSeparatedStringToAuthorityList
(
"ROLE_USER,ROLE_ADMIN"
)));
ArrayList
<
GrantedAuthority
>
authorities
=
new
ArrayList
<
GrantedAuthority
>(
user
.
getAuthorities
());
assertThat
(
authorities
).
containsAll
(
AuthorityUtils
.
commaSeparatedStringToAuthorityList
(
"ROLE_USER,ROLE_ADMIN"
));
}
private
UserDetails
getUser
()
{
...
...
@@ -147,8 +146,8 @@ public class ManagementWebSecurityAutoConfigurationTests {
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"security.ignored:none"
);
this
.
context
.
refresh
();
// Just the application and management endpoints now
assert
Equals
(
2
,
this
.
context
.
getBean
(
FilterChainProxy
.
class
).
getFilterChains
().
size
()
);
assert
That
(
this
.
context
.
getBean
(
FilterChainProxy
.
class
).
getFilterChains
())
.
hasSize
(
2
);
}
@Test
...
...
@@ -160,8 +159,8 @@ public class ManagementWebSecurityAutoConfigurationTests {
this
.
context
.
refresh
();
// Just the management endpoints (one filter) and ignores now plus the backup
// filter on app endpoints
assert
Equals
(
3
,
this
.
context
.
getBean
(
FilterChainProxy
.
class
).
getFilterChains
().
size
()
);
assert
That
(
this
.
context
.
getBean
(
FilterChainProxy
.
class
).
getFilterChains
())
.
hasSize
(
3
);
}
@Test
...
...
@@ -174,8 +173,8 @@ public class ManagementWebSecurityAutoConfigurationTests {
ManagementServerPropertiesAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
assert
Equals
(
this
.
context
.
getBean
(
TestConfiguration
.
class
).
authenticationManager
,
this
.
context
.
getBean
(
AuthenticationManager
.
class
)
);
assert
That
(
this
.
context
.
getBean
(
AuthenticationManager
.
class
)).
isEqualTo
(
this
.
context
.
getBean
(
TestConfiguration
.
class
).
authenticationManager
);
}
@Test
...
...
@@ -188,8 +187,8 @@ public class ManagementWebSecurityAutoConfigurationTests {
ManagementServerPropertiesAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
assert
Equals
(
this
.
context
.
getBean
(
TestConfiguration
.
class
).
authenticationManager
,
this
.
context
.
getBean
(
AuthenticationManager
.
class
)
);
assert
That
(
this
.
context
.
getBean
(
AuthenticationManager
.
class
)).
isEqualTo
(
this
.
context
.
getBean
(
TestConfiguration
.
class
).
authenticationManager
);
}
// gh-2466
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricExportAutoConfigurationTests.java
View file @
94677b35
...
...
@@ -42,9 +42,7 @@ import org.springframework.messaging.MessageHandler;
import
org.springframework.messaging.MessagingException
;
import
org.springframework.messaging.SubscribableChannel
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link MetricExportAutoConfiguration}.
...
...
@@ -76,7 +74,7 @@ public class MetricExportAutoConfigurationTests {
MetricExportAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
MetricExporters
exporter
=
this
.
context
.
getBean
(
MetricExporters
.
class
);
assert
NotNull
(
exporter
);
assert
That
(
exporter
).
isNotNull
(
);
}
@Test
...
...
@@ -86,7 +84,7 @@ public class MetricExportAutoConfigurationTests {
MetricExportAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
GaugeService
gaugeService
=
this
.
context
.
getBean
(
GaugeService
.
class
);
assert
NotNull
(
gaugeService
);
assert
That
(
gaugeService
).
isNotNull
(
);
gaugeService
.
submit
(
"foo"
,
2.7
);
MetricExporters
exporters
=
this
.
context
.
getBean
(
MetricExporters
.
class
);
MetricCopyExporter
exporter
=
(
MetricCopyExporter
)
exporters
.
getExporters
()
...
...
@@ -132,7 +130,7 @@ public class MetricExportAutoConfigurationTests {
MetricExportAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBean
(
StatsdMetricWriter
.
class
)
,
notNullValue
()
);
assertThat
(
this
.
context
.
getBean
(
StatsdMetricWriter
.
class
)
).
isNotNull
(
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java
View file @
94677b35
...
...
@@ -53,11 +53,10 @@ import org.springframework.web.context.request.async.DeferredResult;
import
org.springframework.web.filter.OncePerRequestFilter
;
import
org.springframework.web.util.NestedServletException
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
mockito
.
BDDMockito
.
willAnswer
;
import
static
org
.
mockito
.
BDDMockito
.
willThrow
;
...
...
@@ -173,7 +172,7 @@ public class MetricFilterAutoConfigurationTests {
public
void
skipsFilterIfMissingServices
()
throws
Exception
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
(
MetricFilterAutoConfiguration
.
class
);
assertThat
(
context
.
getBeansOfType
(
Filter
.
class
).
size
()
,
equalTo
(
0
)
);
assertThat
(
context
.
getBeansOfType
(
Filter
.
class
).
size
()
).
isEqualTo
(
0
);
context
.
close
();
}
...
...
@@ -184,7 +183,7 @@ public class MetricFilterAutoConfigurationTests {
"endpoints.metrics.filter.enabled:false"
);
context
.
register
(
Config
.
class
,
MetricFilterAutoConfiguration
.
class
);
context
.
refresh
();
assertThat
(
context
.
getBeansOfType
(
Filter
.
class
).
size
()
,
equalTo
(
0
)
);
assertThat
(
context
.
getBeansOfType
(
Filter
.
class
).
size
()
).
isEqualTo
(
0
);
context
.
close
();
}
...
...
@@ -269,7 +268,7 @@ public class MetricFilterAutoConfigurationTests {
fail
();
}
catch
(
Exception
ex
)
{
assertThat
(
result
.
getRequest
().
getAttribute
(
attributeName
)
,
is
(
nullValue
())
);
assertThat
(
result
.
getRequest
().
getAttribute
(
attributeName
)
).
isNull
(
);
verify
(
context
.
getBean
(
CounterService
.
class
))
.
increment
(
"status.500.createFailure"
);
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfigurationTests.java
View file @
94677b35
...
...
@@ -33,10 +33,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
...
...
@@ -61,12 +58,12 @@ public class MetricRepositoryAutoConfigurationTests {
this
.
context
=
new
AnnotationConfigApplicationContext
(
MetricRepositoryAutoConfiguration
.
class
);
GaugeService
gaugeService
=
this
.
context
.
getBean
(
BufferGaugeService
.
class
);
assert
NotNull
(
gaugeService
);
assert
NotNull
(
this
.
context
.
getBean
(
BufferCounterService
.
class
)
);
assert
NotNull
(
this
.
context
.
getBean
(
PrefixMetricReader
.
class
)
);
assert
That
(
gaugeService
).
isNotNull
(
);
assert
That
(
this
.
context
.
getBean
(
BufferCounterService
.
class
)).
isNotNull
(
);
assert
That
(
this
.
context
.
getBean
(
PrefixMetricReader
.
class
)).
isNotNull
(
);
gaugeService
.
submit
(
"foo"
,
2.7
);
assertEquals
(
2.7
,
this
.
context
.
getBean
(
MetricReader
.
class
).
findOne
(
"gauge.foo"
).
getValue
()
);
MetricReader
bean
=
this
.
context
.
getBean
(
MetricReader
.
class
);
assertThat
(
bean
.
findOne
(
"gauge.foo"
).
getValue
()).
isEqualTo
(
2.7
);
}
@Test
...
...
@@ -75,25 +72,23 @@ public class MetricRepositoryAutoConfigurationTests {
MetricsDropwizardAutoConfiguration
.
class
,
MetricRepositoryAutoConfiguration
.
class
,
AopAutoConfiguration
.
class
);
GaugeService
gaugeService
=
this
.
context
.
getBean
(
GaugeService
.
class
);
assert
NotNull
(
gaugeService
);
assert
That
(
gaugeService
).
isNotNull
(
);
gaugeService
.
submit
(
"foo"
,
2.7
);
DropwizardMetricServices
exporter
=
this
.
context
.
getBean
(
DropwizardMetricServices
.
class
);
assert
Equals
(
gaugeService
,
exporter
);
assert
That
(
exporter
).
isEqualTo
(
gaugeService
);
MetricRegistry
registry
=
this
.
context
.
getBean
(
MetricRegistry
.
class
);
@SuppressWarnings
(
"unchecked"
)
Gauge
<
Double
>
gauge
=
(
Gauge
<
Double
>)
registry
.
getMetrics
().
get
(
"gauge.foo"
);
assert
Equals
(
new
Double
(
2.7
),
gauge
.
getValue
(
));
assert
That
(
gauge
.
getValue
()).
isEqualTo
(
new
Double
(
2.7
));
}
@Test
public
void
skipsIfBeansExist
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigApplicationContext
(
Config
.
class
,
MetricRepositoryAutoConfiguration
.
class
);
assertThat
(
this
.
context
.
getBeansOfType
(
BufferGaugeService
.
class
).
size
(),
equalTo
(
0
));
assertThat
(
this
.
context
.
getBeansOfType
(
BufferCounterService
.
class
).
size
(),
equalTo
(
0
));
assertThat
(
this
.
context
.
getBeansOfType
(
BufferGaugeService
.
class
)).
isEmpty
();
assertThat
(
this
.
context
.
getBeansOfType
(
BufferCounterService
.
class
)).
isEmpty
();
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/PublicMetricsAutoConfigurationTests.java
View file @
94677b35
...
...
@@ -59,10 +59,7 @@ import org.springframework.jdbc.core.ConnectionCallback;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.util.SocketUtils
;
import
static
org
.
hamcrest
.
Matchers
.
hasKey
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -88,14 +85,14 @@ public class PublicMetricsAutoConfigurationTests {
@Test
public
void
systemPublicMetrics
()
throws
Exception
{
load
();
assert
Equals
(
1
,
this
.
context
.
getBeansOfType
(
SystemPublicMetrics
.
class
).
size
()
);
assert
That
(
this
.
context
.
getBeansOfType
(
SystemPublicMetrics
.
class
)).
hasSize
(
1
);
}
@Test
public
void
metricReaderPublicMetrics
()
throws
Exception
{
load
();
assert
Equals
(
1
,
this
.
context
.
getBeansOfType
(
MetricReaderPublicMetrics
.
class
).
size
()
);
assert
That
(
this
.
context
.
getBeansOfType
(
MetricReaderPublicMetrics
.
class
))
.
hasSize
(
1
);
}
@Test
...
...
@@ -104,15 +101,15 @@ public class PublicMetricsAutoConfigurationTests {
RichGaugeReaderConfig
.
class
,
MetricRepositoryAutoConfiguration
.
class
,
PublicMetricsAutoConfiguration
.
class
);
RichGaugeReader
richGaugeReader
=
context
.
getBean
(
RichGaugeReader
.
class
);
assert
NotNull
(
richGaugeReader
);
assert
That
(
richGaugeReader
).
isNotNull
(
);
given
(
richGaugeReader
.
findAll
())
.
willReturn
(
Collections
.
singletonList
(
new
RichGauge
(
"bar"
,
3.7d
)));
RichGaugeReaderPublicMetrics
publicMetrics
=
context
.
getBean
(
RichGaugeReaderPublicMetrics
.
class
);
assert
NotNull
(
publicMetrics
);
assert
That
(
publicMetrics
).
isNotNull
(
);
Collection
<
Metric
<?>>
metrics
=
publicMetrics
.
metrics
();
assert
NotNull
(
metrics
);
assert
Equals
(
metrics
.
size
(),
6
);
assert
That
(
metrics
).
isNotNull
(
);
assert
That
(
6
).
isEqualTo
(
metrics
.
size
()
);
assertHasMetric
(
metrics
,
new
Metric
<
Double
>(
"bar.val"
,
3.7d
));
assertHasMetric
(
metrics
,
new
Metric
<
Double
>(
"bar.avg"
,
3.7d
));
assertHasMetric
(
metrics
,
new
Metric
<
Double
>(
"bar.min"
,
3.7d
));
...
...
@@ -125,8 +122,7 @@ public class PublicMetricsAutoConfigurationTests {
@Test
public
void
noDataSource
()
{
load
();
assertEquals
(
0
,
this
.
context
.
getBeansOfType
(
DataSourcePublicMetrics
.
class
).
size
());
assertThat
(
this
.
context
.
getBeansOfType
(
DataSourcePublicMetrics
.
class
)).
isEmpty
();
}
@Test
...
...
@@ -194,13 +190,13 @@ public class PublicMetricsAutoConfigurationTests {
@Test
public
void
tomcatMetrics
()
throws
Exception
{
loadWeb
(
TomcatConfiguration
.
class
);
assert
Equals
(
1
,
this
.
context
.
getBeansOfType
(
TomcatPublicMetrics
.
class
).
size
()
);
assert
That
(
this
.
context
.
getBeansOfType
(
TomcatPublicMetrics
.
class
)).
hasSize
(
1
);
}
@Test
public
void
noCacheMetrics
()
{
load
();
assert
Equals
(
0
,
this
.
context
.
getBeansOfType
(
CachePublicMetrics
.
class
).
size
()
);
assert
That
(
this
.
context
.
getBeansOfType
(
CachePublicMetrics
.
class
)).
isEmpty
(
);
}
@Test
...
...
@@ -236,7 +232,7 @@ public class PublicMetricsAutoConfigurationTests {
content
.
put
(
metric
.
getName
(),
metric
.
getValue
());
}
for
(
String
key
:
keys
)
{
assertThat
(
content
,
hasKey
(
key
)
);
assertThat
(
content
).
containsKey
(
key
);
}
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ShellPropertiesTests.java
View file @
94677b35
...
...
@@ -40,11 +40,7 @@ import org.springframework.mock.env.MockEnvironment;
import
org.springframework.mock.web.MockServletContext
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ShellProperties}.
...
...
@@ -59,8 +55,8 @@ public class ShellPropertiesTests {
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
props
,
"shell"
);
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"shell.auth"
,
"spring"
)));
assert
False
(
binder
.
getBindingResult
().
hasErrors
()
);
assert
Equals
(
"spring"
,
props
.
getAuth
()
);
assert
That
(
binder
.
getBindingResult
().
hasErrors
()).
isFalse
(
);
assert
That
(
props
.
getAuth
()).
isEqualTo
(
"spring"
);
}
@Test
...
...
@@ -69,8 +65,8 @@ public class ShellPropertiesTests {
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
props
,
"shell"
);
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"shell.auth"
,
""
)));
assertT
rue
(
binder
.
getBindingResult
().
hasErrors
()
);
assert
Equals
(
"simple"
,
props
.
getAuth
()
);
assertT
hat
(
binder
.
getBindingResult
().
hasErrors
()).
isTrue
(
);
assert
That
(
props
.
getAuth
()).
isEqualTo
(
"simple"
);
}
@Test
...
...
@@ -80,8 +76,8 @@ public class ShellPropertiesTests {
binder
.
setConversionService
(
new
DefaultConversionService
());
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"shell.command_refresh_interval"
,
"1"
)));
assert
False
(
binder
.
getBindingResult
().
hasErrors
()
);
assert
Equals
(
1
,
props
.
getCommandRefreshInterval
()
);
assert
That
(
binder
.
getBindingResult
().
hasErrors
()).
isFalse
(
);
assert
That
(
props
.
getCommandRefreshInterval
()).
isEqualTo
(
1
);
}
@Test
...
...
@@ -91,8 +87,8 @@ public class ShellPropertiesTests {
binder
.
setConversionService
(
new
DefaultConversionService
());
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"shell.command_path_patterns"
,
"pattern1, pattern2"
)));
assert
False
(
binder
.
getBindingResult
().
hasErrors
()
);
assert
Equals
(
2
,
props
.
getCommandPathPatterns
().
length
);
assert
That
(
binder
.
getBindingResult
().
hasErrors
()).
isFalse
(
);
assert
That
(
props
.
getCommandPathPatterns
().
length
).
isEqualTo
(
2
);
Assert
.
assertArrayEquals
(
new
String
[]
{
"pattern1"
,
"pattern2"
},
props
.
getCommandPathPatterns
());
}
...
...
@@ -104,8 +100,8 @@ public class ShellPropertiesTests {
binder
.
setConversionService
(
new
DefaultConversionService
());
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"shell.config_path_patterns"
,
"pattern1, pattern2"
)));
assert
False
(
binder
.
getBindingResult
().
hasErrors
()
);
assert
Equals
(
2
,
props
.
getConfigPathPatterns
().
length
);
assert
That
(
binder
.
getBindingResult
().
hasErrors
()).
isFalse
(
);
assert
That
(
props
.
getConfigPathPatterns
().
length
).
isEqualTo
(
2
);
Assert
.
assertArrayEquals
(
new
String
[]
{
"pattern1"
,
"pattern2"
},
props
.
getConfigPathPatterns
());
}
...
...
@@ -117,10 +113,9 @@ public class ShellPropertiesTests {
binder
.
setConversionService
(
new
DefaultConversionService
());
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"shell.disabled_plugins"
,
"pattern1, pattern2"
)));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertEquals
(
2
,
props
.
getDisabledPlugins
().
length
);
assertArrayEquals
(
new
String
[]
{
"pattern1"
,
"pattern2"
},
props
.
getDisabledPlugins
());
assertThat
(
binder
.
getBindingResult
().
hasErrors
()).
isFalse
();
assertThat
(
props
.
getDisabledPlugins
().
length
).
isEqualTo
(
2
);
assertThat
(
props
.
getDisabledPlugins
()).
containsExactly
(
"pattern1"
,
"pattern2"
);
}
@Test
...
...
@@ -130,10 +125,8 @@ public class ShellPropertiesTests {
binder
.
setConversionService
(
new
DefaultConversionService
());
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"shell.disabled_commands"
,
"pattern1, pattern2"
)));
assertFalse
(
binder
.
getBindingResult
().
hasErrors
());
assertEquals
(
2
,
props
.
getDisabledCommands
().
length
);
assertArrayEquals
(
new
String
[]
{
"pattern1"
,
"pattern2"
},
props
.
getDisabledCommands
());
assertThat
(
binder
.
getBindingResult
().
hasErrors
()).
isFalse
();
assertThat
(
props
.
getDisabledCommands
()).
containsExactly
(
"pattern1"
,
"pattern2"
);
}
@Test
...
...
@@ -146,12 +139,12 @@ public class ShellPropertiesTests {
map
.
put
(
"shell.ssh.port"
,
"2222"
);
map
.
put
(
"shell.ssh.key_path"
,
"~/.ssh/test.pem"
);
binder
.
bind
(
new
MutablePropertyValues
(
map
));
assert
False
(
binder
.
getBindingResult
().
hasErrors
()
);
assert
That
(
binder
.
getBindingResult
().
hasErrors
()).
isFalse
(
);
Properties
p
=
props
.
asCrshShellConfig
();
assert
Equals
(
"2222"
,
p
.
get
(
"crash.ssh.port"
)
);
assert
Equals
(
"~/.ssh/test.pem"
,
p
.
get
(
"crash.ssh.keypath"
)
);
assert
That
(
p
.
get
(
"crash.ssh.port"
)).
isEqualTo
(
"2222"
);
assert
That
(
p
.
get
(
"crash.ssh.keypath"
)).
isEqualTo
(
"~/.ssh/test.pem"
);
}
@Test
...
...
@@ -164,12 +157,12 @@ public class ShellPropertiesTests {
map
.
put
(
"shell.ssh.port"
,
"2222"
);
map
.
put
(
"shell.ssh.key_path"
,
"~/.ssh/test.pem"
);
binder
.
bind
(
new
MutablePropertyValues
(
map
));
assert
False
(
binder
.
getBindingResult
().
hasErrors
()
);
assert
That
(
binder
.
getBindingResult
().
hasErrors
()).
isFalse
(
);
Properties
p
=
props
.
asCrshShellConfig
();
assert
Null
(
p
.
get
(
"crash.ssh.port"
)
);
assert
Null
(
p
.
get
(
"crash.ssh.keypath"
)
);
assert
That
(
p
.
get
(
"crash.ssh.port"
)).
isNull
(
);
assert
That
(
p
.
get
(
"crash.ssh.keypath"
)).
isNull
(
);
}
@Test
...
...
@@ -181,11 +174,11 @@ public class ShellPropertiesTests {
map
.
put
(
"shell.telnet.enabled"
,
"true"
);
map
.
put
(
"shell.telnet.port"
,
"2222"
);
binder
.
bind
(
new
MutablePropertyValues
(
map
));
assert
False
(
binder
.
getBindingResult
().
hasErrors
()
);
assert
That
(
binder
.
getBindingResult
().
hasErrors
()).
isFalse
(
);
Properties
p
=
props
.
asCrshShellConfig
();
assert
Equals
(
"2222"
,
p
.
get
(
"crash.telnet.port"
)
);
assert
That
(
p
.
get
(
"crash.telnet.port"
)).
isEqualTo
(
"2222"
);
}
@Test
...
...
@@ -197,11 +190,11 @@ public class ShellPropertiesTests {
map
.
put
(
"shell.telnet.enabled"
,
"false"
);
map
.
put
(
"shell.telnet.port"
,
"2222"
);
binder
.
bind
(
new
MutablePropertyValues
(
map
));
assert
False
(
binder
.
getBindingResult
().
hasErrors
()
);
assert
That
(
binder
.
getBindingResult
().
hasErrors
()).
isFalse
(
);
Properties
p
=
props
.
asCrshShellConfig
();
assert
Null
(
p
.
get
(
"crash.telnet.port"
)
);
assert
That
(
p
.
get
(
"crash.telnet.port"
)).
isNull
(
);
}
@Test
...
...
@@ -212,12 +205,12 @@ public class ShellPropertiesTests {
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"shell.auth.jaas.domain"
,
"my-test-domain"
);
binder
.
bind
(
new
MutablePropertyValues
(
map
));
assert
False
(
binder
.
getBindingResult
().
hasErrors
()
);
assert
That
(
binder
.
getBindingResult
().
hasErrors
()).
isFalse
(
);
Properties
p
=
new
Properties
();
props
.
applyToCrshShellConfig
(
p
);
assert
Equals
(
"my-test-domain"
,
p
.
get
(
"crash.auth.jaas.domain"
)
);
assert
That
(
p
.
get
(
"crash.auth.jaas.domain"
)).
isEqualTo
(
"my-test-domain"
);
}
@Test
...
...
@@ -228,12 +221,12 @@ public class ShellPropertiesTests {
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"shell.auth.key.path"
,
"~/.ssh/test.pem"
);
binder
.
bind
(
new
MutablePropertyValues
(
map
));
assert
False
(
binder
.
getBindingResult
().
hasErrors
()
);
assert
That
(
binder
.
getBindingResult
().
hasErrors
()).
isFalse
(
);
Properties
p
=
new
Properties
();
props
.
applyToCrshShellConfig
(
p
);
assert
Equals
(
"~/.ssh/test.pem"
,
p
.
get
(
"crash.auth.key.path"
)
);
assert
That
(
p
.
get
(
"crash.auth.key.path"
)).
isEqualTo
(
"~/.ssh/test.pem"
);
}
@Test
...
...
@@ -243,12 +236,12 @@ public class ShellPropertiesTests {
binder
.
setConversionService
(
new
DefaultConversionService
());
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
binder
.
bind
(
new
MutablePropertyValues
(
map
));
assert
False
(
binder
.
getBindingResult
().
hasErrors
()
);
assert
That
(
binder
.
getBindingResult
().
hasErrors
()).
isFalse
(
);
Properties
p
=
new
Properties
();
props
.
applyToCrshShellConfig
(
p
);
assert
Null
(
p
.
get
(
"crash.auth.key.path"
)
);
assert
That
(
p
.
get
(
"crash.auth.key.path"
)).
isNull
(
);
}
@Test
...
...
@@ -260,13 +253,13 @@ public class ShellPropertiesTests {
map
.
put
(
"shell.auth.simple.user.name"
,
"username123"
);
map
.
put
(
"shell.auth.simple.user.password"
,
"password123"
);
binder
.
bind
(
new
MutablePropertyValues
(
map
));
assert
False
(
binder
.
getBindingResult
().
hasErrors
()
);
assert
That
(
binder
.
getBindingResult
().
hasErrors
()).
isFalse
(
);
Properties
p
=
new
Properties
();
props
.
applyToCrshShellConfig
(
p
);
assert
Equals
(
"username123"
,
p
.
get
(
"crash.auth.simple.username"
)
);
assert
Equals
(
"password123"
,
p
.
get
(
"crash.auth.simple.password"
)
);
assert
That
(
p
.
get
(
"crash.auth.simple.username"
)).
isEqualTo
(
"username123"
);
assert
That
(
p
.
get
(
"crash.auth.simple.password"
)).
isEqualTo
(
"password123"
);
}
@Test
...
...
@@ -275,8 +268,8 @@ public class ShellPropertiesTests {
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
security
,
"security"
);
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"shell.auth.simple.user.password"
,
"${ADMIN_PASSWORD}"
)));
assert
False
(
binder
.
getBindingResult
().
hasErrors
()
);
assertT
rue
(
security
.
getUser
().
isDefaultPassword
()
);
assert
That
(
binder
.
getBindingResult
().
hasErrors
()).
isFalse
(
);
assertT
hat
(
security
.
getUser
().
isDefaultPassword
()).
isTrue
(
);
}
@Test
...
...
@@ -285,8 +278,8 @@ public class ShellPropertiesTests {
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
security
,
"security"
);
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"shell.auth.simple.user.password"
,
""
)));
assert
False
(
binder
.
getBindingResult
().
hasErrors
()
);
assertT
rue
(
security
.
getUser
().
isDefaultPassword
()
);
assert
That
(
binder
.
getBindingResult
().
hasErrors
()).
isFalse
(
);
assertT
hat
(
security
.
getUser
().
isDefaultPassword
()).
isTrue
(
);
}
@Test
...
...
@@ -295,12 +288,12 @@ public class ShellPropertiesTests {
RelaxedDataBinder
binder
=
new
RelaxedDataBinder
(
props
,
"shell.auth.spring"
);
binder
.
bind
(
new
MutablePropertyValues
(
Collections
.
singletonMap
(
"shell.auth.spring.roles"
,
"role1, role2"
)));
assert
False
(
binder
.
getBindingResult
().
hasErrors
()
);
assert
That
(
binder
.
getBindingResult
().
hasErrors
()).
isFalse
(
);
Properties
p
=
new
Properties
();
props
.
applyToCrshShellConfig
(
p
);
assert
Equals
(
"role1,role2"
,
p
.
get
(
"crash.auth.spring.roles"
)
);
assert
That
(
p
.
get
(
"crash.auth.spring.roles"
)).
isEqualTo
(
"role1,role2"
);
}
@Test
...
...
@@ -316,7 +309,7 @@ public class ShellPropertiesTests {
PluginLifeCycle
lifeCycle
=
context
.
getBean
(
PluginLifeCycle
.
class
);
String
uuid
=
lifeCycle
.
getConfig
().
getProperty
(
"test.uuid"
);
assert
Equals
(
TestShellConfiguration
.
uuid
,
uuid
);
assert
That
(
uuid
).
isEqualTo
(
TestShellConfiguration
.
uuid
);
context
.
close
();
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/TraceRepositoryAutoConfigurationTests.java
View file @
94677b35
...
...
@@ -24,9 +24,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
...
...
@@ -40,7 +38,7 @@ public class TraceRepositoryAutoConfigurationTests {
public
void
configuresInMemoryTraceRepository
()
throws
Exception
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
(
TraceRepositoryAutoConfiguration
.
class
);
assert
NotNull
(
context
.
getBean
(
InMemoryTraceRepository
.
class
)
);
assert
That
(
context
.
getBean
(
InMemoryTraceRepository
.
class
)).
isNotNull
(
);
context
.
close
();
}
...
...
@@ -48,9 +46,8 @@ public class TraceRepositoryAutoConfigurationTests {
public
void
skipsIfRepositoryExists
()
throws
Exception
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
(
Config
.
class
,
TraceRepositoryAutoConfiguration
.
class
);
assertThat
(
context
.
getBeansOfType
(
InMemoryTraceRepository
.
class
).
size
(),
equalTo
(
0
));
assertThat
(
context
.
getBeansOfType
(
TraceRepository
.
class
).
size
(),
equalTo
(
1
));
assertThat
(
context
.
getBeansOfType
(
InMemoryTraceRepository
.
class
)).
isEmpty
();
assertThat
(
context
.
getBeansOfType
(
TraceRepository
.
class
)).
hasSize
(
1
);
context
.
close
();
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfigurationTests.java
View file @
94677b35
...
...
@@ -22,7 +22,7 @@ import org.springframework.boot.actuate.trace.WebRequestTraceFilter;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link TraceWebFilterAutoConfiguration}.
...
...
@@ -37,7 +37,7 @@ public class TraceWebFilterAutoConfigurationTests {
PropertyPlaceholderAutoConfiguration
.
class
,
TraceRepositoryAutoConfiguration
.
class
,
TraceWebFilterAutoConfiguration
.
class
);
assert
NotNull
(
context
.
getBean
(
WebRequestTraceFilter
.
class
)
);
assert
That
(
context
.
getBean
(
WebRequestTraceFilter
.
class
)).
isNotNull
(
);
context
.
close
();
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AbstractEndpointTests.java
View file @
94677b35
...
...
@@ -31,8 +31,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import
org.springframework.core.env.MapPropertySource
;
import
org.springframework.core.env.PropertySource
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Abstract base class for endpoint tests.
...
...
@@ -79,12 +78,12 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
@Test
public
void
getId
()
throws
Exception
{
assertThat
(
getEndpointBean
().
getId
()
,
equalTo
(
this
.
id
)
);
assertThat
(
getEndpointBean
().
getId
()
).
isEqualTo
(
this
.
id
);
}
@Test
public
void
isSensitive
()
throws
Exception
{
assertThat
(
getEndpointBean
().
isSensitive
()
,
equalTo
(
this
.
sensitive
)
);
assertThat
(
getEndpointBean
().
isSensitive
()
).
isEqualTo
(
this
.
sensitive
);
}
@Test
...
...
@@ -93,7 +92,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
this
.
property
+
".id:myid"
);
this
.
context
.
register
(
this
.
configClass
);
this
.
context
.
refresh
();
assertThat
(
getEndpointBean
().
getId
()
,
equalTo
(
"myid"
)
);
assertThat
(
getEndpointBean
().
getId
()
).
isEqualTo
(
"myid"
);
}
@Test
...
...
@@ -105,7 +104,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
this
.
context
.
getEnvironment
().
getPropertySources
().
addFirst
(
propertySource
);
this
.
context
.
register
(
this
.
configClass
);
this
.
context
.
refresh
();
assertThat
(
getEndpointBean
().
isSensitive
()
,
equalTo
(!
this
.
sensitive
)
);
assertThat
(
getEndpointBean
().
isSensitive
()
).
isEqualTo
(!
this
.
sensitive
);
}
@Test
...
...
@@ -118,12 +117,12 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
this
.
context
.
getEnvironment
().
getPropertySources
().
addFirst
(
propertySource
);
this
.
context
.
register
(
this
.
configClass
);
this
.
context
.
refresh
();
assertThat
(
getEndpointBean
().
isSensitive
()
,
equalTo
(!
this
.
sensitive
)
);
assertThat
(
getEndpointBean
().
isSensitive
()
).
isEqualTo
(!
this
.
sensitive
);
}
@Test
public
void
isEnabledByDefault
()
throws
Exception
{
assertThat
(
getEndpointBean
().
isEnabled
()
,
equalTo
(
true
)
);
assertThat
(
getEndpointBean
().
isEnabled
()
).
isTrue
(
);
}
@Test
...
...
@@ -134,7 +133,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
this
.
context
.
getEnvironment
().
getPropertySources
().
addFirst
(
propertySource
);
this
.
context
.
register
(
this
.
configClass
);
this
.
context
.
refresh
();
assertThat
(
getEndpointBean
().
isEnabled
()
,
equalTo
(
false
)
);
assertThat
(
getEndpointBean
().
isEnabled
()
).
isFalse
(
);
}
@Test
...
...
@@ -147,7 +146,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
this
.
context
.
register
(
this
.
configClass
);
this
.
context
.
refresh
();
((
AbstractEndpoint
)
getEndpointBean
()).
setEnabled
(
true
);
assertThat
(
getEndpointBean
().
isEnabled
()
,
equalTo
(
true
)
);
assertThat
(
getEndpointBean
().
isEnabled
()
).
isTrue
(
);
}
@Test
...
...
@@ -158,7 +157,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
this
.
context
.
getEnvironment
().
getPropertySources
().
addFirst
(
propertySource
);
this
.
context
.
register
(
this
.
configClass
);
this
.
context
.
refresh
();
assertThat
(
getEndpointBean
().
isEnabled
()
,
equalTo
(
false
)
);
assertThat
(
getEndpointBean
().
isEnabled
()
).
isFalse
(
);
}
@Test
...
...
@@ -171,7 +170,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
this
.
context
.
getEnvironment
().
getPropertySources
().
addFirst
(
propertySource
);
this
.
context
.
register
(
this
.
configClass
);
this
.
context
.
refresh
();
assertThat
(
getEndpointBean
().
isEnabled
()
,
equalTo
(
true
)
);
assertThat
(
getEndpointBean
().
isEnabled
()
).
isTrue
(
);
}
@Test
...
...
@@ -199,7 +198,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
this
.
context
.
getEnvironment
().
getPropertySources
().
addFirst
(
propertySource
);
this
.
context
.
register
(
this
.
configClass
);
this
.
context
.
refresh
();
assertThat
(
getEndpointBean
().
isSensitive
()
,
equalTo
(
sensitive
)
);
assertThat
(
getEndpointBean
().
isSensitive
()
).
isEqualTo
(
sensitive
);
}
@SuppressWarnings
(
"unchecked"
)
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AutoConfigurationReportEndpointTests.java
View file @
94677b35
...
...
@@ -33,7 +33,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Condition
;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
...
...
@@ -57,9 +57,9 @@ public class AutoConfigurationReportEndpointTests
this
.
context
.
register
(
this
.
configClass
);
this
.
context
.
refresh
();
Report
report
=
getEndpointBean
().
invoke
();
assertT
rue
(
report
.
getPositiveMatches
().
isEmpty
()
);
assertT
rue
(
report
.
getNegativeMatches
().
containsKey
(
"a"
)
);
assertT
rue
(
report
.
getExclusions
().
contains
(
"com.foo.Bar"
)
);
assertT
hat
(
report
.
getPositiveMatches
()).
isEmpty
(
);
assertT
hat
(
report
.
getNegativeMatches
()).
containsKey
(
"a"
);
assertT
hat
(
report
.
getExclusions
()).
contains
(
"com.foo.Bar"
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/BeansEndpointTests.java
View file @
94677b35
...
...
@@ -25,8 +25,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link BeansEndpoint}.
...
...
@@ -42,8 +41,8 @@ public class BeansEndpointTests extends AbstractEndpointTests<BeansEndpoint> {
@Test
public
void
invoke
()
throws
Exception
{
List
<
Object
>
result
=
getEndpointBean
().
invoke
();
assert
Equals
(
1
,
result
.
size
()
);
assertT
rue
(
result
.
get
(
0
)
instanceof
Map
);
assert
That
(
result
).
hasSize
(
1
);
assertT
hat
(
result
.
get
(
0
)).
isInstanceOf
(
Map
.
class
);
}
@Configuration
...
...
@@ -56,4 +55,5 @@ public class BeansEndpointTests extends AbstractEndpointTests<BeansEndpoint> {
}
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointMethodAnnotationsTests.java
View file @
94677b35
...
...
@@ -29,8 +29,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ConfigurationPropertiesReportEndpoint} when used with bean methods.
...
...
@@ -65,9 +64,9 @@ public class ConfigurationPropertiesReportEndpointMethodAnnotationsTests {
Map
<
String
,
Object
>
properties
=
report
.
invoke
();
Map
<
String
,
Object
>
nestedProperties
=
(
Map
<
String
,
Object
>)
properties
.
get
(
"other"
);
assert
NotNull
(
nestedProperties
);
assert
Equals
(
"other"
,
nestedProperties
.
get
(
"prefix"
)
);
assert
NotNull
(
nestedProperties
.
get
(
"properties"
)
);
assert
That
(
nestedProperties
).
isNotNull
(
);
assert
That
(
nestedProperties
.
get
(
"prefix"
)).
isEqualTo
(
"other"
);
assert
That
(
nestedProperties
.
get
(
"properties"
)).
isNotNull
(
);
}
@Test
...
...
@@ -81,9 +80,9 @@ public class ConfigurationPropertiesReportEndpointMethodAnnotationsTests {
Map
<
String
,
Object
>
properties
=
report
.
invoke
();
Map
<
String
,
Object
>
nestedProperties
=
(
Map
<
String
,
Object
>)
properties
.
get
(
"bar"
);
assert
NotNull
(
nestedProperties
);
assert
Equals
(
"other"
,
nestedProperties
.
get
(
"prefix"
)
);
assert
NotNull
(
nestedProperties
.
get
(
"properties"
)
);
assert
That
(
nestedProperties
).
isNotNull
(
);
assert
That
(
nestedProperties
.
get
(
"prefix"
)).
isEqualTo
(
"other"
);
assert
That
(
nestedProperties
.
get
(
"properties"
)).
isNotNull
(
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointParentTests.java
View file @
94677b35
...
...
@@ -28,8 +28,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ConfigurationPropertiesReportEndpoint} when used with a parent
...
...
@@ -63,8 +62,8 @@ public class ConfigurationPropertiesReportEndpointParentTests {
ConfigurationPropertiesReportEndpoint
endpoint
=
this
.
context
.
getBean
(
ConfigurationPropertiesReportEndpoint
.
class
);
Map
<
String
,
Object
>
result
=
endpoint
.
invoke
();
assertT
rue
(
result
.
containsKey
(
"parent"
)
);
assert
Equals
(
3
,
result
.
size
()
);
// the endpoint, the test props and the parent
assertT
hat
(
result
).
containsKey
(
"parent"
);
assert
That
(
result
).
hasSize
(
3
);
// the endpoint, the test props and the parent
// System.err.println(result);
}
...
...
@@ -80,8 +79,8 @@ public class ConfigurationPropertiesReportEndpointParentTests {
ConfigurationPropertiesReportEndpoint
endpoint
=
this
.
context
.
getBean
(
ConfigurationPropertiesReportEndpoint
.
class
);
Map
<
String
,
Object
>
result
=
endpoint
.
invoke
();
assertT
rue
(
result
.
containsKey
(
"parent"
)
);
assert
Equals
(
3
,
result
.
size
()
);
// the endpoint, the test props and the parent
assertT
hat
(
result
.
containsKey
(
"parent"
)).
isTrue
(
);
assert
That
(
result
).
hasSize
(
3
);
// the endpoint, the test props and the parent
// System.err.println(result);
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointProxyTests.java
View file @
94677b35
...
...
@@ -38,8 +38,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ConfigurationPropertiesReportEndpoint} when used against a proxy
...
...
@@ -69,7 +68,7 @@ public class ConfigurationPropertiesReportEndpointProxyTests {
this
.
context
.
refresh
();
Map
<
String
,
Object
>
report
=
this
.
context
.
getBean
(
ConfigurationPropertiesReportEndpoint
.
class
).
invoke
();
assertThat
(
report
.
toString
()
,
containsString
(
"prefix=executor.sql"
)
);
assertThat
(
report
.
toString
()
).
contains
(
"prefix=executor.sql"
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointSerializationTests.java
View file @
94677b35
...
...
@@ -32,8 +32,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ConfigurationPropertiesReportEndpoint} serialization.
...
...
@@ -67,13 +66,13 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
Map
<
String
,
Object
>
properties
=
report
.
invoke
();
Map
<
String
,
Object
>
nestedProperties
=
(
Map
<
String
,
Object
>)
properties
.
get
(
"foo"
);
assert
NotNull
(
nestedProperties
);
assert
Equals
(
"foo"
,
nestedProperties
.
get
(
"prefix"
)
);
assert
That
(
nestedProperties
).
isNotNull
(
);
assert
That
(
nestedProperties
.
get
(
"prefix"
)).
isEqualTo
(
"foo"
);
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
nestedProperties
.
get
(
"properties"
);
assert
NotNull
(
map
);
assert
Equals
(
2
,
map
.
size
()
);
assert
Equals
(
"foo"
,
map
.
get
(
"name"
)
);
assert
That
(
map
).
isNotNull
(
);
assert
That
(
map
).
hasSize
(
2
);
assert
That
(
map
.
get
(
"name"
)).
isEqualTo
(
"foo"
);
}
@Test
...
...
@@ -87,12 +86,12 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
Map
<
String
,
Object
>
properties
=
report
.
invoke
();
Map
<
String
,
Object
>
nestedProperties
=
(
Map
<
String
,
Object
>)
properties
.
get
(
"foo"
);
assert
NotNull
(
nestedProperties
);
assert
That
(
nestedProperties
).
isNotNull
(
);
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
nestedProperties
.
get
(
"properties"
);
assert
NotNull
(
map
);
assert
Equals
(
2
,
map
.
size
()
);
assert
Equals
(
"foo"
,
((
Map
<
String
,
Object
>)
map
.
get
(
"bar"
)).
get
(
"name"
)
);
assert
That
(
map
).
isNotNull
(
);
assert
That
(
map
).
hasSize
(
2
);
assert
That
(((
Map
<
String
,
Object
>)
map
.
get
(
"bar"
)).
get
(
"name"
)).
isEqualTo
(
"foo"
);
}
@Test
...
...
@@ -106,13 +105,13 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
Map
<
String
,
Object
>
properties
=
report
.
invoke
();
Map
<
String
,
Object
>
nestedProperties
=
(
Map
<
String
,
Object
>)
properties
.
get
(
"foo"
);
assert
NotNull
(
nestedProperties
);
assert
Equals
(
"foo"
,
nestedProperties
.
get
(
"prefix"
)
);
assert
That
(
nestedProperties
).
isNotNull
(
);
assert
That
(
nestedProperties
.
get
(
"prefix"
)).
isEqualTo
(
"foo"
);
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
nestedProperties
.
get
(
"properties"
);
assert
NotNull
(
map
);
assert
Equals
(
1
,
map
.
size
()
);
assert
Equals
(
"Cannot serialize 'foo'"
,
map
.
get
(
"error"
)
);
assert
That
(
map
).
isNotNull
(
);
assert
That
(
map
).
hasSize
(
1
);
assert
That
(
map
.
get
(
"error"
)).
isEqualTo
(
"Cannot serialize 'foo'"
);
}
@Test
...
...
@@ -126,13 +125,13 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
Map
<
String
,
Object
>
properties
=
report
.
invoke
();
Map
<
String
,
Object
>
nestedProperties
=
(
Map
<
String
,
Object
>)
properties
.
get
(
"foo"
);
assert
NotNull
(
nestedProperties
);
assert
Equals
(
"foo"
,
nestedProperties
.
get
(
"prefix"
)
);
assert
That
(
nestedProperties
).
isNotNull
(
);
assert
That
(
nestedProperties
.
get
(
"prefix"
)).
isEqualTo
(
"foo"
);
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
nestedProperties
.
get
(
"properties"
);
assert
NotNull
(
map
);
assert
Equals
(
3
,
map
.
size
()
);
assert
Equals
(
"foo"
,
((
Map
<
String
,
Object
>)
map
.
get
(
"map"
)).
get
(
"name"
)
);
assert
That
(
map
).
isNotNull
(
);
assert
That
(
map
).
hasSize
(
3
);
assert
That
(((
Map
<
String
,
Object
>)
map
.
get
(
"map"
)).
get
(
"name"
)).
isEqualTo
(
"foo"
);
}
@Test
...
...
@@ -145,14 +144,14 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
Map
<
String
,
Object
>
properties
=
report
.
invoke
();
Map
<
String
,
Object
>
nestedProperties
=
(
Map
<
String
,
Object
>)
properties
.
get
(
"foo"
);
assert
NotNull
(
nestedProperties
);
assert
That
(
nestedProperties
).
isNotNull
(
);
System
.
err
.
println
(
nestedProperties
);
assert
Equals
(
"foo"
,
nestedProperties
.
get
(
"prefix"
)
);
assert
That
(
nestedProperties
.
get
(
"prefix"
)).
isEqualTo
(
"foo"
);
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
nestedProperties
.
get
(
"properties"
);
assert
NotNull
(
map
);
assert
Equals
(
3
,
map
.
size
()
);
assert
Equals
(
null
,
(
map
.
get
(
"map"
))
);
assert
That
(
map
).
isNotNull
(
);
assert
That
(
map
).
hasSize
(
3
);
assert
That
((
map
.
get
(
"map"
))).
isNull
(
);
}
@Test
...
...
@@ -166,13 +165,13 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
Map
<
String
,
Object
>
properties
=
report
.
invoke
();
Map
<
String
,
Object
>
nestedProperties
=
(
Map
<
String
,
Object
>)
properties
.
get
(
"foo"
);
assert
NotNull
(
nestedProperties
);
assert
Equals
(
"foo"
,
nestedProperties
.
get
(
"prefix"
)
);
assert
That
(
nestedProperties
).
isNotNull
(
);
assert
That
(
nestedProperties
.
get
(
"prefix"
)).
isEqualTo
(
"foo"
);
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
nestedProperties
.
get
(
"properties"
);
assert
NotNull
(
map
);
assert
Equals
(
3
,
map
.
size
()
);
assert
Equals
(
"foo"
,
((
List
<
String
>)
map
.
get
(
"list"
)).
get
(
0
)
);
assert
That
(
map
).
isNotNull
(
);
assert
That
(
map
).
hasSize
(
3
);
assert
That
(((
List
<
String
>)
map
.
get
(
"list"
)).
get
(
0
)).
isEqualTo
(
"foo"
);
}
@Test
...
...
@@ -186,14 +185,14 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
Map
<
String
,
Object
>
properties
=
report
.
invoke
();
Map
<
String
,
Object
>
nestedProperties
=
(
Map
<
String
,
Object
>)
properties
.
get
(
"foo"
);
assert
NotNull
(
nestedProperties
);
assert
That
(
nestedProperties
).
isNotNull
(
);
System
.
err
.
println
(
nestedProperties
);
assert
Equals
(
"foo"
,
nestedProperties
.
get
(
"prefix"
)
);
assert
That
(
nestedProperties
.
get
(
"prefix"
)).
isEqualTo
(
"foo"
);
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
nestedProperties
.
get
(
"properties"
);
assert
NotNull
(
map
);
assert
Equals
(
3
,
map
.
size
()
);
assert
Equals
(
"192.168.1.10"
,
map
.
get
(
"address"
)
);
assert
That
(
map
).
isNotNull
(
);
assert
That
(
map
).
hasSize
(
3
);
assert
That
(
map
.
get
(
"address"
)).
isEqualTo
(
"192.168.1.10"
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointTests.java
View file @
94677b35
...
...
@@ -28,11 +28,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
greaterThan
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ConfigurationPropertiesReportEndpoint}.
...
...
@@ -49,7 +45,7 @@ public class ConfigurationPropertiesReportEndpointTests
@Test
public
void
testInvoke
()
throws
Exception
{
assertThat
(
getEndpointBean
().
invoke
().
size
()
,
greaterThan
(
0
)
);
assertThat
(
getEndpointBean
().
invoke
().
size
()
).
isGreaterThan
(
0
);
}
@Test
...
...
@@ -59,9 +55,9 @@ public class ConfigurationPropertiesReportEndpointTests
Map
<
String
,
Object
>
properties
=
report
.
invoke
();
Map
<
String
,
Object
>
nestedProperties
=
(
Map
<
String
,
Object
>)
properties
.
get
(
"testProperties"
);
assert
NotNull
(
nestedProperties
);
assert
Equals
(
"test"
,
nestedProperties
.
get
(
"prefix"
)
);
assert
NotNull
(
nestedProperties
.
get
(
"properties"
)
);
assert
That
(
nestedProperties
).
isNotNull
(
);
assert
That
(
nestedProperties
.
get
(
"prefix"
)).
isEqualTo
(
"test"
);
assert
That
(
nestedProperties
.
get
(
"properties"
)).
isNotNull
(
);
}
@Test
...
...
@@ -71,9 +67,9 @@ public class ConfigurationPropertiesReportEndpointTests
Map
<
String
,
Object
>
properties
=
report
.
invoke
();
Map
<
String
,
Object
>
nestedProperties
=
(
Map
<
String
,
Object
>)
((
Map
<
String
,
Object
>)
properties
.
get
(
"testProperties"
)).
get
(
"properties"
);
assert
NotNull
(
nestedProperties
);
assert
Equals
(
"******"
,
nestedProperties
.
get
(
"dbPassword"
)
);
assert
Equals
(
"654321"
,
nestedProperties
.
get
(
"myTestProperty"
)
);
assert
That
(
nestedProperties
).
isNotNull
(
);
assert
That
(
nestedProperties
.
get
(
"dbPassword"
)).
isEqualTo
(
"******"
);
assert
That
(
nestedProperties
.
get
(
"myTestProperty"
)).
isEqualTo
(
"654321"
);
}
@Test
...
...
@@ -84,9 +80,9 @@ public class ConfigurationPropertiesReportEndpointTests
Map
<
String
,
Object
>
properties
=
report
.
invoke
();
Map
<
String
,
Object
>
nestedProperties
=
(
Map
<
String
,
Object
>)
((
Map
<
String
,
Object
>)
properties
.
get
(
"testProperties"
)).
get
(
"properties"
);
assert
NotNull
(
nestedProperties
);
assert
Equals
(
"123456"
,
nestedProperties
.
get
(
"dbPassword"
)
);
assert
Equals
(
"******"
,
nestedProperties
.
get
(
"myTestProperty"
)
);
assert
That
(
nestedProperties
).
isNotNull
(
);
assert
That
(
nestedProperties
.
get
(
"dbPassword"
)).
isEqualTo
(
"123456"
);
assert
That
(
nestedProperties
.
get
(
"myTestProperty"
)).
isEqualTo
(
"******"
);
}
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -97,9 +93,9 @@ public class ConfigurationPropertiesReportEndpointTests
Map
<
String
,
Object
>
properties
=
report
.
invoke
();
Map
<
String
,
Object
>
nestedProperties
=
(
Map
<
String
,
Object
>)
((
Map
<
String
,
Object
>)
properties
.
get
(
"testProperties"
)).
get
(
"properties"
);
assert
NotNull
(
nestedProperties
);
assert
Equals
(
"******"
,
nestedProperties
.
get
(
"dbPassword"
)
);
assert
Equals
(
"654321"
,
nestedProperties
.
get
(
"myTestProperty"
)
);
assert
That
(
nestedProperties
).
isNotNull
(
);
assert
That
(
nestedProperties
.
get
(
"dbPassword"
)).
isEqualTo
(
"******"
);
assert
That
(
nestedProperties
.
get
(
"myTestProperty"
)).
isEqualTo
(
"654321"
);
}
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -114,9 +110,9 @@ public class ConfigurationPropertiesReportEndpointTests
Map
<
String
,
Object
>
properties
=
report
.
invoke
();
Map
<
String
,
Object
>
nestedProperties
=
(
Map
<
String
,
Object
>)
((
Map
<
String
,
Object
>)
properties
.
get
(
"testProperties"
)).
get
(
"properties"
);
assert
NotNull
(
nestedProperties
);
assert
Equals
(
"123456"
,
nestedProperties
.
get
(
"dbPassword"
)
);
assert
Equals
(
"******"
,
nestedProperties
.
get
(
"myTestProperty"
)
);
assert
That
(
nestedProperties
).
isNotNull
(
);
assert
That
(
nestedProperties
.
get
(
"dbPassword"
)).
isEqualTo
(
"123456"
);
assert
That
(
nestedProperties
.
get
(
"myTestProperty"
)).
isEqualTo
(
"******"
);
}
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -131,9 +127,9 @@ public class ConfigurationPropertiesReportEndpointTests
Map
<
String
,
Object
>
properties
=
report
.
invoke
();
Map
<
String
,
Object
>
nestedProperties
=
(
Map
<
String
,
Object
>)
((
Map
<
String
,
Object
>)
properties
.
get
(
"testProperties"
)).
get
(
"properties"
);
assert
NotNull
(
nestedProperties
);
assert
Equals
(
"******"
,
nestedProperties
.
get
(
"dbPassword"
)
);
assert
Equals
(
"654321"
,
nestedProperties
.
get
(
"myTestProperty"
)
);
assert
That
(
nestedProperties
).
isNotNull
(
);
assert
That
(
nestedProperties
.
get
(
"dbPassword"
)).
isEqualTo
(
"******"
);
assert
That
(
nestedProperties
.
get
(
"myTestProperty"
)).
isEqualTo
(
"654321"
);
}
@Test
...
...
@@ -149,9 +145,9 @@ public class ConfigurationPropertiesReportEndpointTests
Map
<
String
,
Object
>
properties
=
report
.
invoke
();
Map
<
String
,
Object
>
nestedProperties
=
(
Map
<
String
,
Object
>)
((
Map
<
String
,
Object
>)
properties
.
get
(
"testProperties"
)).
get
(
"properties"
);
assert
NotNull
(
nestedProperties
);
assert
Equals
(
"******"
,
nestedProperties
.
get
(
"dbPassword"
)
);
assert
Equals
(
"******"
,
nestedProperties
.
get
(
"myTestProperty"
)
);
assert
That
(
nestedProperties
).
isNotNull
(
);
assert
That
(
nestedProperties
.
get
(
"dbPassword"
)).
isEqualTo
(
"******"
);
assert
That
(
nestedProperties
.
get
(
"myTestProperty"
)).
isEqualTo
(
"******"
);
}
@Test
...
...
@@ -168,13 +164,13 @@ public class ConfigurationPropertiesReportEndpointTests
Map
<
String
,
Object
>
properties
=
report
.
invoke
();
Map
<
String
,
Object
>
nestedProperties
=
(
Map
<
String
,
Object
>)
((
Map
<
String
,
Object
>)
properties
.
get
(
"testProperties"
)).
get
(
"properties"
);
assert
NotNull
(
nestedProperties
);
assert
That
(
nestedProperties
).
isNotNull
(
);
Map
<
String
,
Object
>
secrets
=
(
Map
<
String
,
Object
>)
nestedProperties
.
get
(
"secrets"
);
Map
<
String
,
Object
>
hidden
=
(
Map
<
String
,
Object
>)
nestedProperties
.
get
(
"hidden"
);
assert
Equals
(
"******"
,
secrets
.
get
(
"mine"
)
);
assert
Equals
(
"******"
,
secrets
.
get
(
"yours"
)
);
assert
Equals
(
"******"
,
hidden
.
get
(
"mine"
)
);
assert
That
(
secrets
.
get
(
"mine"
)).
isEqualTo
(
"******"
);
assert
That
(
secrets
.
get
(
"yours"
)).
isEqualTo
(
"******"
);
assert
That
(
hidden
.
get
(
"mine"
)).
isEqualTo
(
"******"
);
}
@Test
...
...
@@ -184,7 +180,7 @@ public class ConfigurationPropertiesReportEndpointTests
Map
<
String
,
Object
>
properties
=
report
.
invoke
();
Map
<
String
,
Object
>
nestedProperties
=
(
Map
<
String
,
Object
>)
((
Map
<
String
,
Object
>)
properties
.
get
(
"testProperties"
)).
get
(
"properties"
);
assertThat
(
nestedProperties
.
get
(
"mixedBoolean"
)
,
equalTo
((
Object
)
true
)
);
assertThat
(
nestedProperties
.
get
(
"mixedBoolean"
)
).
isEqualTo
(
true
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/DumpEndpointTests.java
View file @
94677b35
...
...
@@ -25,8 +25,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
hamcrest
.
Matchers
.
greaterThan
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link DumpEndpoint}.
...
...
@@ -42,7 +41,7 @@ public class DumpEndpointTests extends AbstractEndpointTests<DumpEndpoint> {
@Test
public
void
invoke
()
throws
Exception
{
List
<
ThreadInfo
>
threadInfo
=
getEndpointBean
().
invoke
();
assertThat
(
threadInfo
.
size
()
,
greaterThan
(
0
)
);
assertThat
(
threadInfo
.
size
()
).
isGreaterThan
(
0
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpointTests.java
View file @
94677b35
...
...
@@ -29,9 +29,7 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.core.env.CompositePropertySource
;
import
org.springframework.core.env.MapPropertySource
;
import
static
org
.
hamcrest
.
Matchers
.
greaterThan
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link EnvironmentEndpoint}.
...
...
@@ -49,7 +47,7 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
@Test
public
void
invoke
()
throws
Exception
{
assertThat
(
getEndpointBean
().
invoke
()
.
size
(),
greaterThan
(
0
)
);
assertThat
(
getEndpointBean
().
invoke
()
).
isNotEmpty
(
);
}
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -63,7 +61,8 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
Collections
.
singletonMap
(
"foo"
,
(
Object
)
"spam"
)));
this
.
context
.
getEnvironment
().
getPropertySources
().
addFirst
(
source
);
Map
<
String
,
Object
>
env
=
report
.
invoke
();
assertEquals
(
"bar"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"composite:one"
)).
get
(
"foo"
));
assertThat
(((
Map
<
String
,
Object
>)
env
.
get
(
"composite:one"
)).
get
(
"foo"
))
.
isEqualTo
(
"bar"
);
}
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -76,16 +75,13 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
System
.
setProperty
(
"VCAP_SERVICES"
,
"123456"
);
EnvironmentEndpoint
report
=
getEndpointBean
();
Map
<
String
,
Object
>
env
=
report
.
invoke
();
assertEquals
(
"******"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
)).
get
(
"dbPassword"
));
assertEquals
(
"******"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
)).
get
(
"apiKey"
));
assertEquals
(
"******"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
)).
get
(
"mySecret"
));
assertEquals
(
"******"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
)).
get
(
"myCredentials"
));
assertEquals
(
"******"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
)).
get
(
"VCAP_SERVICES"
));
Map
<
String
,
Object
>
systemProperties
=
(
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
);
assertThat
(
systemProperties
.
get
(
"dbPassword"
)).
isEqualTo
(
"******"
);
assertThat
(
systemProperties
.
get
(
"apiKey"
)).
isEqualTo
(
"******"
);
assertThat
(
systemProperties
.
get
(
"mySecret"
)).
isEqualTo
(
"******"
);
assertThat
(
systemProperties
.
get
(
"myCredentials"
)).
isEqualTo
(
"******"
);
assertThat
(
systemProperties
.
get
(
"VCAP_SERVICES"
)).
isEqualTo
(
"******"
);
}
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -97,14 +93,14 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
System
.
setProperty
(
"foo.mycredentials.uri"
,
"123456"
);
EnvironmentEndpoint
report
=
getEndpointBean
();
Map
<
String
,
Object
>
env
=
report
.
invoke
();
assertEquals
(
"******"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
))
.
get
(
"
my.services.amqp-free.credentials.uri"
)
);
assert
Equals
(
"******"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties
"
))
.
get
(
"credentials.http_api_uri"
)
);
assert
Equals
(
"******"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
))
.
get
(
"my.services.cleardb-free.credentials"
));
assertEquals
(
"******"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
))
.
get
(
"foo.mycredentials.uri"
)
);
Map
<
String
,
Object
>
systemProperties
=
(
Map
<
String
,
Object
>)
env
.
get
(
"
systemProperties"
);
assert
That
(
systemProperties
.
get
(
"my.services.amqp-free.credentials.uri
"
))
.
isEqualTo
(
"******"
);
assert
That
(
systemProperties
.
get
(
"credentials.http_api_uri"
)).
isEqualTo
(
"******"
);
assertThat
(
systemProperties
.
get
(
"my.services.cleardb-free.credentials"
))
.
isEqualTo
(
"******"
);
assertThat
(
systemProperties
.
get
(
"foo.mycredentials.uri"
)).
isEqualTo
(
"******"
);
}
...
...
@@ -116,10 +112,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
EnvironmentEndpoint
report
=
getEndpointBean
();
report
.
setKeysToSanitize
(
"key"
);
Map
<
String
,
Object
>
env
=
report
.
invoke
();
assertEquals
(
"123456"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
)).
get
(
"dbPassword"
)
);
assert
Equals
(
"******"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
)).
get
(
"apiKey"
)
);
Map
<
String
,
Object
>
systemProperties
=
(
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
);
assert
That
(
systemProperties
.
get
(
"dbPassword"
)).
isEqualTo
(
"123456"
);
assertThat
(
systemProperties
.
get
(
"apiKey"
)).
isEqualTo
(
"******"
);
}
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -130,10 +126,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
EnvironmentEndpoint
report
=
getEndpointBean
();
report
.
setKeysToSanitize
(
".*pass.*"
);
Map
<
String
,
Object
>
env
=
report
.
invoke
();
assertEquals
(
"******"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
)).
get
(
"dbPassword"
)
);
assert
Equals
(
"123456"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
)).
get
(
"apiKey"
)
);
Map
<
String
,
Object
>
systemProperties
=
(
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
);
assert
That
(
systemProperties
.
get
(
"dbPassword"
)).
isEqualTo
(
"******"
);
assertThat
(
systemProperties
.
get
(
"apiKey"
)).
isEqualTo
(
"123456"
);
}
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -148,10 +144,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
System
.
setProperty
(
"apiKey"
,
"123456"
);
EnvironmentEndpoint
report
=
getEndpointBean
();
Map
<
String
,
Object
>
env
=
report
.
invoke
();
assertEquals
(
"123456"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
)).
get
(
"dbPassword"
)
);
assert
Equals
(
"******"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
)).
get
(
"apiKey"
)
);
Map
<
String
,
Object
>
systemProperties
=
(
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
);
assert
That
(
systemProperties
.
get
(
"dbPassword"
)).
isEqualTo
(
"123456"
);
assertThat
(
systemProperties
.
get
(
"apiKey"
)).
isEqualTo
(
"******"
);
}
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -166,10 +162,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
System
.
setProperty
(
"apiKey"
,
"123456"
);
EnvironmentEndpoint
report
=
getEndpointBean
();
Map
<
String
,
Object
>
env
=
report
.
invoke
();
assertEquals
(
"******"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
)).
get
(
"dbPassword"
)
);
assert
Equals
(
"123456"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
)).
get
(
"apiKey"
)
);
Map
<
String
,
Object
>
systemProperties
=
(
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
);
assert
That
(
systemProperties
.
get
(
"dbPassword"
)).
isEqualTo
(
"******"
);
assertThat
(
systemProperties
.
get
(
"apiKey"
)).
isEqualTo
(
"123456"
);
}
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -185,10 +181,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
System
.
setProperty
(
"apiKey"
,
"123456"
);
EnvironmentEndpoint
report
=
getEndpointBean
();
Map
<
String
,
Object
>
env
=
report
.
invoke
();
assertEquals
(
"******"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
)).
get
(
"dbPassword"
)
);
assert
Equals
(
"******"
,
((
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
)).
get
(
"apiKey"
)
);
Map
<
String
,
Object
>
systemProperties
=
(
Map
<
String
,
Object
>)
env
.
get
(
"systemProperties"
);
assert
That
(
systemProperties
.
get
(
"dbPassword"
)).
isEqualTo
(
"******"
);
assertThat
(
systemProperties
.
get
(
"apiKey"
)).
isEqualTo
(
"******"
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/FlywayEndpointTests.java
View file @
94677b35
...
...
@@ -26,8 +26,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link FlywayEndpoint}.
...
...
@@ -42,7 +41,7 @@ public class FlywayEndpointTests extends AbstractEndpointTests<FlywayEndpoint> {
@Test
public
void
invoke
()
throws
Exception
{
assertThat
(
getEndpointBean
().
invoke
()
.
size
(),
is
(
1
)
);
assertThat
(
getEndpointBean
().
invoke
()
).
hasSize
(
1
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/HealthEndpointTests.java
View file @
94677b35
...
...
@@ -29,8 +29,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link HealthEndpoint}.
...
...
@@ -47,7 +46,7 @@ public class HealthEndpointTests extends AbstractEndpointTests<HealthEndpoint> {
@Test
public
void
invoke
()
throws
Exception
{
// As FINE isn't configured in the order we get UNKNOWN
assertThat
(
getEndpointBean
().
invoke
().
getStatus
()
,
equalTo
(
Status
.
UNKNOWN
)
);
assertThat
(
getEndpointBean
().
invoke
().
getStatus
()
).
isEqualTo
(
Status
.
UNKNOWN
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/InfoEndpointTests.java
View file @
94677b35
...
...
@@ -24,8 +24,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link InfoEndpoint}.
...
...
@@ -41,7 +40,7 @@ public class InfoEndpointTests extends AbstractEndpointTests<InfoEndpoint> {
@Test
public
void
invoke
()
throws
Exception
{
assertThat
(
getEndpointBean
().
invoke
().
get
(
"a"
)
,
equalTo
((
Object
)
"b"
)
);
assertThat
(
getEndpointBean
().
invoke
().
get
(
"a"
)
).
isEqualTo
(
"b"
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpointTests.java
View file @
94677b35
...
...
@@ -26,8 +26,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link LiquibaseEndpoint}.
...
...
@@ -43,7 +42,7 @@ public class LiquibaseEndpointTests extends AbstractEndpointTests<LiquibaseEndpo
@Test
public
void
invoke
()
throws
Exception
{
assertThat
(
getEndpointBean
().
invoke
()
.
size
(),
is
(
1
)
);
assertThat
(
getEndpointBean
().
invoke
()
).
hasSize
(
1
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/MetricReaderPublicMetricsTests.java
View file @
94677b35
...
...
@@ -24,7 +24,7 @@ import org.junit.Test;
import
org.springframework.boot.actuate.metrics.Metric
;
import
org.springframework.boot.actuate.metrics.reader.MetricReader
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -43,7 +43,7 @@ public class MetricReaderPublicMetricsTests {
MetricReader
reader
=
mock
(
MetricReader
.
class
);
given
(
reader
.
findAll
()).
willReturn
(
metrics
);
MetricReaderPublicMetrics
publicMetrics
=
new
MetricReaderPublicMetrics
(
reader
);
assert
Equals
(
metrics
,
publicMetrics
.
metrics
()
);
assert
That
(
publicMetrics
.
metrics
()).
isEqualTo
(
metrics
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/MetricsEndpointTests.java
View file @
94677b35
...
...
@@ -33,10 +33,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.Ordered
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link MetricsEndpoint}.
...
...
@@ -57,7 +54,7 @@ public class MetricsEndpointTests extends AbstractEndpointTests<MetricsEndpoint>
@Test
public
void
invoke
()
throws
Exception
{
assertThat
(
getEndpointBean
().
invoke
().
get
(
"a"
)
,
equalTo
((
Object
)
0.5f
)
);
assertThat
(
getEndpointBean
().
invoke
().
get
(
"a"
)
).
isEqualTo
(
0.5f
);
}
@Test
...
...
@@ -68,10 +65,10 @@ public class MetricsEndpointTests extends AbstractEndpointTests<MetricsEndpoint>
publicMetrics
.
add
(
new
TestPublicMetrics
(
1
,
this
.
metric1
));
Map
<
String
,
Object
>
metrics
=
new
MetricsEndpoint
(
publicMetrics
).
invoke
();
Iterator
<
Entry
<
String
,
Object
>>
iterator
=
metrics
.
entrySet
().
iterator
();
assert
Equals
(
"a"
,
iterator
.
next
().
getKey
()
);
assert
Equals
(
"b"
,
iterator
.
next
().
getKey
()
);
assert
Equals
(
"c"
,
iterator
.
next
().
getKey
()
);
assert
False
(
iterator
.
hasNext
()
);
assert
That
(
iterator
.
next
().
getKey
()).
isEqualTo
(
"a"
);
assert
That
(
iterator
.
next
().
getKey
()).
isEqualTo
(
"b"
);
assert
That
(
iterator
.
next
().
getKey
()).
isEqualTo
(
"c"
);
assert
That
(
iterator
.
hasNext
()).
isFalse
(
);
}
private
static
class
TestPublicMetrics
implements
PublicMetrics
,
Ordered
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/RequestMappingEndpointTests.java
View file @
94677b35
...
...
@@ -35,8 +35,7 @@ import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping;
import
org.springframework.web.servlet.handler.AbstractUrlHandlerMapping
;
import
org.springframework.web.servlet.handler.SimpleUrlHandlerMapping
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link RequestMappingEndpoint}.
...
...
@@ -56,10 +55,10 @@ public class RequestMappingEndpointTests {
this
.
endpoint
.
setHandlerMappings
(
Collections
.<
AbstractUrlHandlerMapping
>
singletonList
(
mapping
));
Map
<
String
,
Object
>
result
=
this
.
endpoint
.
invoke
();
assert
Equals
(
1
,
result
.
size
()
);
assert
That
(
result
).
hasSize
(
1
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
result
.
get
(
"/foo"
);
assert
Equals
(
"java.lang.Object"
,
map
.
get
(
"type"
)
);
assert
That
(
map
.
get
(
"type"
)).
isEqualTo
(
"java.lang.Object"
);
}
@Test
...
...
@@ -72,10 +71,10 @@ public class RequestMappingEndpointTests {
context
.
getDefaultListableBeanFactory
().
registerSingleton
(
"mapping"
,
mapping
);
this
.
endpoint
.
setApplicationContext
(
context
);
Map
<
String
,
Object
>
result
=
this
.
endpoint
.
invoke
();
assert
Equals
(
1
,
result
.
size
()
);
assert
That
(
result
).
hasSize
(
1
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
result
.
get
(
"/foo"
);
assert
Equals
(
"mapping"
,
map
.
get
(
"bean"
)
);
assert
That
(
map
.
get
(
"bean"
)).
isEqualTo
(
"mapping"
);
}
@Test
...
...
@@ -84,10 +83,10 @@ public class RequestMappingEndpointTests {
MappingConfiguration
.
class
);
this
.
endpoint
.
setApplicationContext
(
context
);
Map
<
String
,
Object
>
result
=
this
.
endpoint
.
invoke
();
assert
Equals
(
1
,
result
.
size
()
);
assert
That
(
result
).
hasSize
(
1
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
result
.
get
(
"/foo"
);
assert
Equals
(
"scopedTarget.mapping"
,
map
.
get
(
"bean"
)
);
assert
That
(
map
.
get
(
"bean"
)).
isEqualTo
(
"scopedTarget.mapping"
);
}
@Test
...
...
@@ -100,12 +99,12 @@ public class RequestMappingEndpointTests {
context
.
getDefaultListableBeanFactory
().
registerSingleton
(
"mapping"
,
mapping
);
this
.
endpoint
.
setApplicationContext
(
context
);
Map
<
String
,
Object
>
result
=
this
.
endpoint
.
invoke
();
assert
Equals
(
1
,
result
.
size
()
);
assertT
rue
(
result
.
keySet
().
iterator
().
next
().
contains
(
"/dump"
)
);
assert
That
(
result
).
hasSize
(
1
);
assertT
hat
(
result
.
keySet
().
iterator
().
next
().
contains
(
"/dump"
)).
isTrue
(
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
handler
=
(
Map
<
String
,
Object
>)
result
.
values
().
iterator
()
.
next
();
assertT
rue
(
handler
.
containsKey
(
"method"
)
);
assertT
hat
(
handler
.
containsKey
(
"method"
)).
isTrue
(
);
}
@Test
...
...
@@ -117,12 +116,12 @@ public class RequestMappingEndpointTests {
this
.
endpoint
.
setMethodMappings
(
Collections
.<
AbstractHandlerMethodMapping
<?>>
singletonList
(
mapping
));
Map
<
String
,
Object
>
result
=
this
.
endpoint
.
invoke
();
assert
Equals
(
1
,
result
.
size
()
);
assertT
rue
(
result
.
keySet
().
iterator
().
next
().
contains
(
"/dump"
)
);
assert
That
(
result
).
hasSize
(
1
);
assertT
hat
(
result
.
keySet
().
iterator
().
next
().
contains
(
"/dump"
)).
isTrue
(
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
handler
=
(
Map
<
String
,
Object
>)
result
.
values
().
iterator
()
.
next
();
assertT
rue
(
handler
.
containsKey
(
"method"
)
);
assertT
hat
(
handler
.
containsKey
(
"method"
)).
isTrue
(
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/RichGaugeReaderPublicMetricsTests.java
View file @
94677b35
...
...
@@ -25,9 +25,7 @@ import org.junit.Test;
import
org.springframework.boot.actuate.metrics.Metric
;
import
org.springframework.boot.actuate.metrics.rich.InMemoryRichGaugeRepository
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link RichGaugeReaderPublicMetrics}.
...
...
@@ -50,23 +48,23 @@ public class RichGaugeReaderPublicMetricsTests {
for
(
Metric
<?>
metric
:
metrics
.
metrics
())
{
results
.
put
(
metric
.
getName
(),
metric
);
}
assertT
rue
(
results
.
containsKey
(
"a.val"
)
);
assertThat
(
results
.
get
(
"a.val"
).
getValue
().
doubleValue
()
,
equalTo
(
0.5d
)
);
assertT
hat
(
results
.
containsKey
(
"a.val"
)).
isTrue
(
);
assertThat
(
results
.
get
(
"a.val"
).
getValue
().
doubleValue
()
).
isEqualTo
(
0.5d
);
assertT
rue
(
results
.
containsKey
(
"a.avg"
)
);
assertThat
(
results
.
get
(
"a.avg"
).
getValue
().
doubleValue
()
,
equalTo
(
0.25d
)
);
assertT
hat
(
results
.
containsKey
(
"a.avg"
)).
isTrue
(
);
assertThat
(
results
.
get
(
"a.avg"
).
getValue
().
doubleValue
()
).
isEqualTo
(
0.25d
);
assertT
rue
(
results
.
containsKey
(
"a.min"
)
);
assertThat
(
results
.
get
(
"a.min"
).
getValue
().
doubleValue
()
,
equalTo
(
0.0d
)
);
assertT
hat
(
results
.
containsKey
(
"a.min"
)).
isTrue
(
);
assertThat
(
results
.
get
(
"a.min"
).
getValue
().
doubleValue
()
).
isEqualTo
(
0.0d
);
assertT
rue
(
results
.
containsKey
(
"a.max"
)
);
assertThat
(
results
.
get
(
"a.max"
).
getValue
().
doubleValue
()
,
equalTo
(
0.5d
)
);
assertT
hat
(
results
.
containsKey
(
"a.max"
)).
isTrue
(
);
assertThat
(
results
.
get
(
"a.max"
).
getValue
().
doubleValue
()
).
isEqualTo
(
0.5d
);
assertT
rue
(
results
.
containsKey
(
"a.count"
)
);
assertThat
(
results
.
get
(
"a.count"
).
getValue
().
longValue
()
,
equalTo
(
2L
)
);
assertT
hat
(
results
.
containsKey
(
"a.count"
)).
isTrue
(
);
assertThat
(
results
.
get
(
"a.count"
).
getValue
().
longValue
()
).
isEqualTo
(
2L
);
assertT
rue
(
results
.
containsKey
(
"a.alpha"
)
);
assertThat
(
results
.
get
(
"a.alpha"
).
getValue
().
doubleValue
()
,
equalTo
(-
1
.
d
)
);
assertT
hat
(
results
.
containsKey
(
"a.alpha"
)).
isTrue
(
);
assertThat
(
results
.
get
(
"a.alpha"
).
getValue
().
doubleValue
()
).
isEqualTo
(-
1
.
d
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/SanitizerTests.java
View file @
94677b35
...
...
@@ -18,7 +18,7 @@ package org.springframework.boot.actuate.endpoint;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link Sanitizer}.
...
...
@@ -27,23 +27,22 @@ import static org.junit.Assert.assertEquals;
*/
public
class
SanitizerTests
{
private
Sanitizer
sanitizer
=
new
Sanitizer
();
@Test
public
void
defaults
()
throws
Exception
{
assertEquals
(
this
.
sanitizer
.
sanitize
(
"password"
,
"secret"
),
"******"
);
assertEquals
(
this
.
sanitizer
.
sanitize
(
"my-password"
,
"secret"
),
"******"
);
assertEquals
(
this
.
sanitizer
.
sanitize
(
"my-OTHER.paSSword"
,
"secret"
),
"******"
);
assertEquals
(
this
.
sanitizer
.
sanitize
(
"somesecret"
,
"secret"
),
"******"
);
assertEquals
(
this
.
sanitizer
.
sanitize
(
"somekey"
,
"secret"
),
"******"
);
assertEquals
(
this
.
sanitizer
.
sanitize
(
"find"
,
"secret"
),
"secret"
);
Sanitizer
sanitizer
=
new
Sanitizer
();
assertThat
(
sanitizer
.
sanitize
(
"password"
,
"secret"
)).
isEqualTo
(
"******"
);
assertThat
(
sanitizer
.
sanitize
(
"my-password"
,
"secret"
)).
isEqualTo
(
"******"
);
assertThat
(
sanitizer
.
sanitize
(
"my-OTHER.paSSword"
,
"secret"
)).
isEqualTo
(
"******"
);
assertThat
(
sanitizer
.
sanitize
(
"somesecret"
,
"secret"
)).
isEqualTo
(
"******"
);
assertThat
(
sanitizer
.
sanitize
(
"somekey"
,
"secret"
)).
isEqualTo
(
"******"
);
assertThat
(
sanitizer
.
sanitize
(
"find"
,
"secret"
)).
isEqualTo
(
"secret"
);
}
@Test
public
void
regex
()
throws
Exception
{
this
.
sanitizer
.
setKeysToSanitize
(
".*lock.*"
);
assert
Equals
(
this
.
sanitizer
.
sanitize
(
"verylOCkish"
,
"secret"
),
"******"
);
assert
Equals
(
this
.
sanitizer
.
sanitize
(
"veryokish"
,
"secret"
),
"secret"
);
Sanitizer
sanitizer
=
new
Sanitizer
(
".*lock.*"
);
assert
That
(
sanitizer
.
sanitize
(
"verylOCkish"
,
"secret"
)).
isEqualTo
(
"******"
);
assert
That
(
sanitizer
.
sanitize
(
"veryokish"
,
"secret"
)).
isEqualTo
(
"secret"
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ShutdownEndpointTests.java
View file @
94677b35
...
...
@@ -27,10 +27,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.event.ContextClosedEvent
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
startsWith
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ShutdownEndpoint}.
...
...
@@ -48,16 +45,16 @@ public class ShutdownEndpointTests extends AbstractEndpointTests<ShutdownEndpoin
@Override
public
void
isEnabledByDefault
()
throws
Exception
{
// Shutdown is dangerous so is disabled by default
assertThat
(
getEndpointBean
().
isEnabled
()
,
equalTo
(
false
)
);
assertThat
(
getEndpointBean
().
isEnabled
()
).
isFalse
(
);
}
@Test
public
void
invoke
()
throws
Exception
{
CountDownLatch
latch
=
this
.
context
.
getBean
(
Config
.
class
).
latch
;
assertThat
((
String
)
getEndpointBean
().
invoke
().
get
(
"message"
)
,
startsWith
(
"Shutting down"
)
);
assertT
rue
(
this
.
context
.
isActive
()
);
assertT
rue
(
latch
.
await
(
10
,
TimeUnit
.
SECONDS
)
);
assertThat
((
String
)
getEndpointBean
().
invoke
().
get
(
"message"
)
)
.
startsWith
(
"Shutting down"
);
assertT
hat
(
this
.
context
.
isActive
()).
isTrue
(
);
assertT
hat
(
latch
.
await
(
10
,
TimeUnit
.
SECONDS
)).
isTrue
(
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ShutdownParentEndpointTests.java
View file @
94677b35
...
...
@@ -31,9 +31,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.event.ContextClosedEvent
;
import
static
org
.
hamcrest
.
Matchers
.
startsWith
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ShutdownEndpoint}.
...
...
@@ -54,10 +52,10 @@ public class ShutdownParentEndpointTests {
this
.
context
=
new
SpringApplicationBuilder
(
Config
.
class
).
child
(
Empty
.
class
)
.
web
(
false
).
run
();
CountDownLatch
latch
=
this
.
context
.
getBean
(
Config
.
class
).
latch
;
assertThat
((
String
)
getEndpointBean
().
invoke
().
get
(
"message"
)
,
startsWith
(
"Shutting down"
)
);
assertT
rue
(
this
.
context
.
isActive
()
);
assertT
rue
(
latch
.
await
(
10
,
TimeUnit
.
SECONDS
)
);
assertThat
((
String
)
getEndpointBean
().
invoke
().
get
(
"message"
)
)
.
startsWith
(
"Shutting down"
);
assertT
hat
(
this
.
context
.
isActive
()).
isTrue
(
);
assertT
hat
(
latch
.
await
(
10
,
TimeUnit
.
SECONDS
)).
isTrue
(
);
}
@Test
...
...
@@ -65,10 +63,10 @@ public class ShutdownParentEndpointTests {
this
.
context
=
new
SpringApplicationBuilder
(
Empty
.
class
).
child
(
Config
.
class
)
.
web
(
false
).
run
();
CountDownLatch
latch
=
this
.
context
.
getBean
(
Config
.
class
).
latch
;
assertThat
((
String
)
getEndpointBean
().
invoke
().
get
(
"message"
)
,
startsWith
(
"Shutting down"
)
);
assertT
rue
(
this
.
context
.
isActive
()
);
assertT
rue
(
latch
.
await
(
10
,
TimeUnit
.
SECONDS
)
);
assertThat
((
String
)
getEndpointBean
().
invoke
().
get
(
"message"
)
)
.
startsWith
(
"Shutting down"
);
assertT
hat
(
this
.
context
.
isActive
()).
isTrue
(
);
assertT
hat
(
latch
.
await
(
10
,
TimeUnit
.
SECONDS
)).
isTrue
(
);
}
private
ShutdownEndpoint
getEndpointBean
()
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/SystemPublicMetricsTests.java
View file @
94677b35
...
...
@@ -23,7 +23,7 @@ import org.junit.Test;
import
org.springframework.boot.actuate.metrics.Metric
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link SystemPublicMetrics}
...
...
@@ -39,30 +39,26 @@ public class SystemPublicMetricsTests {
for
(
Metric
<?>
metric
:
publicMetrics
.
metrics
())
{
results
.
put
(
metric
.
getName
(),
metric
);
}
assertTrue
(
results
.
containsKey
(
"mem"
));
assertTrue
(
results
.
containsKey
(
"mem.free"
));
assertTrue
(
results
.
containsKey
(
"processors"
));
assertTrue
(
results
.
containsKey
(
"uptime"
));
assertTrue
(
results
.
containsKey
(
"systemload.average"
));
assertTrue
(
results
.
containsKey
(
"heap.committed"
));
assertTrue
(
results
.
containsKey
(
"heap.init"
));
assertTrue
(
results
.
containsKey
(
"heap.used"
));
assertTrue
(
results
.
containsKey
(
"heap"
));
assertTrue
(
results
.
containsKey
(
"nonheap.committed"
));
assertTrue
(
results
.
containsKey
(
"nonheap.init"
));
assertTrue
(
results
.
containsKey
(
"nonheap.used"
));
assertTrue
(
results
.
containsKey
(
"nonheap"
));
assertTrue
(
results
.
containsKey
(
"threads.peak"
));
assertTrue
(
results
.
containsKey
(
"threads.daemon"
));
assertTrue
(
results
.
containsKey
(
"threads.totalStarted"
));
assertTrue
(
results
.
containsKey
(
"threads"
));
assertTrue
(
results
.
containsKey
(
"classes.loaded"
));
assertTrue
(
results
.
containsKey
(
"classes.unloaded"
));
assertTrue
(
results
.
containsKey
(
"classes"
));
assertThat
(
results
).
containsKey
(
"mem"
);
assertThat
(
results
).
containsKey
(
"mem.free"
);
assertThat
(
results
).
containsKey
(
"processors"
);
assertThat
(
results
).
containsKey
(
"uptime"
);
assertThat
(
results
).
containsKey
(
"systemload.average"
);
assertThat
(
results
).
containsKey
(
"heap.committed"
);
assertThat
(
results
).
containsKey
(
"heap.init"
);
assertThat
(
results
).
containsKey
(
"heap.used"
);
assertThat
(
results
).
containsKey
(
"heap"
);
assertThat
(
results
).
containsKey
(
"nonheap.committed"
);
assertThat
(
results
).
containsKey
(
"nonheap.init"
);
assertThat
(
results
).
containsKey
(
"nonheap.used"
);
assertThat
(
results
).
containsKey
(
"nonheap"
);
assertThat
(
results
).
containsKey
(
"threads.peak"
);
assertThat
(
results
).
containsKey
(
"threads.daemon"
);
assertThat
(
results
).
containsKey
(
"threads.totalStarted"
);
assertThat
(
results
).
containsKey
(
"threads"
);
assertThat
(
results
).
containsKey
(
"classes.loaded"
);
assertThat
(
results
).
containsKey
(
"classes.unloaded"
);
assertThat
(
results
).
containsKey
(
"classes"
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetricsTests.java
View file @
94677b35
...
...
@@ -27,8 +27,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.util.SocketUtils
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link TomcatPublicMetrics}
...
...
@@ -46,9 +45,9 @@ public class TomcatPublicMetricsTests {
TomcatPublicMetrics
tomcatMetrics
=
context
.
getBean
(
TomcatPublicMetrics
.
class
);
Iterator
<
Metric
<?>>
metrics
=
tomcatMetrics
.
metrics
().
iterator
();
assertThat
(
metrics
.
next
().
getName
()
,
equalTo
(
"httpsessions.max"
)
);
assertThat
(
metrics
.
next
().
getName
()
,
equalTo
(
"httpsessions.active"
)
);
assertThat
(
metrics
.
hasNext
()
,
equalTo
(
false
)
);
assertThat
(
metrics
.
next
().
getName
()
).
isEqualTo
(
"httpsessions.max"
);
assertThat
(
metrics
.
next
().
getName
()
).
isEqualTo
(
"httpsessions.active"
);
assertThat
(
metrics
.
hasNext
()
).
isFalse
(
);
}
finally
{
context
.
close
();
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/TraceEndpointTests.java
View file @
94677b35
...
...
@@ -27,8 +27,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link TraceEndpoint}.
...
...
@@ -44,7 +43,7 @@ public class TraceEndpointTests extends AbstractEndpointTests<TraceEndpoint> {
@Test
public
void
invoke
()
throws
Exception
{
Trace
trace
=
getEndpointBean
().
invoke
().
get
(
0
);
assertThat
(
trace
.
getInfo
().
get
(
"a"
)
,
equalTo
((
Object
)
"b"
)
);
assertThat
(
trace
.
getInfo
().
get
(
"a"
)
).
isEqualTo
(
"b"
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanExporterTests.java
View file @
94677b35
...
...
@@ -42,13 +42,7 @@ import org.springframework.jmx.export.MBeanExporter;
import
org.springframework.jmx.support.ObjectNameManager
;
import
org.springframework.util.ObjectUtils
;
import
static
org
.
hamcrest
.
Matchers
.
instanceOf
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link EndpointMBeanExporter}
...
...
@@ -78,9 +72,9 @@ public class EndpointMBeanExporterTests {
MBeanExporter
mbeanExporter
=
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
);
MBeanInfo
mbeanInfo
=
mbeanExporter
.
getServer
()
.
getMBeanInfo
(
getObjectName
(
"endpoint1"
,
this
.
context
));
assert
NotNull
(
mbeanInfo
);
assert
Equals
(
3
,
mbeanInfo
.
getOperations
().
length
);
assert
Equals
(
3
,
mbeanInfo
.
getAttributes
().
length
);
assert
That
(
mbeanInfo
).
isNotNull
(
);
assert
That
(
mbeanInfo
.
getOperations
().
length
).
isEqualTo
(
3
);
assert
That
(
mbeanInfo
.
getAttributes
().
length
).
isEqualTo
(
3
);
}
@Test
...
...
@@ -94,8 +88,8 @@ public class EndpointMBeanExporterTests {
new
RootBeanDefinition
(
TestEndpoint
.
class
,
null
,
mpv
));
this
.
context
.
refresh
();
MBeanExporter
mbeanExporter
=
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
);
assert
False
(
mbeanExporter
.
getServer
()
.
isRegistered
(
getObjectName
(
"endpoint1"
,
this
.
context
)));
assert
That
(
mbeanExporter
.
getServer
()
.
isRegistered
(
getObjectName
(
"endpoint1"
,
this
.
context
)))
.
isFalse
()
;
}
@Test
...
...
@@ -109,8 +103,8 @@ public class EndpointMBeanExporterTests {
new
RootBeanDefinition
(
TestEndpoint
.
class
,
null
,
mpv
));
this
.
context
.
refresh
();
MBeanExporter
mbeanExporter
=
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
);
assertT
rue
(
mbeanExporter
.
getServer
()
.
isRegistered
(
getObjectName
(
"endpoint1"
,
this
.
context
)));
assertT
hat
(
mbeanExporter
.
getServer
()
.
isRegistered
(
getObjectName
(
"endpoint1"
,
this
.
context
)))
.
isTrue
()
;
}
@Test
...
...
@@ -124,10 +118,10 @@ public class EndpointMBeanExporterTests {
new
RootBeanDefinition
(
TestEndpoint
.
class
));
this
.
context
.
refresh
();
MBeanExporter
mbeanExporter
=
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
);
assert
NotNull
(
mbeanExporter
.
getServer
()
.
getMBeanInfo
(
getObjectName
(
"endpoint1"
,
this
.
context
)));
assert
NotNull
(
mbeanExporter
.
getServer
()
.
getMBeanInfo
(
getObjectName
(
"endpoint2"
,
this
.
context
)));
assert
That
(
mbeanExporter
.
getServer
()
.
getMBeanInfo
(
getObjectName
(
"endpoint1"
,
this
.
context
)))
.
isNotNull
()
;
assert
That
(
mbeanExporter
.
getServer
()
.
getMBeanInfo
(
getObjectName
(
"endpoint2"
,
this
.
context
)))
.
isNotNull
()
;
}
@Test
...
...
@@ -141,8 +135,9 @@ public class EndpointMBeanExporterTests {
new
RootBeanDefinition
(
TestEndpoint
.
class
));
this
.
context
.
refresh
();
MBeanExporter
mbeanExporter
=
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
);
assertNotNull
(
mbeanExporter
.
getServer
().
getMBeanInfo
(
getObjectName
(
"test-domain"
,
"endpoint1"
,
false
,
this
.
context
)));
assertThat
(
mbeanExporter
.
getServer
().
getMBeanInfo
(
getObjectName
(
"test-domain"
,
"endpoint1"
,
false
,
this
.
context
)))
.
isNotNull
();
}
@Test
...
...
@@ -158,8 +153,9 @@ public class EndpointMBeanExporterTests {
new
RootBeanDefinition
(
TestEndpoint
.
class
));
this
.
context
.
refresh
();
MBeanExporter
mbeanExporter
=
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
);
assertNotNull
(
mbeanExporter
.
getServer
().
getMBeanInfo
(
getObjectName
(
"test-domain"
,
"endpoint1"
,
true
,
this
.
context
)));
assertThat
(
mbeanExporter
.
getServer
().
getMBeanInfo
(
getObjectName
(
"test-domain"
,
"endpoint1"
,
true
,
this
.
context
)))
.
isNotNull
();
}
@Test
...
...
@@ -180,10 +176,9 @@ public class EndpointMBeanExporterTests {
new
RootBeanDefinition
(
TestEndpoint
.
class
));
this
.
context
.
refresh
();
MBeanExporter
mbeanExporter
=
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
);
assertNotNull
(
mbeanExporter
.
getServer
()
.
getMBeanInfo
(
ObjectNameManager
.
getInstance
(
getObjectName
(
"test-domain"
,
"endpoint1"
,
true
,
this
.
context
)
.
toString
()
+
",key1=value1,key2=value2"
)));
assertThat
(
mbeanExporter
.
getServer
().
getMBeanInfo
(
ObjectNameManager
.
getInstance
(
getObjectName
(
"test-domain"
,
"endpoint1"
,
true
,
this
.
context
).
toString
()
+
",key1=value1,key2=value2"
))).
isNotNull
();
}
@Test
...
...
@@ -198,9 +193,8 @@ public class EndpointMBeanExporterTests {
parent
.
refresh
();
this
.
context
.
refresh
();
MBeanExporter
mbeanExporter
=
this
.
context
.
getBean
(
EndpointMBeanExporter
.
class
);
assertNotNull
(
mbeanExporter
.
getServer
()
.
getMBeanInfo
(
getObjectName
(
"endpoint1"
,
this
.
context
)));
assertThat
(
mbeanExporter
.
getServer
()
.
getMBeanInfo
(
getObjectName
(
"endpoint1"
,
this
.
context
))).
isNotNull
();
parent
.
close
();
}
...
...
@@ -216,8 +210,8 @@ public class EndpointMBeanExporterTests {
Object
response
=
mbeanExporter
.
getServer
().
invoke
(
getObjectName
(
"endpoint1"
,
this
.
context
),
"getData"
,
new
Object
[
0
],
new
String
[
0
]);
assertThat
(
response
,
is
(
instanceOf
(
Map
.
class
))
);
assertThat
(((
Map
<?,
?>)
response
).
get
(
"date"
)
,
is
(
instanceOf
(
Long
.
class
))
);
assertThat
(
response
).
isInstanceOf
(
Map
.
class
);
assertThat
(((
Map
<?,
?>)
response
).
get
(
"date"
)
).
isInstanceOf
(
Long
.
class
);
}
@Test
...
...
@@ -237,8 +231,8 @@ public class EndpointMBeanExporterTests {
Object
response
=
mbeanExporter
.
getServer
().
invoke
(
getObjectName
(
"endpoint1"
,
this
.
context
),
"getData"
,
new
Object
[
0
],
new
String
[
0
]);
assertThat
(
response
,
is
(
instanceOf
(
Map
.
class
))
);
assertThat
(((
Map
<?,
?>)
response
).
get
(
"date"
)
,
is
(
instanceOf
(
String
.
class
))
);
assertThat
(
response
).
isInstanceOf
(
Map
.
class
);
assertThat
(((
Map
<?,
?>)
response
).
get
(
"date"
)
).
isInstanceOf
(
String
.
class
);
}
private
ObjectName
getObjectName
(
String
beanKey
,
GenericApplicationContext
context
)
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EndpointHandlerMappingTests.java
View file @
94677b35
...
...
@@ -31,11 +31,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.method.HandlerMethod
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link EndpointHandlerMapping}.
...
...
@@ -61,14 +57,11 @@ public class EndpointHandlerMappingTests {
Arrays
.
asList
(
endpointA
,
endpointB
));
mapping
.
setApplicationContext
(
this
.
context
);
mapping
.
afterPropertiesSet
();
assertThat
(
mapping
.
getHandler
(
new
MockHttpServletRequest
(
"GET"
,
"/a"
)).
getHandler
(),
equalTo
((
Object
)
new
HandlerMethod
(
endpointA
,
this
.
method
)));
assertThat
(
mapping
.
getHandler
(
new
MockHttpServletRequest
(
"GET"
,
"/b"
)).
getHandler
(),
equalTo
((
Object
)
new
HandlerMethod
(
endpointB
,
this
.
method
)));
assertThat
(
mapping
.
getHandler
(
new
MockHttpServletRequest
(
"GET"
,
"/c"
)),
nullValue
());
assertThat
(
mapping
.
getHandler
(
request
(
"GET"
,
"/a"
)).
getHandler
())
.
isEqualTo
(
new
HandlerMethod
(
endpointA
,
this
.
method
));
assertThat
(
mapping
.
getHandler
(
request
(
"GET"
,
"/b"
)).
getHandler
())
.
isEqualTo
(
new
HandlerMethod
(
endpointB
,
this
.
method
));
assertThat
(
mapping
.
getHandler
(
request
(
"GET"
,
"/c"
))).
isNull
();
}
@Test
...
...
@@ -80,16 +73,11 @@ public class EndpointHandlerMappingTests {
mapping
.
setApplicationContext
(
this
.
context
);
mapping
.
setPrefix
(
"/a"
);
mapping
.
afterPropertiesSet
();
assertThat
(
mapping
.
getHandler
(
new
MockHttpServletRequest
(
"GET"
,
"/a/a"
))
.
getHandler
(),
equalTo
((
Object
)
new
HandlerMethod
(
endpointA
,
this
.
method
)));
assertThat
(
mapping
.
getHandler
(
new
MockHttpServletRequest
(
"GET"
,
"/a/b"
))
.
getHandler
(),
equalTo
((
Object
)
new
HandlerMethod
(
endpointB
,
this
.
method
)));
assertThat
(
mapping
.
getHandler
(
new
MockHttpServletRequest
(
"GET"
,
"/a"
)),
nullValue
());
assertThat
(
mapping
.
getHandler
(
new
MockHttpServletRequest
(
"GET"
,
"/a/a"
))
.
getHandler
()).
isEqualTo
(
new
HandlerMethod
(
endpointA
,
this
.
method
));
assertThat
(
mapping
.
getHandler
(
new
MockHttpServletRequest
(
"GET"
,
"/a/b"
))
.
getHandler
()).
isEqualTo
(
new
HandlerMethod
(
endpointB
,
this
.
method
));
assertThat
(
mapping
.
getHandler
(
request
(
"GET"
,
"/a"
))).
isNull
();
}
@Test
(
expected
=
HttpRequestMethodNotSupportedException
.
class
)
...
...
@@ -99,8 +87,8 @@ public class EndpointHandlerMappingTests {
Arrays
.
asList
(
endpoint
));
mapping
.
setApplicationContext
(
this
.
context
);
mapping
.
afterPropertiesSet
();
assert
NotNull
(
mapping
.
getHandler
(
new
MockHttpServletRequest
(
"GET"
,
"/a"
))
);
assert
Null
(
mapping
.
getHandler
(
new
MockHttpServletRequest
(
"POST"
,
"/a"
))
);
assert
That
(
mapping
.
getHandler
(
request
(
"GET"
,
"/a"
))).
isNotNull
(
);
assert
That
(
mapping
.
getHandler
(
request
(
"POST"
,
"/a"
))).
isNull
(
);
}
@Test
...
...
@@ -110,7 +98,7 @@ public class EndpointHandlerMappingTests {
Arrays
.
asList
(
endpoint
));
mapping
.
setApplicationContext
(
this
.
context
);
mapping
.
afterPropertiesSet
();
assert
NotNull
(
mapping
.
getHandler
(
new
MockHttpServletRequest
(
"POST"
,
"/a"
))
);
assert
That
(
mapping
.
getHandler
(
request
(
"POST"
,
"/a"
))).
isNotNull
(
);
}
@Test
(
expected
=
HttpRequestMethodNotSupportedException
.
class
)
...
...
@@ -120,8 +108,8 @@ public class EndpointHandlerMappingTests {
Arrays
.
asList
(
endpoint
));
mapping
.
setApplicationContext
(
this
.
context
);
mapping
.
afterPropertiesSet
();
assert
NotNull
(
mapping
.
getHandler
(
new
MockHttpServletRequest
(
"POST"
,
"/a"
))
);
assert
Null
(
mapping
.
getHandler
(
new
MockHttpServletRequest
(
"GET"
,
"/a"
))
);
assert
That
(
mapping
.
getHandler
(
request
(
"POST"
,
"/a"
))).
isNotNull
(
);
assert
That
(
mapping
.
getHandler
(
request
(
"GET"
,
"/a"
))).
isNull
(
);
}
@Test
...
...
@@ -132,8 +120,7 @@ public class EndpointHandlerMappingTests {
mapping
.
setDisabled
(
true
);
mapping
.
setApplicationContext
(
this
.
context
);
mapping
.
afterPropertiesSet
();
assertThat
(
mapping
.
getHandler
(
new
MockHttpServletRequest
(
"GET"
,
"/a"
)),
nullValue
());
assertThat
(
mapping
.
getHandler
(
request
(
"GET"
,
"/a"
))).
isNull
();
}
@Test
...
...
@@ -145,10 +132,12 @@ public class EndpointHandlerMappingTests {
mapping
.
setDisabled
(
true
);
mapping
.
setApplicationContext
(
this
.
context
);
mapping
.
afterPropertiesSet
();
assertThat
(
mapping
.
getHandler
(
new
MockHttpServletRequest
(
"GET"
,
"/a"
)),
nullValue
());
assertThat
(
mapping
.
getHandler
(
new
MockHttpServletRequest
(
"POST"
,
"/a"
)),
nullValue
());
assertThat
(
mapping
.
getHandler
(
request
(
"GET"
,
"/a"
))).
isNull
();
assertThat
(
mapping
.
getHandler
(
request
(
"POST"
,
"/a"
))).
isNull
();
}
private
MockHttpServletRequest
request
(
String
method
,
String
requestURI
)
{
return
new
MockHttpServletRequest
(
method
,
requestURI
);
}
private
static
class
TestEndpoint
extends
AbstractEndpoint
<
Object
>
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointBrowserPathIntegrationTests.java
View file @
94677b35
...
...
@@ -35,7 +35,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
.
header
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
...
...
@@ -68,7 +68,8 @@ public class HalBrowserMvcEndpointBrowserPathIntegrationTests {
MvcResult
response
=
this
.
mockMvc
.
perform
(
get
(
"/actuator/"
).
accept
(
MediaType
.
TEXT_HTML
))
.
andExpect
(
status
().
isOk
()).
andReturn
();
assertEquals
(
"/actuator/browser.html"
,
response
.
getResponse
().
getForwardedUrl
());
assertThat
(
response
.
getResponse
().
getForwardedUrl
())
.
isEqualTo
(
"/actuator/browser.html"
);
}
@Test
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointDisabledIntegrationTests.java
View file @
94677b35
...
...
@@ -35,7 +35,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
.
header
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
jsonPath
;
...
...
@@ -78,7 +78,8 @@ public class HalBrowserMvcEndpointDisabledIntegrationTests {
MvcResult
response
=
this
.
mockMvc
.
perform
(
get
(
"/actuator/"
).
accept
(
MediaType
.
TEXT_HTML
))
.
andExpect
(
status
().
isOk
()).
andReturn
();
assertEquals
(
"/actuator/browser.html"
,
response
.
getResponse
().
getForwardedUrl
());
assertThat
(
response
.
getResponse
().
getForwardedUrl
())
.
isEqualTo
(
"/actuator/browser.html"
);
}
@Test
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointEndpointsDisabledIntegrationTests.java
View file @
94677b35
...
...
@@ -34,8 +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
.
hamcrest
.
Matchers
.
empty
;
import
static
org
.
junit
.
Assert
.
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
.
result
.
MockMvcResultMatchers
.
status
;
...
...
@@ -91,7 +90,7 @@ public class HalBrowserMvcEndpointEndpointsDisabledIntegrationTests {
@Test
public
void
endpointsAllDisabled
()
throws
Exception
{
assertThat
(
this
.
mvcEndpoints
.
getEndpoints
()
,
empty
()
);
assertThat
(
this
.
mvcEndpoints
.
getEndpoints
()
).
isEmpty
(
);
}
@MinimalActuatorHypermediaApplication
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerContextPathIntegrationTests.java
View file @
94677b35
...
...
@@ -40,8 +40,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
springframework
.
hateoas
.
mvc
.
ControllerLinkBuilder
.
linkTo
;
/**
...
...
@@ -68,9 +67,8 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/spring/"
,
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>(
null
,
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"_links\":"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"_links\":"
);
}
@Test
...
...
@@ -80,9 +78,8 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/spring/actuator/"
,
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>(
null
,
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"<title"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"<title"
);
}
@Test
...
...
@@ -92,9 +89,8 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/spring/actuator"
,
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>(
null
,
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"_links\":"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"_links\":"
);
}
@Test
...
...
@@ -104,9 +100,8 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/spring/actuator/"
,
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>(
null
,
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"_links\":"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"_links\":"
);
}
@MinimalActuatorHypermediaApplication
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerPortIntegrationTests.java
View file @
94677b35
...
...
@@ -40,8 +40,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
springframework
.
hateoas
.
mvc
.
ControllerLinkBuilder
.
linkTo
;
/**
...
...
@@ -68,11 +67,9 @@ public class HalBrowserMvcEndpointServerPortIntegrationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/actuator"
,
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>(
null
,
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"_links\":"
));
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
":"
+
this
.
port
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"_links\":"
);
assertThat
(
entity
.
getBody
()).
contains
(
":"
+
this
.
port
);
}
@Test
...
...
@@ -82,11 +79,9 @@ public class HalBrowserMvcEndpointServerPortIntegrationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/actuator/"
,
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>(
null
,
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"\"_links\":"
));
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
":"
+
this
.
port
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"_links\":"
);
assertThat
(
entity
.
getBody
()).
contains
(
":"
+
this
.
port
);
}
@Test
...
...
@@ -96,9 +91,8 @@ public class HalBrowserMvcEndpointServerPortIntegrationTests {
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/actuator/"
,
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>(
null
,
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertTrue
(
"Wrong body: "
+
entity
.
getBody
(),
entity
.
getBody
().
contains
(
"<title"
));
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"<title"
);
}
@MinimalActuatorHypermediaApplication
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointVanillaIntegrationTests.java
View file @
94677b35
...
...
@@ -39,7 +39,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
.
header
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
jsonPath
;
...
...
@@ -90,7 +90,8 @@ public class HalBrowserMvcEndpointVanillaIntegrationTests {
MvcResult
response
=
this
.
mockMvc
.
perform
(
get
(
"/actuator/"
).
accept
(
MediaType
.
TEXT_HTML
))
.
andExpect
(
status
().
isOk
()).
andReturn
();
assertEquals
(
"/actuator/browser.html"
,
response
.
getResponse
().
getForwardedUrl
());
assertThat
(
response
.
getResponse
().
getForwardedUrl
())
.
isEqualTo
(
"/actuator/browser.html"
);
}
@Test
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpointTests.java
View file @
94677b35
...
...
@@ -32,12 +32,7 @@ import org.springframework.mock.env.MockEnvironment;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
import
org.springframework.security.core.authority.AuthorityUtils
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -81,8 +76,8 @@ public class HealthMvcEndpointTests {
public
void
up
()
{
given
(
this
.
endpoint
.
invoke
()).
willReturn
(
new
Health
.
Builder
().
up
().
build
());
Object
result
=
this
.
mvc
.
invoke
(
null
);
assertT
rue
(
result
instanceof
Health
);
assertT
rue
(((
Health
)
result
).
getStatus
()
==
Status
.
UP
);
assertT
hat
(
result
instanceof
Health
).
isTrue
(
);
assertT
hat
(((
Health
)
result
).
getStatus
()
==
Status
.
UP
).
isTrue
(
);
}
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -90,10 +85,10 @@ public class HealthMvcEndpointTests {
public
void
down
()
{
given
(
this
.
endpoint
.
invoke
()).
willReturn
(
new
Health
.
Builder
().
down
().
build
());
Object
result
=
this
.
mvc
.
invoke
(
null
);
assertT
rue
(
result
instanceof
ResponseEntity
);
assertT
hat
(
result
instanceof
ResponseEntity
).
isTrue
(
);
ResponseEntity
<
Health
>
response
=
(
ResponseEntity
<
Health
>)
result
;
assertT
rue
(
response
.
getBody
().
getStatus
()
==
Status
.
DOWN
);
assert
Equals
(
HttpStatus
.
SERVICE_UNAVAILABLE
,
response
.
getStatusCode
()
);
assertT
hat
(
response
.
getBody
().
getStatus
()
==
Status
.
DOWN
).
isTrue
(
);
assert
That
(
response
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
SERVICE_UNAVAILABLE
);
}
@Test
...
...
@@ -104,10 +99,10 @@ public class HealthMvcEndpointTests {
this
.
mvc
.
setStatusMapping
(
Collections
.
singletonMap
(
"OK"
,
HttpStatus
.
INTERNAL_SERVER_ERROR
));
Object
result
=
this
.
mvc
.
invoke
(
null
);
assertT
rue
(
result
instanceof
ResponseEntity
);
assertT
hat
(
result
instanceof
ResponseEntity
).
isTrue
(
);
ResponseEntity
<
Health
>
response
=
(
ResponseEntity
<
Health
>)
result
;
assertT
rue
(
response
.
getBody
().
getStatus
().
equals
(
new
Status
(
"OK"
))
);
assert
Equals
(
HttpStatus
.
INTERNAL_SERVER_ERROR
,
response
.
getStatusCode
()
);
assertT
hat
(
response
.
getBody
().
getStatus
().
equals
(
new
Status
(
"OK"
))).
isTrue
(
);
assert
That
(
response
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
@Test
...
...
@@ -118,10 +113,10 @@ public class HealthMvcEndpointTests {
this
.
mvc
.
setStatusMapping
(
Collections
.
singletonMap
(
"out-of-service"
,
HttpStatus
.
INTERNAL_SERVER_ERROR
));
Object
result
=
this
.
mvc
.
invoke
(
null
);
assertT
rue
(
result
instanceof
ResponseEntity
);
assertT
hat
(
result
instanceof
ResponseEntity
).
isTrue
(
);
ResponseEntity
<
Health
>
response
=
(
ResponseEntity
<
Health
>)
result
;
assertT
rue
(
response
.
getBody
().
getStatus
().
equals
(
Status
.
OUT_OF_SERVICE
)
);
assert
Equals
(
HttpStatus
.
INTERNAL_SERVER_ERROR
,
response
.
getStatusCode
()
);
assertT
hat
(
response
.
getBody
().
getStatus
().
equals
(
Status
.
OUT_OF_SERVICE
)).
isTrue
(
);
assert
That
(
response
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
@Test
...
...
@@ -130,9 +125,9 @@ public class HealthMvcEndpointTests {
.
willReturn
(
new
Health
.
Builder
().
up
().
withDetail
(
"foo"
,
"bar"
).
build
());
given
(
this
.
endpoint
.
isSensitive
()).
willReturn
(
false
);
Object
result
=
this
.
mvc
.
invoke
(
this
.
admin
);
assertT
rue
(
result
instanceof
Health
);
assertT
rue
(((
Health
)
result
).
getStatus
()
==
Status
.
UP
);
assert
Equals
(
"bar"
,
((
Health
)
result
).
getDetails
().
get
(
"foo"
)
);
assertT
hat
(
result
instanceof
Health
).
isTrue
(
);
assertT
hat
(((
Health
)
result
).
getStatus
()
==
Status
.
UP
).
isTrue
(
);
assert
That
(((
Health
)
result
).
getDetails
().
get
(
"foo"
)).
isEqualTo
(
"bar"
);
}
@Test
...
...
@@ -140,9 +135,9 @@ public class HealthMvcEndpointTests {
given
(
this
.
endpoint
.
invoke
())
.
willReturn
(
new
Health
.
Builder
().
up
().
withDetail
(
"foo"
,
"bar"
).
build
());
Object
result
=
this
.
mvc
.
invoke
(
this
.
user
);
assertT
rue
(
result
instanceof
Health
);
assertT
rue
(((
Health
)
result
).
getStatus
()
==
Status
.
UP
);
assert
Null
(((
Health
)
result
).
getDetails
().
get
(
"foo"
)
);
assertT
hat
(
result
instanceof
Health
).
isTrue
(
);
assertT
hat
(((
Health
)
result
).
getStatus
()
==
Status
.
UP
).
isTrue
(
);
assert
That
(((
Health
)
result
).
getDetails
().
get
(
"foo"
)).
isNull
(
);
}
@Test
...
...
@@ -152,19 +147,19 @@ public class HealthMvcEndpointTests {
given
(
this
.
endpoint
.
invoke
())
.
willReturn
(
new
Health
.
Builder
().
up
().
withDetail
(
"foo"
,
"bar"
).
build
());
Object
result
=
this
.
mvc
.
invoke
(
this
.
admin
);
assertT
rue
(
result
instanceof
Health
);
assertT
hat
(
result
instanceof
Health
).
isTrue
(
);
Health
health
=
(
Health
)
result
;
assertT
rue
(
health
.
getStatus
()
==
Status
.
UP
);
assertThat
(
health
.
getDetails
()
.
size
(),
is
(
equalTo
(
1
))
);
assertThat
(
health
.
getDetails
().
get
(
"foo"
)
,
is
(
equalTo
((
Object
)
"bar"
))
);
assertT
hat
(
health
.
getStatus
()
==
Status
.
UP
).
isTrue
(
);
assertThat
(
health
.
getDetails
()
).
hasSize
(
1
);
assertThat
(
health
.
getDetails
().
get
(
"foo"
)
).
isEqualTo
(
"bar"
);
given
(
this
.
endpoint
.
invoke
()).
willReturn
(
new
Health
.
Builder
().
down
().
build
());
result
=
this
.
mvc
.
invoke
(
null
);
// insecure now
assertT
rue
(
result
instanceof
Health
);
assertT
hat
(
result
instanceof
Health
).
isTrue
(
);
health
=
(
Health
)
result
;
// so the result is cached
assertT
rue
(
health
.
getStatus
()
==
Status
.
UP
);
assertT
hat
(
health
.
getStatus
()
==
Status
.
UP
).
isTrue
(
);
// but the details are hidden
assertThat
(
health
.
getDetails
()
.
size
(),
is
(
equalTo
(
0
))
);
assertThat
(
health
.
getDetails
()
).
isEmpty
(
);
}
@Test
...
...
@@ -174,9 +169,9 @@ public class HealthMvcEndpointTests {
given
(
this
.
endpoint
.
invoke
())
.
willReturn
(
new
Health
.
Builder
().
up
().
withDetail
(
"foo"
,
"bar"
).
build
());
Object
result
=
this
.
mvc
.
invoke
(
null
);
assertT
rue
(
result
instanceof
Health
);
assertT
rue
(((
Health
)
result
).
getStatus
()
==
Status
.
UP
);
assert
Equals
(
"bar"
,
((
Health
)
result
).
getDetails
().
get
(
"foo"
)
);
assertT
hat
(
result
instanceof
Health
).
isTrue
(
);
assertT
hat
(((
Health
)
result
).
getStatus
()
==
Status
.
UP
).
isTrue
(
);
assert
That
(((
Health
)
result
).
getDetails
().
get
(
"foo"
)).
isEqualTo
(
"bar"
);
}
@Test
...
...
@@ -185,9 +180,9 @@ public class HealthMvcEndpointTests {
given
(
this
.
endpoint
.
invoke
())
.
willReturn
(
new
Health
.
Builder
().
up
().
withDetail
(
"foo"
,
"bar"
).
build
());
Object
result
=
this
.
mvc
.
invoke
(
null
);
assertT
rue
(
result
instanceof
Health
);
assertT
rue
(((
Health
)
result
).
getStatus
()
==
Status
.
UP
);
assert
Null
(((
Health
)
result
).
getDetails
().
get
(
"foo"
)
);
assertT
hat
(
result
instanceof
Health
).
isTrue
(
);
assertT
hat
(((
Health
)
result
).
getStatus
()
==
Status
.
UP
).
isTrue
(
);
assert
That
(((
Health
)
result
).
getDetails
().
get
(
"foo"
)).
isNull
(
);
}
@Test
...
...
@@ -198,9 +193,9 @@ public class HealthMvcEndpointTests {
given
(
this
.
endpoint
.
invoke
())
.
willReturn
(
new
Health
.
Builder
().
up
().
withDetail
(
"foo"
,
"bar"
).
build
());
Object
result
=
this
.
mvc
.
invoke
(
null
);
assertT
rue
(
result
instanceof
Health
);
assertT
rue
(((
Health
)
result
).
getStatus
()
==
Status
.
UP
);
assert
Equals
(
"bar"
,
((
Health
)
result
).
getDetails
().
get
(
"foo"
)
);
assertT
hat
(
result
instanceof
Health
).
isTrue
(
);
assertT
hat
(((
Health
)
result
).
getStatus
()
==
Status
.
UP
).
isTrue
(
);
assert
That
(((
Health
)
result
).
getDetails
().
get
(
"foo"
)).
isEqualTo
(
"bar"
);
}
@Test
...
...
@@ -209,13 +204,13 @@ public class HealthMvcEndpointTests {
given
(
this
.
endpoint
.
invoke
())
.
willReturn
(
new
Health
.
Builder
().
up
().
withDetail
(
"foo"
,
"bar"
).
build
());
Object
result
=
this
.
mvc
.
invoke
(
null
);
assertT
rue
(
result
instanceof
Health
);
assertT
rue
(((
Health
)
result
).
getStatus
()
==
Status
.
UP
);
assertT
hat
(
result
instanceof
Health
).
isTrue
(
);
assertT
hat
(((
Health
)
result
).
getStatus
()
==
Status
.
UP
).
isTrue
(
);
given
(
this
.
endpoint
.
invoke
()).
willReturn
(
new
Health
.
Builder
().
down
().
build
());
result
=
this
.
mvc
.
invoke
(
null
);
@SuppressWarnings
(
"unchecked"
)
Health
health
=
((
ResponseEntity
<
Health
>)
result
).
getBody
();
assertT
rue
(
health
.
getStatus
()
==
Status
.
DOWN
);
assertT
hat
(
health
.
getStatus
()
==
Status
.
DOWN
).
isTrue
(
);
}
@Test
...
...
@@ -225,14 +220,14 @@ public class HealthMvcEndpointTests {
given
(
this
.
endpoint
.
invoke
())
.
willReturn
(
new
Health
.
Builder
().
up
().
withDetail
(
"foo"
,
"bar"
).
build
());
Object
result
=
this
.
mvc
.
invoke
(
null
);
assertT
rue
(
result
instanceof
Health
);
assertT
rue
(((
Health
)
result
).
getStatus
()
==
Status
.
UP
);
assertT
hat
(
result
instanceof
Health
).
isTrue
(
);
assertT
hat
(((
Health
)
result
).
getStatus
()
==
Status
.
UP
).
isTrue
(
);
Thread
.
sleep
(
100
);
given
(
this
.
endpoint
.
invoke
()).
willReturn
(
new
Health
.
Builder
().
down
().
build
());
result
=
this
.
mvc
.
invoke
(
null
);
@SuppressWarnings
(
"unchecked"
)
Health
health
=
((
ResponseEntity
<
Health
>)
result
).
getBody
();
assertT
rue
(
health
.
getStatus
()
==
Status
.
DOWN
);
assertT
hat
(
health
.
getStatus
()
==
Status
.
DOWN
).
isTrue
(
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/JolokiaMvcEndpointTests.java
View file @
94677b35
...
...
@@ -18,7 +18,6 @@ package org.springframework.boot.actuate.endpoint.mvc;
import
java.util.Set
;
import
org.hamcrest.Matcher
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
...
...
@@ -43,10 +42,8 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
hasItem
;
import
static
org
.
hamcrest
.
Matchers
.
instanceOf
;
import
static
org
.
junit
.
Assert
.
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
;
...
...
@@ -78,10 +75,9 @@ public class JolokiaMvcEndpointTests {
}
@Test
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
public
void
endpointRegistered
()
throws
Exception
{
Set
<?
extends
MvcEndpoint
>
values
=
this
.
endpoints
.
getEndpoints
();
assertThat
(
values
,
(
Matcher
)
hasItem
(
instanceOf
(
JolokiaMvcEndpoint
.
class
))
);
assertThat
(
values
).
hasAtLeastOneElementOfType
(
JolokiaMvcEndpoint
.
class
);
}
@Test
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/LogFileMvcEndpointTests.java
View file @
94677b35
...
...
@@ -31,9 +31,7 @@ import org.springframework.mock.web.MockHttpServletRequest;
import
org.springframework.mock.web.MockHttpServletResponse
;
import
org.springframework.util.FileCopyUtils
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link LogFileMvcEndpoint}.
...
...
@@ -67,7 +65,7 @@ public class LogFileMvcEndpointTests {
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
HttpMethod
.
HEAD
.
name
(),
"/logfile"
);
this
.
mvc
.
invoke
(
request
,
response
);
assertThat
(
response
.
getStatus
()
,
equalTo
(
HttpStatus
.
NOT_FOUND
.
value
()
));
assertThat
(
response
.
getStatus
()
).
isEqualTo
(
HttpStatus
.
NOT_FOUND
.
value
(
));
}
@Test
...
...
@@ -77,7 +75,7 @@ public class LogFileMvcEndpointTests {
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
HttpMethod
.
HEAD
.
name
(),
"/logfile"
);
this
.
mvc
.
invoke
(
request
,
response
);
assertThat
(
response
.
getStatus
()
,
equalTo
(
HttpStatus
.
NOT_FOUND
.
value
()
));
assertThat
(
response
.
getStatus
()
).
isEqualTo
(
HttpStatus
.
NOT_FOUND
.
value
(
));
}
@Test
...
...
@@ -87,7 +85,7 @@ public class LogFileMvcEndpointTests {
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
HttpMethod
.
HEAD
.
name
(),
"/logfile"
);
this
.
mvc
.
invoke
(
request
,
response
);
assertThat
(
response
.
getStatus
()
,
equalTo
(
HttpStatus
.
OK
.
value
()
));
assertThat
(
response
.
getStatus
()
).
isEqualTo
(
HttpStatus
.
OK
.
value
(
));
}
@Test
...
...
@@ -98,7 +96,7 @@ public class LogFileMvcEndpointTests {
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
HttpMethod
.
HEAD
.
name
(),
"/logfile"
);
this
.
mvc
.
invoke
(
request
,
response
);
assertThat
(
response
.
getStatus
()
,
equalTo
(
HttpStatus
.
NOT_FOUND
.
value
()
));
assertThat
(
response
.
getStatus
()
).
isEqualTo
(
HttpStatus
.
NOT_FOUND
.
value
(
));
}
@Test
...
...
@@ -108,8 +106,8 @@ public class LogFileMvcEndpointTests {
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
HttpMethod
.
GET
.
name
(),
"/logfile"
);
this
.
mvc
.
invoke
(
request
,
response
);
assertThat
(
response
.
getStatus
()
,
equalTo
(
HttpStatus
.
OK
.
value
()
));
assert
Equals
(
"--TEST--"
,
response
.
getContentAsString
()
);
assertThat
(
response
.
getStatus
()
).
isEqualTo
(
HttpStatus
.
OK
.
value
(
));
assert
That
(
response
.
getContentAsString
()).
isEqualTo
(
"--TEST--"
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointsTests.java
View file @
94677b35
...
...
@@ -22,7 +22,7 @@ import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.context.support.StaticApplicationContext
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link MvcEndpoints}.
...
...
@@ -41,7 +41,7 @@ public class MvcEndpointsTests {
new
TestEndpoint
());
this
.
endpoints
.
setApplicationContext
(
this
.
context
);
this
.
endpoints
.
afterPropertiesSet
();
assert
Equals
(
1
,
this
.
endpoints
.
getEndpoints
().
size
()
);
assert
That
(
this
.
endpoints
.
getEndpoints
()).
hasSize
(
1
);
}
@Test
...
...
@@ -52,7 +52,7 @@ public class MvcEndpointsTests {
new
TestEndpoint
());
this
.
endpoints
.
setApplicationContext
(
this
.
context
);
this
.
endpoints
.
afterPropertiesSet
();
assert
Equals
(
1
,
this
.
endpoints
.
getEndpoints
().
size
()
);
assert
That
(
this
.
endpoints
.
getEndpoints
()).
hasSize
(
1
);
}
@Test
...
...
@@ -61,7 +61,7 @@ public class MvcEndpointsTests {
new
EndpointMvcAdapter
(
new
TestEndpoint
()));
this
.
endpoints
.
setApplicationContext
(
this
.
context
);
this
.
endpoints
.
afterPropertiesSet
();
assert
Equals
(
1
,
this
.
endpoints
.
getEndpoints
().
size
()
);
assert
That
(
this
.
endpoints
.
getEndpoints
()).
hasSize
(
1
);
}
@Test
...
...
@@ -72,9 +72,9 @@ public class MvcEndpointsTests {
new
TestEndpoint
());
this
.
endpoints
.
setApplicationContext
(
this
.
context
);
this
.
endpoints
.
afterPropertiesSet
();
assert
Equals
(
1
,
this
.
endpoints
.
getEndpoints
().
size
()
);
assert
Equals
(
"/foo/bar"
,
this
.
endpoints
.
getEndpoints
().
iterator
().
next
().
getPath
()
);
assert
That
(
this
.
endpoints
.
getEndpoints
()).
hasSize
(
1
);
assert
That
(
this
.
endpoints
.
getEndpoints
().
iterator
().
next
().
getPath
())
.
isEqualTo
(
"/foo/bar"
);
}
protected
static
class
TestEndpoint
extends
AbstractEndpoint
<
String
>
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NamePatternFilterTests.java
View file @
94677b35
...
...
@@ -20,11 +20,7 @@ import java.util.Map;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
hasEntry
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link NamePatternFilter}.
...
...
@@ -37,54 +33,54 @@ public class NamePatternFilterTests {
@Test
public
void
nonRegex
()
throws
Exception
{
MockNamePatternFilter
filter
=
new
MockNamePatternFilter
();
assertThat
(
filter
.
getResults
(
"not.a.regex"
),
hasEntry
(
"not.a.regex"
,
(
Object
)
"not.a.regex"
)
);
assertThat
(
filter
.
isGetNamesCalled
()
,
equalTo
(
false
)
);
assertThat
(
filter
.
getResults
(
"not.a.regex"
)
).
containsEntry
(
"not.a.regex"
,
"not.a.regex"
);
assertThat
(
filter
.
isGetNamesCalled
()
).
isFalse
(
);
}
@Test
public
void
regexRepetitionZeroOrMore
()
{
MockNamePatternFilter
filter
=
new
MockNamePatternFilter
();
Map
<
String
,
Object
>
results
=
filter
.
getResults
(
"fo.*"
);
assertThat
(
results
.
get
(
"foo"
)
,
equalTo
((
Object
)
"foo"
)
);
assertThat
(
results
.
get
(
"fool"
)
,
equalTo
((
Object
)
"fool"
)
);
assertThat
(
filter
.
isGetNamesCalled
()
,
equalTo
(
true
)
);
assertThat
(
results
.
get
(
"foo"
)
).
isEqualTo
(
"foo"
);
assertThat
(
results
.
get
(
"fool"
)
).
isEqualTo
(
"fool"
);
assertThat
(
filter
.
isGetNamesCalled
()
).
isTrue
(
);
}
@Test
public
void
regexRepetitionOneOrMore
()
{
MockNamePatternFilter
filter
=
new
MockNamePatternFilter
();
Map
<
String
,
Object
>
results
=
filter
.
getResults
(
"fo.+"
);
assertThat
(
results
.
get
(
"foo"
)
,
equalTo
((
Object
)
"foo"
)
);
assertThat
(
results
.
get
(
"fool"
)
,
equalTo
((
Object
)
"fool"
)
);
assertThat
(
filter
.
isGetNamesCalled
()
,
equalTo
(
true
)
);
assertThat
(
results
.
get
(
"foo"
)
).
isEqualTo
(
"foo"
);
assertThat
(
results
.
get
(
"fool"
)
).
isEqualTo
(
"fool"
);
assertThat
(
filter
.
isGetNamesCalled
()
).
isTrue
(
);
}
@Test
public
void
regexEndAnchor
()
{
MockNamePatternFilter
filter
=
new
MockNamePatternFilter
();
Map
<
String
,
Object
>
results
=
filter
.
getResults
(
"foo$"
);
assertThat
(
results
.
get
(
"foo"
)
,
equalTo
((
Object
)
"foo"
)
);
assertThat
(
results
.
get
(
"fool"
)
,
is
(
nullValue
())
);
assertThat
(
filter
.
isGetNamesCalled
()
,
equalTo
(
true
)
);
assertThat
(
results
.
get
(
"foo"
)
).
isEqualTo
(
"foo"
);
assertThat
(
results
.
get
(
"fool"
)
).
isNull
(
);
assertThat
(
filter
.
isGetNamesCalled
()
).
isTrue
(
);
}
@Test
public
void
regexStartAnchor
()
{
MockNamePatternFilter
filter
=
new
MockNamePatternFilter
();
Map
<
String
,
Object
>
results
=
filter
.
getResults
(
"^foo"
);
assertThat
(
results
.
get
(
"foo"
)
,
equalTo
((
Object
)
"foo"
)
);
assertThat
(
results
.
get
(
"fool"
)
,
is
(
nullValue
())
);
assertThat
(
filter
.
isGetNamesCalled
()
,
equalTo
(
true
)
);
assertThat
(
results
.
get
(
"foo"
)
).
isEqualTo
(
"foo"
);
assertThat
(
results
.
get
(
"fool"
)
).
isNull
(
);
assertThat
(
filter
.
isGetNamesCalled
()
).
isTrue
(
);
}
@Test
public
void
regexCharacterClass
()
{
MockNamePatternFilter
filter
=
new
MockNamePatternFilter
();
Map
<
String
,
Object
>
results
=
filter
.
getResults
(
"fo[a-z]l"
);
assertThat
(
results
.
get
(
"foo"
)
,
is
(
nullValue
())
);
assertThat
(
results
.
get
(
"fool"
)
,
equalTo
((
Object
)
"fool"
)
);
assertThat
(
filter
.
isGetNamesCalled
()
,
equalTo
(
true
)
);
assertThat
(
results
.
get
(
"foo"
)
).
isNull
(
);
assertThat
(
results
.
get
(
"fool"
)
).
isEqualTo
(
"fool"
);
assertThat
(
filter
.
isGetNamesCalled
()
).
isTrue
(
);
}
private
static
class
MockNamePatternFilter
extends
NamePatternFilter
<
Object
>
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/ShutdownMvcEndpointTests.java
View file @
94677b35
...
...
@@ -24,7 +24,7 @@ import org.springframework.boot.actuate.endpoint.ShutdownEndpoint;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
...
...
@@ -43,7 +43,7 @@ public class ShutdownMvcEndpointTests {
@SuppressWarnings
(
"unchecked"
)
ResponseEntity
<
Map
<
String
,
String
>>
response
=
(
ResponseEntity
<
Map
<
String
,
String
>>)
this
.
mvc
.
invoke
();
assert
Equals
(
HttpStatus
.
NOT_FOUND
,
response
.
getStatusCode
()
);
assert
That
(
response
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ApplicationHealthIndicatorTests.java
View file @
94677b35
...
...
@@ -18,7 +18,7 @@ package org.springframework.boot.actuate.health;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ApplicationHealthIndicator}.
...
...
@@ -30,7 +30,7 @@ public class ApplicationHealthIndicatorTests {
@Test
public
void
indicatesUp
()
throws
Exception
{
ApplicationHealthIndicator
healthIndicator
=
new
ApplicationHealthIndicator
();
assert
Equals
(
Status
.
UP
,
healthIndicator
.
health
().
getStatus
()
);
assert
That
(
healthIndicator
.
health
().
getStatus
()).
isEqualTo
(
Status
.
UP
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/CompositeHealthIndicatorTests.java
View file @
94677b35
...
...
@@ -25,10 +25,7 @@ import org.junit.Test;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
hasEntry
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
/**
...
...
@@ -72,11 +69,11 @@ public class CompositeHealthIndicatorTests {
CompositeHealthIndicator
composite
=
new
CompositeHealthIndicator
(
this
.
healthAggregator
,
indicators
);
Health
result
=
composite
.
health
();
assertThat
(
result
.
getDetails
()
.
size
(),
equalTo
(
2
)
);
assertThat
(
result
.
getDetails
()
,
ha
sEntry
(
"one"
,
(
Object
)
new
Health
.
Builder
().
unknown
().
withDetail
(
"1"
,
"1"
).
build
()
));
assertThat
(
result
.
getDetails
()
,
ha
sEntry
(
"two"
,
(
Object
)
new
Health
.
Builder
().
unknown
().
withDetail
(
"2"
,
"2"
).
build
()
));
assertThat
(
result
.
getDetails
()
).
hasSize
(
2
);
assertThat
(
result
.
getDetails
()
).
contain
sEntry
(
"one"
,
new
Health
.
Builder
().
unknown
().
withDetail
(
"1"
,
"1"
).
build
(
));
assertThat
(
result
.
getDetails
()
).
contain
sEntry
(
"two"
,
new
Health
.
Builder
().
unknown
().
withDetail
(
"2"
,
"2"
).
build
(
));
}
@Test
...
...
@@ -88,13 +85,13 @@ public class CompositeHealthIndicatorTests {
this
.
healthAggregator
,
indicators
);
composite
.
addHealthIndicator
(
"three"
,
this
.
three
);
Health
result
=
composite
.
health
();
assertThat
(
result
.
getDetails
()
.
size
(),
equalTo
(
3
)
);
assertThat
(
result
.
getDetails
()
,
ha
sEntry
(
"one"
,
(
Object
)
new
Health
.
Builder
().
unknown
().
withDetail
(
"1"
,
"1"
).
build
()
));
assertThat
(
result
.
getDetails
()
,
ha
sEntry
(
"two"
,
(
Object
)
new
Health
.
Builder
().
unknown
().
withDetail
(
"2"
,
"2"
).
build
()
));
assertThat
(
result
.
getDetails
()
,
ha
sEntry
(
"three"
,
(
Object
)
new
Health
.
Builder
().
unknown
().
withDetail
(
"3"
,
"3"
).
build
()
));
assertThat
(
result
.
getDetails
()
).
hasSize
(
3
);
assertThat
(
result
.
getDetails
()
).
contain
sEntry
(
"one"
,
new
Health
.
Builder
().
unknown
().
withDetail
(
"1"
,
"1"
).
build
(
));
assertThat
(
result
.
getDetails
()
).
contain
sEntry
(
"two"
,
new
Health
.
Builder
().
unknown
().
withDetail
(
"2"
,
"2"
).
build
(
));
assertThat
(
result
.
getDetails
()
).
contain
sEntry
(
"three"
,
new
Health
.
Builder
().
unknown
().
withDetail
(
"3"
,
"3"
).
build
(
));
}
@Test
...
...
@@ -104,11 +101,11 @@ public class CompositeHealthIndicatorTests {
composite
.
addHealthIndicator
(
"one"
,
this
.
one
);
composite
.
addHealthIndicator
(
"two"
,
this
.
two
);
Health
result
=
composite
.
health
();
assertThat
(
result
.
getDetails
().
size
()
,
equalTo
(
2
)
);
assertThat
(
result
.
getDetails
()
,
ha
sEntry
(
"one"
,
(
Object
)
new
Health
.
Builder
().
unknown
().
withDetail
(
"1"
,
"1"
).
build
()
));
assertThat
(
result
.
getDetails
()
,
ha
sEntry
(
"two"
,
(
Object
)
new
Health
.
Builder
().
unknown
().
withDetail
(
"2"
,
"2"
).
build
()
));
assertThat
(
result
.
getDetails
().
size
()
).
isEqualTo
(
2
);
assertThat
(
result
.
getDetails
()
).
contain
sEntry
(
"one"
,
new
Health
.
Builder
().
unknown
().
withDetail
(
"1"
,
"1"
).
build
(
));
assertThat
(
result
.
getDetails
()
).
contain
sEntry
(
"two"
,
new
Health
.
Builder
().
unknown
().
withDetail
(
"2"
,
"2"
).
build
(
));
}
@Test
...
...
@@ -121,15 +118,12 @@ public class CompositeHealthIndicatorTests {
CompositeHealthIndicator
composite
=
new
CompositeHealthIndicator
(
this
.
healthAggregator
);
composite
.
addHealthIndicator
(
"db"
,
innerComposite
);
Health
result
=
composite
.
health
();
ObjectMapper
mapper
=
new
ObjectMapper
();
assert
Equals
(
"{\"status\":\"UNKNOWN\",\"db\":{\"status\":\"UNKNOWN\""
assert
That
(
mapper
.
writeValueAsString
(
result
))
.
isEqualTo
(
"{\"status\":\"UNKNOWN\",\"db\":{\"status\":\"UNKNOWN\""
+
",\"db1\":{\"status\":\"UNKNOWN\",\"1\":\"1\"},"
+
"\"db2\":{\"status\":\"UNKNOWN\",\"2\":\"2\"}}}"
,
mapper
.
writeValueAsString
(
result
));
+
"\"db2\":{\"status\":\"UNKNOWN\",\"2\":\"2\"}}}"
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java
View file @
94677b35
...
...
@@ -29,12 +29,7 @@ import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.datasource.SingleConnectionDataSource
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
times
;
...
...
@@ -70,8 +65,8 @@ public class DataSourceHealthIndicatorTests {
public
void
database
()
{
this
.
indicator
.
setDataSource
(
this
.
dataSource
);
Health
health
=
this
.
indicator
.
health
();
assert
NotNull
(
health
.
getDetails
().
get
(
"database"
)
);
assert
NotNull
(
health
.
getDetails
().
get
(
"hello"
)
);
assert
That
(
health
.
getDetails
().
get
(
"database"
)).
isNotNull
(
);
assert
That
(
health
.
getDetails
().
get
(
"hello"
)).
isNotNull
(
);
}
@Test
...
...
@@ -82,9 +77,9 @@ public class DataSourceHealthIndicatorTests {
this
.
indicator
.
setQuery
(
"SELECT COUNT(*) from FOO"
);
Health
health
=
this
.
indicator
.
health
();
System
.
err
.
println
(
health
);
assert
NotNull
(
health
.
getDetails
().
get
(
"database"
)
);
assert
Equals
(
Status
.
UP
,
health
.
getStatus
()
);
assert
NotNull
(
health
.
getDetails
().
get
(
"hello"
)
);
assert
That
(
health
.
getDetails
().
get
(
"database"
)).
isNotNull
(
);
assert
That
(
health
.
getStatus
()).
isEqualTo
(
Status
.
UP
);
assert
That
(
health
.
getDetails
().
get
(
"hello"
)).
isNotNull
(
);
}
@Test
...
...
@@ -92,8 +87,8 @@ public class DataSourceHealthIndicatorTests {
this
.
indicator
.
setDataSource
(
this
.
dataSource
);
this
.
indicator
.
setQuery
(
"SELECT COUNT(*) from BAR"
);
Health
health
=
this
.
indicator
.
health
();
assertThat
(
health
.
getDetails
().
get
(
"database"
)
,
notNullValue
()
);
assert
Equals
(
Status
.
DOWN
,
health
.
getStatus
()
);
assertThat
(
health
.
getDetails
().
get
(
"database"
)
).
isNotNull
(
);
assert
That
(
health
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
}
@Test
...
...
@@ -105,24 +100,24 @@ public class DataSourceHealthIndicatorTests {
given
(
dataSource
.
getConnection
()).
willReturn
(
connection
);
this
.
indicator
.
setDataSource
(
dataSource
);
Health
health
=
this
.
indicator
.
health
();
assert
NotNull
(
health
.
getDetails
().
get
(
"database"
)
);
assert
That
(
health
.
getDetails
().
get
(
"database"
)).
isNotNull
(
);
verify
(
connection
,
times
(
2
)).
close
();
}
@Test
public
void
productLookups
()
throws
Exception
{
assertThat
(
Product
.
forProduct
(
"newone"
)
,
nullValue
()
);
assertThat
(
Product
.
forProduct
(
"HSQL Database Engine"
)
,
equalTo
(
Product
.
HSQLDB
)
);
assertThat
(
Product
.
forProduct
(
"Oracle"
)
,
equalTo
(
Product
.
ORACLE
)
);
assertThat
(
Product
.
forProduct
(
"Apache Derby"
)
,
equalTo
(
Product
.
DERBY
)
);
assertThat
(
Product
.
forProduct
(
"DB2"
)
,
equalTo
(
Product
.
DB2
)
);
assertThat
(
Product
.
forProduct
(
"DB2/LINUXX8664"
)
,
equalTo
(
Product
.
DB2
)
);
assertThat
(
Product
.
forProduct
(
"DB2 UDB for AS/400"
)
,
equalTo
(
Product
.
DB2_AS400
)
);
assertThat
(
Product
.
forProduct
(
"DB3 XDB for AS/400"
)
,
equalTo
(
Product
.
DB2_AS400
)
);
assertThat
(
Product
.
forProduct
(
"Informix Dynamic Server"
)
,
equalTo
(
Product
.
INFORMIX
)
);
assertThat
(
Product
.
forProduct
(
"Firebird 2.5.WI"
)
,
equalTo
(
Product
.
FIREBIRD
)
);
assertThat
(
Product
.
forProduct
(
"Firebird 2.1.LI"
)
,
equalTo
(
Product
.
FIREBIRD
)
);
assertThat
(
Product
.
forProduct
(
"newone"
)
).
isNull
(
);
assertThat
(
Product
.
forProduct
(
"HSQL Database Engine"
)
).
isEqualTo
(
Product
.
HSQLDB
);
assertThat
(
Product
.
forProduct
(
"Oracle"
)
).
isEqualTo
(
Product
.
ORACLE
);
assertThat
(
Product
.
forProduct
(
"Apache Derby"
)
).
isEqualTo
(
Product
.
DERBY
);
assertThat
(
Product
.
forProduct
(
"DB2"
)
).
isEqualTo
(
Product
.
DB2
);
assertThat
(
Product
.
forProduct
(
"DB2/LINUXX8664"
)
).
isEqualTo
(
Product
.
DB2
);
assertThat
(
Product
.
forProduct
(
"DB2 UDB for AS/400"
)
).
isEqualTo
(
Product
.
DB2_AS400
);
assertThat
(
Product
.
forProduct
(
"DB3 XDB for AS/400"
)
).
isEqualTo
(
Product
.
DB2_AS400
);
assertThat
(
Product
.
forProduct
(
"Informix Dynamic Server"
)
)
.
isEqualTo
(
Product
.
INFORMIX
);
assertThat
(
Product
.
forProduct
(
"Firebird 2.5.WI"
)
).
isEqualTo
(
Product
.
FIREBIRD
);
assertThat
(
Product
.
forProduct
(
"Firebird 2.1.LI"
)
).
isEqualTo
(
Product
.
FIREBIRD
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorTests.java
View file @
94677b35
...
...
@@ -26,7 +26,7 @@ import org.junit.runner.RunWith;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
/**
...
...
@@ -60,10 +60,10 @@ public class DiskSpaceHealthIndicatorTests {
given
(
this
.
fileMock
.
getFreeSpace
()).
willReturn
(
THRESHOLD_BYTES
+
10
);
given
(
this
.
fileMock
.
getTotalSpace
()).
willReturn
(
THRESHOLD_BYTES
*
10
);
Health
health
=
this
.
healthIndicator
.
health
();
assert
Equals
(
Status
.
UP
,
health
.
getStatus
()
);
assert
Equals
(
THRESHOLD_BYTES
,
health
.
getDetails
().
get
(
"threshold"
)
);
assert
Equals
(
THRESHOLD_BYTES
+
10
,
health
.
getDetails
().
get
(
"free"
)
);
assert
Equals
(
THRESHOLD_BYTES
*
10
,
health
.
getDetails
().
get
(
"total"
)
);
assert
That
(
health
.
getStatus
()).
isEqualTo
(
Status
.
UP
);
assert
That
(
health
.
getDetails
().
get
(
"threshold"
)).
isEqualTo
(
THRESHOLD_BYTES
);
assert
That
(
health
.
getDetails
().
get
(
"free"
)).
isEqualTo
(
THRESHOLD_BYTES
+
10
);
assert
That
(
health
.
getDetails
().
get
(
"total"
)).
isEqualTo
(
THRESHOLD_BYTES
*
10
);
}
@Test
...
...
@@ -71,10 +71,10 @@ public class DiskSpaceHealthIndicatorTests {
given
(
this
.
fileMock
.
getFreeSpace
()).
willReturn
(
THRESHOLD_BYTES
-
10
);
given
(
this
.
fileMock
.
getTotalSpace
()).
willReturn
(
THRESHOLD_BYTES
*
10
);
Health
health
=
this
.
healthIndicator
.
health
();
assert
Equals
(
Status
.
DOWN
,
health
.
getStatus
()
);
assert
Equals
(
THRESHOLD_BYTES
,
health
.
getDetails
().
get
(
"threshold"
)
);
assert
Equals
(
THRESHOLD_BYTES
-
10
,
health
.
getDetails
().
get
(
"free"
)
);
assert
Equals
(
THRESHOLD_BYTES
*
10
,
health
.
getDetails
().
get
(
"total"
)
);
assert
That
(
health
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
assert
That
(
health
.
getDetails
().
get
(
"threshold"
)).
isEqualTo
(
THRESHOLD_BYTES
);
assert
That
(
health
.
getDetails
().
get
(
"free"
)).
isEqualTo
(
THRESHOLD_BYTES
-
10
);
assert
That
(
health
.
getDetails
().
get
(
"total"
)).
isEqualTo
(
THRESHOLD_BYTES
*
10
);
}
private
DiskSpaceHealthIndicatorProperties
createProperties
(
File
path
,
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java
View file @
94677b35
...
...
@@ -39,11 +39,7 @@ import org.mockito.ArgumentCaptor;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
static
org
.
hamcrest
.
Matchers
.
arrayContaining
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Matchers
.
any
;
...
...
@@ -84,9 +80,9 @@ public class ElasticsearchHealthIndicatorTests {
.
forClass
(
ClusterHealthRequest
.
class
);
given
(
this
.
cluster
.
health
(
requestCaptor
.
capture
())).
willReturn
(
responseFuture
);
Health
health
=
this
.
indicator
.
health
();
assertThat
(
responseFuture
.
getTimeout
,
is
(
100L
)
);
assertThat
(
requestCaptor
.
getValue
().
indices
()
,
is
(
arrayContaining
(
"_all"
))
);
assertThat
(
health
.
getStatus
()
,
is
(
Status
.
UP
)
);
assertThat
(
responseFuture
.
getTimeout
).
isEqualTo
(
100L
);
assertThat
(
requestCaptor
.
getValue
().
indices
()
).
contains
(
"_all"
);
assertThat
(
health
.
getStatus
()
).
isEqualTo
(
Status
.
UP
);
}
@Test
...
...
@@ -99,9 +95,9 @@ public class ElasticsearchHealthIndicatorTests {
this
.
properties
.
getIndices
()
.
addAll
(
Arrays
.
asList
(
"test-index-1"
,
"test-index-2"
));
Health
health
=
this
.
indicator
.
health
();
assertThat
(
requestCaptor
.
getValue
().
indices
(),
is
(
arrayContaining
(
"test-index-1"
,
"test-index-2"
))
);
assertThat
(
health
.
getStatus
()
,
is
(
Status
.
UP
)
);
assertThat
(
requestCaptor
.
getValue
().
indices
()
).
contains
(
"test-index-1"
,
"test-index-2"
);
assertThat
(
health
.
getStatus
()
).
isEqualTo
(
Status
.
UP
);
}
@Test
...
...
@@ -113,7 +109,7 @@ public class ElasticsearchHealthIndicatorTests {
given
(
this
.
cluster
.
health
(
requestCaptor
.
capture
())).
willReturn
(
responseFuture
);
this
.
properties
.
setResponseTimeout
(
1000L
);
this
.
indicator
.
health
();
assertThat
(
responseFuture
.
getTimeout
,
is
(
1000L
)
);
assertThat
(
responseFuture
.
getTimeout
).
isEqualTo
(
1000L
);
}
@Test
...
...
@@ -123,7 +119,7 @@ public class ElasticsearchHealthIndicatorTests {
given
(
this
.
cluster
.
health
(
any
(
ClusterHealthRequest
.
class
)))
.
willReturn
(
responseFuture
);
Health
health
=
this
.
indicator
.
health
();
assertThat
(
health
.
getStatus
()
,
is
(
Status
.
UP
)
);
assertThat
(
health
.
getStatus
()
).
isEqualTo
(
Status
.
UP
);
Map
<
String
,
Object
>
details
=
health
.
getDetails
();
assertDetail
(
details
,
"clusterName"
,
"test-cluster"
);
assertDetail
(
details
,
"activeShards"
,
1
);
...
...
@@ -141,7 +137,7 @@ public class ElasticsearchHealthIndicatorTests {
responseFuture
.
onResponse
(
new
StubClusterHealthResponse
(
ClusterHealthStatus
.
RED
));
given
(
this
.
cluster
.
health
(
any
(
ClusterHealthRequest
.
class
)))
.
willReturn
(
responseFuture
);
assertThat
(
this
.
indicator
.
health
().
getStatus
()
,
is
(
Status
.
DOWN
)
);
assertThat
(
this
.
indicator
.
health
().
getStatus
()
).
isEqualTo
(
Status
.
DOWN
);
}
@Test
...
...
@@ -151,7 +147,7 @@ public class ElasticsearchHealthIndicatorTests {
.
onResponse
(
new
StubClusterHealthResponse
(
ClusterHealthStatus
.
YELLOW
));
given
(
this
.
cluster
.
health
(
any
(
ClusterHealthRequest
.
class
)))
.
willReturn
(
responseFuture
);
assertThat
(
this
.
indicator
.
health
().
getStatus
()
,
is
(
Status
.
UP
)
);
assertThat
(
this
.
indicator
.
health
().
getStatus
()
).
isEqualTo
(
Status
.
UP
);
}
@Test
...
...
@@ -160,14 +156,14 @@ public class ElasticsearchHealthIndicatorTests {
given
(
this
.
cluster
.
health
(
any
(
ClusterHealthRequest
.
class
)))
.
willReturn
(
responseFuture
);
Health
health
=
this
.
indicator
.
health
();
assertThat
(
health
.
getStatus
()
,
is
(
Status
.
DOWN
)
);
assertThat
((
String
)
health
.
getDetails
().
get
(
"error"
)
,
containsString
(
ElasticsearchTimeoutException
.
class
.
getName
()
));
assertThat
(
health
.
getStatus
()
).
isEqualTo
(
Status
.
DOWN
);
assertThat
((
String
)
health
.
getDetails
().
get
(
"error"
)
)
.
contains
(
ElasticsearchTimeoutException
.
class
.
getName
(
));
}
@SuppressWarnings
(
"unchecked"
)
private
<
T
>
void
assertDetail
(
Map
<
String
,
Object
>
details
,
String
detail
,
T
value
)
{
assertThat
((
T
)
details
.
get
(
detail
)
,
is
(
equalTo
(
value
))
);
assertThat
((
T
)
details
.
get
(
detail
)
).
isEqualTo
(
value
);
}
private
final
static
class
StubClusterHealthResponse
extends
ClusterHealthResponse
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthTests.java
View file @
94677b35
...
...
@@ -22,9 +22,7 @@ import org.junit.Rule;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link Health}.
...
...
@@ -46,16 +44,16 @@ public class HealthTests {
@Test
public
void
createWithStatus
()
throws
Exception
{
Health
health
=
Health
.
status
(
Status
.
UP
).
build
();
assertThat
(
health
.
getStatus
()
,
equalTo
(
Status
.
UP
)
);
assertThat
(
health
.
getDetails
().
size
()
,
equalTo
(
0
)
);
assertThat
(
health
.
getStatus
()
).
isEqualTo
(
Status
.
UP
);
assertThat
(
health
.
getDetails
().
size
()
).
isEqualTo
(
0
);
}
@Test
public
void
createWithDetails
()
throws
Exception
{
Health
health
=
new
Health
.
Builder
(
Status
.
UP
,
Collections
.
singletonMap
(
"a"
,
"b"
))
.
build
();
assertThat
(
health
.
getStatus
()
,
equalTo
(
Status
.
UP
)
);
assertThat
(
health
.
getDetails
().
get
(
"a"
)
,
equalTo
((
Object
)
"b"
)
);
assertThat
(
health
.
getStatus
()
).
isEqualTo
(
Status
.
UP
);
assertThat
(
health
.
getDetails
().
get
(
"a"
)
).
isEqualTo
(
"b"
);
}
@Test
...
...
@@ -65,12 +63,12 @@ public class HealthTests {
Health
h2
=
new
Health
.
Builder
(
Status
.
UP
,
Collections
.
singletonMap
(
"a"
,
"b"
))
.
build
();
Health
h3
=
new
Health
.
Builder
(
Status
.
UP
).
build
();
assertThat
(
h1
,
equalTo
(
h1
)
);
assertThat
(
h1
,
equalTo
(
h2
)
);
assertThat
(
h1
,
not
(
equalTo
(
h3
))
);
assertThat
(
h1
.
hashCode
()
,
equalTo
(
h1
.
hashCode
()
));
assertThat
(
h1
.
hashCode
()
,
equalTo
(
h2
.
hashCode
()
));
assertThat
(
h1
.
hashCode
()
,
not
(
equalTo
(
h3
.
hashCode
())
));
assertThat
(
h1
).
isEqualTo
(
h1
);
assertThat
(
h1
).
isEqualTo
(
h2
);
assertThat
(
h1
).
isNotEqualTo
(
h3
);
assertThat
(
h1
.
hashCode
()
).
isEqualTo
(
h1
.
hashCode
(
));
assertThat
(
h1
.
hashCode
()
).
isEqualTo
(
h2
.
hashCode
(
));
assertThat
(
h1
.
hashCode
()
).
isNotEqualTo
(
h3
.
hashCode
(
));
}
@Test
...
...
@@ -78,82 +76,82 @@ public class HealthTests {
RuntimeException
ex
=
new
RuntimeException
(
"bang"
);
Health
health
=
new
Health
.
Builder
(
Status
.
UP
,
Collections
.
singletonMap
(
"a"
,
"b"
))
.
withException
(
ex
).
build
();
assertThat
(
health
.
getDetails
().
get
(
"a"
)
,
equalTo
((
Object
)
"b"
)
);
assertThat
(
health
.
getDetails
().
get
(
"error"
)
,
equalTo
((
Object
)
"java.lang.RuntimeException: bang"
)
);
assertThat
(
health
.
getDetails
().
get
(
"a"
)
).
isEqualTo
(
"b"
);
assertThat
(
health
.
getDetails
().
get
(
"error"
)
)
.
isEqualTo
(
"java.lang.RuntimeException: bang"
);
}
@Test
public
void
withDetails
()
throws
Exception
{
Health
health
=
new
Health
.
Builder
(
Status
.
UP
,
Collections
.
singletonMap
(
"a"
,
"b"
))
.
withDetail
(
"c"
,
"d"
).
build
();
assertThat
(
health
.
getDetails
().
get
(
"a"
)
,
equalTo
((
Object
)
"b"
)
);
assertThat
(
health
.
getDetails
().
get
(
"c"
)
,
equalTo
((
Object
)
"d"
)
);
assertThat
(
health
.
getDetails
().
get
(
"a"
)
).
isEqualTo
(
"b"
);
assertThat
(
health
.
getDetails
().
get
(
"c"
)
).
isEqualTo
(
"d"
);
}
@Test
public
void
unknownWithDetails
()
throws
Exception
{
Health
health
=
new
Health
.
Builder
().
unknown
().
withDetail
(
"a"
,
"b"
).
build
();
assertThat
(
health
.
getStatus
()
,
equalTo
(
Status
.
UNKNOWN
)
);
assertThat
(
health
.
getDetails
().
get
(
"a"
)
,
equalTo
((
Object
)
"b"
)
);
assertThat
(
health
.
getStatus
()
).
isEqualTo
(
Status
.
UNKNOWN
);
assertThat
(
health
.
getDetails
().
get
(
"a"
)
).
isEqualTo
(
"b"
);
}
@Test
public
void
unknown
()
throws
Exception
{
Health
health
=
new
Health
.
Builder
().
unknown
().
build
();
assertThat
(
health
.
getStatus
()
,
equalTo
(
Status
.
UNKNOWN
)
);
assertThat
(
health
.
getDetails
().
size
()
,
equalTo
(
0
)
);
assertThat
(
health
.
getStatus
()
).
isEqualTo
(
Status
.
UNKNOWN
);
assertThat
(
health
.
getDetails
().
size
()
).
isEqualTo
(
0
);
}
@Test
public
void
upWithDetails
()
throws
Exception
{
Health
health
=
new
Health
.
Builder
().
up
().
withDetail
(
"a"
,
"b"
).
build
();
assertThat
(
health
.
getStatus
()
,
equalTo
(
Status
.
UP
)
);
assertThat
(
health
.
getDetails
().
get
(
"a"
)
,
equalTo
((
Object
)
"b"
)
);
assertThat
(
health
.
getStatus
()
).
isEqualTo
(
Status
.
UP
);
assertThat
(
health
.
getDetails
().
get
(
"a"
)
).
isEqualTo
(
"b"
);
}
@Test
public
void
up
()
throws
Exception
{
Health
health
=
new
Health
.
Builder
().
up
().
build
();
assertThat
(
health
.
getStatus
()
,
equalTo
(
Status
.
UP
)
);
assertThat
(
health
.
getDetails
().
size
()
,
equalTo
(
0
)
);
assertThat
(
health
.
getStatus
()
).
isEqualTo
(
Status
.
UP
);
assertThat
(
health
.
getDetails
().
size
()
).
isEqualTo
(
0
);
}
@Test
public
void
downWithException
()
throws
Exception
{
RuntimeException
ex
=
new
RuntimeException
(
"bang"
);
Health
health
=
Health
.
down
(
ex
).
build
();
assertThat
(
health
.
getStatus
()
,
equalTo
(
Status
.
DOWN
)
);
assertThat
(
health
.
getDetails
().
get
(
"error"
)
,
equalTo
((
Object
)
"java.lang.RuntimeException: bang"
)
);
assertThat
(
health
.
getStatus
()
).
isEqualTo
(
Status
.
DOWN
);
assertThat
(
health
.
getDetails
().
get
(
"error"
)
)
.
isEqualTo
(
"java.lang.RuntimeException: bang"
);
}
@Test
public
void
down
()
throws
Exception
{
Health
health
=
Health
.
down
().
build
();
assertThat
(
health
.
getStatus
()
,
equalTo
(
Status
.
DOWN
)
);
assertThat
(
health
.
getDetails
().
size
()
,
equalTo
(
0
)
);
assertThat
(
health
.
getStatus
()
).
isEqualTo
(
Status
.
DOWN
);
assertThat
(
health
.
getDetails
().
size
()
).
isEqualTo
(
0
);
}
@Test
public
void
outOfService
()
throws
Exception
{
Health
health
=
Health
.
outOfService
().
build
();
assertThat
(
health
.
getStatus
()
,
equalTo
(
Status
.
OUT_OF_SERVICE
)
);
assertThat
(
health
.
getDetails
().
size
()
,
equalTo
(
0
)
);
assertThat
(
health
.
getStatus
()
).
isEqualTo
(
Status
.
OUT_OF_SERVICE
);
assertThat
(
health
.
getDetails
().
size
()
).
isEqualTo
(
0
);
}
@Test
public
void
statusCode
()
throws
Exception
{
Health
health
=
Health
.
status
(
"UP"
).
build
();
assertThat
(
health
.
getStatus
()
,
equalTo
(
Status
.
UP
)
);
assertThat
(
health
.
getDetails
().
size
()
,
equalTo
(
0
)
);
assertThat
(
health
.
getStatus
()
).
isEqualTo
(
Status
.
UP
);
assertThat
(
health
.
getDetails
().
size
()
).
isEqualTo
(
0
);
}
@Test
public
void
status
()
throws
Exception
{
Health
health
=
Health
.
status
(
Status
.
UP
).
build
();
assertThat
(
health
.
getStatus
()
,
equalTo
(
Status
.
UP
)
);
assertThat
(
health
.
getDetails
().
size
()
,
equalTo
(
0
)
);
assertThat
(
health
.
getStatus
()
).
isEqualTo
(
Status
.
UP
);
assertThat
(
health
.
getDetails
().
size
()
).
isEqualTo
(
0
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/JmsHealthIndicatorTests.java
View file @
94677b35
...
...
@@ -23,7 +23,7 @@ import javax.jms.JMSException;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
times
;
...
...
@@ -46,8 +46,8 @@ public class JmsHealthIndicatorTests {
given
(
connectionFactory
.
createConnection
()).
willReturn
(
connection
);
JmsHealthIndicator
indicator
=
new
JmsHealthIndicator
(
connectionFactory
);
Health
health
=
indicator
.
health
();
assert
Equals
(
Status
.
UP
,
health
.
getStatus
()
);
assert
Equals
(
"JMS test provider"
,
health
.
getDetails
().
get
(
"provider"
)
);
assert
That
(
health
.
getStatus
()).
isEqualTo
(
Status
.
UP
);
assert
That
(
health
.
getDetails
().
get
(
"provider"
)).
isEqualTo
(
"JMS test provider"
);
verify
(
connection
,
times
(
1
)).
close
();
}
...
...
@@ -58,8 +58,8 @@ public class JmsHealthIndicatorTests {
.
willThrow
(
new
JMSException
(
"test"
,
"123"
));
JmsHealthIndicator
indicator
=
new
JmsHealthIndicator
(
connectionFactory
);
Health
health
=
indicator
.
health
();
assert
Equals
(
Status
.
DOWN
,
health
.
getStatus
()
);
assert
Equals
(
null
,
health
.
getDetails
().
get
(
"provider"
)
);
assert
That
(
health
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
assert
That
(
health
.
getDetails
().
get
(
"provider"
)).
isNull
(
);
}
@Test
...
...
@@ -73,8 +73,8 @@ public class JmsHealthIndicatorTests {
given
(
connectionFactory
.
createConnection
()).
willReturn
(
connection
);
JmsHealthIndicator
indicator
=
new
JmsHealthIndicator
(
connectionFactory
);
Health
health
=
indicator
.
health
();
assert
Equals
(
Status
.
DOWN
,
health
.
getStatus
()
);
assert
Equals
(
null
,
health
.
getDetails
().
get
(
"provider"
)
);
assert
That
(
health
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
assert
That
(
health
.
getDetails
().
get
(
"provider"
)).
isNull
(
);
verify
(
connection
,
times
(
1
)).
close
();
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MailHealthIndicatorTests.java
View file @
94677b35
...
...
@@ -32,9 +32,7 @@ import org.junit.Test;
import
org.springframework.mail.javamail.JavaMailSenderImpl
;
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
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
BDDMockito
.
willThrow
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -67,8 +65,8 @@ public class MailHealthIndicatorTests {
public
void
smtpIsUp
()
{
given
(
this
.
mailSender
.
getProtocol
()).
willReturn
(
"success"
);
Health
health
=
this
.
indicator
.
health
();
assert
Equals
(
Status
.
UP
,
health
.
getStatus
()
);
assert
Equals
(
"smtp.acme.org:25"
,
health
.
getDetails
().
get
(
"location"
)
);
assert
That
(
health
.
getStatus
()).
isEqualTo
(
Status
.
UP
);
assert
That
(
health
.
getDetails
().
get
(
"location"
)).
isEqualTo
(
"smtp.acme.org:25"
);
}
@Test
...
...
@@ -76,11 +74,11 @@ public class MailHealthIndicatorTests {
willThrow
(
new
MessagingException
(
"A test exception"
)).
given
(
this
.
mailSender
)
.
testConnection
();
Health
health
=
this
.
indicator
.
health
();
assert
Equals
(
Status
.
DOWN
,
health
.
getStatus
()
);
assert
Equals
(
"smtp.acme.org:25"
,
health
.
getDetails
().
get
(
"location"
)
);
assert
That
(
health
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
assert
That
(
health
.
getDetails
().
get
(
"location"
)).
isEqualTo
(
"smtp.acme.org:25"
);
Object
errorMessage
=
health
.
getDetails
().
get
(
"error"
);
assert
NotNull
(
errorMessage
);
assertT
rue
(
errorMessage
.
toString
().
contains
(
"A test exception"
)
);
assert
That
(
errorMessage
).
isNotNull
(
);
assertT
hat
(
errorMessage
.
toString
().
contains
(
"A test exception"
)).
isTrue
(
);
}
public
static
class
SuccessTransport
extends
Transport
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java
View file @
94677b35
...
...
@@ -29,9 +29,7 @@ import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
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
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
...
...
@@ -58,10 +56,11 @@ public class MongoHealthIndicatorTests {
PropertyPlaceholderAutoConfiguration
.
class
,
MongoAutoConfiguration
.
class
,
MongoDataAutoConfiguration
.
class
,
EndpointAutoConfiguration
.
class
,
HealthIndicatorAutoConfiguration
.
class
);
assertEquals
(
1
,
this
.
context
.
getBeanNamesForType
(
MongoTemplate
.
class
).
length
);
assertThat
(
this
.
context
.
getBeanNamesForType
(
MongoTemplate
.
class
).
length
)
.
isEqualTo
(
1
);
MongoHealthIndicator
healthIndicator
=
this
.
context
.
getBean
(
MongoHealthIndicator
.
class
);
assert
NotNull
(
healthIndicator
);
assert
That
(
healthIndicator
).
isNotNull
(
);
}
@Test
...
...
@@ -71,11 +70,9 @@ public class MongoHealthIndicatorTests {
MongoTemplate
mongoTemplate
=
mock
(
MongoTemplate
.
class
);
given
(
mongoTemplate
.
executeCommand
(
"{ buildInfo: 1 }"
)).
willReturn
(
commandResult
);
MongoHealthIndicator
healthIndicator
=
new
MongoHealthIndicator
(
mongoTemplate
);
Health
health
=
healthIndicator
.
health
();
assertEquals
(
Status
.
UP
,
health
.
getStatus
());
assertEquals
(
"2.6.4"
,
health
.
getDetails
().
get
(
"version"
));
assertThat
(
health
.
getStatus
()).
isEqualTo
(
Status
.
UP
);
assertThat
(
health
.
getDetails
().
get
(
"version"
)).
isEqualTo
(
"2.6.4"
);
verify
(
commandResult
).
getString
(
"version"
);
verify
(
mongoTemplate
).
executeCommand
(
"{ buildInfo: 1 }"
);
}
...
...
@@ -86,12 +83,11 @@ public class MongoHealthIndicatorTests {
given
(
mongoTemplate
.
executeCommand
(
"{ buildInfo: 1 }"
))
.
willThrow
(
new
MongoException
(
"Connection failed"
));
MongoHealthIndicator
healthIndicator
=
new
MongoHealthIndicator
(
mongoTemplate
);
Health
health
=
healthIndicator
.
health
();
assert
Equals
(
Status
.
DOWN
,
health
.
getStatus
()
);
assertT
rue
(((
String
)
health
.
getDetails
().
get
(
"error"
))
assert
That
(
health
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
assertT
hat
(((
String
)
health
.
getDetails
().
get
(
"error"
))
.
contains
(
"Connection failed"
));
verify
(
mongoTemplate
).
executeCommand
(
"{ buildInfo: 1 }"
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/OrderedHealthAggregatorTests.java
View file @
94677b35
...
...
@@ -23,7 +23,7 @@ import java.util.Map;
import
org.junit.Before
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link OrderedHealthAggregator}.
...
...
@@ -46,7 +46,8 @@ public class OrderedHealthAggregatorTests {
healths
.
put
(
"h2"
,
new
Health
.
Builder
().
status
(
Status
.
UP
).
build
());
healths
.
put
(
"h3"
,
new
Health
.
Builder
().
status
(
Status
.
UNKNOWN
).
build
());
healths
.
put
(
"h4"
,
new
Health
.
Builder
().
status
(
Status
.
OUT_OF_SERVICE
).
build
());
assertEquals
(
Status
.
DOWN
,
this
.
healthAggregator
.
aggregate
(
healths
).
getStatus
());
assertThat
(
this
.
healthAggregator
.
aggregate
(
healths
).
getStatus
())
.
isEqualTo
(
Status
.
DOWN
);
}
@Test
...
...
@@ -58,8 +59,8 @@ public class OrderedHealthAggregatorTests {
healths
.
put
(
"h2"
,
new
Health
.
Builder
().
status
(
Status
.
UP
).
build
());
healths
.
put
(
"h3"
,
new
Health
.
Builder
().
status
(
Status
.
UNKNOWN
).
build
());
healths
.
put
(
"h4"
,
new
Health
.
Builder
().
status
(
Status
.
OUT_OF_SERVICE
).
build
());
assert
Equals
(
Status
.
UNKNOWN
,
this
.
healthAggregator
.
aggregate
(
healths
).
getStatus
()
);
assert
That
(
this
.
healthAggregator
.
aggregate
(
healths
).
getStatus
())
.
isEqualTo
(
Status
.
UNKNOWN
);
}
@Test
...
...
@@ -70,7 +71,8 @@ public class OrderedHealthAggregatorTests {
healths
.
put
(
"h3"
,
new
Health
.
Builder
().
status
(
Status
.
UNKNOWN
).
build
());
healths
.
put
(
"h4"
,
new
Health
.
Builder
().
status
(
Status
.
OUT_OF_SERVICE
).
build
());
healths
.
put
(
"h5"
,
new
Health
.
Builder
().
status
(
new
Status
(
"CUSTOM"
)).
build
());
assertEquals
(
Status
.
DOWN
,
this
.
healthAggregator
.
aggregate
(
healths
).
getStatus
());
assertThat
(
this
.
healthAggregator
.
aggregate
(
healths
).
getStatus
())
.
isEqualTo
(
Status
.
DOWN
);
}
@Test
...
...
@@ -83,7 +85,8 @@ public class OrderedHealthAggregatorTests {
healths
.
put
(
"h3"
,
new
Health
.
Builder
().
status
(
Status
.
UNKNOWN
).
build
());
healths
.
put
(
"h4"
,
new
Health
.
Builder
().
status
(
Status
.
OUT_OF_SERVICE
).
build
());
healths
.
put
(
"h5"
,
new
Health
.
Builder
().
status
(
new
Status
(
"CUSTOM"
)).
build
());
assertEquals
(
Status
.
DOWN
,
this
.
healthAggregator
.
aggregate
(
healths
).
getStatus
());
assertThat
(
this
.
healthAggregator
.
aggregate
(
healths
).
getStatus
())
.
isEqualTo
(
Status
.
DOWN
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RabbitHealthIndicatorTests.java
View file @
94677b35
...
...
@@ -26,8 +26,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link RabbitHealthIndicator}.
...
...
@@ -50,10 +49,11 @@ public class RabbitHealthIndicatorTests {
this
.
context
=
new
AnnotationConfigApplicationContext
(
PropertyPlaceholderAutoConfiguration
.
class
,
RabbitAutoConfiguration
.
class
,
EndpointAutoConfiguration
.
class
,
HealthIndicatorAutoConfiguration
.
class
);
assertEquals
(
1
,
this
.
context
.
getBeanNamesForType
(
RabbitAdmin
.
class
).
length
);
assertThat
(
this
.
context
.
getBeanNamesForType
(
RabbitAdmin
.
class
).
length
)
.
isEqualTo
(
1
);
RabbitHealthIndicator
healthIndicator
=
this
.
context
.
getBean
(
RabbitHealthIndicator
.
class
);
assert
NotNull
(
healthIndicator
);
assert
That
(
healthIndicator
).
isNotNull
(
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java
View file @
94677b35
...
...
@@ -30,9 +30,7 @@ import org.springframework.data.redis.RedisConnectionFailureException;
import
org.springframework.data.redis.connection.RedisConnection
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
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
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
...
...
@@ -58,18 +56,17 @@ public class RedisHealthIndicatorTests {
this
.
context
=
new
AnnotationConfigApplicationContext
(
PropertyPlaceholderAutoConfiguration
.
class
,
RedisAutoConfiguration
.
class
,
EndpointAutoConfiguration
.
class
,
HealthIndicatorAutoConfiguration
.
class
);
assert
Equals
(
1
,
this
.
context
.
getBeanNamesForType
(
RedisConnectionFactory
.
class
).
length
);
assert
That
(
this
.
context
.
getBeanNamesForType
(
RedisConnectionFactory
.
class
))
.
hasSize
(
1
);
RedisHealthIndicator
healthIndicator
=
this
.
context
.
getBean
(
RedisHealthIndicator
.
class
);
assert
NotNull
(
healthIndicator
);
assert
That
(
healthIndicator
).
isNotNull
(
);
}
@Test
public
void
redisIsUp
()
throws
Exception
{
Properties
info
=
new
Properties
();
info
.
put
(
"redis_version"
,
"2.8.9"
);
RedisConnection
redisConnection
=
mock
(
RedisConnection
.
class
);
RedisConnectionFactory
redisConnectionFactory
=
mock
(
RedisConnectionFactory
.
class
);
...
...
@@ -77,11 +74,9 @@ public class RedisHealthIndicatorTests {
given
(
redisConnection
.
info
()).
willReturn
(
info
);
RedisHealthIndicator
healthIndicator
=
new
RedisHealthIndicator
(
redisConnectionFactory
);
Health
health
=
healthIndicator
.
health
();
assertEquals
(
Status
.
UP
,
health
.
getStatus
());
assertEquals
(
"2.8.9"
,
health
.
getDetails
().
get
(
"version"
));
assertThat
(
health
.
getStatus
()).
isEqualTo
(
Status
.
UP
);
assertThat
(
health
.
getDetails
().
get
(
"version"
)).
isEqualTo
(
"2.8.9"
);
verify
(
redisConnectionFactory
).
getConnection
();
verify
(
redisConnection
).
info
();
}
...
...
@@ -96,13 +91,12 @@ public class RedisHealthIndicatorTests {
.
willThrow
(
new
RedisConnectionFailureException
(
"Connection failed"
));
RedisHealthIndicator
healthIndicator
=
new
RedisHealthIndicator
(
redisConnectionFactory
);
Health
health
=
healthIndicator
.
health
();
assert
Equals
(
Status
.
DOWN
,
health
.
getStatus
()
);
assertT
rue
(((
String
)
health
.
getDetails
().
get
(
"error"
))
assert
That
(
health
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
assertT
hat
(((
String
)
health
.
getDetails
().
get
(
"error"
))
.
contains
(
"Connection failed"
));
verify
(
redisConnectionFactory
).
getConnection
();
verify
(
redisConnection
).
info
();
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SolrHealthIndicatorTests.java
View file @
94677b35
...
...
@@ -30,9 +30,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import
org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
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
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -57,10 +55,11 @@ public class SolrHealthIndicatorTests {
this
.
context
=
new
AnnotationConfigApplicationContext
(
PropertyPlaceholderAutoConfiguration
.
class
,
SolrAutoConfiguration
.
class
,
EndpointAutoConfiguration
.
class
,
HealthIndicatorAutoConfiguration
.
class
);
assertEquals
(
1
,
this
.
context
.
getBeanNamesForType
(
SolrServer
.
class
).
length
);
assertThat
(
this
.
context
.
getBeanNamesForType
(
SolrServer
.
class
).
length
)
.
isEqualTo
(
1
);
SolrHealthIndicator
healthIndicator
=
this
.
context
.
getBean
(
SolrHealthIndicator
.
class
);
assert
NotNull
(
healthIndicator
);
assert
That
(
healthIndicator
).
isNotNull
(
);
}
@Test
...
...
@@ -71,22 +70,21 @@ public class SolrHealthIndicatorTests {
response
.
add
(
"status"
,
"OK"
);
pingResponse
.
setResponse
(
response
);
given
(
solrServer
.
ping
()).
willReturn
(
pingResponse
);
SolrHealthIndicator
healthIndicator
=
new
SolrHealthIndicator
(
solrServer
);
Health
health
=
healthIndicator
.
health
();
assert
Equals
(
Status
.
UP
,
health
.
getStatus
()
);
assert
Equals
(
"OK"
,
health
.
getDetails
().
get
(
"solrStatus"
)
);
assert
That
(
health
.
getStatus
()).
isEqualTo
(
Status
.
UP
);
assert
That
(
health
.
getDetails
().
get
(
"solrStatus"
)).
isEqualTo
(
"OK"
);
}
@Test
public
void
solrIsDown
()
throws
Exception
{
SolrServer
solrServer
=
mock
(
SolrServer
.
class
);
given
(
solrServer
.
ping
()).
willThrow
(
new
IOException
(
"Connection failed"
));
SolrHealthIndicator
healthIndicator
=
new
SolrHealthIndicator
(
solrServer
);
Health
health
=
healthIndicator
.
health
();
assert
Equals
(
Status
.
DOWN
,
health
.
getStatus
()
);
assertT
rue
(((
String
)
health
.
getDetails
().
get
(
"error"
))
assert
That
(
health
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
assertT
hat
(((
String
)
health
.
getDetails
().
get
(
"error"
))
.
contains
(
"Connection failed"
));
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/aggregate/AggregateMetricReaderTests.java
View file @
94677b35
...
...
@@ -24,8 +24,7 @@ import org.springframework.boot.actuate.metrics.Metric;
import
org.springframework.boot.actuate.metrics.repository.InMemoryMetricRepository
;
import
org.springframework.boot.actuate.metrics.writer.Delta
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link AggregateMetricReader}.
...
...
@@ -41,20 +40,21 @@ public class AggregateMetricReaderTests {
@Test
public
void
writeAndReadDefaults
()
{
this
.
source
.
set
(
new
Metric
<
Double
>(
"foo.bar.spam"
,
2.3
));
assert
Equals
(
2.3
,
this
.
reader
.
findOne
(
"aggregate.spam"
).
getValue
()
);
assert
That
(
this
.
reader
.
findOne
(
"aggregate.spam"
).
getValue
()).
isEqualTo
(
2.3
);
}
@Test
public
void
defaultKeyPattern
()
{
this
.
source
.
set
(
new
Metric
<
Double
>(
"foo.bar.spam.bucket.wham"
,
2.3
));
assertEquals
(
2.3
,
this
.
reader
.
findOne
(
"aggregate.spam.bucket.wham"
).
getValue
());
assertThat
(
this
.
reader
.
findOne
(
"aggregate.spam.bucket.wham"
).
getValue
())
.
isEqualTo
(
2.3
);
}
@Test
public
void
addKeyPattern
()
{
this
.
source
.
set
(
new
Metric
<
Double
>(
"foo.bar.spam.bucket.wham"
,
2.3
));
this
.
reader
.
setKeyPattern
(
"d.d.k.d"
);
assert
Equals
(
2.3
,
this
.
reader
.
findOne
(
"aggregate.spam.wham"
).
getValue
()
);
assert
That
(
this
.
reader
.
findOne
(
"aggregate.spam.wham"
).
getValue
()).
isEqualTo
(
2.3
);
}
@Test
...
...
@@ -63,42 +63,43 @@ public class AggregateMetricReaderTests {
this
.
source
.
set
(
new
Metric
<
Double
>(
"off.bar.spam.bucket.wham"
,
2.4
));
this
.
reader
.
setPrefix
(
"www"
);
this
.
reader
.
setKeyPattern
(
"k.d.k.d"
);
assert
Equals
(
2.3
,
this
.
reader
.
findOne
(
"www.foo.spam.wham"
).
getValue
()
);
assert
Equals
(
2
,
this
.
reader
.
count
()
);
assert
That
(
this
.
reader
.
findOne
(
"www.foo.spam.wham"
).
getValue
()).
isEqualTo
(
2.3
);
assert
That
(
this
.
reader
.
count
()).
isEqualTo
(
2
);
}
@Test
public
void
writeAndReadExtraLong
()
{
this
.
source
.
set
(
new
Metric
<
Double
>(
"blee.foo.bar.spam"
,
2.3
));
this
.
reader
.
setKeyPattern
(
"d.d.d.k"
);
assert
Equals
(
2.3
,
this
.
reader
.
findOne
(
"aggregate.spam"
).
getValue
()
);
assert
That
(
this
.
reader
.
findOne
(
"aggregate.spam"
).
getValue
()).
isEqualTo
(
2.3
);
}
@Test
public
void
writeAndReadLatestValue
()
{
this
.
source
.
set
(
new
Metric
<
Double
>(
"foo.bar.spam"
,
2.3
,
new
Date
(
100L
)));
this
.
source
.
set
(
new
Metric
<
Double
>(
"oof.rab.spam"
,
2.4
,
new
Date
(
0L
)));
assert
Equals
(
2.3
,
this
.
reader
.
findOne
(
"aggregate.spam"
).
getValue
()
);
assert
That
(
this
.
reader
.
findOne
(
"aggregate.spam"
).
getValue
()).
isEqualTo
(
2.3
);
}
@Test
public
void
onlyPrefixed
()
{
this
.
source
.
set
(
new
Metric
<
Double
>(
"foo.bar.spam"
,
2.3
));
assert
Null
(
this
.
reader
.
findOne
(
"spam"
)
);
assert
That
(
this
.
reader
.
findOne
(
"spam"
)).
isNull
(
);
}
@Test
public
void
incrementCounter
()
{
this
.
source
.
increment
(
new
Delta
<
Long
>(
"foo.bar.counter.spam"
,
2L
));
this
.
source
.
increment
(
new
Delta
<
Long
>(
"oof.rab.counter.spam"
,
3L
));
assertEquals
(
5L
,
this
.
reader
.
findOne
(
"aggregate.counter.spam"
).
getValue
());
assertThat
(
this
.
reader
.
findOne
(
"aggregate.counter.spam"
).
getValue
())
.
isEqualTo
(
5L
);
}
@Test
public
void
countGauges
()
{
this
.
source
.
set
(
new
Metric
<
Double
>(
"foo.bar.spam"
,
2.3
));
this
.
source
.
set
(
new
Metric
<
Double
>(
"oof.rab.spam"
,
2.4
));
assert
Equals
(
1
,
this
.
reader
.
count
()
);
assert
That
(
this
.
reader
.
count
()).
isEqualTo
(
1
);
}
@Test
...
...
@@ -107,7 +108,7 @@ public class AggregateMetricReaderTests {
this
.
source
.
set
(
new
Metric
<
Double
>(
"oof.rab.spam"
,
2.4
));
this
.
source
.
increment
(
new
Delta
<
Long
>(
"foo.bar.counter.spam"
,
2L
));
this
.
source
.
increment
(
new
Delta
<
Long
>(
"oof.rab.counter.spam"
,
3L
));
assert
Equals
(
2
,
this
.
reader
.
count
()
);
assert
That
(
this
.
reader
.
count
()).
isEqualTo
(
2
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/BufferGaugeServiceSpeedTests.java
View file @
94677b35
...
...
@@ -42,7 +42,7 @@ import org.springframework.boot.actuate.metrics.Metric;
import
org.springframework.lang.UsesJava8
;
import
org.springframework.util.StopWatch
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Speed tests for {@link BufferGaugeService}.
...
...
@@ -117,7 +117,7 @@ public class BufferGaugeServiceSpeedTests {
});
watch
.
stop
();
System
.
err
.
println
(
"Read("
+
count
+
")="
+
watch
.
getLastTaskTimeMillis
()
+
"ms"
);
assertT
rue
(
number
*
threadCount
<
total
.
longValue
()
);
assertT
hat
(
number
*
threadCount
<
total
.
longValue
()).
isTrue
(
);
}
@Theory
...
...
@@ -141,7 +141,7 @@ public class BufferGaugeServiceSpeedTests {
});
watch
.
stop
();
System
.
err
.
println
(
"Read("
+
count
+
")="
+
watch
.
getLastTaskTimeMillis
()
+
"ms"
);
assertT
rue
(
0
<
total
.
longValue
()
);
assertT
hat
(
0
<
total
.
longValue
()).
isTrue
(
);
}
private
void
iterate
(
String
taskName
)
throws
Exception
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/BufferMetricReaderTests.java
View file @
94677b35
...
...
@@ -18,8 +18,7 @@ package org.springframework.boot.actuate.metrics.buffer;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link BufferMetricReader}.
...
...
@@ -39,21 +38,21 @@ public class BufferMetricReaderTests {
public
void
countReflectsNumberOfMetrics
()
{
this
.
gauges
.
set
(
"foo"
,
1
);
this
.
counters
.
increment
(
"bar"
,
2
);
assert
Equals
(
2
,
this
.
reader
.
count
()
);
assert
That
(
this
.
reader
.
count
()).
isEqualTo
(
2
);
}
@Test
public
void
findGauge
()
{
this
.
gauges
.
set
(
"foo"
,
1
);
assert
NotNull
(
this
.
reader
.
findOne
(
"foo"
)
);
assert
Equals
(
1
,
this
.
reader
.
count
()
);
assert
That
(
this
.
reader
.
findOne
(
"foo"
)).
isNotNull
(
);
assert
That
(
this
.
reader
.
count
()).
isEqualTo
(
1
);
}
@Test
public
void
findCounter
()
{
this
.
counters
.
increment
(
"foo"
,
1
);
assert
NotNull
(
this
.
reader
.
findOne
(
"foo"
)
);
assert
Equals
(
1
,
this
.
reader
.
count
()
);
assert
That
(
this
.
reader
.
findOne
(
"foo"
)).
isNotNull
(
);
assert
That
(
this
.
reader
.
count
()).
isEqualTo
(
1
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/CounterBuffersTests.java
View file @
94677b35
...
...
@@ -20,8 +20,7 @@ import java.util.function.Consumer;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link CounterBuffers}.
...
...
@@ -43,7 +42,7 @@ public class CounterBuffersTests {
CounterBuffersTests
.
this
.
value
=
buffer
.
getValue
();
}
});
assert
Equals
(
2
,
this
.
value
);
assert
That
(
this
.
value
).
isEqualTo
(
2
);
}
@Test
...
...
@@ -54,12 +53,12 @@ public class CounterBuffersTests {
CounterBuffersTests
.
this
.
value
=
buffer
.
getValue
();
}
});
assert
Equals
(
0
,
this
.
value
);
assert
That
(
this
.
value
).
isEqualTo
(
0
);
}
@Test
public
void
findNonExistent
()
{
assert
Null
(
this
.
buffers
.
find
(
"foo"
)
);
assert
That
(
this
.
buffers
.
find
(
"foo"
)).
isNull
(
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/CounterServiceSpeedTests.java
View file @
94677b35
...
...
@@ -41,7 +41,7 @@ import org.springframework.boot.actuate.metrics.Metric;
import
org.springframework.lang.UsesJava8
;
import
org.springframework.util.StopWatch
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Speed tests for {@link CounterService}.
...
...
@@ -116,7 +116,7 @@ public class CounterServiceSpeedTests {
});
watch
.
stop
();
System
.
err
.
println
(
"Read("
+
count
+
")="
+
watch
.
getLastTaskTimeMillis
()
+
"ms"
);
assert
Equals
(
number
*
threadCount
,
total
.
longValue
()
);
assert
That
(
total
.
longValue
()).
isEqualTo
(
number
*
threadCount
);
}
@Theory
...
...
@@ -140,7 +140,7 @@ public class CounterServiceSpeedTests {
});
watch
.
stop
();
System
.
err
.
println
(
"Read("
+
count
+
")="
+
watch
.
getLastTaskTimeMillis
()
+
"ms"
);
assert
Equals
(
number
*
threadCount
,
total
.
longValue
()
);
assert
That
(
total
.
longValue
()).
isEqualTo
(
number
*
threadCount
);
}
private
void
iterate
(
String
taskName
)
throws
Exception
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/DefaultCounterServiceSpeedTests.java
View file @
94677b35
...
...
@@ -41,7 +41,7 @@ import org.springframework.boot.actuate.metrics.writer.DefaultCounterService;
import
org.springframework.lang.UsesJava8
;
import
org.springframework.util.StopWatch
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Speed tests for {@link DefaultCounterService}.
...
...
@@ -124,7 +124,7 @@ public class DefaultCounterServiceSpeedTests {
});
watch
.
stop
();
System
.
err
.
println
(
"Read("
+
count
+
")="
+
watch
.
getLastTaskTimeMillis
()
+
"ms"
);
assert
Equals
(
number
*
threadCount
,
total
.
longValue
()
);
assert
That
(
total
.
longValue
()).
isEqualTo
(
number
*
threadCount
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/DefaultGaugeServiceSpeedTests.java
View file @
94677b35
...
...
@@ -41,7 +41,7 @@ import org.springframework.boot.actuate.metrics.writer.DefaultGaugeService;
import
org.springframework.lang.UsesJava8
;
import
org.springframework.util.StopWatch
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Speed tests for {@link DefaultGaugeService}.
...
...
@@ -125,7 +125,7 @@ public class DefaultGaugeServiceSpeedTests {
});
watch
.
stop
();
System
.
err
.
println
(
"Read("
+
count
+
")="
+
watch
.
getLastTaskTimeMillis
()
+
"ms"
);
assertT
rue
(
0
<
total
.
longValue
()
);
assertT
hat
(
0
<
total
.
longValue
()).
isTrue
(
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/DropwizardCounterServiceSpeedTests.java
View file @
94677b35
...
...
@@ -42,7 +42,7 @@ import org.springframework.boot.actuate.metrics.reader.MetricRegistryMetricReade
import
org.springframework.lang.UsesJava8
;
import
org.springframework.util.StopWatch
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Speeds tests for {@link DropwizardMetricServices DropwizardMetricServices'}
...
...
@@ -127,7 +127,7 @@ public class DropwizardCounterServiceSpeedTests {
});
watch
.
stop
();
System
.
err
.
println
(
"Read("
+
count
+
")="
+
watch
.
getLastTaskTimeMillis
()
+
"ms"
);
assert
Equals
(
number
*
threadCount
,
total
.
longValue
()
);
assert
That
(
total
.
longValue
()).
isEqualTo
(
number
*
threadCount
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/dropwizard/DropwizardMetricServicesTests.java
View file @
94677b35
...
...
@@ -23,8 +23,7 @@ import com.codahale.metrics.Gauge;
import
com.codahale.metrics.MetricRegistry
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link DropwizardMetricServices}.
...
...
@@ -42,7 +41,7 @@ public class DropwizardMetricServicesTests {
this
.
writer
.
increment
(
"foo"
);
this
.
writer
.
increment
(
"foo"
);
this
.
writer
.
increment
(
"foo"
);
assert
Equals
(
3
,
this
.
registry
.
counter
(
"counter.foo"
).
getCount
()
);
assert
That
(
this
.
registry
.
counter
(
"counter.foo"
).
getCount
()).
isEqualTo
(
3
);
}
@Test
...
...
@@ -50,7 +49,7 @@ public class DropwizardMetricServicesTests {
this
.
writer
.
increment
(
"meter.foo"
);
this
.
writer
.
increment
(
"meter.foo"
);
this
.
writer
.
increment
(
"meter.foo"
);
assert
Equals
(
3
,
this
.
registry
.
meter
(
"meter.foo"
).
getCount
()
);
assert
That
(
this
.
registry
.
meter
(
"meter.foo"
).
getCount
()).
isEqualTo
(
3
);
}
@Test
...
...
@@ -58,7 +57,7 @@ public class DropwizardMetricServicesTests {
this
.
writer
.
increment
(
"counter.foo"
);
this
.
writer
.
increment
(
"counter.foo"
);
this
.
writer
.
increment
(
"counter.foo"
);
assert
Equals
(
3
,
this
.
registry
.
counter
(
"counter.foo"
).
getCount
()
);
assert
That
(
this
.
registry
.
counter
(
"counter.foo"
).
getCount
()).
isEqualTo
(
3
);
}
@Test
...
...
@@ -66,23 +65,23 @@ public class DropwizardMetricServicesTests {
this
.
writer
.
submit
(
"foo"
,
2.1
);
@SuppressWarnings
(
"unchecked"
)
Gauge
<
Double
>
gauge
=
(
Gauge
<
Double
>)
this
.
registry
.
getMetrics
().
get
(
"gauge.foo"
);
assert
Equals
(
new
Double
(
2.1
),
gauge
.
getValue
(
));
assert
That
(
gauge
.
getValue
()).
isEqualTo
(
new
Double
(
2.1
));
this
.
writer
.
submit
(
"foo"
,
2.3
);
assert
Equals
(
new
Double
(
2.3
),
gauge
.
getValue
(
));
assert
That
(
gauge
.
getValue
()).
isEqualTo
(
new
Double
(
2.3
));
}
@Test
public
void
setPredefinedTimer
()
{
this
.
writer
.
submit
(
"timer.foo"
,
200
);
this
.
writer
.
submit
(
"timer.foo"
,
300
);
assert
Equals
(
2
,
this
.
registry
.
timer
(
"timer.foo"
).
getCount
()
);
assert
That
(
this
.
registry
.
timer
(
"timer.foo"
).
getCount
()).
isEqualTo
(
2
);
}
@Test
public
void
setPredefinedHistogram
()
{
this
.
writer
.
submit
(
"histogram.foo"
,
2.1
);
this
.
writer
.
submit
(
"histogram.foo"
,
2.3
);
assert
Equals
(
2
,
this
.
registry
.
histogram
(
"histogram.foo"
).
getCount
()
);
assert
That
(
this
.
registry
.
histogram
(
"histogram.foo"
).
getCount
()).
isEqualTo
(
2
);
}
/**
...
...
@@ -108,7 +107,8 @@ public class DropwizardMetricServicesTests {
}
for
(
WriterThread
thread
:
threads
)
{
assertFalse
(
"expected thread caused unexpected exception"
,
thread
.
isFailed
());
assertThat
(
thread
.
isFailed
())
.
as
(
"expected thread caused unexpected exception"
).
isFalse
();
}
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/MetricCopyExporterTests.java
View file @
94677b35
...
...
@@ -25,7 +25,7 @@ import org.springframework.boot.actuate.metrics.repository.InMemoryMetricReposit
import
org.springframework.boot.actuate.metrics.writer.Delta
;
import
org.springframework.boot.actuate.metrics.writer.GaugeWriter
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link MetricCopyExporter}.
...
...
@@ -45,18 +45,18 @@ public class MetricCopyExporterTests {
public
void
export
()
{
this
.
reader
.
set
(
new
Metric
<
Number
>(
"foo"
,
2.3
));
this
.
exporter
.
export
();
assert
Equals
(
1
,
this
.
writer
.
count
()
);
assert
That
(
this
.
writer
.
count
()).
isEqualTo
(
1
);
}
@Test
public
void
counter
()
{
this
.
reader
.
increment
(
new
Delta
<
Number
>(
"counter.foo"
,
2
));
this
.
exporter
.
export
();
assert
Equals
(
1
,
this
.
writer
.
count
()
);
assert
That
(
this
.
writer
.
count
()).
isEqualTo
(
1
);
this
.
reader
.
increment
(
new
Delta
<
Number
>(
"counter.foo"
,
3
));
this
.
exporter
.
export
();
this
.
exporter
.
flush
();
assert
Equals
(
5L
,
this
.
writer
.
findOne
(
"counter.foo"
).
getValue
()
);
assert
That
(
this
.
writer
.
findOne
(
"counter.foo"
).
getValue
()).
isEqualTo
(
5L
);
}
@Test
...
...
@@ -68,7 +68,7 @@ public class MetricCopyExporterTests {
this
.
reader
.
increment
(
new
Delta
<
Number
>(
"counter.foo"
,
3
));
exporter
.
export
();
exporter
.
flush
();
assert
Equals
(
5L
,
writer
.
getValue
().
getValue
()
);
assert
That
(
writer
.
getValue
().
getValue
()).
isEqualTo
(
5L
);
}
@Test
...
...
@@ -76,7 +76,7 @@ public class MetricCopyExporterTests {
this
.
exporter
.
setIncludes
(
"*"
);
this
.
reader
.
set
(
new
Metric
<
Number
>(
"foo"
,
2.3
));
this
.
exporter
.
export
();
assert
Equals
(
1
,
this
.
writer
.
count
()
);
assert
That
(
this
.
writer
.
count
()).
isEqualTo
(
1
);
}
@Test
...
...
@@ -86,7 +86,7 @@ public class MetricCopyExporterTests {
this
.
reader
.
set
(
new
Metric
<
Number
>(
"foo"
,
2.3
));
this
.
reader
.
set
(
new
Metric
<
Number
>(
"bar"
,
2.4
));
this
.
exporter
.
export
();
assert
Equals
(
1
,
this
.
writer
.
count
()
);
assert
That
(
this
.
writer
.
count
()).
isEqualTo
(
1
);
}
@Test
...
...
@@ -95,7 +95,7 @@ public class MetricCopyExporterTests {
this
.
reader
.
set
(
new
Metric
<
Number
>(
"foo"
,
2.3
));
this
.
reader
.
set
(
new
Metric
<
Number
>(
"bar"
,
2.4
));
this
.
exporter
.
export
();
assert
Equals
(
1
,
this
.
writer
.
count
()
);
assert
That
(
this
.
writer
.
count
()).
isEqualTo
(
1
);
}
@Test
...
...
@@ -103,7 +103,7 @@ public class MetricCopyExporterTests {
this
.
reader
.
set
(
new
Metric
<
Number
>(
"foo"
,
2.3
));
this
.
exporter
.
setEarliestTimestamp
(
new
Date
(
System
.
currentTimeMillis
()
+
10000
));
this
.
exporter
.
export
();
assert
Equals
(
0
,
this
.
writer
.
count
()
);
assert
That
(
this
.
writer
.
count
()).
isEqualTo
(
0
);
}
@Test
...
...
@@ -112,7 +112,7 @@ public class MetricCopyExporterTests {
this
.
exporter
.
setIgnoreTimestamps
(
true
);
this
.
exporter
.
setEarliestTimestamp
(
new
Date
(
System
.
currentTimeMillis
()
+
10000
));
this
.
exporter
.
export
();
assert
Equals
(
1
,
this
.
writer
.
count
()
);
assert
That
(
this
.
writer
.
count
()).
isEqualTo
(
1
);
}
private
static
class
SimpleGaugeWriter
implements
GaugeWriter
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/MetricExportersTests.java
View file @
94677b35
...
...
@@ -28,8 +28,7 @@ import org.springframework.boot.actuate.metrics.writer.GaugeWriter;
import
org.springframework.boot.actuate.metrics.writer.MetricWriter
;
import
org.springframework.scheduling.config.ScheduledTaskRegistrar
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link MetricExporters}.
...
...
@@ -54,8 +53,8 @@ public class MetricExportersTests {
this
.
exporters
.
setReader
(
this
.
reader
);
this
.
exporters
.
setWriters
(
this
.
writers
);
this
.
exporters
.
configureTasks
(
new
ScheduledTaskRegistrar
());
assert
NotNull
(
this
.
exporters
.
getExporters
()
);
assert
Equals
(
0
,
this
.
exporters
.
getExporters
().
size
()
);
assert
That
(
this
.
exporters
.
getExporters
()).
isNotNull
(
);
assert
That
(
this
.
exporters
.
getExporters
()).
isEmpty
(
);
}
@Test
...
...
@@ -66,8 +65,8 @@ public class MetricExportersTests {
this
.
exporters
.
setReader
(
this
.
reader
);
this
.
exporters
.
setWriters
(
this
.
writers
);
this
.
exporters
.
configureTasks
(
new
ScheduledTaskRegistrar
());
assert
NotNull
(
this
.
exporters
.
getExporters
()
);
assert
Equals
(
1
,
this
.
exporters
.
getExporters
().
size
()
);
assert
That
(
this
.
exporters
.
getExporters
()).
isNotNull
(
);
assert
That
(
this
.
exporters
.
getExporters
()).
hasSize
(
1
);
}
@Test
...
...
@@ -77,8 +76,8 @@ public class MetricExportersTests {
this
.
exporters
.
setExporters
(
Collections
.<
String
,
Exporter
>
singletonMap
(
"foo"
,
new
MetricCopyExporter
(
this
.
reader
,
this
.
writer
)));
this
.
exporters
.
configureTasks
(
new
ScheduledTaskRegistrar
());
assert
NotNull
(
this
.
exporters
.
getExporters
()
);
assert
Equals
(
1
,
this
.
exporters
.
getExporters
().
size
()
);
assert
That
(
this
.
exporters
.
getExporters
()).
isNotNull
(
);
assert
That
(
this
.
exporters
.
getExporters
()).
hasSize
(
1
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/PrefixMetricGroupExporterTests.java
View file @
94677b35
...
...
@@ -25,7 +25,7 @@ import org.springframework.boot.actuate.metrics.Iterables;
import
org.springframework.boot.actuate.metrics.Metric
;
import
org.springframework.boot.actuate.metrics.repository.InMemoryMetricRepository
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link PrefixMetricGroupExporter}.
...
...
@@ -47,7 +47,7 @@ public class PrefixMetricGroupExporterTests {
this
.
reader
.
set
(
new
Metric
<
Number
>(
"foo.spam"
,
1.3
));
this
.
exporter
.
setGroups
(
Collections
.
singleton
(
"foo"
));
this
.
exporter
.
export
();
assert
Equals
(
1
,
Iterables
.
collection
(
this
.
writer
.
groups
()).
size
()
);
assert
That
(
Iterables
.
collection
(
this
.
writer
.
groups
())).
hasSize
(
1
);
}
@Test
...
...
@@ -56,7 +56,7 @@ public class PrefixMetricGroupExporterTests {
this
.
reader
.
set
(
new
Metric
<
Number
>(
"foo.spam"
,
1.3
));
this
.
exporter
.
setGroups
(
Collections
.
singleton
(
"bar"
));
this
.
exporter
.
export
();
assert
Equals
(
0
,
Iterables
.
collection
(
this
.
writer
.
groups
()).
size
()
);
assert
That
(
Iterables
.
collection
(
this
.
writer
.
groups
())).
isEmpty
(
);
}
@Test
...
...
@@ -64,8 +64,8 @@ public class PrefixMetricGroupExporterTests {
this
.
reader
.
set
(
"foo"
,
Arrays
.<
Metric
<?>>
asList
(
new
Metric
<
Number
>(
"bar"
,
2.3
),
new
Metric
<
Number
>(
"spam"
,
1.3
)));
this
.
exporter
.
export
();
assert
Equals
(
1
,
this
.
writer
.
countGroups
()
);
assert
Equals
(
2
,
Iterables
.
collection
(
this
.
writer
.
findAll
(
"foo"
)).
size
()
);
assert
That
(
this
.
writer
.
countGroups
()).
isEqualTo
(
1
);
assert
That
(
Iterables
.
collection
(
this
.
writer
.
findAll
(
"foo"
))).
hasSize
(
2
);
}
@Test
...
...
@@ -75,7 +75,7 @@ public class PrefixMetricGroupExporterTests {
this
.
reader
.
set
(
new
Metric
<
Number
>(
"foobar.spam"
,
1.3
));
this
.
exporter
.
setGroups
(
Collections
.
singleton
(
"foo"
));
this
.
exporter
.
export
();
assert
Equals
(
1
,
Iterables
.
collection
(
this
.
writer
.
groups
()).
size
()
);
assert
That
(
Iterables
.
collection
(
this
.
writer
.
groups
())).
hasSize
(
1
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/RichGaugeExporterTests.java
View file @
94677b35
...
...
@@ -23,7 +23,7 @@ import org.springframework.boot.actuate.metrics.Metric;
import
org.springframework.boot.actuate.metrics.repository.InMemoryMetricRepository
;
import
org.springframework.boot.actuate.metrics.rich.InMemoryRichGaugeRepository
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link RichGaugeExporter}.
...
...
@@ -43,7 +43,7 @@ public class RichGaugeExporterTests {
public
void
prefixedMetricsCopied
()
{
this
.
reader
.
set
(
new
Metric
<
Number
>(
"foo"
,
2.3
));
this
.
exporter
.
export
();
assert
Equals
(
1
,
Iterables
.
collection
(
this
.
writer
.
groups
()).
size
()
);
assert
That
(
Iterables
.
collection
(
this
.
writer
.
groups
())).
hasSize
(
1
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricReaderTests.java
View file @
94677b35
...
...
@@ -32,7 +32,7 @@ import org.springframework.integration.monitor.IntegrationMBeanExporter;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link SpringIntegrationMetricReader}.
...
...
@@ -50,7 +50,7 @@ public class SpringIntegrationMetricReaderTests {
@Test
public
void
test
()
{
assertT
rue
(
this
.
reader
.
count
()
>
0
);
assertT
hat
(
this
.
reader
.
count
()
>
0
).
isTrue
(
);
}
@Configuration
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/jmx/DefaultMetricNamingStrategyTests.java
View file @
94677b35
...
...
@@ -20,7 +20,7 @@ import javax.management.ObjectName;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link DefaultMetricNamingStrategy}.
...
...
@@ -35,37 +35,37 @@ public class DefaultMetricNamingStrategyTests {
public
void
simpleName
()
throws
Exception
{
ObjectName
name
=
this
.
strategy
.
getObjectName
(
null
,
"domain:type=MetricValue,name=foo"
);
assert
Equals
(
"domain"
,
name
.
getDomain
()
);
assert
Equals
(
"foo"
,
name
.
getKeyProperty
(
"type"
)
);
assert
That
(
name
.
getDomain
()).
isEqualTo
(
"domain"
);
assert
That
(
name
.
getKeyProperty
(
"type"
)).
isEqualTo
(
"foo"
);
}
@Test
public
void
onePeriod
()
throws
Exception
{
ObjectName
name
=
this
.
strategy
.
getObjectName
(
null
,
"domain:type=MetricValue,name=foo.bar"
);
assert
Equals
(
"domain"
,
name
.
getDomain
()
);
assert
Equals
(
"foo"
,
name
.
getKeyProperty
(
"type"
)
);
assert
Equals
(
"Wrong name: "
+
name
,
"bar"
,
name
.
getKeyProperty
(
"value"
)
);
assert
That
(
name
.
getDomain
()).
isEqualTo
(
"domain"
);
assert
That
(
name
.
getKeyProperty
(
"type"
)).
isEqualTo
(
"foo"
);
assert
That
(
name
.
getKeyProperty
(
"value"
)).
isEqualTo
(
"bar"
);
}
@Test
public
void
twoPeriods
()
throws
Exception
{
ObjectName
name
=
this
.
strategy
.
getObjectName
(
null
,
"domain:type=MetricValue,name=foo.bar.spam"
);
assert
Equals
(
"domain"
,
name
.
getDomain
()
);
assert
Equals
(
"foo"
,
name
.
getKeyProperty
(
"type"
)
);
assert
Equals
(
"Wrong name: "
+
name
,
"bar"
,
name
.
getKeyProperty
(
"name"
)
);
assert
Equals
(
"Wrong name: "
+
name
,
"spam"
,
name
.
getKeyProperty
(
"value"
)
);
assert
That
(
name
.
getDomain
()).
isEqualTo
(
"domain"
);
assert
That
(
name
.
getKeyProperty
(
"type"
)).
isEqualTo
(
"foo"
);
assert
That
(
name
.
getKeyProperty
(
"name"
)).
isEqualTo
(
"bar"
);
assert
That
(
name
.
getKeyProperty
(
"value"
)).
isEqualTo
(
"spam"
);
}
@Test
public
void
threePeriods
()
throws
Exception
{
ObjectName
name
=
this
.
strategy
.
getObjectName
(
null
,
"domain:type=MetricValue,name=foo.bar.spam.bucket"
);
assert
Equals
(
"domain"
,
name
.
getDomain
()
);
assert
Equals
(
"foo"
,
name
.
getKeyProperty
(
"type"
)
);
assert
Equals
(
"Wrong name: "
+
name
,
"bar"
,
name
.
getKeyProperty
(
"name"
)
);
assert
Equals
(
"Wrong name: "
+
name
,
"spam.bucket"
,
name
.
getKeyProperty
(
"value"
)
);
assert
That
(
name
.
getDomain
()).
isEqualTo
(
"domain"
);
assert
That
(
name
.
getKeyProperty
(
"type"
)).
isEqualTo
(
"foo"
);
assert
That
(
name
.
getKeyProperty
(
"name"
)).
isEqualTo
(
"bar"
);
assert
That
(
name
.
getKeyProperty
(
"value"
)).
isEqualTo
(
"spam.bucket"
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/reader/MetricRegistryMetricReaderTests.java
View file @
94677b35
...
...
@@ -25,10 +25,7 @@ import org.junit.Test;
import
org.springframework.boot.actuate.metrics.Metric
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link MetricRegistryMetricReader}.
...
...
@@ -52,9 +49,9 @@ public class MetricRegistryMetricReaderTests {
}
});
assertThat
(
this
.
metricReader
.
findOne
(
"test"
)
,
is
(
nullValue
())
);
assertThat
(
this
.
metricReader
.
findOne
(
"test"
)
).
isNull
(
);
this
.
metricRegistry
.
remove
(
"test"
);
assertThat
(
this
.
metricReader
.
findOne
(
"test"
)
,
is
(
nullValue
())
);
assertThat
(
this
.
metricReader
.
findOne
(
"test"
)
).
isNull
(
);
}
@Test
...
...
@@ -69,9 +66,9 @@ public class MetricRegistryMetricReaderTests {
});
Metric
<
Integer
>
metric
=
(
Metric
<
Integer
>)
this
.
metricReader
.
findOne
(
"test"
);
assertThat
(
metric
.
getValue
()
,
equalTo
(
Integer
.
valueOf
(
5
)
));
assertThat
(
metric
.
getValue
()
).
isEqualTo
(
Integer
.
valueOf
(
5
));
this
.
metricRegistry
.
remove
(
"test"
);
assertThat
(
this
.
metricReader
.
findOne
(
"test"
)
,
is
(
nullValue
())
);
assertThat
(
this
.
metricReader
.
findOne
(
"test"
)
).
isNull
(
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/InMemoryMetricRepositoryTests.java
View file @
94677b35
...
...
@@ -23,7 +23,8 @@ import org.junit.Test;
import
org.springframework.boot.actuate.metrics.Metric
;
import
org.springframework.boot.actuate.metrics.writer.Delta
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
offset
;
/**
* Tests for {@link InMemoryMetricRepository}.
...
...
@@ -35,13 +36,15 @@ public class InMemoryMetricRepositoryTests {
@Test
public
void
increment
()
{
this
.
repository
.
increment
(
new
Delta
<
Integer
>(
"foo"
,
1
,
new
Date
()));
assertEquals
(
1.0
,
this
.
repository
.
findOne
(
"foo"
).
getValue
().
doubleValue
(),
0.01
);
assertThat
(
this
.
repository
.
findOne
(
"foo"
).
getValue
().
doubleValue
()).
isEqualTo
(
1.0
,
offset
(
0.01
));
}
@Test
public
void
set
()
{
this
.
repository
.
set
(
new
Metric
<
Double
>(
"foo"
,
2.5
,
new
Date
()));
assertEquals
(
2.5
,
this
.
repository
.
findOne
(
"foo"
).
getValue
().
doubleValue
(),
0.01
);
assertThat
(
this
.
repository
.
findOne
(
"foo"
).
getValue
().
doubleValue
()).
isEqualTo
(
2.5
,
offset
(
0.01
));
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/InMemoryPrefixMetricRepositoryTests.java
View file @
94677b35
...
...
@@ -24,8 +24,7 @@ import org.junit.Test;
import
org.springframework.boot.actuate.metrics.Metric
;
import
org.springframework.boot.actuate.metrics.writer.Delta
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* @author Dave Syer
...
...
@@ -43,8 +42,8 @@ public class InMemoryPrefixMetricRepositoryTests {
for
(
Metric
<?>
metric
:
this
.
repository
.
findAll
(
"foo"
))
{
names
.
add
(
metric
.
getName
());
}
assert
Equals
(
2
,
names
.
size
()
);
assertT
rue
(
names
.
contains
(
"foo.bar"
)
);
assert
That
(
names
).
hasSize
(
2
);
assertT
hat
(
names
.
contains
(
"foo.bar"
)).
isTrue
(
);
}
@Test
...
...
@@ -54,8 +53,8 @@ public class InMemoryPrefixMetricRepositoryTests {
for
(
Metric
<?>
metric
:
this
.
repository
.
findAll
(
"foo.*"
))
{
names
.
add
(
metric
.
getName
());
}
assert
Equals
(
1
,
names
.
size
()
);
assertT
rue
(
names
.
contains
(
"foo.bar"
)
);
assert
That
(
names
).
hasSize
(
1
);
assertT
hat
(
names
.
contains
(
"foo.bar"
)).
isTrue
(
);
}
@Test
...
...
@@ -65,8 +64,8 @@ public class InMemoryPrefixMetricRepositoryTests {
for
(
Metric
<?>
metric
:
this
.
repository
.
findAll
(
"foo."
))
{
names
.
add
(
metric
.
getName
());
}
assert
Equals
(
1
,
names
.
size
()
);
assertT
rue
(
names
.
contains
(
"foo.bar"
)
);
assert
That
(
names
).
hasSize
(
1
);
assertT
hat
(
names
.
contains
(
"foo.bar"
)).
isTrue
(
);
}
@Test
...
...
@@ -77,8 +76,8 @@ public class InMemoryPrefixMetricRepositoryTests {
for
(
Metric
<?>
metric
:
this
.
repository
.
findAll
(
"foo"
))
{
names
.
add
(
metric
.
getName
());
}
assert
Equals
(
1
,
names
.
size
()
);
assertT
rue
(
names
.
contains
(
"foo.bar"
)
);
assert
That
(
names
).
hasSize
(
1
);
assertT
hat
(
names
.
contains
(
"foo.bar"
)).
isTrue
(
);
}
@Test
...
...
@@ -90,9 +89,9 @@ public class InMemoryPrefixMetricRepositoryTests {
for
(
Metric
<?>
metric
:
this
.
repository
.
findAll
(
"foo"
))
{
names
.
add
(
metric
.
getName
());
}
assert
Equals
(
2
,
names
.
size
()
);
assertT
rue
(
names
.
contains
(
"foo.bar"
)
);
assert
Equals
(
3L
,
this
.
repository
.
findOne
(
"foo.bar"
).
getValue
()
);
assert
That
(
names
).
hasSize
(
2
);
assertT
hat
(
names
.
contains
(
"foo.bar"
)).
isTrue
(
);
assert
That
(
this
.
repository
.
findOne
(
"foo.bar"
).
getValue
()).
isEqualTo
(
3L
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/redis/RedisMetricRepositoryTests.java
View file @
94677b35
...
...
@@ -27,9 +27,8 @@ import org.springframework.boot.actuate.metrics.writer.Delta;
import
org.springframework.boot.redis.RedisTestServer
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
offset
;
/**
* Tests for {@link RedisMetricRepository}.
...
...
@@ -54,26 +53,26 @@ public class RedisMetricRepositoryTests {
@After
public
void
clear
()
{
assert
NotNull
(
new
StringRedisTemplate
(
this
.
redis
.
getConnectionFactory
())
.
opsForValue
().
get
(
this
.
prefix
+
".foo"
));
assert
That
(
new
StringRedisTemplate
(
this
.
redis
.
getConnectionFactory
())
.
opsForValue
().
get
(
this
.
prefix
+
".foo"
))
.
isNotNull
()
;
this
.
repository
.
reset
(
"foo"
);
this
.
repository
.
reset
(
"bar"
);
assert
Null
(
new
StringRedisTemplate
(
this
.
redis
.
getConnectionFactory
())
.
opsForValue
().
get
(
this
.
prefix
+
".foo"
));
assert
That
(
new
StringRedisTemplate
(
this
.
redis
.
getConnectionFactory
())
.
opsForValue
().
get
(
this
.
prefix
+
".foo"
))
.
isNull
()
;
}
@Test
public
void
setAndGet
()
{
this
.
repository
.
set
(
new
Metric
<
Number
>(
"foo"
,
12.3
));
Metric
<?>
metric
=
this
.
repository
.
findOne
(
"foo"
);
assert
Equals
(
"foo"
,
metric
.
getName
()
);
assert
Equals
(
12.3
,
metric
.
getValue
().
doubleValue
(),
0.01
);
assert
That
(
metric
.
getName
()).
isEqualTo
(
"foo"
);
assert
That
(
metric
.
getValue
().
doubleValue
()).
isEqualTo
(
12.3
,
offset
(
0.01
)
);
}
@Test
public
void
incrementAndGet
()
{
this
.
repository
.
increment
(
new
Delta
<
Long
>(
"foo"
,
3L
));
assert
Equals
(
3
,
this
.
repository
.
findOne
(
"foo"
).
getValue
().
longValue
()
);
assert
That
(
this
.
repository
.
findOne
(
"foo"
).
getValue
().
longValue
()).
isEqualTo
(
3
);
}
@Test
...
...
@@ -81,29 +80,29 @@ public class RedisMetricRepositoryTests {
this
.
repository
.
set
(
new
Metric
<
Number
>(
"foo"
,
12.3
));
this
.
repository
.
increment
(
new
Delta
<
Long
>(
"foo"
,
3L
));
Metric
<?>
metric
=
this
.
repository
.
findOne
(
"foo"
);
assert
Equals
(
"foo"
,
metric
.
getName
()
);
assert
Equals
(
15.3
,
metric
.
getValue
().
doubleValue
(),
0.01
);
assert
That
(
metric
.
getName
()).
isEqualTo
(
"foo"
);
assert
That
(
metric
.
getValue
().
doubleValue
()).
isEqualTo
(
15.3
,
offset
(
0.01
)
);
}
@Test
public
void
findAll
()
{
this
.
repository
.
increment
(
new
Delta
<
Long
>(
"foo"
,
3L
));
this
.
repository
.
set
(
new
Metric
<
Number
>(
"bar"
,
12.3
));
assert
Equals
(
2
,
Iterables
.
collection
(
this
.
repository
.
findAll
()).
size
()
);
assert
That
(
Iterables
.
collection
(
this
.
repository
.
findAll
())).
hasSize
(
2
);
}
@Test
public
void
findOneWithAll
()
{
this
.
repository
.
increment
(
new
Delta
<
Long
>(
"foo"
,
3L
));
Metric
<?>
metric
=
this
.
repository
.
findAll
().
iterator
().
next
();
assert
Equals
(
"foo"
,
metric
.
getName
()
);
assert
That
(
metric
.
getName
()).
isEqualTo
(
"foo"
);
}
@Test
public
void
count
()
{
this
.
repository
.
increment
(
new
Delta
<
Long
>(
"foo"
,
3L
));
this
.
repository
.
set
(
new
Metric
<
Number
>(
"bar"
,
12.3
));
assert
Equals
(
2
,
this
.
repository
.
count
()
);
assert
That
(
this
.
repository
.
count
()).
isEqualTo
(
2
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/redis/RedisMultiMetricRepositoryTests.java
View file @
94677b35
...
...
@@ -37,9 +37,7 @@ import org.springframework.boot.actuate.metrics.writer.Delta;
import
org.springframework.boot.redis.RedisTestServer
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link RedisMultiMetricRepository}.
...
...
@@ -77,14 +75,14 @@ public class RedisMultiMetricRepositoryTests {
@After
public
void
clear
()
{
assertT
rue
(
new
StringRedisTemplate
(
this
.
redis
.
getConnectionFactory
()).
opsForZSet
()
.
size
(
"keys."
+
this
.
prefix
)
>
0
);
assertT
hat
(
new
StringRedisTemplate
(
this
.
redis
.
getConnectionFactory
()).
opsForZSet
()
.
size
(
"keys."
+
this
.
prefix
)
).
isGreaterThan
(
0
);
this
.
repository
.
reset
(
"foo"
);
this
.
repository
.
reset
(
"bar"
);
assert
Null
(
new
StringRedisTemplate
(
this
.
redis
.
getConnectionFactory
())
.
opsForValue
().
get
(
this
.
prefix
+
".foo"
));
assert
Null
(
new
StringRedisTemplate
(
this
.
redis
.
getConnectionFactory
())
.
opsForValue
().
get
(
this
.
prefix
+
".bar"
));
assert
That
(
new
StringRedisTemplate
(
this
.
redis
.
getConnectionFactory
())
.
opsForValue
().
get
(
this
.
prefix
+
".foo"
))
.
isNull
()
;
assert
That
(
new
StringRedisTemplate
(
this
.
redis
.
getConnectionFactory
())
.
opsForValue
().
get
(
this
.
prefix
+
".bar"
))
.
isNull
()
;
}
@Test
...
...
@@ -93,8 +91,8 @@ public class RedisMultiMetricRepositoryTests {
Arrays
.<
Metric
<?>>
asList
(
new
Metric
<
Number
>(
"foo.bar"
,
12.3
)));
this
.
repository
.
set
(
"foo"
,
Arrays
.<
Metric
<?>>
asList
(
new
Metric
<
Number
>(
"foo.bar"
,
15.3
)));
assert
Equals
(
15.3
,
Iterables
.
collection
(
this
.
repository
.
findAll
(
"foo"
)).
iterator
()
.
next
().
getValue
()
);
assert
That
(
Iterables
.
collection
(
this
.
repository
.
findAll
(
"foo"
)).
iterator
().
next
()
.
getValue
()).
isEqualTo
(
15.3
);
}
@Test
...
...
@@ -102,7 +100,7 @@ public class RedisMultiMetricRepositoryTests {
this
.
repository
.
set
(
"foo"
,
Arrays
.<
Metric
<?>>
asList
(
new
Metric
<
Number
>(
"foo.val"
,
12.3
),
new
Metric
<
Number
>(
"foo.bar"
,
11.3
)));
assert
Equals
(
2
,
Iterables
.
collection
(
this
.
repository
.
findAll
(
"foo"
)).
size
()
);
assert
That
(
Iterables
.
collection
(
this
.
repository
.
findAll
(
"foo"
))).
hasSize
(
2
);
}
@Test
...
...
@@ -114,8 +112,7 @@ public class RedisMultiMetricRepositoryTests {
Arrays
.<
Metric
<?>>
asList
(
new
Metric
<
Number
>(
"bar.val"
,
12.3
),
new
Metric
<
Number
>(
"bar.foo"
,
11.3
)));
Collection
<
String
>
groups
=
Iterables
.
collection
(
this
.
repository
.
groups
());
assertEquals
(
2
,
groups
.
size
());
assertTrue
(
"Wrong groups: "
+
groups
,
groups
.
contains
(
"foo"
));
assertThat
(
groups
).
hasSize
(
2
).
contains
(
"foo"
);
}
@Test
...
...
@@ -126,7 +123,7 @@ public class RedisMultiMetricRepositoryTests {
this
.
repository
.
set
(
"bar"
,
Arrays
.<
Metric
<?>>
asList
(
new
Metric
<
Number
>(
"bar.val"
,
12.3
),
new
Metric
<
Number
>(
"bar.foo"
,
11.3
)));
assert
Equals
(
2
,
this
.
repository
.
countGroups
()
);
assert
That
(
this
.
repository
.
countGroups
()).
isEqualTo
(
2
);
}
@Test
...
...
@@ -142,9 +139,8 @@ public class RedisMultiMetricRepositoryTests {
bar
=
metric
;
}
}
assertEquals
(
2
,
names
.
size
());
assertTrue
(
"Wrong names: "
+
names
,
names
.
contains
(
"foo.bar"
));
assertEquals
(
3
d
,
bar
.
getValue
());
assertThat
(
names
).
hasSize
(
2
).
contains
(
"foo.bar"
);
assertThat
(
bar
.
getValue
()).
isEqualTo
(
3
d
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/rich/InMemoryRichGaugeRepositoryTests.java
View file @
94677b35
...
...
@@ -20,7 +20,8 @@ import org.junit.Test;
import
org.springframework.boot.actuate.metrics.Metric
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
offset
;
/**
* @author Dave Syer
...
...
@@ -33,8 +34,8 @@ public class InMemoryRichGaugeRepositoryTests {
public
void
writeAndRead
()
{
this
.
repository
.
set
(
new
Metric
<
Double
>(
"foo"
,
1
d
));
this
.
repository
.
set
(
new
Metric
<
Double
>(
"foo"
,
2
d
));
assert
Equals
(
2L
,
this
.
repository
.
findOne
(
"foo"
).
getCount
()
);
assert
Equals
(
2
d
,
this
.
repository
.
findOne
(
"foo"
).
getValue
(),
0.01
);
assert
That
(
this
.
repository
.
findOne
(
"foo"
).
getCount
()).
isEqualTo
(
2L
);
assert
That
(
this
.
repository
.
findOne
(
"foo"
).
getValue
()).
isEqualTo
(
2
d
,
offset
(
0.01
)
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/rich/MultiMetricRichGaugeReaderTests.java
View file @
94677b35
...
...
@@ -22,8 +22,7 @@ import org.springframework.boot.actuate.metrics.Metric;
import
org.springframework.boot.actuate.metrics.export.RichGaugeExporter
;
import
org.springframework.boot.actuate.metrics.repository.InMemoryMetricRepository
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link MultiMetricRichGaugeReader}.
...
...
@@ -45,11 +44,11 @@ public class MultiMetricRichGaugeReaderTests {
this
.
data
.
set
(
new
Metric
<
Integer
>(
"foo"
,
1
));
this
.
exporter
.
export
();
// Check the exporter worked
assert
Equals
(
6
,
this
.
repository
.
count
()
);
assert
Equals
(
1
,
this
.
reader
.
count
()
);
assert
That
(
this
.
repository
.
count
()).
isEqualTo
(
6
);
assert
That
(
this
.
reader
.
count
()).
isEqualTo
(
1
);
RichGauge
one
=
this
.
reader
.
findOne
(
"foo"
);
assert
NotNull
(
one
);
assert
Equals
(
2
,
one
.
getCount
()
);
assert
That
(
one
).
isNotNull
(
);
assert
That
(
one
.
getCount
()).
isEqualTo
(
2
);
}
@Test
...
...
@@ -57,10 +56,10 @@ public class MultiMetricRichGaugeReaderTests {
this
.
data
.
set
(
new
Metric
<
Integer
>(
"foo"
,
1
));
this
.
data
.
set
(
new
Metric
<
Integer
>(
"bar"
,
1
));
this
.
exporter
.
export
();
assert
Equals
(
2
,
this
.
reader
.
count
()
);
assert
That
(
this
.
reader
.
count
()).
isEqualTo
(
2
);
RichGauge
one
=
this
.
reader
.
findOne
(
"foo"
);
assert
NotNull
(
one
);
assert
Equals
(
1
,
one
.
getCount
()
);
assert
That
(
one
).
isNotNull
(
);
assert
That
(
one
.
getCount
()).
isEqualTo
(
1
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/statsd/StatsdMetricWriterTests.java
View file @
94677b35
...
...
@@ -30,7 +30,7 @@ import org.springframework.boot.actuate.metrics.Metric;
import
org.springframework.boot.actuate.metrics.writer.Delta
;
import
org.springframework.util.SocketUtils
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link StatsdMetricWriter}.
...
...
@@ -56,14 +56,14 @@ public class StatsdMetricWriterTests {
public
void
increment
()
{
this
.
writer
.
increment
(
new
Delta
<
Long
>(
"counter.foo"
,
3L
));
this
.
server
.
waitForMessage
();
assert
Equals
(
"me.counter.foo:3|c"
,
this
.
server
.
messagesReceived
().
get
(
0
)
);
assert
That
(
this
.
server
.
messagesReceived
().
get
(
0
)).
isEqualTo
(
"me.counter.foo:3|c"
);
}
@Test
public
void
setLongMetric
()
throws
Exception
{
this
.
writer
.
set
(
new
Metric
<
Long
>(
"gauge.foo"
,
3L
));
this
.
server
.
waitForMessage
();
assert
Equals
(
"me.gauge.foo:3|g"
,
this
.
server
.
messagesReceived
().
get
(
0
)
);
assert
That
(
this
.
server
.
messagesReceived
().
get
(
0
)).
isEqualTo
(
"me.gauge.foo:3|g"
);
}
@Test
...
...
@@ -71,14 +71,14 @@ public class StatsdMetricWriterTests {
this
.
writer
.
set
(
new
Metric
<
Double
>(
"gauge.foo"
,
3.7
));
this
.
server
.
waitForMessage
();
// Doubles are truncated
assert
Equals
(
"me.gauge.foo:3.7|g"
,
this
.
server
.
messagesReceived
().
get
(
0
)
);
assert
That
(
this
.
server
.
messagesReceived
().
get
(
0
)).
isEqualTo
(
"me.gauge.foo:3.7|g"
);
}
@Test
public
void
setTimerMetric
()
throws
Exception
{
this
.
writer
.
set
(
new
Metric
<
Long
>(
"timer.foo"
,
37L
));
this
.
server
.
waitForMessage
();
assert
Equals
(
"me.timer.foo:37|ms"
,
this
.
server
.
messagesReceived
().
get
(
0
)
);
assert
That
(
this
.
server
.
messagesReceived
().
get
(
0
)).
isEqualTo
(
"me.timer.foo:37|ms"
);
}
@Test
...
...
@@ -86,7 +86,7 @@ public class StatsdMetricWriterTests {
this
.
writer
=
new
StatsdMetricWriter
(
"localhost"
,
this
.
port
);
this
.
writer
.
set
(
new
Metric
<
Long
>(
"gauge.foo"
,
3L
));
this
.
server
.
waitForMessage
();
assert
Equals
(
"gauge.foo:3|g"
,
this
.
server
.
messagesReceived
().
get
(
0
)
);
assert
That
(
this
.
server
.
messagesReceived
().
get
(
0
)).
isEqualTo
(
"gauge.foo:3|g"
);
}
@Test
...
...
@@ -94,10 +94,10 @@ public class StatsdMetricWriterTests {
this
.
writer
=
new
StatsdMetricWriter
(
"my."
,
"localhost"
,
this
.
port
);
this
.
writer
.
set
(
new
Metric
<
Long
>(
"gauge.foo"
,
3L
));
this
.
server
.
waitForMessage
();
assert
Equals
(
"my.gauge.foo:3|g"
,
this
.
server
.
messagesReceived
().
get
(
0
)
);
assert
That
(
this
.
server
.
messagesReceived
().
get
(
0
)).
isEqualTo
(
"my.gauge.foo:3|g"
);
}
private
static
final
class
DummyStatsDServer
{
private
static
final
class
DummyStatsDServer
implements
Runnable
{
private
final
List
<
String
>
messagesReceived
=
new
ArrayList
<
String
>();
...
...
@@ -107,31 +107,29 @@ public class StatsdMetricWriterTests {
try
{
this
.
server
=
new
DatagramSocket
(
port
);
}
catch
(
SocketException
e
)
{
throw
new
IllegalStateException
(
e
);
catch
(
SocketException
e
x
)
{
throw
new
IllegalStateException
(
e
x
);
}
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
final
DatagramPacket
packet
=
new
DatagramPacket
(
new
byte
[
256
],
256
);
DummyStatsDServer
.
this
.
server
.
receive
(
packet
);
DummyStatsDServer
.
this
.
messagesReceived
.
add
(
new
String
(
packet
.
getData
(),
Charset
.
forName
(
"UTF-8"
))
.
trim
());
}
catch
(
Exception
e
)
{
// Ignore
}
}
}).
start
();
new
Thread
(
this
).
start
();
}
public
void
stop
()
{
this
.
server
.
close
();
}
@Override
public
void
run
()
{
try
{
DatagramPacket
packet
=
new
DatagramPacket
(
new
byte
[
256
],
256
);
this
.
server
.
receive
(
packet
);
this
.
messagesReceived
.
add
(
new
String
(
packet
.
getData
(),
Charset
.
forName
(
"UTF-8"
)).
trim
());
}
catch
(
Exception
ex
)
{
// Ignore
}
}
public
void
waitForMessage
()
{
while
(
this
.
messagesReceived
.
isEmpty
())
{
try
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/util/InMemoryRepositoryTests.java
→
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/util/
Simple
InMemoryRepositoryTests.java
100644 → 100755
View file @
94677b35
...
...
@@ -29,21 +29,21 @@ import org.junit.Test;
import
org.springframework.boot.actuate.metrics.util.SimpleInMemoryRepository.Callback
;
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
;
/**
* Tests for {@link SimpleInMemoryRepository}.
*
* @author Dave Syer
*/
public
class
InMemoryRepositoryTests
{
public
class
Simple
InMemoryRepositoryTests
{
private
final
SimpleInMemoryRepository
<
String
>
repository
=
new
SimpleInMemoryRepository
<
String
>();
@Test
public
void
setAndGet
()
{
this
.
repository
.
set
(
"foo"
,
"bar"
);
assert
Equals
(
"bar"
,
this
.
repository
.
findOne
(
"foo"
)
);
assert
That
(
this
.
repository
.
findOne
(
"foo"
)).
isEqualTo
(
"bar"
);
}
@Test
...
...
@@ -55,7 +55,7 @@ public class InMemoryRepositoryTests {
return
"bar"
;
}
});
assert
Equals
(
"bar"
,
this
.
repository
.
findOne
(
"foo"
)
);
assert
That
(
this
.
repository
.
findOne
(
"foo"
)).
isEqualTo
(
"bar"
);
}
@Test
...
...
@@ -66,7 +66,7 @@ public class InMemoryRepositoryTests {
return
"bar"
;
}
});
assert
Equals
(
"bar"
,
this
.
repository
.
findOne
(
"foo"
)
);
assert
That
(
this
.
repository
.
findOne
(
"foo"
)).
isEqualTo
(
"bar"
);
}
@Test
...
...
@@ -75,59 +75,59 @@ public class InMemoryRepositoryTests {
this
.
repository
.
set
(
"foo.bar"
,
"one"
);
this
.
repository
.
set
(
"foo.min"
,
"two"
);
this
.
repository
.
set
(
"foo.max"
,
"three"
);
assertEquals
(
3
,
((
Collection
<?>)
this
.
repository
.
findAllWithPrefix
(
"foo"
)).
size
());
assertThat
(((
Collection
<?>)
this
.
repository
.
findAllWithPrefix
(
"foo"
))).
hasSize
(
3
);
}
@Test
public
void
patternsAcceptedForRegisteredPrefix
()
{
this
.
repository
.
set
(
"foo.bar"
,
"spam"
);
Iterator
<
String
>
iterator
=
this
.
repository
.
findAllWithPrefix
(
"foo.*"
).
iterator
();
assert
Equals
(
"spam"
,
iterator
.
next
()
);
assert
False
(
iterator
.
hasNext
()
);
assert
That
(
iterator
.
next
()).
isEqualTo
(
"spam"
);
assert
That
(
iterator
.
hasNext
()).
isFalse
(
);
}
@Test
public
void
updateConcurrent
()
throws
Exception
{
final
SimpleInMemoryRepository
<
Integer
>
repository
=
new
SimpleInMemoryRepository
<
Integer
>();
SimpleInMemoryRepository
<
Integer
>
repository
=
new
SimpleInMemoryRepository
<
Integer
>();
Collection
<
Callable
<
Boolean
>>
tasks
=
new
ArrayList
<
Callable
<
Boolean
>>();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
tasks
.
add
(
new
Callable
<
Boolean
>()
{
@Override
public
Boolean
call
()
throws
Exception
{
repository
.
update
(
"foo"
,
new
Callback
<
Integer
>()
{
@Override
public
Integer
modify
(
Integer
current
)
{
if
(
current
==
null
)
{
return
1
;
}
return
current
+
1
;
}
});
return
true
;
}
});
tasks
.
add
(
new
Callable
<
Boolean
>()
{
@Override
public
Boolean
call
()
throws
Exception
{
repository
.
update
(
"foo"
,
new
Callback
<
Integer
>()
{
@Override
public
Integer
modify
(
Integer
current
)
{
if
(
current
==
null
)
{
return
-
1
;
}
return
current
-
1
;
}
});
return
true
;
}
});
tasks
.
add
(
new
RepositoryUpdate
(
repository
,
1
));
tasks
.
add
(
new
RepositoryUpdate
(
repository
,
-
1
));
}
List
<
Future
<
Boolean
>>
all
=
Executors
.
newFixedThreadPool
(
10
).
invokeAll
(
tasks
);
for
(
Future
<
Boolean
>
future
:
all
)
{
assertT
rue
(
future
.
get
(
1
,
TimeUnit
.
SECONDS
)
);
assertT
hat
(
future
.
get
(
1
,
TimeUnit
.
SECONDS
)).
isTrue
(
);
}
assertEquals
(
Integer
.
valueOf
(
0
),
repository
.
findOne
(
"foo"
));
assertThat
(
repository
.
findOne
(
"foo"
)).
isEqualTo
(
0
);
}
private
static
class
RepositoryUpdate
implements
Callable
<
Boolean
>
{
private
final
SimpleInMemoryRepository
<
Integer
>
repository
;
private
final
int
delta
;
RepositoryUpdate
(
SimpleInMemoryRepository
<
Integer
>
repository
,
int
delta
)
{
this
.
repository
=
repository
;
this
.
delta
=
delta
;
}
@Override
public
Boolean
call
()
throws
Exception
{
this
.
repository
.
update
(
"foo"
,
new
Callback
<
Integer
>()
{
@Override
public
Integer
modify
(
Integer
current
)
{
if
(
current
==
null
)
{
return
RepositoryUpdate
.
this
.
delta
;
}
return
current
+
RepositoryUpdate
.
this
.
delta
;
}
});
return
true
;
}
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/DefaultCounterServiceTests.java
View file @
94677b35
...
...
@@ -22,12 +22,14 @@ import org.mockito.ArgumentCaptor;
import
org.mockito.Captor
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
/**
* Tests for {@link DefaultCounterService}.
*
* @author Dave Syer
*/
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
DefaultCounterServiceTests
{
...
...
@@ -44,32 +46,32 @@ public class DefaultCounterServiceTests {
public
void
incrementWithExistingCounter
()
{
this
.
service
.
increment
(
"counter.foo"
);
verify
(
this
.
repository
).
increment
(
this
.
captor
.
capture
());
assert
Equals
(
"counter.foo"
,
this
.
captor
.
getValue
().
getName
()
);
assert
Equals
(
1L
,
this
.
captor
.
getValue
().
getValue
()
);
assert
That
(
this
.
captor
.
getValue
().
getName
()).
isEqualTo
(
"counter.foo"
);
assert
That
(
this
.
captor
.
getValue
().
getValue
()).
isEqualTo
(
1L
);
}
@Test
public
void
incrementWithExistingNearCounter
()
{
this
.
service
.
increment
(
"counter-foo"
);
verify
(
this
.
repository
).
increment
(
this
.
captor
.
capture
());
assert
Equals
(
"counter.counter-foo"
,
this
.
captor
.
getValue
().
getName
()
);
assert
Equals
(
1L
,
this
.
captor
.
getValue
().
getValue
()
);
assert
That
(
this
.
captor
.
getValue
().
getName
()).
isEqualTo
(
"counter.counter-foo"
);
assert
That
(
this
.
captor
.
getValue
().
getValue
()).
isEqualTo
(
1L
);
}
@Test
public
void
incrementPrependsCounter
()
{
this
.
service
.
increment
(
"foo"
);
verify
(
this
.
repository
).
increment
(
this
.
captor
.
capture
());
assert
Equals
(
"counter.foo"
,
this
.
captor
.
getValue
().
getName
()
);
assert
Equals
(
1L
,
this
.
captor
.
getValue
().
getValue
()
);
assert
That
(
this
.
captor
.
getValue
().
getName
()).
isEqualTo
(
"counter.foo"
);
assert
That
(
this
.
captor
.
getValue
().
getValue
()).
isEqualTo
(
1L
);
}
@Test
public
void
decrementPrependsCounter
()
{
this
.
service
.
decrement
(
"foo"
);
verify
(
this
.
repository
).
increment
(
this
.
captor
.
capture
());
assert
Equals
(
"counter.foo"
,
this
.
captor
.
getValue
().
getName
()
);
assert
Equals
(-
1L
,
this
.
captor
.
getValue
().
getValue
()
);
assert
That
(
this
.
captor
.
getValue
().
getName
()).
isEqualTo
(
"counter.foo"
);
assert
That
(
this
.
captor
.
getValue
().
getValue
()).
isEqualTo
(-
1L
);
}
@Test
...
...
@@ -77,4 +79,5 @@ public class DefaultCounterServiceTests {
this
.
service
.
reset
(
"foo"
);
verify
(
this
.
repository
).
reset
(
"counter.foo"
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/DefaultGaugeServiceTests.java
View file @
94677b35
...
...
@@ -21,12 +21,14 @@ import org.mockito.ArgumentCaptor;
import
org.springframework.boot.actuate.metrics.Metric
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
/**
* Tests for {@link DefaultGaugeService}.
*
* @author Dave Syer
*/
public
class
DefaultGaugeServiceTests
{
...
...
@@ -40,8 +42,8 @@ public class DefaultGaugeServiceTests {
@SuppressWarnings
(
"rawtypes"
)
ArgumentCaptor
<
Metric
>
captor
=
ArgumentCaptor
.
forClass
(
Metric
.
class
);
verify
(
this
.
repository
).
set
(
captor
.
capture
());
assert
Equals
(
"gauge.foo"
,
captor
.
getValue
().
getName
()
);
assert
Equals
(
2.3
,
captor
.
getValue
().
getValue
()
);
assert
That
(
captor
.
getValue
().
getName
()).
isEqualTo
(
"gauge.foo"
);
assert
That
(
captor
.
getValue
().
getValue
()).
isEqualTo
(
2.3
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java
View file @
94677b35
...
...
@@ -32,8 +32,7 @@ import org.springframework.security.core.authority.AuthorityUtils;
import
org.springframework.security.core.userdetails.User
;
import
org.springframework.security.web.authentication.switchuser.AuthenticationSwitchUserEvent
;
import
static
org
.
hamcrest
.
Matchers
.
hasEntry
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Matchers
.
anyObject
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
never
;
...
...
@@ -97,8 +96,8 @@ public class AuthenticationAuditListenerTests {
ArgumentCaptor
<
AuditApplicationEvent
>
auditApplicationEvent
=
ArgumentCaptor
.
forClass
(
AuditApplicationEvent
.
class
);
verify
(
this
.
publisher
).
publishEvent
(
auditApplicationEvent
.
capture
());
assertThat
(
auditApplicationEvent
.
getValue
().
getAuditEvent
().
getData
()
,
hasEntry
(
"details"
,
details
)
);
assertThat
(
auditApplicationEvent
.
getValue
().
getAuditEvent
().
getData
()
)
.
containsEntry
(
"details"
,
details
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/ApplicationPidFileWriterTests.java
View file @
94677b35
...
...
@@ -37,9 +37,7 @@ import org.springframework.core.env.StandardEnvironment;
import
org.springframework.mock.env.MockPropertySource
;
import
org.springframework.util.FileCopyUtils
;
import
static
org
.
hamcrest
.
Matchers
.
isEmptyString
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -76,8 +74,8 @@ public class ApplicationPidFileWriterTests {
File
file
=
this
.
temporaryFolder
.
newFile
();
ApplicationPidFileWriter
listener
=
new
ApplicationPidFileWriter
(
file
);
listener
.
onApplicationEvent
(
EVENT
);
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
)),
not
(
isEmptyString
())
);
FileReader
reader
=
new
FileReader
(
file
);
assertThat
(
FileCopyUtils
.
copyToString
(
reader
)).
isNotEmpty
(
);
}
@Test
...
...
@@ -86,9 +84,8 @@ public class ApplicationPidFileWriterTests {
System
.
setProperty
(
"PIDFILE"
,
this
.
temporaryFolder
.
newFile
().
getAbsolutePath
());
ApplicationPidFileWriter
listener
=
new
ApplicationPidFileWriter
(
file
);
listener
.
onApplicationEvent
(
EVENT
);
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
System
.
getProperty
(
"PIDFILE"
))),
not
(
isEmptyString
()));
FileReader
reader
=
new
FileReader
(
System
.
getProperty
(
"PIDFILE"
));
assertThat
(
FileCopyUtils
.
copyToString
(
reader
)).
isNotEmpty
();
}
@Test
...
...
@@ -98,8 +95,7 @@ public class ApplicationPidFileWriterTests {
file
.
getAbsolutePath
());
ApplicationPidFileWriter
listener
=
new
ApplicationPidFileWriter
();
listener
.
onApplicationEvent
(
event
);
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
)),
not
(
isEmptyString
()));
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
))).
isNotEmpty
();
}
@Test
...
...
@@ -109,11 +105,10 @@ public class ApplicationPidFileWriterTests {
file
.
getAbsolutePath
());
ApplicationPidFileWriter
listener
=
new
ApplicationPidFileWriter
();
listener
.
onApplicationEvent
(
event
);
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
))
,
isEmptyString
()
);
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
))
).
isEmpty
(
);
listener
.
setTriggerEventType
(
ApplicationEnvironmentPreparedEvent
.
class
);
listener
.
onApplicationEvent
(
event
);
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
)),
not
(
isEmptyString
()));
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
))).
isNotEmpty
();
}
@Test
...
...
@@ -123,8 +118,7 @@ public class ApplicationPidFileWriterTests {
listener
.
setTriggerEventType
(
ApplicationStartedEvent
.
class
);
listener
.
onApplicationEvent
(
new
ApplicationStartedEvent
(
new
SpringApplication
(),
new
String
[]
{}));
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
)),
not
(
isEmptyString
()));
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
))).
isNotEmpty
();
}
@Test
...
...
@@ -133,7 +127,7 @@ public class ApplicationPidFileWriterTests {
file
.
setReadOnly
();
ApplicationPidFileWriter
listener
=
new
ApplicationPidFileWriter
(
file
);
listener
.
onApplicationEvent
(
EVENT
);
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
))
,
isEmptyString
()
);
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
))
).
isEmpty
(
);
}
@Test
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/EmbeddedServerPortFileWriterTests.java
View file @
94677b35
...
...
@@ -33,9 +33,7 @@ import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext;
import
org.springframework.util.FileCopyUtils
;
import
org.springframework.util.StringUtils
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
hasItem
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -62,7 +60,7 @@ public class EmbeddedServerPortFileWriterTests {
File
file
=
this
.
temporaryFolder
.
newFile
();
EmbeddedServerPortFileWriter
listener
=
new
EmbeddedServerPortFileWriter
(
file
);
listener
.
onApplicationEvent
(
mockEvent
(
""
,
8080
));
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
))
,
equalTo
(
"8080"
)
);
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
))
).
isEqualTo
(
"8080"
);
}
@Test
...
...
@@ -70,8 +68,8 @@ public class EmbeddedServerPortFileWriterTests {
System
.
setProperty
(
"PORTFILE"
,
this
.
temporaryFolder
.
newFile
().
getAbsolutePath
());
EmbeddedServerPortFileWriter
listener
=
new
EmbeddedServerPortFileWriter
();
listener
.
onApplicationEvent
(
mockEvent
(
""
,
8080
));
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
System
.
getProperty
(
"PORTFILE"
))),
equalTo
(
"8080"
)
);
FileReader
reader
=
new
FileReader
(
System
.
getProperty
(
"PORTFILE"
));
assertThat
(
FileCopyUtils
.
copyToString
(
reader
)).
isEqualTo
(
"8080"
);
}
@Test
...
...
@@ -80,8 +78,8 @@ public class EmbeddedServerPortFileWriterTests {
System
.
setProperty
(
"PORTFILE"
,
this
.
temporaryFolder
.
newFile
().
getAbsolutePath
());
EmbeddedServerPortFileWriter
listener
=
new
EmbeddedServerPortFileWriter
(
file
);
listener
.
onApplicationEvent
(
mockEvent
(
""
,
8080
));
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
System
.
getProperty
(
"PORTFILE"
))),
equalTo
(
"8080"
)
);
FileReader
reader
=
new
FileReader
(
System
.
getProperty
(
"PORTFILE"
));
assertThat
(
FileCopyUtils
.
copyToString
(
reader
)).
isEqualTo
(
"8080"
);
}
@Test
...
...
@@ -90,17 +88,16 @@ public class EmbeddedServerPortFileWriterTests {
EmbeddedServerPortFileWriter
listener
=
new
EmbeddedServerPortFileWriter
(
file
);
listener
.
onApplicationEvent
(
mockEvent
(
""
,
8080
));
listener
.
onApplicationEvent
(
mockEvent
(
"management"
,
9090
));
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
))
,
equalTo
(
"8080"
)
);
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
))
).
isEqualTo
(
"8080"
);
String
managementFile
=
file
.
getName
();
managementFile
=
managementFile
.
substring
(
0
,
managementFile
.
length
()
-
StringUtils
.
getFilenameExtension
(
managementFile
).
length
()
-
1
);
managementFile
=
managementFile
+
"-management."
+
StringUtils
.
getFilenameExtension
(
file
.
getName
());
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
new
File
(
file
.
getParentFile
(),
managementFile
))),
equalTo
(
"9090"
));
assertThat
(
collectFileNames
(
file
.
getParentFile
()),
hasItem
(
managementFile
));
FileReader
reader
=
new
FileReader
(
new
File
(
file
.
getParentFile
(),
managementFile
));
assertThat
(
FileCopyUtils
.
copyToString
(
reader
)).
isEqualTo
(
"9090"
);
assertThat
(
collectFileNames
(
file
.
getParentFile
())).
contains
(
managementFile
);
}
@Test
...
...
@@ -114,11 +111,10 @@ public class EmbeddedServerPortFileWriterTests {
-
StringUtils
.
getFilenameExtension
(
managementFile
).
length
()
-
1
);
managementFile
=
managementFile
+
"-MANAGEMENT."
+
StringUtils
.
getFilenameExtension
(
file
.
getName
());
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
new
File
(
file
.
getParentFile
(),
managementFile
))),
equalTo
(
"9090"
));
assertThat
(
collectFileNames
(
file
.
getParentFile
()),
hasItem
(
managementFile
));
FileReader
reader
=
new
FileReader
(
new
File
(
file
.
getParentFile
(),
managementFile
));
assertThat
(
FileCopyUtils
.
copyToString
(
reader
)).
isEqualTo
(
"9090"
);
assertThat
(
collectFileNames
(
file
.
getParentFile
())).
contains
(
managementFile
);
}
private
EmbeddedServletContainerInitializedEvent
mockEvent
(
String
name
,
int
port
)
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/InMemoryTraceRepositoryTests.java
View file @
94677b35
...
...
@@ -21,7 +21,7 @@ import java.util.List;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link InMemoryTraceRepository}.
...
...
@@ -39,9 +39,9 @@ public class InMemoryTraceRepositoryTests {
this
.
repository
.
add
(
Collections
.<
String
,
Object
>
singletonMap
(
"bar"
,
"foo"
));
this
.
repository
.
add
(
Collections
.<
String
,
Object
>
singletonMap
(
"bar"
,
"bar"
));
List
<
Trace
>
traces
=
this
.
repository
.
findAll
();
assert
Equals
(
2
,
traces
.
size
()
);
assert
Equals
(
"bar"
,
traces
.
get
(
0
).
getInfo
().
get
(
"bar"
)
);
assert
Equals
(
"foo"
,
traces
.
get
(
1
).
getInfo
().
get
(
"bar"
)
);
assert
That
(
traces
).
hasSize
(
2
);
assert
That
(
traces
.
get
(
0
).
getInfo
().
get
(
"bar"
)).
isEqualTo
(
"bar"
);
assert
That
(
traces
.
get
(
1
).
getInfo
().
get
(
"bar"
)).
isEqualTo
(
"foo"
);
}
@Test
...
...
@@ -52,9 +52,9 @@ public class InMemoryTraceRepositoryTests {
this
.
repository
.
add
(
Collections
.<
String
,
Object
>
singletonMap
(
"bar"
,
"foo"
));
this
.
repository
.
add
(
Collections
.<
String
,
Object
>
singletonMap
(
"bar"
,
"bar"
));
List
<
Trace
>
traces
=
this
.
repository
.
findAll
();
assert
Equals
(
2
,
traces
.
size
()
);
assert
Equals
(
"bar"
,
traces
.
get
(
1
).
getInfo
().
get
(
"bar"
)
);
assert
Equals
(
"foo"
,
traces
.
get
(
0
).
getInfo
().
get
(
"bar"
)
);
assert
That
(
traces
).
hasSize
(
2
);
assert
That
(
traces
.
get
(
1
).
getInfo
().
get
(
"bar"
)).
isEqualTo
(
"bar"
);
assert
That
(
traces
.
get
(
0
).
getInfo
().
get
(
"bar"
)).
isEqualTo
(
"foo"
);
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/WebRequestTraceFilterTests.java
View file @
94677b35
...
...
@@ -37,8 +37,7 @@ import org.springframework.boot.autoconfigure.web.DefaultErrorAttributes;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
org.springframework.mock.web.MockHttpServletResponse
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link WebRequestTraceFilter}.
...
...
@@ -62,10 +61,10 @@ public class WebRequestTraceFilterTests {
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
"GET"
,
"/foo"
);
request
.
addHeader
(
"Accept"
,
"application/json"
);
Map
<
String
,
Object
>
trace
=
this
.
filter
.
getTrace
(
request
);
assert
Equals
(
"GET"
,
trace
.
get
(
"method"
)
);
assert
Equals
(
"/foo"
,
trace
.
get
(
"path"
)
);
assert
That
(
trace
.
get
(
"method"
)).
isEqualTo
(
"GET"
);
assert
That
(
trace
.
get
(
"path"
)).
isEqualTo
(
"/foo"
);
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
trace
.
get
(
"headers"
);
assert
Equals
(
"{Accept=application/json}"
,
map
.
get
(
"request"
).
toString
()
);
assert
That
(
map
.
get
(
"request"
).
toString
()).
isEqualTo
(
"{Accept=application/json}"
);
}
@Test
...
...
@@ -110,22 +109,23 @@ public class WebRequestTraceFilterTests {
}
});
assert
Equals
(
1
,
this
.
repository
.
findAll
().
size
()
);
assert
That
(
this
.
repository
.
findAll
()).
hasSize
(
1
);
Map
<
String
,
Object
>
trace
=
this
.
repository
.
findAll
().
iterator
().
next
().
getInfo
();
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
trace
.
get
(
"headers"
);
assertEquals
(
"{Content-Type=application/json, status=200}"
,
map
.
get
(
"response"
).
toString
());
assertEquals
(
"GET"
,
trace
.
get
(
"method"
));
assertEquals
(
"/foo"
,
trace
.
get
(
"path"
));
assertEquals
(
"paramvalue"
,
((
String
[])
((
Map
)
trace
.
get
(
"parameters"
)).
get
(
"param"
))[
0
]);
assertEquals
(
"some.remote.addr"
,
trace
.
get
(
"remoteAddress"
));
assertEquals
(
"some.query.string"
,
trace
.
get
(
"query"
));
assertEquals
(
principal
.
getName
(),
trace
.
get
(
"userPrincipal"
));
assertEquals
(
"some.context.path"
,
trace
.
get
(
"contextPath"
));
assertEquals
(
url
,
trace
.
get
(
"pathInfo"
));
assertEquals
(
"authType"
,
trace
.
get
(
"authType"
));
assertEquals
(
"{Accept=application/json}"
,
map
.
get
(
"request"
).
toString
());
assertThat
(
map
.
get
(
"response"
).
toString
())
.
isEqualTo
(
"{Content-Type=application/json, status=200}"
);
assertThat
(
trace
.
get
(
"method"
)).
isEqualTo
(
"GET"
);
assertThat
(
trace
.
get
(
"path"
)).
isEqualTo
(
"/foo"
);
assertThat
(((
String
[])
((
Map
)
trace
.
get
(
"parameters"
)).
get
(
"param"
))[
0
])
.
isEqualTo
(
"paramvalue"
);
assertThat
(
trace
.
get
(
"remoteAddress"
)).
isEqualTo
(
"some.remote.addr"
);
assertThat
(
trace
.
get
(
"query"
)).
isEqualTo
(
"some.query.string"
);
assertThat
(
trace
.
get
(
"userPrincipal"
)).
isEqualTo
(
principal
.
getName
());
assertThat
(
trace
.
get
(
"contextPath"
)).
isEqualTo
(
"some.context.path"
);
assertThat
(
trace
.
get
(
"pathInfo"
)).
isEqualTo
(
url
);
assertThat
(
trace
.
get
(
"authType"
)).
isEqualTo
(
"authType"
);
assertThat
(
map
.
get
(
"request"
).
toString
()).
isEqualTo
(
"{Accept=application/json}"
);
}
@Test
...
...
@@ -144,7 +144,7 @@ public class WebRequestTraceFilterTests {
});
Map
<
String
,
Object
>
info
=
this
.
repository
.
findAll
().
iterator
().
next
().
getInfo
();
Map
<
String
,
Object
>
headers
=
(
Map
<
String
,
Object
>)
info
.
get
(
"headers"
);
assertT
rue
(
headers
.
get
(
"response"
)
==
null
);
assertT
hat
(
headers
.
get
(
"response"
)
==
null
).
isTrue
(
);
}
@Test
...
...
@@ -158,7 +158,7 @@ public class WebRequestTraceFilterTests {
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
((
Map
<
String
,
Object
>)
trace
.
get
(
"headers"
)).
get
(
"response"
);
assert
Equals
(
"404"
,
map
.
get
(
"status"
).
toString
()
);
assert
That
(
map
.
get
(
"status"
).
toString
()).
isEqualTo
(
"404"
);
}
@Test
...
...
@@ -175,7 +175,7 @@ public class WebRequestTraceFilterTests {
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
trace
.
get
(
"error"
);
System
.
err
.
println
(
map
);
assert
Equals
(
"Foo"
,
map
.
get
(
"message"
).
toString
()
);
assert
That
(
map
.
get
(
"message"
).
toString
()).
isEqualTo
(
"Foo"
);
}
}
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