1616package com .datastax .oss .driver .internal .core .channel ;
1717
1818import static com .datastax .oss .driver .Assertions .assertThat ;
19- import static org .mockito .Mockito .atLeast ;
2019
21- import ch .qos .logback .classic .Level ;
22- import ch .qos .logback .classic .Logger ;
23- import ch .qos .logback .classic .spi .ILoggingEvent ;
24- import ch .qos .logback .core .Appender ;
2520import com .datastax .oss .driver .api .core .CqlIdentifier ;
2621import com .datastax .oss .driver .api .core .DefaultProtocolVersion ;
2722import com .datastax .oss .driver .api .core .InvalidKeyspaceException ;
5651import java .util .List ;
5752import java .util .Optional ;
5853import java .util .concurrent .TimeUnit ;
59- import org .assertj .core .api .filter .Filters ;
60- import org .junit .After ;
6154import org .junit .Before ;
6255import org .junit .Test ;
63- import org .mockito .ArgumentCaptor ;
64- import org .mockito .Captor ;
6556import org .mockito .Mock ;
6657import org .mockito .Mockito ;
6758import org .mockito .MockitoAnnotations ;
68- import org .slf4j .LoggerFactory ;
6959
7060public class ProtocolInitHandlerTest extends ChannelHandlerTestBase {
7161
@@ -75,13 +65,10 @@ public class ProtocolInitHandlerTest extends ChannelHandlerTestBase {
7565 @ Mock private DriverConfig driverConfig ;
7666 @ Mock private DriverConfigProfile defaultConfigProfile ;
7767 @ Mock private Compressor <ByteBuf > compressor ;
78- @ Mock private Appender <ILoggingEvent > appender ;
79- @ Captor private ArgumentCaptor <ILoggingEvent > loggingEventCaptor ;
8068
8169 private ProtocolVersionRegistry protocolVersionRegistry =
8270 new CassandraProtocolVersionRegistry ("test" );
8371 private HeartbeatHandler heartbeatHandler ;
84- private Logger logger ;
8572
8673 @ Before
8774 @ Override
@@ -96,10 +83,6 @@ public void setup() {
9683 Mockito .when (
9784 defaultConfigProfile .getDuration (DefaultDriverOption .CONNECTION_HEARTBEAT_INTERVAL ))
9885 .thenReturn (Duration .ofSeconds (30 ));
99- Mockito .when (
100- defaultConfigProfile .getBoolean (
101- DefaultDriverOption .AUTH_PROVIDER_WARN_IF_NO_SERVER_AUTH ))
102- .thenReturn (true );
10386 Mockito .when (internalDriverContext .protocolVersionRegistry ())
10487 .thenReturn (protocolVersionRegistry );
10588 Mockito .when (internalDriverContext .compressor ()).thenReturn (compressor );
@@ -119,14 +102,6 @@ public void setup() {
119102 "test" ));
120103
121104 heartbeatHandler = new HeartbeatHandler (defaultConfigProfile );
122-
123- logger = (Logger ) LoggerFactory .getLogger (ProtocolInitHandler .class );
124- logger .addAppender (appender );
125- }
126-
127- @ After
128- public void teardown () {
129- logger .detachAppender (appender );
130105 }
131106
132107 @ Test
@@ -321,7 +296,7 @@ public void should_initialize_with_authentication() {
321296 }
322297
323298 @ Test
324- public void should_warn_if_auth_configured_but_server_does_not_send_challenge () {
299+ public void should_invoke_auth_provider_when_server_does_not_send_challenge () {
325300 channel
326301 .pipeline ()
327302 .addLast (
@@ -341,16 +316,11 @@ public void should_warn_if_auth_configured_but_server_does_not_send_challenge()
341316 Frame requestFrame = readOutboundFrame ();
342317 assertThat (requestFrame .message ).isInstanceOf (Startup .class );
343318
344- // Simulate a READY response, a warning should be logged
319+ // Simulate a READY response, the provider should be notified
345320 writeInboundFrame (buildInboundFrame (requestFrame , new Ready ()));
346- Mockito .verify (appender , atLeast (1 )).doAppend (loggingEventCaptor .capture ());
347- Iterable <ILoggingEvent > warnLogs =
348- Filters .filter (loggingEventCaptor .getAllValues ()).with ("level" , Level .WARN ).get ();
349- assertThat (warnLogs ).hasSize (1 );
350- assertThat (warnLogs .iterator ().next ().getFormattedMessage ())
351- .contains ("did not send an authentication challenge" );
352-
353- // Apart from the warning, init should proceed normally
321+ Mockito .verify (authProvider ).onMissingChallenge (channel .remoteAddress ());
322+
323+ // Since our mock does nothing, init should proceed normally
354324 requestFrame = readOutboundFrame ();
355325 assertThat (requestFrame .message ).isInstanceOf (Query .class );
356326 writeInboundFrame (requestFrame , TestResponses .clusterNameResponse ("someClusterName" ));
0 commit comments