21
21
import static org .junit .Assert .assertNull ;
22
22
import static org .junit .Assert .assertTrue ;
23
23
import static org .junit .Assert .fail ;
24
- import static org .mockserver .model .Header .header ;
25
- import static org .mockserver .model .HttpForward .forward ;
26
- import static org .mockserver .model .HttpRequest .request ;
27
- import static org .mockserver .model .HttpResponse .response ;
28
24
29
25
import com .google .api .client .http .GenericUrl ;
30
26
import com .google .api .client .http .HttpRequestFactory ;
59
55
import org .junit .BeforeClass ;
60
56
import org .junit .Test ;
61
57
62
- import org .mockserver .integration .ClientAndServer ;
63
- import org .mockserver .model .HttpForward .Scheme ;
64
- import org .mockserver .socket .PortFactory ;
65
-
66
58
public class ApacheHttp2TransportIT {
67
59
private static FirebaseApp app ;
68
60
private static final GoogleCredentials MOCK_CREDENTIALS = new MockGoogleCredentials ("test_token" );
@@ -79,9 +71,6 @@ public class ApacheHttp2TransportIT {
79
71
private static Socket fillerSocket ;
80
72
private static int port ;
81
73
82
- private static ClientAndServer mockProxy ;
83
- private static ClientAndServer mockServer ;
84
-
85
74
@ BeforeClass
86
75
public static void setUpClass () throws IOException {
87
76
// Start server socket with a backlog queue of 1 and a automatically assigned
@@ -109,14 +98,6 @@ public void cleanup() {
109
98
app .delete ();
110
99
}
111
100
112
- if (mockProxy != null && mockProxy .isRunning ()) {
113
- mockProxy .close ();
114
- }
115
-
116
- if (mockServer != null && mockServer .isRunning ()) {
117
- mockServer .close ();
118
- }
119
-
120
101
System .clearProperty ("http.proxyHost" );
121
102
System .clearProperty ("http.proxyPort" );
122
103
System .clearProperty ("https.proxyHost" );
@@ -311,62 +292,6 @@ public void testVerifyProxyIsRespected() {
311
292
}
312
293
}
313
294
314
- @ Test (timeout = 10_000L )
315
- public void testProxyMockHttp () throws Exception {
316
- // Start MockServer
317
- mockProxy = ClientAndServer .startClientAndServer (PortFactory .findFreePort ());
318
- mockServer = ClientAndServer .startClientAndServer (PortFactory .findFreePort ());
319
-
320
- System .setProperty ("http.proxyHost" , "localhost" );
321
- System .setProperty ("http.proxyPort" , mockProxy .getPort ().toString ());
322
-
323
- // Configure proxy to receieve requests and forward them to a mock destination
324
- // server
325
- mockProxy
326
- .when (
327
- request ())
328
- .forward (
329
- forward ()
330
- .withHost ("localhost" )
331
- .withPort (mockServer .getPort ())
332
- .withScheme (Scheme .HTTP ));
333
-
334
- // Configure server to listen and respond
335
- mockServer
336
- .when (
337
- request ())
338
- .respond (
339
- response ()
340
- .withStatusCode (200 )
341
- .withBody ("Expected server response" ));
342
-
343
- // Send a request through the proxy
344
- app = FirebaseApp .initializeApp (FirebaseOptions .builder ()
345
- .setCredentials (MOCK_CREDENTIALS )
346
- .setWriteTimeout (100 )
347
- .build (), "test-app" );
348
- ErrorHandlingHttpClient <FirebaseException > httpClient = getHttpClient (true , app );
349
- HttpRequestInfo request = HttpRequestInfo .buildGetRequest ("http://www.google.com" );
350
- IncomingHttpResponse response = httpClient .send (request );
351
-
352
- // Verify that the proxy received request with destination host
353
- mockProxy .verify (
354
- request ()
355
- .withMethod ("GET" )
356
- .withPath ("/" )
357
- .withHeader (header ("Host" , "www.google.com" )));
358
-
359
- // Verify the forwarded request is received by the server
360
- mockServer .verify (
361
- request ()
362
- .withMethod ("GET" )
363
- .withPath ("/" ));
364
-
365
- // Verify response
366
- assertEquals (200 , response .getStatusCode ());
367
- assertEquals (response .getContent (), "Expected server response" );
368
- }
369
-
370
295
private static ErrorHandlingHttpClient <FirebaseException > getHttpClient (boolean authorized ,
371
296
FirebaseApp app ) {
372
297
HttpRequestFactory requestFactory ;
0 commit comments