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
a869d25d
Commit
a869d25d
authored
Jul 27, 2017
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
eac4c7e8
Changes
17
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
566 additions
and
573 deletions
+566
-573
SpringApplicationAdminJmxAutoConfigurationTests.java
...dmin/SpringApplicationAdminJmxAutoConfigurationTests.java
+20
-19
RabbitAutoConfigurationTests.java
...boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java
+253
-222
AopAutoConfigurationTests.java
...ork/boot/autoconfigure/aop/AopAutoConfigurationTests.java
+6
-6
BatchAutoConfigurationTests.java
...boot/autoconfigure/batch/BatchAutoConfigurationTests.java
+135
-116
BatchAutoConfigurationWithoutJpaTests.java
...onfigure/batch/BatchAutoConfigurationWithoutJpaTests.java
+36
-33
JobLauncherCommandLineRunnerTests.java
...utoconfigure/batch/JobLauncherCommandLineRunnerTests.java
+1
-2
CassandraAutoConfigurationTests.java
...oconfigure/cassandra/CassandraAutoConfigurationTests.java
+33
-30
ConditionalOnBeanTests.java
.../boot/autoconfigure/condition/ConditionalOnBeanTests.java
+27
-28
ConditionalOnClassTests.java
...boot/autoconfigure/condition/ConditionalOnClassTests.java
+18
-19
ConditionalOnCloudPlatformTests.java
...oconfigure/condition/ConditionalOnCloudPlatformTests.java
+3
-16
ConditionalOnExpressionTests.java
...autoconfigure/condition/ConditionalOnExpressionTests.java
+3
-17
ConditionalOnJavaTests.java
.../boot/autoconfigure/condition/ConditionalOnJavaTests.java
+7
-19
ConditionalOnJndiTests.java
.../boot/autoconfigure/condition/ConditionalOnJndiTests.java
+10
-19
AbstractApplicationContextRunner.java
...test/context/runner/AbstractApplicationContextRunner.java
+4
-11
JsonContent.java
.../java/org/springframework/boot/test/json/JsonContent.java
+1
-1
TestPropertyValues.java
...rg/springframework/boot/test/util/TestPropertyValues.java
+7
-14
AbstractApplicationContextRunnerTests.java
...context/runner/AbstractApplicationContextRunnerTests.java
+2
-1
No files found.
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfigurationTests.java
View file @
a869d25d
...
...
@@ -59,7 +59,7 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
@Rule
public
final
ExpectedException
thrown
=
ExpectedException
.
none
();
private
final
MBeanServer
mBeanS
erver
=
ManagementFactory
.
getPlatformMBeanServer
();
private
final
MBeanServer
s
erver
=
ManagementFactory
.
getPlatformMBeanServer
();
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
JmxAutoConfiguration
.
class
,
...
...
@@ -70,7 +70,7 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
throws
MalformedObjectNameException
,
InstanceNotFoundException
{
this
.
contextRunner
.
run
((
context
)
->
{
this
.
thrown
.
expect
(
InstanceNotFoundException
.
class
);
this
.
mBeanS
erver
.
getObjectInstance
(
createDefaultObjectName
());
this
.
s
erver
.
getObjectInstance
(
createDefaultObjectName
());
});
}
...
...
@@ -78,7 +78,7 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
public
void
registeredWithProperty
()
throws
Exception
{
this
.
contextRunner
.
withPropertyValues
(
ENABLE_ADMIN_PROP
).
run
((
context
)
->
{
ObjectName
objectName
=
createDefaultObjectName
();
ObjectInstance
objectInstance
=
this
.
mBeanS
erver
.
getObjectInstance
(
objectName
);
ObjectInstance
objectInstance
=
this
.
s
erver
.
getObjectInstance
(
objectName
);
assertThat
(
objectInstance
).
as
(
"Lifecycle bean should have been registered"
)
.
isNotNull
();
});
...
...
@@ -87,17 +87,19 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
@Test
public
void
registerWithCustomJmxName
()
throws
InstanceNotFoundException
{
String
customJmxName
=
"org.acme:name=FooBar"
;
this
.
contextRunner
.
withSystemProperties
(
this
.
contextRunner
.
withSystemProperties
(
"spring.application.admin.jmx-name="
+
customJmxName
)
.
withPropertyValues
(
ENABLE_ADMIN_PROP
).
run
((
context
)
->
{
try
{
this
.
mBeanS
erver
.
getObjectInstance
(
createObjectName
(
customJmxName
));
this
.
s
erver
.
getObjectInstance
(
createObjectName
(
customJmxName
));
}
catch
(
InstanceNotFoundException
ex
)
{
fail
(
"Admin MBean should have been exposed with custom name"
);
}
this
.
thrown
.
expect
(
InstanceNotFoundException
.
class
);
// Should not be exposed
this
.
mBeanServer
.
getObjectInstance
(
createDefaultObjectName
());
this
.
thrown
.
expect
(
InstanceNotFoundException
.
class
);
// Should not be
// exposed
this
.
server
.
getObjectInstance
(
createDefaultObjectName
());
});
}
...
...
@@ -110,7 +112,7 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
SpringApplicationAdminJmxAutoConfiguration
.
class
)
.
run
(
"--"
+
ENABLE_ADMIN_PROP
,
"--server.port=0"
))
{
assertThat
(
context
).
isInstanceOf
(
ServletWebServerApplicationContext
.
class
);
assertThat
(
this
.
mBeanS
erver
.
getAttribute
(
createDefaultObjectName
(),
assertThat
(
this
.
s
erver
.
getAttribute
(
createDefaultObjectName
(),
"EmbeddedWebApplication"
)).
isEqualTo
(
Boolean
.
TRUE
);
int
expected
=
((
ServletWebServerApplicationContext
)
context
).
getWebServer
()
.
getPort
();
...
...
@@ -128,7 +130,6 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
.
child
(
JmxAutoConfiguration
.
class
,
SpringApplicationAdminJmxAutoConfiguration
.
class
)
.
web
(
WebApplicationType
.
NONE
);
try
(
ConfigurableApplicationContext
parent
=
parentBuilder
.
run
(
"--"
+
ENABLE_ADMIN_PROP
);
ConfigurableApplicationContext
child
=
childBuilder
...
...
@@ -155,7 +156,7 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
}
private
String
getProperty
(
ObjectName
objectName
,
String
key
)
throws
Exception
{
return
(
String
)
this
.
mBeanS
erver
.
invoke
(
objectName
,
"getProperty"
,
return
(
String
)
this
.
s
erver
.
invoke
(
objectName
,
"getProperty"
,
new
Object
[]
{
key
},
new
String
[]
{
String
.
class
.
getName
()
});
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java
View file @
a869d25d
This diff is collapsed.
Click to expand it.
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/aop/AopAutoConfigurationTests.java
View file @
a869d25d
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java
View file @
a869d25d
This diff is collapsed.
Click to expand it.
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationWithoutJpaTests.java
View file @
a869d25d
...
...
@@ -54,42 +54,45 @@ public class BatchAutoConfigurationWithoutJpaTests {
@Test
public
void
jdbcWithDefaultSettings
()
throws
Exception
{
this
.
contextRunner
.
withUserConfiguration
(
DefaultConfiguration
.
class
,
EmbeddedDataSourceConfiguration
.
class
).
withPropertyValues
(
"spring.datasource.generate-unique-name=true"
).
run
((
context
)
->
{
this
.
contextRunner
.
withUserConfiguration
(
DefaultConfiguration
.
class
,
EmbeddedDataSourceConfiguration
.
class
)
.
withPropertyValues
(
"spring.datasource.generate-unique-name=true"
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
JobLauncher
.
class
);
assertThat
(
context
).
hasSingleBean
(
JobExplorer
.
class
);
assertThat
(
context
).
hasSingleBean
(
JobRepository
.
class
);
assertThat
(
context
).
hasSingleBean
(
PlatformTransactionManager
.
class
);
assertThat
(
context
.
getBean
(
PlatformTransactionManager
.
class
).
toString
())
.
contains
(
"DataSourceTransactionManager"
);
assertThat
(
context
.
getBean
(
BatchProperties
.
class
).
getInitializer
().
isEnabled
())
.
isTrue
();
context
.
getBean
(
PlatformTransactionManager
.
class
).
toString
())
.
contains
(
"DataSourceTransactionManager"
);
assertThat
(
context
.
getBean
(
BatchProperties
.
class
).
getInitializer
()
.
isEnabled
()).
isTrue
();
assertThat
(
new
JdbcTemplate
(
context
.
getBean
(
DataSource
.
class
))
.
queryForList
(
"select * from BATCH_JOB_EXECUTION"
)).
isEmpty
();
assertThat
(
context
.
getBean
(
JobExplorer
.
class
).
findRunningJobExecutions
(
"test"
))
.
isEmpty
();
assertThat
(
context
.
getBean
(
JobRepository
.
class
).
getLastJobExecution
(
"test"
,
new
JobParameters
())).
isNull
();
assertThat
(
context
.
getBean
(
JobExplorer
.
class
)
.
findRunningJobExecutions
(
"test"
)).
isEmpty
();
assertThat
(
context
.
getBean
(
JobRepository
.
class
)
.
getLastJobExecution
(
"test"
,
new
JobParameters
())).
isNull
();
});
}
@Test
public
void
jdbcWithCustomPrefix
()
throws
Exception
{
this
.
contextRunner
.
withUserConfiguration
(
DefaultConfiguration
.
class
,
EmbeddedDataSourceConfiguration
.
class
).
withPropertyValues
(
"spring.datasource.generate-unique-name=true"
,
this
.
contextRunner
.
withUserConfiguration
(
DefaultConfiguration
.
class
,
EmbeddedDataSourceConfiguration
.
class
)
.
withPropertyValues
(
"spring.datasource.generate-unique-name=true"
,
"spring.batch.schema:classpath:batch/custom-schema-hsql.sql"
,
"spring.batch.tablePrefix:PREFIX_"
).
run
((
context
)
->
{
"spring.batch.tablePrefix:PREFIX_"
)
.
run
((
context
)
->
{
assertThat
(
new
JdbcTemplate
(
context
.
getBean
(
DataSource
.
class
))
.
queryForList
(
"select * from PREFIX_JOB_EXECUTION"
)).
isEmpty
();
assertThat
(
context
.
getBean
(
JobExplorer
.
class
).
findRunningJobExecutions
(
"test"
))
.
queryForList
(
"select * from PREFIX_JOB_EXECUTION"
))
.
isEmpty
();
assertThat
(
context
.
getBean
(
JobRepository
.
class
).
getLastJobExecution
(
"test"
,
new
JobParameters
())).
isNull
();
assertThat
(
context
.
getBean
(
JobExplorer
.
class
)
.
findRunningJobExecutions
(
"test"
)).
isEmpty
();
assertThat
(
context
.
getBean
(
JobRepository
.
class
)
.
getLastJobExecution
(
"test"
,
new
JobParameters
())).
isNull
();
});
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/JobLauncherCommandLineRunnerTests.java
View file @
a869d25d
...
...
@@ -80,8 +80,7 @@ public class JobLauncherCommandLineRunnerTests {
this
.
step
=
this
.
steps
.
get
(
"step"
).
tasklet
(
tasklet
).
build
();
this
.
job
=
this
.
jobs
.
get
(
"job"
).
start
(
this
.
step
).
build
();
this
.
jobExplorer
=
this
.
context
.
getBean
(
JobExplorer
.
class
);
this
.
runner
=
new
JobLauncherCommandLineRunner
(
jobLauncher
,
this
.
jobExplorer
);
this
.
runner
=
new
JobLauncherCommandLineRunner
(
jobLauncher
,
this
.
jobExplorer
);
this
.
context
.
getBean
(
BatchConfiguration
.
class
).
clear
();
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfigurationTests.java
View file @
a869d25d
...
...
@@ -50,8 +50,9 @@ public class CassandraAutoConfigurationTests {
@Test
public
void
createClusterWithOverrides
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.data.cassandra.cluster-name=testcluster"
).
run
((
context
)
->
{
this
.
contextRunner
.
withPropertyValues
(
"spring.data.cassandra.cluster-name=testcluster"
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
);
assertThat
(
context
.
getBean
(
Cluster
.
class
).
getClusterName
())
.
isEqualTo
(
"testcluster"
);
...
...
@@ -60,8 +61,8 @@ public class CassandraAutoConfigurationTests {
@Test
public
void
createCustomizeCluster
()
{
this
.
contextRunner
.
withUserConfiguration
(
MockCustomizerConfig
.
class
)
.
run
((
context
)
->
{
this
.
contextRunner
.
withUserConfiguration
(
MockCustomizerConfig
.
class
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
);
assertThat
(
context
).
hasSingleBean
(
ClusterBuilderCustomizer
.
class
);
});
...
...
@@ -70,7 +71,8 @@ public class CassandraAutoConfigurationTests {
@Test
public
void
customizerOverridesAutoConfig
()
{
this
.
contextRunner
.
withUserConfiguration
(
SimpleCustomizerConfig
.
class
)
.
withPropertyValues
(
"spring.data.cassandra.cluster-name=testcluster"
).
run
((
context
)
->
{
.
withPropertyValues
(
"spring.data.cassandra.cluster-name=testcluster"
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
);
assertThat
(
context
.
getBean
(
Cluster
.
class
).
getClusterName
())
.
isEqualTo
(
"overridden-name"
);
...
...
@@ -96,22 +98,23 @@ public class CassandraAutoConfigurationTests {
@Test
public
void
customizePoolOptions
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.data.cassandra.pool.idle-timeout=42"
,
this
.
contextRunner
.
withPropertyValues
(
"spring.data.cassandra.pool.idle-timeout=42"
,
"spring.data.cassandra.pool.pool-timeout=52"
,
"spring.data.cassandra.pool.heartbeat-interval=62"
,
"spring.data.cassandra.pool.max-queue-size=72"
).
run
((
context
)
->
{
"spring.data.cassandra.pool.max-queue-size=72"
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
);
PoolingOptions
poolingOptions
=
context
.
getBean
(
Cluster
.
class
)
.
getConfiguration
().
getPoolingOptions
();
assertThat
(
poolingOptions
.
getIdleTimeoutSeconds
()).
isEqualTo
(
42
);
assertThat
(
poolingOptions
.
getPoolTimeoutMillis
()).
isEqualTo
(
52
);
assertThat
(
poolingOptions
.
getHeartbeatIntervalSeconds
()).
isEqualTo
(
62
);
assertThat
(
poolingOptions
.
getHeartbeatIntervalSeconds
())
.
isEqualTo
(
62
);
assertThat
(
poolingOptions
.
getMaxQueueSize
()).
isEqualTo
(
72
);
});
}
@Configuration
static
class
MockCustomizerConfig
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnBeanTests.java
View file @
a869d25d
...
...
@@ -30,7 +30,6 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import
org.springframework.beans.factory.support.RootBeanDefinition
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ContextConsumer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
...
...
@@ -55,40 +54,42 @@ public class ConditionalOnBeanTests {
@Test
public
void
testNameOnBeanCondition
()
{
this
.
contextRunner
.
withUserConfiguration
(
FooConfiguration
.
class
,
OnBeanNameConfiguration
.
class
).
run
(
hasBarBean
()
);
OnBeanNameConfiguration
.
class
).
run
(
this
::
hasBarBean
);
}
@Test
public
void
testNameAndTypeOnBeanCondition
()
{
this
.
contextRunner
.
withUserConfiguration
(
FooConfiguration
.
class
,
OnBeanNameAndTypeConfiguration
.
class
).
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
"bar"
));
this
.
contextRunner
.
withUserConfiguration
(
FooConfiguration
.
class
,
OnBeanNameAndTypeConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
"bar"
));
}
@Test
public
void
testNameOnBeanConditionReverseOrder
()
{
// Ideally this should be true
this
.
contextRunner
.
withUserConfiguration
(
OnBeanNameConfiguration
.
class
,
FooConfiguration
.
class
).
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
"bar"
));
this
.
contextRunner
.
withUserConfiguration
(
OnBeanNameConfiguration
.
class
,
FooConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
"bar"
));
}
@Test
public
void
testClassOnBeanCondition
()
{
this
.
contextRunner
.
withUserConfiguration
(
FooConfiguration
.
class
,
OnBeanClassConfiguration
.
class
).
run
(
hasBarBean
()
);
OnBeanClassConfiguration
.
class
).
run
(
this
::
hasBarBean
);
}
@Test
public
void
testClassOnBeanClassNameCondition
()
{
this
.
contextRunner
.
withUserConfiguration
(
FooConfiguration
.
class
,
OnBeanClassNameConfiguration
.
class
).
run
(
hasBarBean
()
);
OnBeanClassNameConfiguration
.
class
).
run
(
this
::
hasBarBean
);
}
@Test
public
void
testOnBeanConditionWithXml
()
{
this
.
contextRunner
.
withUserConfiguration
(
XmlConfiguration
.
class
,
OnBeanNameConfiguration
.
class
).
run
(
hasBarBean
()
);
OnBeanNameConfiguration
.
class
).
run
(
this
::
hasBarBean
);
}
@Test
...
...
@@ -101,20 +102,21 @@ public class ConditionalOnBeanTests {
@Test
public
void
testAnnotationOnBeanCondition
()
{
this
.
contextRunner
.
withUserConfiguration
(
FooConfiguration
.
class
,
OnAnnotationConfiguration
.
class
).
run
(
hasBarBean
()
);
OnAnnotationConfiguration
.
class
).
run
(
this
::
hasBarBean
);
}
@Test
public
void
testOnMissingBeanType
()
throws
Exception
{
this
.
contextRunner
.
withUserConfiguration
(
FooConfiguration
.
class
,
OnBeanMissingClassConfiguration
.
class
).
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
"bar"
));
this
.
contextRunner
.
withUserConfiguration
(
FooConfiguration
.
class
,
OnBeanMissingClassConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
"bar"
));
}
@Test
public
void
withPropertyPlaceholderClassName
()
throws
Exception
{
this
.
contextRunner
.
withUserConfiguration
(
PropertySourcesPlaceholderConfigurer
.
class
,
this
.
contextRunner
.
withUserConfiguration
(
PropertySourcesPlaceholderConfigurer
.
class
,
WithPropertyPlaceholderClassName
.
class
,
OnBeanClassConfiguration
.
class
)
.
withPropertyValues
(
"mybeanclass=java.lang.String"
)
...
...
@@ -130,14 +132,11 @@ public class ConditionalOnBeanTests {
});
}
private
ContextConsumer
<
AssertableApplicationContext
>
hasBarBean
()
{
return
(
context
)
->
{
private
void
hasBarBean
(
AssertableApplicationContext
context
)
{
assertThat
(
context
).
hasBean
(
"bar"
);
assertThat
(
context
.
getBean
(
"bar"
)).
isEqualTo
(
"bar"
);
};
}
@Configuration
@ConditionalOnBean
(
name
=
"foo"
)
protected
static
class
OnBeanNameConfiguration
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnClassTests.java
View file @
a869d25d
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -20,7 +20,6 @@ import org.junit.Test;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ContextConsumer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
...
...
@@ -40,38 +39,38 @@ public class ConditionalOnClassTests {
@Test
public
void
testVanillaOnClassCondition
()
{
this
.
contextRunner
.
withUserConfiguration
(
BasicConfiguration
.
class
,
FooConfiguration
.
class
).
run
(
hasBarBean
());
this
.
contextRunner
.
withUserConfiguration
(
BasicConfiguration
.
class
,
FooConfiguration
.
class
)
.
run
(
this
::
hasBarBean
);
}
@Test
public
void
testMissingOnClassCondition
()
{
this
.
contextRunner
.
withUserConfiguration
(
MissingConfiguration
.
class
,
FooConfiguration
.
class
).
run
((
context
)
->
{
this
.
contextRunner
.
withUserConfiguration
(
MissingConfiguration
.
class
,
FooConfiguration
.
class
)
.
run
((
context
)
->
{
assertThat
(
context
).
doesNotHaveBean
(
"bar"
);
assertThat
(
context
).
hasBean
(
"foo"
);
assertThat
(
context
.
getBean
(
"foo"
)).
isEqualTo
(
"foo"
);
});
}
@Test
public
void
testOnClassConditionWithXml
()
{
this
.
contextRunner
.
withUserConfiguration
(
BasicConfiguration
.
class
,
XmlConfiguration
.
class
).
run
(
hasBarBean
());
this
.
contextRunner
.
withUserConfiguration
(
BasicConfiguration
.
class
,
XmlConfiguration
.
class
)
.
run
(
this
::
hasBarBean
);
}
@Test
public
void
testOnClassConditionWithCombinedXml
()
{
this
.
contextRunner
.
withUserConfiguration
(
CombinedXmlConfiguration
.
class
)
.
run
(
hasBarBean
()
);
.
run
(
this
::
hasBarBean
);
}
private
ContextConsumer
<
AssertableApplicationContext
>
hasBarBean
()
{
return
(
context
)
->
{
private
void
hasBarBean
(
AssertableApplicationContext
context
)
{
assertThat
(
context
).
hasBean
(
"bar"
);
assertThat
(
context
.
getBean
(
"bar"
)).
isEqualTo
(
"bar"
);
};
}
@Configuration
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnCloudPlatformTests.java
View file @
a869d25d
...
...
@@ -19,9 +19,7 @@ package org.springframework.boot.autoconfigure.condition;
import
org.junit.Test
;
import
org.springframework.boot.cloud.CloudPlatform
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ContextConsumer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -37,32 +35,21 @@ public class ConditionalOnCloudPlatformTests {
@Test
public
void
outcomeWhenCloudfoundryPlatformNotPresentShouldNotMatch
()
{
this
.
contextRunner
.
withUserConfiguration
(
CloudFoundryPlatformConfig
.
class
)
.
run
(
match
(
false
));
.
run
(
(
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
"foo"
));
}
@Test
public
void
outcomeWhenCloudfoundryPlatformPresentShouldMatch
()
{
this
.
contextRunner
.
withUserConfiguration
(
CloudFoundryPlatformConfig
.
class
)
.
withPropertyValues
(
"VCAP_APPLICATION:---"
)
.
run
(
match
(
true
));
.
run
(
(
context
)
->
assertThat
(
context
).
hasBean
(
"foo"
));
}
@Test
public
void
outcomeWhenCloudfoundryPlatformPresentAndMethodTargetShouldMatch
()
{
this
.
contextRunner
.
withUserConfiguration
(
CloudFoundryPlatformOnMethodConfig
.
class
)
.
withPropertyValues
(
"VCAP_APPLICATION:---"
)
.
run
(
match
(
true
));
}
private
ContextConsumer
<
AssertableApplicationContext
>
match
(
boolean
expected
)
{
return
(
context
)
->
{
if
(
expected
)
{
assertThat
(
context
).
hasBean
(
"foo"
);
}
else
{
assertThat
(
context
).
doesNotHaveBean
(
"foo"
);
}
};
.
run
((
context
)
->
assertThat
(
context
).
hasBean
(
"foo"
));
}
@Configuration
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnExpressionTests.java
View file @
a869d25d
...
...
@@ -18,9 +18,7 @@ package org.springframework.boot.autoconfigure.condition;
import
org.junit.Test
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ContextConsumer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -39,31 +37,19 @@ public class ConditionalOnExpressionTests {
@Test
public
void
expressionIsTrue
()
{
this
.
contextRunner
.
withUserConfiguration
(
BasicConfiguration
.
class
)
.
run
(
match
(
true
));
.
run
(
(
context
)
->
assertThat
(
context
.
getBean
(
"foo"
)).
isEqualTo
(
"foo"
));
}
@Test
public
void
expressionIsFalse
()
{
this
.
contextRunner
.
withUserConfiguration
(
MissingConfiguration
.
class
)
.
run
(
match
(
false
));
.
run
(
(
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
"foo"
));
}
@Test
public
void
expressionIsNull
()
{
this
.
contextRunner
.
withUserConfiguration
(
NullConfiguration
.
class
)
.
run
(
match
(
false
));
}
private
ContextConsumer
<
AssertableApplicationContext
>
match
(
boolean
expected
)
{
return
(
context
)
->
{
if
(
expected
)
{
assertThat
(
context
).
hasBean
(
"foo"
);
assertThat
(
context
.
getBean
(
"foo"
)).
isEqualTo
(
"foo"
);
}
else
{
assertThat
(
context
).
doesNotHaveBean
(
"foo"
);
}
};
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
"foo"
));
}
@Configuration
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJavaTests.java
View file @
a869d25d
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -29,9 +29,7 @@ import org.junit.Test;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnJava.JavaVersion
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnJava.Range
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ContextConsumer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.util.ReflectionUtils
;
...
...
@@ -52,17 +50,20 @@ public class ConditionalOnJavaTests {
@Test
public
void
doesNotMatchIfBetterVersionIsRequired
()
{
this
.
contextRunner
.
withUserConfiguration
(
Java9Required
.
class
).
run
(
match
(
false
));
this
.
contextRunner
.
withUserConfiguration
(
Java9Required
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
String
.
class
));
}
@Test
public
void
doesNotMatchIfLowerIsRequired
()
{
this
.
contextRunner
.
withUserConfiguration
(
Java7Required
.
class
).
run
(
match
(
false
));
this
.
contextRunner
.
withUserConfiguration
(
Java7Required
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
String
.
class
));
}
@Test
public
void
matchesIfVersionIsInRange
()
{
this
.
contextRunner
.
withUserConfiguration
(
Java8Required
.
class
).
run
(
match
(
true
));
this
.
contextRunner
.
withUserConfiguration
(
Java8Required
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
hasSingleBean
(
String
.
class
));
}
@Test
...
...
@@ -105,10 +106,8 @@ public class ConditionalOnJavaTests {
private
String
getJavaVersion
(
Class
<?>...
hiddenClasses
)
throws
Exception
{
URL
[]
urls
=
((
URLClassLoader
)
getClass
().
getClassLoader
()).
getURLs
();
URLClassLoader
classLoader
=
new
ClassHidingClassLoader
(
urls
,
hiddenClasses
);
Class
<?>
javaVersionClass
=
classLoader
.
loadClass
(
ConditionalOnJava
.
JavaVersion
.
class
.
getName
());
Method
getJavaVersionMethod
=
ReflectionUtils
.
findMethod
(
javaVersionClass
,
"getJavaVersion"
);
Object
javaVersion
=
ReflectionUtils
.
invokeMethod
(
getJavaVersionMethod
,
null
);
...
...
@@ -123,17 +122,6 @@ public class ConditionalOnJavaTests {
assertThat
(
outcome
.
isMatch
()).
as
(
outcome
.
getMessage
()).
isEqualTo
(
expected
);
}
private
ContextConsumer
<
AssertableApplicationContext
>
match
(
boolean
expected
)
{
return
(
context
)
->
{
if
(
expected
)
{
assertThat
(
context
).
hasSingleBean
(
String
.
class
);
}
else
{
assertThat
(
context
).
doesNotHaveBean
(
String
.
class
);
}
};
}
private
final
class
ClassHidingClassLoader
extends
URLClassLoader
{
private
final
List
<
Class
<?>>
hiddenClasses
;
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJndiTests.java
View file @
a869d25d
...
...
@@ -27,9 +27,7 @@ import org.junit.Test;
import
org.springframework.boot.autoconfigure.jndi.JndiPropertiesHidingClassLoader
;
import
org.springframework.boot.autoconfigure.jndi.TestableInitialContextFactory
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ContextConsumer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
...
...
@@ -77,22 +75,26 @@ public class ConditionalOnJndiTests {
@Test
public
void
jndiNotAvailable
()
{
this
.
contextRunner
.
withUserConfiguration
(
JndiAvailableConfiguration
.
class
,
JndiConditionConfiguration
.
class
).
run
(
match
(
false
));
this
.
contextRunner
.
withUserConfiguration
(
JndiAvailableConfiguration
.
class
,
JndiConditionConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
String
.
class
));
}
@Test
public
void
jndiAvailable
()
{
setupJndi
();
this
.
contextRunner
.
withUserConfiguration
(
JndiAvailableConfiguration
.
class
,
JndiConditionConfiguration
.
class
).
run
(
match
(
true
));
this
.
contextRunner
.
withUserConfiguration
(
JndiAvailableConfiguration
.
class
,
JndiConditionConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
hasSingleBean
(
String
.
class
));
}
@Test
public
void
jndiLocationNotBound
()
{
setupJndi
();
this
.
contextRunner
.
withUserConfiguration
(
JndiConditionConfiguration
.
class
)
.
run
(
match
(
false
));
.
run
(
(
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
String
.
class
));
}
@Test
...
...
@@ -100,7 +102,7 @@ public class ConditionalOnJndiTests {
setupJndi
();
TestableInitialContextFactory
.
bind
(
"java:/FooManager"
,
new
Object
());
this
.
contextRunner
.
withUserConfiguration
(
JndiConditionConfiguration
.
class
)
.
run
(
match
(
true
));
.
run
(
(
context
)
->
assertThat
(
context
).
hasSingleBean
(
String
.
class
));
}
@Test
...
...
@@ -124,17 +126,6 @@ public class ConditionalOnJndiTests {
TestableInitialContextFactory
.
class
.
getName
());
}
private
ContextConsumer
<
AssertableApplicationContext
>
match
(
boolean
expected
)
{
return
(
context
)
->
{
if
(
expected
)
{
assertThat
(
context
).
hasSingleBean
(
String
.
class
);
}
else
{
assertThat
(
context
).
doesNotHaveBean
(
String
.
class
);
}
};
}
private
AnnotatedTypeMetadata
mockMetaData
(
String
...
value
)
{
AnnotatedTypeMetadata
metadata
=
mock
(
AnnotatedTypeMetadata
.
class
);
Map
<
String
,
Object
>
attributes
=
new
HashMap
<>();
...
...
spring-boot-test/src/main/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunner.java
View file @
a869d25d
...
...
@@ -292,20 +292,13 @@ abstract class AbstractApplicationContextRunner<SELF extends AbstractApplication
consumer
.
accept
(
context
);
}
catch
(
Throwable
ex
)
{
AnyThrow
.
throwUnchecked
(
ex
);
rethrow
(
ex
);
}
}
private
static
class
AnyThrow
{
static
void
throwUnchecked
(
Throwable
e
)
{
AnyThrow
.
throwAny
(
e
);
}
@SuppressWarnings
(
"unchecked"
)
private
static
<
E
extends
Throwable
>
void
throwAny
(
Throwable
e
)
throws
E
{
private
<
E
extends
Throwable
>
void
rethrow
(
Throwable
e
)
throws
E
{
throw
(
E
)
e
;
}
}
}
spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonContent.java
View file @
a869d25d
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
spring-boot-test/src/main/java/org/springframework/boot/test/util/TestPropertyValues.java
View file @
a869d25d
...
...
@@ -130,11 +130,16 @@ public final class TestPropertyValues {
return
call
.
call
();
}
catch
(
Exception
ex
)
{
AnyThrow
.
throwUnchecked
(
ex
);
return
null
;
// never reached
rethrow
(
ex
);
throw
new
IllegalStateException
(
"Original cause not rethrown"
,
ex
);
}
}
@SuppressWarnings
(
"unchecked"
)
private
<
E
extends
Throwable
>
void
rethrow
(
Throwable
e
)
throws
E
{
throw
(
E
)
e
;
}
@SuppressWarnings
(
"unchecked"
)
private
void
addToSources
(
MutablePropertySources
sources
,
Type
type
,
String
name
)
{
if
(
sources
.
contains
(
name
))
{
...
...
@@ -310,16 +315,4 @@ public final class TestPropertyValues {
}
private
static
class
AnyThrow
{
static
void
throwUnchecked
(
Throwable
e
)
{
AnyThrow
.
throwAny
(
e
);
}
@SuppressWarnings
(
"unchecked"
)
private
static
<
E
extends
Throwable
>
void
throwAny
(
Throwable
e
)
throws
E
{
throw
(
E
)
e
;
}
}
}
spring-boot-test/src/test/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunnerTests.java
View file @
a869d25d
...
...
@@ -153,7 +153,8 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
new
HidePackagesClassLoader
(
Gson
.
class
.
getPackage
().
getName
()))
.
run
((
context
)
->
{
try
{
ClassUtils
.
forName
(
Gson
.
class
.
getName
(),
context
.
getClassLoader
());
ClassUtils
.
forName
(
Gson
.
class
.
getName
(),
context
.
getClassLoader
());
fail
(
"Should have thrown a ClassNotFoundException"
);
}
catch
(
ClassNotFoundException
e
)
{
...
...
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