22
33import me .proxer .library .BuildConfig ;
44import me .proxer .library .ProxerTest ;
5+ import me .proxer .library .api .ProxerApi .Builder .LoggingConstraints ;
56import me .proxer .library .api .ProxerApi .Builder .LoggingStrategy ;
67import okhttp3 .Request ;
78import okhttp3 .mockwebserver .MockResponse ;
1112
1213import java .io .ByteArrayOutputStream ;
1314import java .io .IOException ;
15+ import java .nio .charset .StandardCharsets ;
1416import java .security .GeneralSecurityException ;
1517import java .util .concurrent .CountDownLatch ;
1618import java .util .logging .Formatter ;
@@ -63,7 +65,7 @@ public void testLog() throws IOException, ProxerException {
6365 loggerHandler .flush ();
6466 loggerStream .flush ();
6567
66- assertThat (loggerStream .toString ("UTF-8" )).isEqualTo ("Requesting https://"
68+ assertThat (loggerStream .toString (StandardCharsets . UTF_8 )).isEqualTo ("Requesting https://"
6769 + server .getHostName () + ":" + server .getPort ()
6870 + "/api/v1/notifications/news with method GET and these headers:\n "
6971 + "proxer-api-key: mockKey\n "
@@ -83,7 +85,7 @@ public void testLogWithBody() throws IOException, ProxerException {
8385 loggerHandler .flush ();
8486 loggerStream .flush ();
8587
86- assertThat (loggerStream .toString ("UTF-8" )).isEqualTo ("Requesting https://"
88+ assertThat (loggerStream .toString (StandardCharsets . UTF_8 )).isEqualTo ("Requesting https://"
8789 + server .getHostName () + ":" + server .getPort ()
8890 + "/api/v1/user/login with method POST, these headers:\n "
8991 + "proxer-api-key: mockKey\n "
@@ -104,7 +106,7 @@ public void testLogWithEmptyBody() throws IOException, ProxerException {
104106 loggerHandler .flush ();
105107 loggerStream .flush ();
106108
107- assertThat (loggerStream .toString ("UTF-8" )).isEqualTo ("Requesting https://"
109+ assertThat (loggerStream .toString (StandardCharsets . UTF_8 )).isEqualTo ("Requesting https://"
108110 + server .getHostName () + ":" + server .getPort ()
109111 + "/api/v1/user/logout with method POST, these headers:\n "
110112 + "proxer-api-key: mockKey\n "
@@ -124,7 +126,7 @@ public void testLogAllOtherHost() throws IOException {
124126 loggerHandler .flush ();
125127 loggerStream .flush ();
126128
127- assertThat (loggerStream .toString ("UTF-8" )).isEqualTo ("Requesting http://"
129+ assertThat (loggerStream .toString (StandardCharsets . UTF_8 )).isEqualTo ("Requesting http://"
128130 + server .getHostName () + ":" + server .getPort ()
129131 + "/test with method GET and no headers." );
130132 }
@@ -142,7 +144,7 @@ public void testLogApiOnly() throws IOException {
142144 loggerHandler .flush ();
143145 loggerStream .flush ();
144146
145- assertThat (loggerStream .toString ("UTF-8" )).isEmpty ();
147+ assertThat (loggerStream .toString (StandardCharsets . UTF_8 )).isEmpty ();
146148 }
147149
148150 @ Test
@@ -158,7 +160,28 @@ public void testLogNone() throws IOException {
158160 loggerHandler .flush ();
159161 loggerStream .flush ();
160162
161- assertThat (loggerStream .toString ("UTF-8" )).isEmpty ();
163+ assertThat (loggerStream .toString (StandardCharsets .UTF_8 )).isEmpty ();
164+ }
165+
166+ @ Test
167+ public void testLogRequestOnly () throws IOException {
168+ startHttpOnlyServer ();
169+
170+ api = constructApi ()
171+ .loggingStrategy (LoggingStrategy .ALL )
172+ .loggingConstraints (LoggingConstraints .URL_ONLY )
173+ .build ();
174+
175+ server .enqueue (new MockResponse ());
176+
177+ api .client ().newCall (new Request .Builder ().url ("http://example.com/test" ).build ()).execute ();
178+
179+ loggerHandler .flush ();
180+ loggerStream .flush ();
181+
182+ assertThat (loggerStream .toString (StandardCharsets .UTF_8 )).isEqualTo ("Requesting http://"
183+ + server .getHostName () + ":" + server .getPort ()
184+ + "/test with method GET." );
162185 }
163186
164187 @ Test
0 commit comments