|
1 | 1 | package com.auth0.client.mgmt; |
2 | 2 |
|
3 | 3 | import com.auth0.client.MockServer; |
| 4 | +import com.auth0.net.TelemetryInterceptor; |
| 5 | +import okhttp3.Interceptor; |
| 6 | +import okhttp3.logging.HttpLoggingInterceptor; |
4 | 7 | import org.junit.After; |
5 | 8 | import org.junit.Before; |
6 | 9 | import org.junit.Test; |
7 | 10 | import org.junit.rules.ExpectedException; |
8 | 11 |
|
9 | 12 | import static com.auth0.client.UrlMatcher.isUrl; |
10 | | -import static org.hamcrest.Matchers.notNullValue; |
| 13 | +import static okhttp3.logging.HttpLoggingInterceptor.Level; |
| 14 | +import static org.hamcrest.Matchers.*; |
11 | 15 | import static org.junit.Assert.assertThat; |
12 | 16 |
|
13 | 17 | public class MgmtAPITest { |
@@ -68,6 +72,74 @@ public void shouldThrowWhenApiTokenIsNull() throws Exception { |
68 | 72 | new MgmtAPI(DOMAIN, null); |
69 | 73 | } |
70 | 74 |
|
| 75 | + @Test |
| 76 | + public void shouldAddAndEnableTelemetryInterceptor() throws Exception { |
| 77 | + MgmtAPI api = new MgmtAPI(DOMAIN, API_TOKEN); |
| 78 | + assertThat(api.getClient().interceptors(), hasItem(isA(TelemetryInterceptor.class))); |
| 79 | + |
| 80 | + for (Interceptor i : api.getClient().interceptors()) { |
| 81 | + if (i instanceof TelemetryInterceptor) { |
| 82 | + TelemetryInterceptor telemetry = (TelemetryInterceptor) i; |
| 83 | + assertThat(telemetry.isEnabled(), is(true)); |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + @Test |
| 89 | + public void shouldDisableTelemetryInterceptor() throws Exception { |
| 90 | + MgmtAPI api = new MgmtAPI(DOMAIN, API_TOKEN); |
| 91 | + assertThat(api.getClient().interceptors(), hasItem(isA(TelemetryInterceptor.class))); |
| 92 | + api.doNotSendTelemetry(); |
| 93 | + |
| 94 | + for (Interceptor i : api.getClient().interceptors()) { |
| 95 | + if (i instanceof TelemetryInterceptor) { |
| 96 | + TelemetryInterceptor telemetry = (TelemetryInterceptor) i; |
| 97 | + assertThat(telemetry.isEnabled(), is(false)); |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + @Test |
| 103 | + public void shouldAddAndDisableLoggingInterceptor() throws Exception { |
| 104 | + MgmtAPI api = new MgmtAPI(DOMAIN, API_TOKEN); |
| 105 | + assertThat(api.getClient().interceptors(), hasItem(isA(HttpLoggingInterceptor.class))); |
| 106 | + |
| 107 | + for (Interceptor i : api.getClient().interceptors()) { |
| 108 | + if (i instanceof HttpLoggingInterceptor) { |
| 109 | + HttpLoggingInterceptor logging = (HttpLoggingInterceptor) i; |
| 110 | + assertThat(logging.getLevel(), is(Level.NONE)); |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + @Test |
| 116 | + public void shouldEnableLoggingInterceptor() throws Exception { |
| 117 | + MgmtAPI api = new MgmtAPI(DOMAIN, API_TOKEN); |
| 118 | + assertThat(api.getClient().interceptors(), hasItem(isA(HttpLoggingInterceptor.class))); |
| 119 | + api.setLoggingEnabled(true); |
| 120 | + |
| 121 | + for (Interceptor i : api.getClient().interceptors()) { |
| 122 | + if (i instanceof HttpLoggingInterceptor) { |
| 123 | + HttpLoggingInterceptor logging = (HttpLoggingInterceptor) i; |
| 124 | + assertThat(logging.getLevel(), is(Level.BODY)); |
| 125 | + } |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + @Test |
| 130 | + public void shouldDisableLoggingInterceptor() throws Exception { |
| 131 | + MgmtAPI api = new MgmtAPI(DOMAIN, API_TOKEN); |
| 132 | + assertThat(api.getClient().interceptors(), hasItem(isA(HttpLoggingInterceptor.class))); |
| 133 | + api.setLoggingEnabled(false); |
| 134 | + |
| 135 | + for (Interceptor i : api.getClient().interceptors()) { |
| 136 | + if (i instanceof HttpLoggingInterceptor) { |
| 137 | + HttpLoggingInterceptor logging = (HttpLoggingInterceptor) i; |
| 138 | + assertThat(logging.getLevel(), is(Level.NONE)); |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + |
71 | 143 | //Entities |
72 | 144 |
|
73 | 145 | @Test |
|
0 commit comments