|
| 1 | +package com.microsoft.graph.httpcore; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertNotNull; |
| 4 | +import static org.junit.Assert.assertTrue; |
| 5 | + |
| 6 | +import java.io.IOException; |
| 7 | + |
| 8 | +import org.junit.Ignore; |
| 9 | +import org.junit.Test; |
| 10 | + |
| 11 | +import okhttp3.Interceptor; |
| 12 | +import okhttp3.OkHttpClient; |
| 13 | +import okhttp3.Request; |
| 14 | +import okhttp3.Response; |
| 15 | + |
| 16 | +@Ignore |
| 17 | +public class TelemetryHandlerTest { |
| 18 | + @Test |
| 19 | + public void telemetryInitTest() { |
| 20 | + TelemetryHandler telemetryHandler = new TelemetryHandler(); |
| 21 | + assertNotNull(telemetryHandler); |
| 22 | + } |
| 23 | + |
| 24 | + @Test |
| 25 | + public void interceptTest() throws IOException { |
| 26 | + String expectedHeader = TelemetryHandler.SDK_VERSION + TelemetryHandler.GRAPH_VERSION_PREFIX +"/" |
| 27 | + +TelemetryHandler.VERSION; |
| 28 | + OkHttpClient client = HttpClients.createDefault(new ICoreAuthenticationProvider() { |
| 29 | + @Override |
| 30 | + public Request authenticateRequest(Request request) { |
| 31 | + return request; |
| 32 | + } |
| 33 | + }); |
| 34 | + Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); |
| 35 | + Response response = client.newCall(request).execute(); |
| 36 | + assertNotNull(response); |
| 37 | + assertTrue(response.request().header("SdkVersion").contains(expectedHeader)); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void arrayInterceptorsTest() throws IOException { |
| 42 | + |
| 43 | + AuthenticationHandler authenticationHandler = new AuthenticationHandler(new ICoreAuthenticationProvider() { |
| 44 | + |
| 45 | + @Override |
| 46 | + public Request authenticateRequest(Request request) { |
| 47 | + return request; |
| 48 | + } |
| 49 | + }); |
| 50 | + Interceptor[] interceptors = {new RetryHandler(), new RedirectHandler(), authenticationHandler}; |
| 51 | + OkHttpClient client = HttpClients.createFromInterceptors(interceptors); |
| 52 | + String expectedHeader = TelemetryHandler.SDK_VERSION + TelemetryHandler.GRAPH_VERSION_PREFIX +"/" |
| 53 | + +TelemetryHandler.VERSION; |
| 54 | + Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); |
| 55 | + Response response = client.newCall(request).execute(); |
| 56 | + assertNotNull(response); |
| 57 | + assertTrue(response.request().header("SdkVersion").contains(expectedHeader)); |
| 58 | + } |
| 59 | +} |
0 commit comments