2828import java .sql .SQLException ;
2929import java .util .Properties ;
3030import java .util .concurrent .TimeUnit ;
31- import okhttp3 .mockwebserver .MockResponse ;
32- import okhttp3 .mockwebserver .MockWebServer ;
33- import okhttp3 .mockwebserver .RecordedRequest ;
31+ import mockwebserver3 .MockResponse ;
32+ import mockwebserver3 .MockWebServer ;
33+ import mockwebserver3 .RecordedRequest ;
34+ import mockwebserver3 .junit5 .StartStop ;
3435import org .apache .arrow .driver .jdbc .authentication .TokenAuthentication ;
3536import org .apache .arrow .driver .jdbc .utils .ArrowFlightConnectionConfigImpl .ArrowFlightConnectionProperty ;
3637import org .apache .arrow .driver .jdbc .utils .MockFlightSqlProducer ;
@@ -75,7 +76,7 @@ public class OAuthIntegrationTest {
7576 .build ();
7677 }
7778
78- private MockWebServer oauthServer ;
79+ @ StartStop private final MockWebServer oauthServer = new MockWebServer () ;
7980 private URI tokenEndpoint ;
8081
8182 @ BeforeAll
@@ -121,15 +122,13 @@ public static void tearDownClass() {
121122 }
122123
123124 @ BeforeEach
124- public void setUp () throws Exception {
125- oauthServer = new MockWebServer ();
126- oauthServer .start ();
125+ public void setUp () {
127126 tokenEndpoint = oauthServer .url ("/oauth/token" ).uri ();
128127 }
129128
130129 @ AfterEach
131- public void tearDown () throws Exception {
132- oauthServer .shutdown ();
130+ public void tearDown () {
131+ oauthServer .close ();
133132 }
134133
135134 // Helper methods for mock OAuth responses
@@ -144,20 +143,22 @@ private void enqueueSuccessfulTokenResponse(String token, int expiresIn) {
144143 "{\" access_token\" :\" %s\" ,\" token_type\" :\" Bearer\" ,\" expires_in\" :%d}" ,
145144 token , expiresIn );
146145 oauthServer .enqueue (
147- new MockResponse ()
148- .setResponseCode (200 )
146+ new MockResponse . Builder ()
147+ .code (200 )
149148 .setHeader ("Content-Type" , "application/json" )
150- .setBody (body ));
149+ .body (body )
150+ .build ());
151151 }
152152
153153 private void enqueueErrorResponse (String error , String description ) {
154154 String body =
155155 String .format ("{\" error\" :\" %s\" ,\" error_description\" :\" %s\" }" , error , description );
156156 oauthServer .enqueue (
157- new MockResponse ()
158- .setResponseCode (400 )
157+ new MockResponse . Builder ()
158+ .code (400 )
159159 .setHeader ("Content-Type" , "application/json" )
160- .setBody (body ));
160+ .body (body )
161+ .build ());
161162 }
162163
163164 private Properties createBaseProperties () {
@@ -197,7 +198,7 @@ public void testClientCredentialsFlowSuccess() throws Exception {
197198 RecordedRequest oauthRequest = oauthServer .takeRequest (5 , TimeUnit .SECONDS );
198199 assertNotNull (oauthRequest , "OAuth request should have been made" );
199200 assertEquals ("POST" , oauthRequest .getMethod ());
200- String body = oauthRequest .getBody ().readUtf8 ();
201+ String body = oauthRequest .getBody ().utf8 ();
201202 assertTrue (body .contains ("grant_type=client_credentials" ));
202203 assertTrue (body .contains ("scope=" + TEST_SCOPE ));
203204 }
@@ -280,7 +281,7 @@ public void testTokenExchangeFlowMinimalParameters() throws Exception {
280281
281282 RecordedRequest oauthRequest = oauthServer .takeRequest (5 , TimeUnit .SECONDS );
282283 assertNotNull (oauthRequest , "OAuth request should have been made" );
283- String body = oauthRequest .getBody ().readUtf8 ();
284+ String body = oauthRequest .getBody ().utf8 ();
284285 assertTrue (
285286 body .contains ("grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange" ),
286287 "Should contain token exchange grant type" );
@@ -323,7 +324,7 @@ public void testTokenExchangeFlowWithAllParameters() throws Exception {
323324
324325 RecordedRequest oauthRequest = oauthServer .takeRequest (5 , TimeUnit .SECONDS );
325326 assertNotNull (oauthRequest , "OAuth request should have been made" );
326- String body = oauthRequest .getBody ().readUtf8 ();
327+ String body = oauthRequest .getBody ().utf8 ();
327328 assertTrue (body .contains ("subject_token=" + SUBJECT_TOKEN ));
328329 assertTrue (body .contains ("actor_token=" + actorToken ));
329330 }
@@ -349,7 +350,7 @@ public void testTokenExchangeFlowWithClientAuthentication() throws Exception {
349350
350351 RecordedRequest oauthRequest = oauthServer .takeRequest (5 , TimeUnit .SECONDS );
351352 assertNotNull (oauthRequest , "OAuth request should have been made" );
352- String authHeader = oauthRequest .getHeader ("Authorization" );
353+ String authHeader = oauthRequest .getHeaders (). get ("Authorization" );
353354 assertNotNull (authHeader , "Should have Basic auth header for client authentication" );
354355 assertTrue (authHeader .startsWith ("Basic " ));
355356 }
0 commit comments