30
30
import org .springframework .boot .test .context .ContextLoader ;
31
31
import org .springframework .boot .testsupport .runner .classpath .ClassPathExclusions ;
32
32
import org .springframework .boot .testsupport .runner .classpath .ModifiedClassPathRunner ;
33
+ import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
33
34
import org .springframework .context .annotation .Bean ;
34
35
import org .springframework .context .annotation .Configuration ;
35
36
import org .springframework .core .io .ClassPathResource ;
45
46
@ ClassPathExclusions ("hazelcast-client-*.jar" )
46
47
public class HazelcastAutoConfigurationServerTests {
47
48
48
- private final ContextLoader contextLoader = new ContextLoader ()
49
- .autoConfig (HazelcastAutoConfiguration .class );
49
+ private final ContextLoader < AnnotationConfigApplicationContext > contextLoader = ContextLoader
50
+ .standard (). autoConfig (HazelcastAutoConfiguration .class );
50
51
51
52
@ Test
52
53
public void defaultConfigFile () throws IOException {
@@ -61,8 +62,9 @@ public void defaultConfigFile() throws IOException {
61
62
62
63
@ Test
63
64
public void systemProperty () throws IOException {
64
- this .contextLoader .systemProperty (HazelcastServerConfiguration .CONFIG_SYSTEM_PROPERTY ,
65
- "classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml" )
65
+ this .contextLoader
66
+ .systemProperty (HazelcastServerConfiguration .CONFIG_SYSTEM_PROPERTY ,
67
+ "classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml" )
66
68
.load (context -> {
67
69
68
70
HazelcastInstance hazelcastInstance = context
@@ -75,32 +77,36 @@ public void systemProperty() throws IOException {
75
77
76
78
@ Test
77
79
public void explicitConfigFile () throws IOException {
78
- this .contextLoader .env ("spring.hazelcast.config=org/springframework/boot/autoconfigure/hazelcast/"
79
- + "hazelcast-specific.xml" ).load (context -> {
80
- HazelcastInstance hazelcastInstance = context
81
- .getBean (HazelcastInstance .class );
82
- assertThat (hazelcastInstance .getConfig ().getConfigurationFile ()).isEqualTo (
83
- new ClassPathResource ("org/springframework/boot/autoconfigure/hazelcast"
84
- + "/hazelcast-specific.xml" ).getFile ());
85
- });
80
+ this .contextLoader
81
+ .env ("spring.hazelcast.config=org/springframework/boot/autoconfigure/hazelcast/"
82
+ + "hazelcast-specific.xml" )
83
+ .load (context -> {
84
+ HazelcastInstance hazelcastInstance = context
85
+ .getBean (HazelcastInstance .class );
86
+ assertThat (hazelcastInstance .getConfig ().getConfigurationFile ())
87
+ .isEqualTo (new ClassPathResource (
88
+ "org/springframework/boot/autoconfigure/hazelcast"
89
+ + "/hazelcast-specific.xml" ).getFile ());
90
+ });
86
91
}
87
92
88
93
@ Test
89
94
public void explicitConfigUrl () throws IOException {
90
- this .contextLoader
91
- .env ("spring.hazelcast.config=hazelcast-default.xml" ).load (context -> {
92
- HazelcastInstance hazelcastInstance = context
93
- .getBean (HazelcastInstance .class );
94
- assertThat (hazelcastInstance .getConfig ().getConfigurationUrl ())
95
- .isEqualTo (new ClassPathResource ("hazelcast-default.xml" ).getURL ());
96
- });
95
+ this .contextLoader .env ("spring.hazelcast.config=hazelcast-default.xml" )
96
+ .load (context -> {
97
+ HazelcastInstance hazelcastInstance = context
98
+ .getBean (HazelcastInstance .class );
99
+ assertThat (hazelcastInstance .getConfig ().getConfigurationUrl ())
100
+ .isEqualTo (new ClassPathResource ("hazelcast-default.xml" )
101
+ .getURL ());
102
+ });
97
103
}
98
104
99
105
@ Test
100
106
public void unknownConfigFile () {
101
- this .contextLoader .env ("spring.hazelcast.config=foo/bar/unknown.xml" )
102
- . loadAndFail ( BeanCreationException .class , ex ->
103
- assertThat (ex .getMessage ()).contains ("foo/bar/unknown.xml" ));
107
+ this .contextLoader .env ("spring.hazelcast.config=foo/bar/unknown.xml" ). loadAndFail (
108
+ BeanCreationException .class ,
109
+ ex -> assertThat (ex .getMessage ()).contains ("foo/bar/unknown.xml" ));
104
110
}
105
111
106
112
@ Test
@@ -109,15 +115,16 @@ public void configInstanceWithName() {
109
115
HazelcastInstance existingHazelcastInstance = Hazelcast
110
116
.newHazelcastInstance (config );
111
117
try {
112
- this .contextLoader .config (HazelcastConfigWithName .class ).env (
113
- "spring.hazelcast.config=this-is-ignored.xml" ).load (context -> {
114
- HazelcastInstance hazelcastInstance = context
115
- .getBean (HazelcastInstance .class );
116
- assertThat (hazelcastInstance .getConfig ().getInstanceName ())
117
- .isEqualTo ("my-test-instance" );
118
- // Should reuse any existing instance by default.
119
- assertThat (hazelcastInstance ).isEqualTo (existingHazelcastInstance );
120
- });
118
+ this .contextLoader .config (HazelcastConfigWithName .class )
119
+ .env ("spring.hazelcast.config=this-is-ignored.xml" ).load (context -> {
120
+ HazelcastInstance hazelcastInstance = context
121
+ .getBean (HazelcastInstance .class );
122
+ assertThat (hazelcastInstance .getConfig ().getInstanceName ())
123
+ .isEqualTo ("my-test-instance" );
124
+ // Should reuse any existing instance by default.
125
+ assertThat (hazelcastInstance )
126
+ .isEqualTo (existingHazelcastInstance );
127
+ });
121
128
}
122
129
finally {
123
130
existingHazelcastInstance .shutdown ();
@@ -128,12 +135,12 @@ public void configInstanceWithName() {
128
135
public void configInstanceWithoutName () {
129
136
this .contextLoader .config (HazelcastConfigNoName .class )
130
137
.env ("spring.hazelcast.config=this-is-ignored.xml" ).load (context -> {
131
- HazelcastInstance hazelcastInstance = context
132
- .getBean (HazelcastInstance .class );
133
- Map <String , QueueConfig > queueConfigs = hazelcastInstance .getConfig ()
134
- .getQueueConfigs ();
135
- assertThat (queueConfigs ).hasSize (1 ).containsKey ("another-queue" );
136
- });
138
+ HazelcastInstance hazelcastInstance = context
139
+ .getBean (HazelcastInstance .class );
140
+ Map <String , QueueConfig > queueConfigs = hazelcastInstance .getConfig ()
141
+ .getQueueConfigs ();
142
+ assertThat (queueConfigs ).hasSize (1 ).containsKey ("another-queue" );
143
+ });
137
144
}
138
145
139
146
@ Configuration
0 commit comments