16
16
package org .springframework .data .gemfire ;
17
17
18
18
import static org .assertj .core .api .Assertions .assertThat ;
19
+ import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
20
+ import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
19
21
import static org .mockito .ArgumentMatchers .any ;
20
22
import static org .mockito .ArgumentMatchers .eq ;
21
23
import static org .mockito .Mockito .doAnswer ;
26
28
import static org .mockito .Mockito .spy ;
27
29
import static org .mockito .Mockito .times ;
28
30
import static org .mockito .Mockito .verify ;
31
+ import static org .mockito .Mockito .verifyNoMoreInteractions ;
29
32
import static org .mockito .Mockito .when ;
30
33
31
34
import java .net .InetAddress ;
@@ -63,7 +66,6 @@ public class LocatorFactoryBeanUnitTests {
63
66
64
67
@ Before
65
68
public void setup () {
66
-
67
69
this .locatorFactoryBean = spy (new LocatorFactoryBean ());
68
70
}
69
71
@@ -169,9 +171,9 @@ public void configuresLocatorLauncherBuilderGemFireProperties() {
169
171
170
172
Properties gemfireProperties = new Properties ();
171
173
172
- gemfireProperties .setProperty ("name" , "TEST" );
173
- gemfireProperties .setProperty ("log-level" , "config" );
174
- gemfireProperties .setProperty ("locators" , "localhost[11235],skullbox[12480]" );
174
+ gemfireProperties .setProperty (GemFireProperties . NAME . getName () , "TEST" );
175
+ gemfireProperties .setProperty (GemFireProperties . LOG_LEVEL . getName () , "config" );
176
+ gemfireProperties .setProperty (GemFireProperties . LOCATORS . getName () , "localhost[11235],skullbox[12480]" );
175
177
176
178
LocatorLauncher .Builder locatorBuilderSpy = spy (new LocatorLauncher .Builder ());
177
179
@@ -181,6 +183,11 @@ public void configuresLocatorLauncherBuilderGemFireProperties() {
181
183
gemfireProperties .stringPropertyNames ().forEach (propertyName ->
182
184
verify (locatorBuilderSpy , times (1 ))
183
185
.set (eq (propertyName ), eq (gemfireProperties .getProperty (propertyName ))));
186
+
187
+ verify (locatorBuilderSpy , times (1 ))
188
+ .set (eq (GemFireProperties .USE_CLUSTER_CONFIGURATION .getName ()), eq ("false" ));
189
+
190
+ verifyNoMoreInteractions (locatorBuilderSpy );
184
191
}
185
192
186
193
@ Test
@@ -195,19 +202,13 @@ public void getObjectReturnsLocator() throws Exception {
195
202
verify (this .locatorFactoryBean , times (1 )).getLocator ();
196
203
}
197
204
198
- @ Test ( expected = IllegalStateException . class )
205
+ @ Test
199
206
public void getObjectThrowsIllegalStateException () throws Exception {
200
207
201
- try {
202
- this .locatorFactoryBean .getObject ();
203
- }
204
- catch (IllegalStateException expected ) {
205
-
206
- assertThat (expected ).hasMessage ("Locator was not configured and initialized" );
207
- assertThat (expected ).hasNoCause ();
208
-
209
- throw expected ;
210
- }
208
+ assertThatIllegalStateException ()
209
+ .isThrownBy (() -> this .locatorFactoryBean .getObject ())
210
+ .withMessage ("Locator was not configured and initialized" )
211
+ .withNoCause ();
211
212
}
212
213
213
214
@ Test
@@ -385,33 +386,49 @@ public void setPortToValidValue() {
385
386
assertThat (this .locatorFactoryBean .getPort ()).isEqualTo (54321 );
386
387
}
387
388
388
- @ Test ( expected = IllegalArgumentException . class )
389
+ @ Test
389
390
public void setPortToOverflowValue () {
390
391
391
- try {
392
- this .locatorFactoryBean .setPort (65536 );
393
- }
394
- catch (IllegalArgumentException expected ) {
392
+ assertThatIllegalArgumentException ()
393
+ .isThrownBy (() -> this .locatorFactoryBean .setPort (65536 ))
394
+ .withMessage ("Network port [65536] is not valid" )
395
+ .withNoCause ();
396
+ }
395
397
396
- assertThat ( expected ). hasMessage ( "Network port [65536] is not valid" );
397
- assertThat ( expected ). hasNoCause ();
398
+ @ Test
399
+ public void setPortToUnderflowValue () {
398
400
399
- throw expected ;
400
- }
401
+ assertThatIllegalArgumentException ()
402
+ .isThrownBy (() -> this .locatorFactoryBean .setPort (-1 ))
403
+ .withMessage ("Network port [-1] is not valid" )
404
+ .withNoCause ();
401
405
}
402
406
403
- @ Test (expected = IllegalArgumentException .class )
404
- public void setPortToUnderflowValue () {
407
+ @ Test
408
+ public void locatorFactoryBeanUseOfBeanFactoryLocator () {
409
+
410
+ assertThat (this .locatorFactoryBean .isUseBeanFactoryLocator ()).isFalse ();
411
+
412
+ this .locatorFactoryBean .setUseBeanFactoryLocator (true );
413
+
414
+ assertThat (this .locatorFactoryBean .isUseBeanFactoryLocator ()).isTrue ();
415
+
416
+ this .locatorFactoryBean .setUseBeanFactoryLocator (false );
417
+
418
+ assertThat (this .locatorFactoryBean .isUseBeanFactoryLocator ()).isFalse ();
419
+ }
420
+
421
+ @ Test
422
+ public void locatorFactoryBeanUseOfClusterConfigurationService () {
423
+
424
+ assertThat (this .locatorFactoryBean .isUseClusterConfigurationService ()).isFalse ();
425
+
426
+ this .locatorFactoryBean .setUseClusterConfigurationService (true );
405
427
406
- try {
407
- this .locatorFactoryBean .setPort (-1 );
408
- }
409
- catch (IllegalArgumentException expected ) {
428
+ assertThat (this .locatorFactoryBean .isUseClusterConfigurationService ()).isTrue ();
410
429
411
- assertThat (expected ).hasMessage ("Network port [-1] is not valid" );
412
- assertThat (expected ).hasNoCause ();
430
+ this .locatorFactoryBean .setUseClusterConfigurationService (false );
413
431
414
- throw expected ;
415
- }
432
+ assertThat (this .locatorFactoryBean .isUseClusterConfigurationService ()).isFalse ();
416
433
}
417
434
}
0 commit comments