2424import org .apache .zookeeper .ZooDefs ;
2525import org .apache .zookeeper .client .ZKClientConfig ;
2626import org .apache .zookeeper .common .ClientX509Util ;
27- import org .hamcrest .Matcher ;
28- import org .hamcrest .core .IsNull ;
2927import org .junit .jupiter .api .BeforeEach ;
3028import org .junit .jupiter .api .Test ;
3129import org .mockito .ArgumentCaptor ;
3533
3634import java .util .Arrays ;
3735
38- import static org .hamcrest .CoreMatchers .anyOf ;
39- import static org .hamcrest .CoreMatchers .containsString ;
40- import static org .hamcrest .CoreMatchers .is ;
41- import static org .hamcrest .MatcherAssert .assertThat ;
36+ import static org .assertj .core .api .Assertions .assertThat ;
4237import static org .junit .jupiter .api .Assertions .assertThrows ;
4338import static org .mockito .ArgumentCaptor .forClass ;
4439import static org .mockito .ArgumentMatchers .isA ;
@@ -219,14 +214,18 @@ public void testSSLConfiguration() {
219214 verify (cfBuilder ).zkClientConfig (clientConfCaptor .capture ());
220215 ZKClientConfig conf = clientConfCaptor .getValue ();
221216
222- assertThat (conf .getProperty (ZKClientConfig .SECURE_CLIENT ), is ("true" ) );
223- assertThat (conf .getProperty (ZKClientConfig .ZOOKEEPER_CLIENT_CNXN_SOCKET ),
224- is ("org.apache.zookeeper.ClientCnxnSocketNetty" ) );
217+ assertThat (conf .getProperty (ZKClientConfig .SECURE_CLIENT )). isEqualTo ("true" );
218+ assertThat (conf .getProperty (ZKClientConfig .ZOOKEEPER_CLIENT_CNXN_SOCKET ))
219+ . isEqualTo ("org.apache.zookeeper.ClientCnxnSocketNetty" );
225220 try (ClientX509Util sslOpts = new ClientX509Util ()) {
226- assertThat (conf .getProperty (sslOpts .getSslKeystoreLocationProperty ()), is ("keystoreLoc" ));
227- assertThat (conf .getProperty (sslOpts .getSslKeystorePasswdProperty ()), is ("ksPass" ));
228- assertThat (conf .getProperty (sslOpts .getSslTruststoreLocationProperty ()), is ("truststoreLoc" ));
229- assertThat (conf .getProperty (sslOpts .getSslTruststorePasswdProperty ()), is ("tsPass" ));
221+ assertThat (conf .getProperty (sslOpts .getSslKeystoreLocationProperty ()))
222+ .isEqualTo ("keystoreLoc" );
223+ assertThat (conf .getProperty (sslOpts .getSslKeystorePasswdProperty ()))
224+ .isEqualTo ("ksPass" );
225+ assertThat (conf .getProperty (sslOpts .getSslTruststoreLocationProperty ()))
226+ .isEqualTo ("truststoreLoc" );
227+ assertThat (conf .getProperty (sslOpts .getSslTruststorePasswdProperty ()))
228+ .isEqualTo ("tsPass" );
230229 }
231230
232231 verifyDummyConnectionString ();
@@ -244,39 +243,39 @@ public void testNoConnectionString(){
244243 clientConfigurer .withConnectionString (null );
245244
246245 Throwable t = assertThrows (NullPointerException .class , () -> clientConfigurer .create ());
247- assertThat (t .getMessage (), containsString ("Zookeeper connection string cannot be null!" ) );
246+ assertThat (t .getMessage ()). contains ("Zookeeper connection string cannot be null!" );
248247 }
249248
250249 @ Test
251250 public void testNoRetryPolicy () {
252251 clientConfigurer .withRetryPolicy (null );
253252
254253 Throwable t = assertThrows (NullPointerException .class , () -> clientConfigurer .create ());
255- assertThat (t .getMessage (), containsString ("Zookeeper connection retry policy cannot be null!" ) );
254+ assertThat (t .getMessage ()). contains ("Zookeeper connection retry policy cannot be null!" );
256255 }
257256
258257 @ Test
259258 public void testNoAuthType () {
260259 clientConfigurer .withAuthType (null );
261260
262261 Throwable t = assertThrows (NullPointerException .class , () -> clientConfigurer .create ());
263- assertThat (t .getMessage (), containsString ("Zookeeper authType cannot be null!" ) );
262+ assertThat (t .getMessage ()). contains ("Zookeeper authType cannot be null!" );
264263 }
265264
266265 @ Test
267266 public void testUnrecognizedAuthType () {
268267 clientConfigurer .withAuthType ("something" );
269268
270269 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
271- assertThat (t .getMessage (), is ("Zookeeper authType must be one of [none, sasl]!" ) );
270+ assertThat (t .getMessage ()). isEqualTo ("Zookeeper authType must be one of [none, sasl]!" );
272271 }
273272
274273 @ Test
275274 public void testSaslAuthTypeWithoutKeytab () {
276275 clientConfigurer .withAuthType ("sasl" );
277276
278277 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
279- assertThat (t .getMessage (), is ("Zookeeper client's Kerberos Keytab must be specified!" ) );
278+ assertThat (t .getMessage ()). isEqualTo ("Zookeeper client's Kerberos Keytab must be specified!" );
280279 }
281280
282281 @ Test
@@ -286,7 +285,8 @@ public void testSaslAuthTypeWithEmptyKeytab() {
286285 .withKeytab ("" );
287286
288287 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
289- assertThat (t .getMessage (), is ("Zookeeper client's Kerberos Keytab must be specified!" ));
288+
289+ assertThat (t .getMessage ()).isEqualTo ("Zookeeper client's Kerberos Keytab must be specified!" );
290290 }
291291
292292 @ Test
@@ -296,7 +296,7 @@ public void testSaslAuthTypeWithoutPrincipal() {
296296 .withKeytab ("keytabLoc" );
297297
298298 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
299- assertThat (t .getMessage (), is ("Zookeeper client's Kerberos Principal must be specified!" ) );
299+ assertThat (t .getMessage ()). isEqualTo ("Zookeeper client's Kerberos Principal must be specified!" );
300300 }
301301
302302 @ Test
@@ -307,7 +307,7 @@ public void testSaslAuthTypeWithEmptyPrincipal() {
307307 .withPrincipal ("" );
308308
309309 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
310- assertThat (t .getMessage (), is ("Zookeeper client's Kerberos Principal must be specified!" ) );
310+ assertThat (t .getMessage ()). isEqualTo ("Zookeeper client's Kerberos Principal must be specified!" );
311311 }
312312
313313 @ Test
@@ -319,7 +319,7 @@ public void testSaslAuthTypeWithoutJaasLoginEntryName() {
319319 .withJaasLoginEntryName (null );
320320
321321 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
322- assertThat (t .getMessage (), is ("JAAS Login Entry name must be specified!" ) );
322+ assertThat (t .getMessage ()). isEqualTo ("JAAS Login Entry name must be specified!" );
323323 }
324324
325325 @ Test
@@ -331,7 +331,7 @@ public void testSaslAuthTypeWithEmptyJaasLoginEntryName() {
331331 .withJaasLoginEntryName ("" );
332332
333333 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
334- assertThat (t .getMessage (), is ("JAAS Login Entry name must be specified!" ) );
334+ assertThat (t .getMessage ()). isEqualTo ("JAAS Login Entry name must be specified!" );
335335 }
336336
337337 @ Test
@@ -340,8 +340,7 @@ public void testSSLWithoutKeystore() {
340340 .enableSSL (true );
341341
342342 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
343- assertThat (t .getMessage (),
344- is ("The keystore location parameter is empty for the ZooKeeper client connection." ));
343+ assertThat (t .getMessage ()).isEqualTo ("The keystore location parameter is empty for the ZooKeeper client connection." );
345344 }
346345
347346 @ Test
@@ -351,8 +350,7 @@ public void testSSLWithEmptyKeystore() {
351350 .withKeystore ("" );
352351
353352 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
354- assertThat (t .getMessage (),
355- is ("The keystore location parameter is empty for the ZooKeeper client connection." ));
353+ assertThat (t .getMessage ()).isEqualTo ("The keystore location parameter is empty for the ZooKeeper client connection." );
356354 }
357355
358356 @ Test
@@ -362,8 +360,7 @@ public void testSSLWithoutTruststore() {
362360 .withKeystore ("keyStoreLoc" );
363361
364362 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
365- assertThat (t .getMessage (),
366- is ("The truststore location parameter is empty for the ZooKeeper client connection." ));
363+ assertThat (t .getMessage ()).isEqualTo ("The truststore location parameter is empty for the ZooKeeper client connection." );
367364 }
368365
369366 @ Test
@@ -374,8 +371,7 @@ public void testSSLWithEmptyTruststore() {
374371 .withTruststore ("" );
375372
376373 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
377- assertThat (t .getMessage (),
378- is ("The truststore location parameter is empty for the ZooKeeper client connection." ));
374+ assertThat (t .getMessage ()).isEqualTo ("The truststore location parameter is empty for the ZooKeeper client connection." );
379375 }
380376
381377 private void testSaslAuthType (String vendor ) {
@@ -395,36 +391,37 @@ private void testSaslAuthType(String vendor) {
395391 verify (cfBuilder ).aclProvider (aclProviderCaptor .capture ());
396392 SASLOwnerACLProvider aclProvider = aclProviderCaptor .getValue ();
397393
398- assertThat (aclProvider .getDefaultAcl ().size (), is ( 1 ) );
399- assertThat (aclProvider .getDefaultAcl ().get (0 ).getId ().getScheme (), is ("sasl" ) );
400- assertThat (aclProvider .getDefaultAcl ().get (0 ).getId ().getId (), is ("principal" ) );
401- assertThat (aclProvider .getDefaultAcl ().get (0 ).getPerms (), is (ZooDefs .Perms .ALL ) );
394+ assertThat (aclProvider .getDefaultAcl ().size ()). isEqualTo ( 1 );
395+ assertThat (aclProvider .getDefaultAcl ().get (0 ).getId ().getScheme ()). isEqualTo ("sasl" );
396+ assertThat (aclProvider .getDefaultAcl ().get (0 ).getId ().getId ()). isEqualTo ("principal" );
397+ assertThat (aclProvider .getDefaultAcl ().get (0 ).getPerms ()). isEqualTo (ZooDefs .Perms .ALL );
402398
403399 Arrays .stream (new String [] {"/" , "/foo" , "/foo/bar/baz" , "/random/path" })
404400 .forEach (s -> {
405- assertThat (aclProvider .getAclForPath (s ).size (), is ( 1 ) );
406- assertThat (aclProvider .getAclForPath (s ).get (0 ).getId ().getScheme (), is ("sasl" ) );
407- assertThat (aclProvider .getAclForPath (s ).get (0 ).getId ().getId (), is ("principal" ) );
408- assertThat (aclProvider .getAclForPath (s ).get (0 ).getPerms (), is (ZooDefs .Perms .ALL ) );
401+ assertThat (aclProvider .getAclForPath (s ).size ()). isEqualTo ( 1 );
402+ assertThat (aclProvider .getAclForPath (s ).get (0 ).getId ().getScheme ()). isEqualTo ("sasl" );
403+ assertThat (aclProvider .getAclForPath (s ).get (0 ).getId ().getId ()). isEqualTo ("principal" );
404+ assertThat (aclProvider .getAclForPath (s ).get (0 ).getPerms ()). isEqualTo (ZooDefs .Perms .ALL );
409405 });
410406
411- assertThat (System .getProperty (ZKClientConfig .LOGIN_CONTEXT_NAME_KEY ), is ("TestEntry" ) );
412- assertThat (System .getProperty ("zookeeper.authProvider.1" ),
413- is ( "org.apache.zookeeper.server.auth.SASLAuthenticationProvider" ) );
407+ assertThat (System .getProperty (ZKClientConfig .LOGIN_CONTEXT_NAME_KEY )). isEqualTo ("TestEntry" );
408+ assertThat (System .getProperty ("zookeeper.authProvider.1" )). isEqualTo (
409+ "org.apache.zookeeper.server.auth.SASLAuthenticationProvider" );
414410
415411 Configuration config = Configuration .getConfiguration ();
416- assertThat (config .getAppConfigurationEntry ("TestEntry" ).length , is ( 1 ) );
412+ assertThat (config .getAppConfigurationEntry ("TestEntry" ).length ). isEqualTo ( 1 );
417413 AppConfigurationEntry entry = config .getAppConfigurationEntry ("TestEntry" )[0 ];
418- assertThat (entry .getOptions ().get ("keyTab" ), is ("keytabLoc" ));
419- assertThat (entry .getOptions ().get ("principal" ), is ("principal@some.host/SOME.REALM" ));
420- assertThat (entry .getOptions ().get ("useKeyTab" ), is ("true" ));
421- assertThat (entry .getOptions ().get ("storeKey" ), is ("true" ));
422- assertThat (entry .getOptions ().get ("useTicketCache" ), is ("false" ));
423- assertThat (entry .getOptions ().get ("refreshKrb5Config" ), is ("true" ));
414+ assertThat (entry .getOptions ().get ("keyTab" )).isEqualTo ("keytabLoc" );
415+ assertThat (entry .getOptions ().get ("principal" )).isEqualTo ("principal@some.host/SOME.REALM" );
416+ assertThat (entry .getOptions ().get ("useKeyTab" )).isEqualTo ("true" );
417+ assertThat (entry .getOptions ().get ("storeKey" )).isEqualTo ("true" );
418+ assertThat (entry .getOptions ().get ("useTicketCache" )).isEqualTo ("false" );
419+ assertThat (entry .getOptions ().get ("refreshKrb5Config" )).isEqualTo ("true" );
420+
424421 if (System .getProperty ("java.vendor" ).contains ("IBM" )){
425- assertThat (entry .getLoginModuleName (), is ("com.ibm.security.auth.module.Krb5LoginModule" ) );
422+ assertThat (entry .getLoginModuleName ()). isEqualTo ("com.ibm.security.auth.module.Krb5LoginModule" );
426423 } else {
427- assertThat (entry .getLoginModuleName (), is ("com.sun.security.auth.module.Krb5LoginModule" ) );
424+ assertThat (entry .getLoginModuleName ()). isEqualTo ("com.sun.security.auth.module.Krb5LoginModule" );
428425 }
429426 } finally {
430427 Configuration .setConfiguration (origConf );
@@ -465,8 +462,8 @@ private void verifyDefaultRetryPolicy() {
465462 verify (cfBuilder ).retryPolicy (retry .capture ());
466463 ExponentialBackoffRetry policy = retry .getValue ();
467464
468- assertThat (policy .getBaseSleepTimeMs (), is (1000 ) );
469- assertThat (policy .getN (), is ( 3 ) );
465+ assertThat (policy .getBaseSleepTimeMs ()). isEqualTo (1000 );
466+ assertThat (policy .getN ()). isEqualTo ( 3 );
470467 }
471468
472469 private void verifyDefaultAclProvider () {
@@ -478,21 +475,16 @@ private void verifyDefaultZKClientConfig() {
478475 verify (cfBuilder ).zkClientConfig (clientConfCaptor .capture ());
479476 ZKClientConfig conf = clientConfCaptor .getValue ();
480477
481- assertThat (conf .getProperty (ZKClientConfig .SECURE_CLIENT ), isEmptyOrFalse ());
478+ assertThat (conf .getProperty (ZKClientConfig .SECURE_CLIENT ))
479+ .satisfiesAnyOf (value -> assertThat (value ).isNullOrEmpty (),
480+ value -> assertThat (value ).isEqualTo ("false" ));
481+
482482 try (ClientX509Util sslOpts = new ClientX509Util ()) {
483- assertThat (conf .getProperty (sslOpts .getSslKeystoreLocationProperty ()), isEmpty () );
484- assertThat (conf .getProperty (sslOpts .getSslKeystorePasswdProperty ()), isEmpty () );
485- assertThat (conf .getProperty (sslOpts .getSslTruststoreLocationProperty ()), isEmpty () );
486- assertThat (conf .getProperty (sslOpts .getSslTruststorePasswdProperty ()), isEmpty () );
483+ assertThat (conf .getProperty (sslOpts .getSslKeystoreLocationProperty ())). isNullOrEmpty ( );
484+ assertThat (conf .getProperty (sslOpts .getSslKeystorePasswdProperty ())). isNullOrEmpty ( );
485+ assertThat (conf .getProperty (sslOpts .getSslTruststoreLocationProperty ())). isNullOrEmpty ( );
486+ assertThat (conf .getProperty (sslOpts .getSslTruststorePasswdProperty ())). isNullOrEmpty ( );
487487 }
488488 }
489489
490- private Matcher <String > isEmptyOrFalse () {
491- return anyOf (isEmpty (), is ("false" ));
492- }
493-
494- private Matcher <String > isEmpty () {
495- return anyOf (new IsNull <>(), is ("" ));
496- }
497-
498490}
0 commit comments