15
15
import com .google .firebase .FirebaseException ;
16
16
import com .google .firebase .FirebaseOptions ;
17
17
import com .google .firebase .IncomingHttpResponse ;
18
- import com .google .firebase .TestOnlyImplFirebaseTrampolines ;
19
18
import com .google .firebase .auth .MockGoogleCredentials ;
20
19
21
20
import java .io .IOException ;
25
24
import org .junit .Test ;
26
25
27
26
public class ApacheHttp2TransportIT {
27
+ private static FirebaseApp app ;
28
28
private static final GoogleCredentials MOCK_CREDENTIALS = new MockGoogleCredentials ("test_token" );
29
29
private static final ImmutableMap <String , Object > payload =
30
30
ImmutableMap .<String , Object >of ("foo" , "bar" );
31
+
31
32
// Sets a 1 second delay before response
32
33
private static final String DELAY_URL = "https://nghttp2.org/httpbin/delay/1" ;
33
34
private static final String POST_URL = "https://nghttp2.org/httpbin/post" ;
@@ -38,7 +39,7 @@ public static void setUpClass() {
38
39
39
40
@ After
40
41
public void cleanup () {
41
- TestOnlyImplFirebaseTrampolines . clearInstancesForTest ();
42
+ app . delete ();
42
43
}
43
44
44
45
@ Test
@@ -51,11 +52,11 @@ public void testUnauthorizedPostRequest() throws FirebaseException {
51
52
52
53
@ Test
53
54
public void testConnectTimeoutAuthorizedGet () throws FirebaseException {
54
- FirebaseApp timeoutApp = FirebaseApp .initializeApp (FirebaseOptions .builder ()
55
+ app = FirebaseApp .initializeApp (FirebaseOptions .builder ()
55
56
.setCredentials (MOCK_CREDENTIALS )
56
57
.setConnectTimeout (1 )
57
- .build ());
58
- ErrorHandlingHttpClient <FirebaseException > httpClient = getHttpClient (true , timeoutApp );
58
+ .build (), "test-app" );
59
+ ErrorHandlingHttpClient <FirebaseException > httpClient = getHttpClient (true , app );
59
60
HttpRequestInfo request = HttpRequestInfo .buildGetRequest (DELAY_URL );
60
61
61
62
try {
@@ -70,11 +71,11 @@ public void testConnectTimeoutAuthorizedGet() throws FirebaseException {
70
71
71
72
@ Test
72
73
public void testConnectTimeoutAuthorizedPost () throws FirebaseException {
73
- FirebaseApp timeoutApp = FirebaseApp .initializeApp (FirebaseOptions .builder ()
74
+ app = FirebaseApp .initializeApp (FirebaseOptions .builder ()
74
75
.setCredentials (MOCK_CREDENTIALS )
75
76
.setConnectTimeout (1 )
76
- .build ());
77
- ErrorHandlingHttpClient <FirebaseException > httpClient = getHttpClient (true , timeoutApp );
77
+ .build (), "test-app" );
78
+ ErrorHandlingHttpClient <FirebaseException > httpClient = getHttpClient (true , app );
78
79
HttpRequestInfo request = HttpRequestInfo .buildJsonPostRequest (DELAY_URL , payload );
79
80
80
81
try {
@@ -89,11 +90,11 @@ public void testConnectTimeoutAuthorizedPost() throws FirebaseException {
89
90
90
91
@ Test
91
92
public void testReadTimeoutAuthorizedGet () throws FirebaseException {
92
- FirebaseApp timeoutApp = FirebaseApp .initializeApp (FirebaseOptions .builder ()
93
+ app = FirebaseApp .initializeApp (FirebaseOptions .builder ()
93
94
.setCredentials (MOCK_CREDENTIALS )
94
95
.setReadTimeout (1 )
95
- .build ());
96
- ErrorHandlingHttpClient <FirebaseException > httpClient = getHttpClient (true , timeoutApp );
96
+ .build (), "test-app" );
97
+ ErrorHandlingHttpClient <FirebaseException > httpClient = getHttpClient (true , app );
97
98
HttpRequestInfo request = HttpRequestInfo .buildGetRequest (DELAY_URL );
98
99
99
100
try {
@@ -108,11 +109,11 @@ public void testReadTimeoutAuthorizedGet() throws FirebaseException {
108
109
109
110
@ Test
110
111
public void testReadTimeoutAuthorizedPost () throws FirebaseException {
111
- FirebaseApp timeoutApp = FirebaseApp .initializeApp (FirebaseOptions .builder ()
112
+ app = FirebaseApp .initializeApp (FirebaseOptions .builder ()
112
113
.setCredentials (MOCK_CREDENTIALS )
113
114
.setReadTimeout (1 )
114
- .build ());
115
- ErrorHandlingHttpClient <FirebaseException > httpClient = getHttpClient (true , timeoutApp );
115
+ .build (), "test-app" );
116
+ ErrorHandlingHttpClient <FirebaseException > httpClient = getHttpClient (true , app );
116
117
HttpRequestInfo request = HttpRequestInfo .buildJsonPostRequest (DELAY_URL , payload );
117
118
118
119
try {
@@ -127,11 +128,11 @@ public void testReadTimeoutAuthorizedPost() throws FirebaseException {
127
128
128
129
@ Test
129
130
public void testWriteTimeoutAuthorizedGet () throws FirebaseException {
130
- FirebaseApp timeoutApp = FirebaseApp .initializeApp (FirebaseOptions .builder ()
131
+ app = FirebaseApp .initializeApp (FirebaseOptions .builder ()
131
132
.setCredentials (MOCK_CREDENTIALS )
132
133
.setWriteTimeout (1 )
133
- .build ());
134
- ErrorHandlingHttpClient <FirebaseException > httpClient = getHttpClient (true , timeoutApp );
134
+ .build (), "test-app" );
135
+ ErrorHandlingHttpClient <FirebaseException > httpClient = getHttpClient (true , app );
135
136
HttpRequestInfo request = HttpRequestInfo .buildGetRequest (DELAY_URL );
136
137
137
138
try {
@@ -146,11 +147,11 @@ public void testWriteTimeoutAuthorizedGet() throws FirebaseException {
146
147
147
148
@ Test
148
149
public void testWriteTimeoutAuthorizedPost () throws FirebaseException {
149
- FirebaseApp timeoutApp = FirebaseApp .initializeApp (FirebaseOptions .builder ()
150
+ app = FirebaseApp .initializeApp (FirebaseOptions .builder ()
150
151
.setCredentials (MOCK_CREDENTIALS )
151
152
.setWriteTimeout (1 )
152
- .build ());
153
- ErrorHandlingHttpClient <FirebaseException > httpClient = getHttpClient (true , timeoutApp );
153
+ .build (), "test-app" );
154
+ ErrorHandlingHttpClient <FirebaseException > httpClient = getHttpClient (true , app );
154
155
HttpRequestInfo request = HttpRequestInfo .buildJsonPostRequest (DELAY_URL , payload );
155
156
156
157
try {
@@ -177,9 +178,10 @@ private static ErrorHandlingHttpClient<FirebaseException> getHttpClient(boolean
177
178
}
178
179
179
180
private static ErrorHandlingHttpClient <FirebaseException > getHttpClient (boolean authorized ) {
180
- return getHttpClient ( authorized , FirebaseApp .initializeApp (FirebaseOptions .builder ()
181
+ app = FirebaseApp .initializeApp (FirebaseOptions .builder ()
181
182
.setCredentials (MOCK_CREDENTIALS )
182
- .build (), "test-app" ));
183
+ .build (), "test-app" );
184
+ return getHttpClient (authorized , app );
183
185
}
184
186
185
187
0 commit comments