|
1 | 1 | package com.instabug.flutter;
|
2 | 2 |
|
3 |
| -import static com.instabug.flutter.util.GlobalMocks.reflected; |
4 |
| -import static com.instabug.flutter.util.MockResult.makeResult; |
5 |
| -import static org.junit.Assert.assertEquals; |
6 |
| -import static org.mockito.ArgumentMatchers.any; |
7 |
| -import static org.mockito.ArgumentMatchers.anyInt; |
8 |
| -import static org.mockito.ArgumentMatchers.anyString; |
9 |
| -import static org.mockito.ArgumentMatchers.eq; |
10 |
| -import static org.mockito.Mockito.mock; |
11 |
| -import static org.mockito.Mockito.mockConstruction; |
12 |
| -import static org.mockito.Mockito.mockStatic; |
13 |
| -import static org.mockito.Mockito.verify; |
14 |
| -import static org.mockito.Mockito.when; |
15 |
| - |
16 | 3 | import com.instabug.apm.APM;
|
17 | 4 | import com.instabug.apm.InternalAPM;
|
18 | 5 | import com.instabug.apm.configuration.cp.APMFeature;
|
19 |
| -import com.instabug.apm.InternalAPM; |
20 |
| -import com.instabug.apm.configuration.cp.APMFeature; |
21 | 6 | import com.instabug.apm.configuration.cp.FeatureAvailabilityCallback;
|
22 | 7 | import com.instabug.apm.model.ExecutionTrace;
|
23 | 8 | import com.instabug.apm.networking.APMNetworkLogger;
|
24 |
| -import com.instabug.apm.networkinterception.cp.APMCPNetworkLog; |
25 | 9 | import com.instabug.flutter.generated.ApmPigeon;
|
26 | 10 | import com.instabug.flutter.modules.ApmApi;
|
27 | 11 | import com.instabug.flutter.util.GlobalMocks;
|
@@ -278,143 +262,7 @@ public void testNetworkLogAndroid() {
|
278 | 262 | responseContentType,
|
279 | 263 | errorDomain,
|
280 | 264 | null,
|
281 |
| - serverErrorMessage, |
282 |
| - null |
283 |
| - )); |
284 |
| - |
285 |
| - mAPMNetworkLogger.close(); |
286 |
| - mJSONObject.close(); |
287 |
| - } |
288 |
| - |
289 |
| - @Test |
290 |
| - public void testNetworkLogAndroidWithCaughtW3Header() { |
291 |
| - Map<String, Object> data = new HashMap<>(); |
292 |
| - String requestUrl = "https://example.com"; |
293 |
| - String requestBody = "hi"; |
294 |
| - String responseBody = "{\"hello\":\"world\"}"; |
295 |
| - String requestMethod = "POST"; |
296 |
| - String requestContentType = "text/plain"; |
297 |
| - String responseContentType = "application/json"; |
298 |
| - long requestBodySize = 20; |
299 |
| - long responseBodySize = 50; |
300 |
| - int responseCode = 401; |
301 |
| - long requestDuration = 23000; |
302 |
| - long requestStartTime = System.currentTimeMillis() / 1000; |
303 |
| - HashMap<String, String> requestHeaders = new HashMap<>(); |
304 |
| - requestHeaders.put("traceparent","1234"); |
305 |
| - HashMap<String, String> responseHeaders = new HashMap<>(); |
306 |
| - String errorDomain = "ERROR_DOMAIN"; |
307 |
| - String serverErrorMessage = "SERVER_ERROR_MESSAGE"; |
308 |
| - data.put("url", requestUrl); |
309 |
| - data.put("requestBody", requestBody); |
310 |
| - data.put("responseBody", responseBody); |
311 |
| - data.put("method", requestMethod); |
312 |
| - data.put("requestContentType", requestContentType); |
313 |
| - data.put("responseContentType", responseContentType); |
314 |
| - data.put("requestBodySize", requestBodySize); |
315 |
| - data.put("responseBodySize", responseBodySize); |
316 |
| - data.put("errorDomain", errorDomain); |
317 |
| - data.put("responseCode", responseCode); |
318 |
| - data.put("requestDuration", requestDuration); |
319 |
| - data.put("startTime", requestStartTime); |
320 |
| - data.put("requestHeaders", requestHeaders); |
321 |
| - data.put("responseHeaders", responseHeaders); |
322 |
| - data.put("duration", requestDuration); |
323 |
| - data.put("serverErrorMessage", serverErrorMessage); |
324 |
| - data.put("isW3cHeaderFound", true); |
325 |
| - data.put("w3CCaughtHeader", "1234"); |
326 |
| - |
327 |
| - MockedConstruction<APMNetworkLogger> mAPMNetworkLogger = mockConstruction(APMNetworkLogger.class); |
328 |
| - MockedConstruction<JSONObject> mJSONObject = mockConstruction(JSONObject.class, (mock, context) -> when(mock.toString(anyInt())).thenReturn("{}")); |
329 |
| - |
330 |
| - api.networkLogAndroid(data); |
331 |
| - |
332 |
| - reflected.verify(() -> MockReflected.apmNetworkLog( |
333 |
| - requestStartTime * 1000, |
334 |
| - requestDuration / 1000, |
335 |
| - "{}", |
336 |
| - requestBody, |
337 |
| - requestBodySize, |
338 |
| - requestMethod, |
339 |
| - requestUrl, |
340 |
| - requestContentType, |
341 |
| - "{}", |
342 |
| - responseBody, |
343 |
| - responseBodySize, |
344 |
| - responseCode, |
345 |
| - responseContentType, |
346 |
| - errorDomain, |
347 |
| - null, |
348 |
| - serverErrorMessage, |
349 |
| - new APMCPNetworkLog.W3CExternalTraceAttributes(true,null,null,null,"1234") |
350 |
| - )); |
351 |
| - |
352 |
| - mAPMNetworkLogger.close(); |
353 |
| - mJSONObject.close(); |
354 |
| - } |
355 |
| - |
356 |
| - @Test |
357 |
| - public void testNetworkLogAndroidWithGeneratedW3Header() { |
358 |
| - Map<String, Object> data = new HashMap<>(); |
359 |
| - String requestUrl = "https://example.com"; |
360 |
| - String requestBody = "hi"; |
361 |
| - String responseBody = "{\"hello\":\"world\"}"; |
362 |
| - String requestMethod = "POST"; |
363 |
| - String requestContentType = "text/plain"; |
364 |
| - String responseContentType = "application/json"; |
365 |
| - long requestBodySize = 20; |
366 |
| - long responseBodySize = 50; |
367 |
| - int responseCode = 401; |
368 |
| - long requestDuration = 23000; |
369 |
| - long requestStartTime = System.currentTimeMillis() / 1000; |
370 |
| - HashMap<String, String> requestHeaders = new HashMap<>(); |
371 |
| - HashMap<String, String> responseHeaders = new HashMap<>(); |
372 |
| - String errorDomain = "ERROR_DOMAIN"; |
373 |
| - String serverErrorMessage = "SERVER_ERROR_MESSAGE"; |
374 |
| - data.put("url", requestUrl); |
375 |
| - data.put("requestBody", requestBody); |
376 |
| - data.put("responseBody", responseBody); |
377 |
| - data.put("method", requestMethod); |
378 |
| - data.put("requestContentType", requestContentType); |
379 |
| - data.put("responseContentType", responseContentType); |
380 |
| - data.put("requestBodySize", requestBodySize); |
381 |
| - data.put("responseBodySize", responseBodySize); |
382 |
| - data.put("errorDomain", errorDomain); |
383 |
| - data.put("responseCode", responseCode); |
384 |
| - data.put("requestDuration", requestDuration); |
385 |
| - data.put("startTime", requestStartTime); |
386 |
| - data.put("requestHeaders", requestHeaders); |
387 |
| - data.put("responseHeaders", responseHeaders); |
388 |
| - data.put("duration", requestDuration); |
389 |
| - data.put("serverErrorMessage", serverErrorMessage); |
390 |
| - data.put("isW3cHeaderFound", false); |
391 |
| - data.put("partialId", 12); |
392 |
| - data.put("networkStartTimeInSeconds", 34); |
393 |
| - data.put("w3CGeneratedHeader", "12-34"); |
394 |
| - |
395 |
| - MockedConstruction<APMNetworkLogger> mAPMNetworkLogger = mockConstruction(APMNetworkLogger.class); |
396 |
| - MockedConstruction<JSONObject> mJSONObject = mockConstruction(JSONObject.class, (mock, context) -> when(mock.toString(anyInt())).thenReturn("{}")); |
397 |
| - |
398 |
| - api.networkLogAndroid(data); |
399 |
| - |
400 |
| - reflected.verify(() -> MockReflected.apmNetworkLog( |
401 |
| - requestStartTime * 1000, |
402 |
| - requestDuration / 1000, |
403 |
| - "{}", |
404 |
| - requestBody, |
405 |
| - requestBodySize, |
406 |
| - requestMethod, |
407 |
| - requestUrl, |
408 |
| - requestContentType, |
409 |
| - "{}", |
410 |
| - responseBody, |
411 |
| - responseBodySize, |
412 |
| - responseCode, |
413 |
| - responseContentType, |
414 |
| - errorDomain, |
415 |
| - null, |
416 |
| - serverErrorMessage, |
417 |
| - new APMCPNetworkLog.W3CExternalTraceAttributes(false,12L,34L,"12-34",null) |
| 265 | + serverErrorMessage |
418 | 266 | ));
|
419 | 267 |
|
420 | 268 | mAPMNetworkLogger.close();
|
|
0 commit comments