14
14
15
15
package com .google .api .client .http ;
16
16
17
- import static org .junit .Assert .assertEquals ;
18
- import static org .junit .Assert .assertFalse ;
19
- import static org .junit .Assert .assertNotNull ;
20
- import static org .junit .Assert .assertNull ;
21
- import static org .junit .Assert .assertTrue ;
22
- import static org .junit .Assert .fail ;
23
-
24
17
import com .google .api .client .testing .http .HttpTesting ;
25
18
import com .google .api .client .testing .http .MockHttpTransport ;
26
19
import com .google .api .client .testing .http .MockHttpUnsuccessfulResponseHandler ;
61
54
*
62
55
* @author Yaniv Inbar
63
56
*/
64
- public class HttpRequestTest {
57
+ public class HttpRequestTest extends TestCase {
65
58
66
59
private static final ImmutableSet <String > BASIC_METHODS =
67
60
ImmutableSet .of (HttpMethods .GET , HttpMethods .PUT , HttpMethods .POST , HttpMethods .DELETE );
68
61
private static final ImmutableSet <String > OTHER_METHODS =
69
62
ImmutableSet .of (HttpMethods .HEAD , HttpMethods .PATCH );
70
63
71
- @ Before
64
+ @ Override
72
65
public void setUp () {
73
66
// suppress logging warnings to the console
74
67
HttpTransport .LOGGER .setLevel (java .util .logging .Level .SEVERE );
75
68
}
76
69
77
- @ After
70
+ @ Override
78
71
public void tearDown () {
79
72
// back to the standard logging level for console
80
73
HttpTransport .LOGGER .setLevel (java .util .logging .Level .WARNING );
81
74
}
82
75
83
- @ Test
84
76
public void testNotSupportedByDefault () throws Exception {
85
77
MockHttpTransport transport = new MockHttpTransport ();
86
78
HttpRequest request =
@@ -119,7 +111,6 @@ public void execute(Runnable command) {
119
111
}
120
112
}
121
113
122
- @ Deprecated
123
114
private static class MockBackOffPolicy implements BackOffPolicy {
124
115
125
116
int backOffCalls ;
@@ -211,7 +202,6 @@ public boolean handleResponse(
211
202
});
212
203
}
213
204
214
- @ Test
215
205
public void test301Redirect () throws Exception {
216
206
// Set up RedirectTransport to redirect on the first request and then return success.
217
207
RedirectTransport fakeTransport = new RedirectTransport ();
@@ -224,7 +214,6 @@ public void test301Redirect() throws Exception {
224
214
}
225
215
226
216
@ Deprecated
227
- @ Test
228
217
public void test301RedirectWithUnsuccessfulResponseHandled () throws Exception {
229
218
MockHttpUnsuccessfulResponseHandler handler = new MockHttpUnsuccessfulResponseHandler (true );
230
219
MockBackOffPolicy backOffPolicy = new MockBackOffPolicy ();
@@ -248,7 +237,6 @@ public void test301RedirectWithUnsuccessfulResponseHandled() throws Exception {
248
237
assertTrue (handler .isCalled ());
249
238
}
250
239
251
- @ Test
252
240
public void test301RedirectWithBackOffUnsuccessfulResponseHandled () throws Exception {
253
241
MockHttpUnsuccessfulResponseHandler handler = new MockHttpUnsuccessfulResponseHandler (true );
254
242
// Set up RedirectTransport to redirect on the first request and then return success.
@@ -295,7 +283,6 @@ public void test301RedirectWithUnsuccessfulResponseNotHandled() throws Exception
295
283
assertEquals (0 , backOffPolicy .backOffCalls );
296
284
}
297
285
298
- @ Test
299
286
public void test301RedirectWithBackOffUnsuccessfulResponseNotHandled () throws Exception {
300
287
// Create an Unsuccessful response handler that always returns false.
301
288
MockHttpUnsuccessfulResponseHandler handler = new MockHttpUnsuccessfulResponseHandler (false );
@@ -318,7 +305,6 @@ public void test301RedirectWithBackOffUnsuccessfulResponseNotHandled() throws Ex
318
305
assertEquals (0 , backOff .getNumberOfTries ());
319
306
}
320
307
321
- @ Test
322
308
public void test303Redirect () throws Exception {
323
309
// Set up RedirectTransport to redirect on the first request and then return success.
324
310
RedirectTransport fakeTransport = new RedirectTransport ();
@@ -341,7 +327,6 @@ public void test303Redirect() throws Exception {
341
327
assertNull (request .getContent ());
342
328
}
343
329
344
- @ Test
345
330
public void testInfiniteRedirects () throws Exception {
346
331
// Set up RedirectTransport to cause infinite redirections.
347
332
RedirectTransport fakeTransport = new RedirectTransport ();
@@ -359,7 +344,6 @@ public void testInfiniteRedirects() throws Exception {
359
344
assertEquals (request .getNumberOfRetries () + 1 , fakeTransport .lowLevelExecCalls );
360
345
}
361
346
362
- @ Test
363
347
public void testMissingLocationRedirect () throws Exception {
364
348
// Set up RedirectTransport to set responses with missing location headers.
365
349
RedirectTransport fakeTransport = new RedirectTransport ();
@@ -469,7 +453,6 @@ public LowLevelHttpRequest buildRequest(String method, String url) {
469
453
}
470
454
}
471
455
472
- @ Test
473
456
public void testHandleRedirect () throws Exception {
474
457
StatusCodesTransport transport = new StatusCodesTransport ();
475
458
HttpRequest req =
@@ -524,7 +507,6 @@ private void subtestRedirect(int statusCode, boolean setLocation) throws Excepti
524
507
}
525
508
}
526
509
527
- @ Test
528
510
public void testHandleRedirect_relativeLocation () throws IOException {
529
511
subtestHandleRedirect_relativeLocation ("http://some.org/a/b" , "z" , "http://some.org/a/z" );
530
512
subtestHandleRedirect_relativeLocation ("http://some.org/a/b" , "z/" , "http://some.org/a/z/" );
@@ -544,7 +526,6 @@ public void subtestHandleRedirect_relativeLocation(
544
526
}
545
527
546
528
@ Deprecated
547
- @ Test
548
529
public void testExecuteErrorWithRetryEnabled () throws Exception {
549
530
int callsBeforeSuccess = 3 ;
550
531
FailThenSuccessConnectionErrorTransport fakeTransport =
@@ -559,7 +540,6 @@ public void testExecuteErrorWithRetryEnabled() throws Exception {
559
540
assertEquals (4 , fakeTransport .lowLevelExecCalls );
560
541
}
561
542
562
- @ Test
563
543
public void testExecuteErrorWithIOExceptionHandler () throws Exception {
564
544
int callsBeforeSuccess = 3 ;
565
545
FailThenSuccessConnectionErrorTransport fakeTransport =
@@ -575,7 +555,6 @@ public void testExecuteErrorWithIOExceptionHandler() throws Exception {
575
555
}
576
556
577
557
@ Deprecated
578
- @ Test
579
558
public void testExecuteErrorWithRetryEnabledBeyondRetryLimit () throws Exception {
580
559
int callsBeforeSuccess = 11 ;
581
560
FailThenSuccessConnectionErrorTransport fakeTransport =
@@ -593,7 +572,6 @@ public void testExecuteErrorWithRetryEnabledBeyondRetryLimit() throws Exception
593
572
assertEquals (callsBeforeSuccess , fakeTransport .lowLevelExecCalls );
594
573
}
595
574
596
- @ Test
597
575
public void testExecuteErrorWithIOExceptionHandlerBeyondRetryLimit () throws Exception {
598
576
int callsBeforeSuccess = 11 ;
599
577
FailThenSuccessConnectionErrorTransport fakeTransport =
@@ -611,7 +589,6 @@ public void testExecuteErrorWithIOExceptionHandlerBeyondRetryLimit() throws Exce
611
589
assertEquals (callsBeforeSuccess , fakeTransport .lowLevelExecCalls );
612
590
}
613
591
614
- @ Test
615
592
public void testExecuteErrorWithoutIOExceptionHandler () throws Exception {
616
593
int callsBeforeSuccess = 3 ;
617
594
FailThenSuccessConnectionErrorTransport fakeTransport =
@@ -630,7 +607,6 @@ public void testExecuteErrorWithoutIOExceptionHandler() throws Exception {
630
607
}
631
608
632
609
@ Deprecated
633
- @ Test
634
610
public void testUserAgentWithExecuteErrorAndRetryEnabled () throws Exception {
635
611
int callsBeforeSuccess = 3 ;
636
612
FailThenSuccessConnectionErrorTransport fakeTransport =
@@ -647,7 +623,6 @@ public void testUserAgentWithExecuteErrorAndRetryEnabled() throws Exception {
647
623
assertEquals (4 , fakeTransport .lowLevelExecCalls );
648
624
}
649
625
650
- @ Test
651
626
public void testUserAgentWithExecuteErrorAndIOExceptionHandler () throws Exception {
652
627
int callsBeforeSuccess = 3 ;
653
628
FailThenSuccessConnectionErrorTransport fakeTransport =
@@ -664,7 +639,6 @@ public void testUserAgentWithExecuteErrorAndIOExceptionHandler() throws Exceptio
664
639
assertEquals (4 , fakeTransport .lowLevelExecCalls );
665
640
}
666
641
667
- @ Test
668
642
public void testAbnormalResponseHandlerWithNoBackOff () throws Exception {
669
643
FailThenSuccessBackoffTransport fakeTransport =
670
644
new FailThenSuccessBackoffTransport (HttpStatusCodes .STATUS_CODE_UNAUTHORIZED , 1 );
@@ -681,7 +655,6 @@ public void testAbnormalResponseHandlerWithNoBackOff() throws Exception {
681
655
}
682
656
683
657
@ Deprecated
684
- @ Test
685
658
public void testAbnormalResponseHandlerWithBackOff () throws Exception {
686
659
FailThenSuccessBackoffTransport fakeTransport =
687
660
new FailThenSuccessBackoffTransport (HttpStatusCodes .STATUS_CODE_SERVER_ERROR , 1 );
@@ -701,7 +674,6 @@ public void testAbnormalResponseHandlerWithBackOff() throws Exception {
701
674
assertTrue (handler .isCalled ());
702
675
}
703
676
704
- @ Test
705
677
public void testAbnormalResponseHandlerWithBackOffUnsuccessfulResponseHandler () throws Exception {
706
678
FailThenSuccessBackoffTransport fakeTransport =
707
679
new FailThenSuccessBackoffTransport (HttpStatusCodes .STATUS_CODE_SERVER_ERROR , 1 );
@@ -720,7 +692,6 @@ public void testAbnormalResponseHandlerWithBackOffUnsuccessfulResponseHandler()
720
692
}
721
693
722
694
@ Deprecated
723
- @ Test
724
695
public void testBackOffSingleCall () throws Exception {
725
696
FailThenSuccessBackoffTransport fakeTransport =
726
697
new FailThenSuccessBackoffTransport (HttpStatusCodes .STATUS_CODE_SERVER_ERROR , 1 );
@@ -740,7 +711,6 @@ public void testBackOffSingleCall() throws Exception {
740
711
assertTrue (handler .isCalled ());
741
712
}
742
713
743
- @ Test
744
714
public void testBackOffUnsuccessfulResponseSingleCall () throws Exception {
745
715
FailThenSuccessBackoffTransport fakeTransport =
746
716
new FailThenSuccessBackoffTransport (HttpStatusCodes .STATUS_CODE_SERVER_ERROR , 1 );
@@ -759,7 +729,6 @@ public void testBackOffUnsuccessfulResponseSingleCall() throws Exception {
759
729
}
760
730
761
731
@ Deprecated
762
- @ Test
763
732
public void testBackOffMultipleCalls () throws Exception {
764
733
int callsBeforeSuccess = 5 ;
765
734
FailThenSuccessBackoffTransport fakeTransport =
@@ -781,7 +750,6 @@ public void testBackOffMultipleCalls() throws Exception {
781
750
assertTrue (handler .isCalled ());
782
751
}
783
752
784
- @ Test
785
753
public void testBackOffUnsucessfulReponseMultipleCalls () throws Exception {
786
754
int callsBeforeSuccess = 5 ;
787
755
FailThenSuccessBackoffTransport fakeTransport =
@@ -802,7 +770,6 @@ public void testBackOffUnsucessfulReponseMultipleCalls() throws Exception {
802
770
}
803
771
804
772
@ Deprecated
805
- @ Test
806
773
public void testBackOffCallsBeyondRetryLimit () throws Exception {
807
774
int callsBeforeSuccess = 11 ;
808
775
FailThenSuccessBackoffTransport fakeTransport =
@@ -827,7 +794,6 @@ public void testBackOffCallsBeyondRetryLimit() throws Exception {
827
794
assertTrue (handler .isCalled ());
828
795
}
829
796
830
- @ Test
831
797
public void testBackOffUnsuccessfulReponseCallsBeyondRetryLimit () throws Exception {
832
798
int callsBeforeSuccess = 11 ;
833
799
FailThenSuccessBackoffTransport fakeTransport =
@@ -851,7 +817,6 @@ public void testBackOffUnsuccessfulReponseCallsBeyondRetryLimit() throws Excepti
851
817
}
852
818
853
819
@ Deprecated
854
- @ Test
855
820
public void testBackOffUnRecognizedStatusCode () throws Exception {
856
821
FailThenSuccessBackoffTransport fakeTransport =
857
822
new FailThenSuccessBackoffTransport (HttpStatusCodes .STATUS_CODE_UNAUTHORIZED , 1 );
@@ -874,7 +839,6 @@ public void testBackOffUnRecognizedStatusCode() throws Exception {
874
839
assertTrue (handler .isCalled ());
875
840
}
876
841
877
- @ Test
878
842
public void testBackOffUnsuccessfulReponseUnRecognizedStatusCode () throws Exception {
879
843
FailThenSuccessBackoffTransport fakeTransport =
880
844
new FailThenSuccessBackoffTransport (HttpStatusCodes .STATUS_CODE_UNAUTHORIZED , 1 );
@@ -896,7 +860,6 @@ public void testBackOffUnsuccessfulReponseUnRecognizedStatusCode() throws Except
896
860
}
897
861
898
862
@ Deprecated
899
- @ Test
900
863
public void testBackOffStop () throws Exception {
901
864
int callsBeforeSuccess = 5 ;
902
865
FailThenSuccessBackoffTransport fakeTransport =
@@ -923,7 +886,6 @@ public void testBackOffStop() throws Exception {
923
886
assertTrue (handler .isCalled ());
924
887
}
925
888
926
- @ Test
927
889
public void testBackOffUnsucessfulResponseStop () throws Exception {
928
890
int callsBeforeSuccess = 5 ;
929
891
FailThenSuccessBackoffTransport fakeTransport =
@@ -970,7 +932,6 @@ public static class MyHeaders extends HttpHeaders {
970
932
@ Key E otherValue ;
971
933
}
972
934
973
- @ Test
974
935
public void testExecute_headerSerialization () throws Exception {
975
936
// custom headers
976
937
MyHeaders myHeaders = new MyHeaders ();
@@ -1011,7 +972,6 @@ public LowLevelHttpRequest buildRequest(String method, String url) throws IOExce
1011
972
assertEquals (ImmutableList .of ("other" ), lowLevelRequest .getHeaderValues ("othervalue" ));
1012
973
}
1013
974
1014
- @ Test
1015
975
public void testGZipEncoding () throws Exception {
1016
976
class MyTransport extends MockHttpTransport {
1017
977
@@ -1061,7 +1021,6 @@ public LowLevelHttpResponse execute() throws IOException {
1061
1021
request .execute ();
1062
1022
}
1063
1023
1064
- @ Test
1065
1024
public void testContentLoggingLimitWithLoggingEnabledAndDisabled () throws Exception {
1066
1025
1067
1026
class MyTransport extends MockHttpTransport {
@@ -1128,20 +1087,17 @@ public LowLevelHttpResponse execute() throws IOException {
1128
1087
}
1129
1088
}
1130
1089
1131
- @ Test
1132
1090
public void testVersion () {
1133
1091
assertNotNull ("version constant should not be null" , HttpRequest .VERSION );
1134
1092
Pattern semverPattern = Pattern .compile ("\\ d+\\ .\\ d+\\ .\\ d+(-sp\\ .\\ d+)?(-SNAPSHOT)?" );
1135
1093
assertTrue (semverPattern .matcher (HttpRequest .VERSION ).matches ());
1136
1094
}
1137
1095
1138
- @ Test
1139
1096
public void testUserAgent () {
1140
1097
assertTrue (HttpRequest .USER_AGENT_SUFFIX .contains ("Google-HTTP-Java-Client" ));
1141
1098
assertTrue (HttpRequest .USER_AGENT_SUFFIX .contains ("gzip" ));
1142
1099
}
1143
1100
1144
- @ Test
1145
1101
public void testExecute_headers () throws Exception {
1146
1102
HttpTransport transport = new MockHttpTransport ();
1147
1103
HttpRequest request =
@@ -1151,7 +1107,6 @@ public void testExecute_headers() throws Exception {
1151
1107
request .execute ();
1152
1108
}
1153
1109
1154
- @ Test
1155
1110
public void testSuppressUserAgentSuffix () throws Exception {
1156
1111
class MyTransport extends MockHttpTransport {
1157
1112
String expectedUserAgent ;
@@ -1194,7 +1149,6 @@ public LowLevelHttpResponse execute() throws IOException {
1194
1149
request .execute ();
1195
1150
}
1196
1151
1197
- @ Test
1198
1152
public void testExecuteAsync ()
1199
1153
throws IOException , InterruptedException , ExecutionException , TimeoutException {
1200
1154
MockExecutor mockExecutor = new MockExecutor ();
@@ -1209,7 +1163,6 @@ public void testExecuteAsync()
1209
1163
assertNotNull (futureResponse .get (10 , TimeUnit .MILLISECONDS ));
1210
1164
}
1211
1165
1212
- @ Test
1213
1166
public void testExecute_redirects () throws Exception {
1214
1167
class MyTransport extends MockHttpTransport {
1215
1168
int count = 1 ;
@@ -1240,7 +1193,6 @@ public LowLevelHttpRequest buildRequest(String method, String url) throws IOExce
1240
1193
}
1241
1194
}
1242
1195
1243
- @ Test
1244
1196
public void testExecute_redirectWithIncorrectContentRetryableSetting () throws Exception {
1245
1197
// TODO(yanivi): any way we can warn user about this?
1246
1198
RedirectTransport fakeTransport = new RedirectTransport ();
@@ -1261,7 +1213,6 @@ public void testExecute_redirectWithIncorrectContentRetryableSetting() throws Ex
1261
1213
assertEquals (2 , fakeTransport .lowLevelExecCalls );
1262
1214
}
1263
1215
1264
- @ Test
1265
1216
public void testExecute_curlLogger () throws Exception {
1266
1217
LogRecordingHandler recorder = new LogRecordingHandler ();
1267
1218
HttpTransport .LOGGER .setLevel (Level .CONFIG );
@@ -1284,7 +1235,6 @@ public void testExecute_curlLogger() throws Exception {
1284
1235
assertTrue (found );
1285
1236
}
1286
1237
1287
- @ Test
1288
1238
public void testExecute_curlLoggerWithContentEncoding () throws Exception {
1289
1239
LogRecordingHandler recorder = new LogRecordingHandler ();
1290
1240
HttpTransport .LOGGER .setLevel (Level .CONFIG );
@@ -1318,7 +1268,6 @@ public void testExecute_curlLoggerWithContentEncoding() throws Exception {
1318
1268
assertTrue (found );
1319
1269
}
1320
1270
1321
- @ Test
1322
1271
public void testVersion_matchesAcceptablePatterns () throws Exception {
1323
1272
String acceptableVersionPattern =
1324
1273
"unknown-version|(?:\\ d+\\ .\\ d+\\ .\\ d+(?:-.*?)?(?:-SNAPSHOT)?)" ;
0 commit comments