1515 */
1616package com .datastax .driver .core ;
1717
18- import java .net .InetAddress ;
19- import java .net .InetSocketAddress ;
20- import java .util .Map ;
2118import java .util .concurrent .TimeUnit ;
2219
2320import org .slf4j .Logger ;
@@ -36,17 +33,18 @@ public class AuthenticationTest {
3633
3734 private static final Logger logger = LoggerFactory .getLogger (AuthenticationTest .class );
3835
39- private CCMBridge cassandraCluster ;
36+ private CCMBridge ccm ;
4037
4138 /**
4239 * creates a cluster and turns on password authentication before starting it.
4340 */
4441 @ BeforeClass (groups = "short" )
4542 public void setupClusterWithAuthentication () throws InterruptedException {
46- cassandraCluster = CCMBridge .create ("test" );
47- cassandraCluster .populate (1 );
48- cassandraCluster .updateConfig ("authenticator" , "PasswordAuthenticator" );
49- cassandraCluster .start (1 , "-Dcassandra.superuser_setup_delay_ms=0" );
43+ ccm = CCMBridge .builder ("test" )
44+ .withCassandraConfiguration ("authenticator" , "PasswordAuthenticator" )
45+ .notStarted ()
46+ .build ();
47+ ccm .start (1 , "-Dcassandra.superuser_setup_delay_ms=0" );
5048
5149 // Even though we've override the default user setup delay, still wait
5250 // one second to make sure we don't race
@@ -55,51 +53,42 @@ public void setupClusterWithAuthentication() throws InterruptedException {
5553
5654 @ AfterClass (groups = "short" )
5755 public void shutdownCluster () {
58- if (null != cassandraCluster )
59- cassandraCluster .stop ();
56+ if (ccm != null )
57+ ccm .stop ();
6058 }
6159
6260 @ Test (groups = "short" )
63- public void testAuthenticatedConnection () throws InterruptedException {
61+ public void should_connect_with_credentials () throws InterruptedException {
6462 try {
6563 Cluster .builder ().addContactPoint (CCMBridge .IP_PREFIX + '1' )
6664 .withCredentials ("cassandra" , "cassandra" )
6765 .build ()
6866 .connect ();
6967 } catch (NoHostAvailableException e ) {
70-
71- for (Map .Entry <InetSocketAddress , Throwable > entry : e .getErrors ().entrySet ())
72- logger .error ("Error connecting to " + entry .getKey (), entry .getValue ());
73- throw new RuntimeException (e );
68+ logger .error (e .getCustomMessage (1 , true , true ));
7469 }
7570 }
7671
7772 @ Test (groups = "short" , expectedExceptions = AuthenticationException .class )
78- public void testConnectionAttemptWithIncorrectCredentialsIsRefused () throws InterruptedException {
73+ public void should_fail_to_connect_with_wrong_credentials () throws InterruptedException {
7974 try {
8075 Cluster .builder ().addContactPoint (CCMBridge .IP_PREFIX + '1' )
8176 .withCredentials ("bogus" , "bogus" )
8277 .build ()
8378 .connect ();
8479 } catch (NoHostAvailableException e ) {
85-
86- for (Map .Entry <InetSocketAddress , Throwable > entry : e .getErrors ().entrySet ())
87- logger .info ("Error connecting to " + entry .getKey () + ": " + entry .getValue ());
88- throw new RuntimeException (e );
80+ logger .error (e .getCustomMessage (1 , true , true ));
8981 }
9082 }
9183
9284 @ Test (groups = "short" , expectedExceptions = AuthenticationException .class )
93- public void testConnectionAttemptWithoutCredentialsIsRefused () throws InterruptedException {
85+ public void should_fail_to_connect_without_credentials () throws InterruptedException {
9486 try {
9587 Cluster .builder ().addContactPoint (CCMBridge .IP_PREFIX + '1' )
9688 .build ()
9789 .connect ();
9890 } catch (NoHostAvailableException e ) {
99-
100- for (Map .Entry <InetSocketAddress , Throwable > entry : e .getErrors ().entrySet ())
101- logger .info ("Error connecting to " + entry .getKey () + ": " + entry .getValue ());
102- throw new RuntimeException (e );
91+ logger .error (e .getCustomMessage (1 , true , true ));
10392 }
10493 }
10594}
0 commit comments