Skip to content

Commit 8f7dc0c

Browse files
committed
Updating readme and test.
1 parent 43beee6 commit 8f7dc0c

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ dependency to your Maven configuration:
2626
As of version 2.0.0, this client targets the **Philter 4.0.0** API. Earlier versions of the client are not
2727
compatible with Philter 4.0.0 and later.
2828

29+
| philter-sdk-java | Philter API |
30+
|------------------|-------------|
31+
| 2.0.0 and later | 4.0.0 |
32+
| 1.x | 1.x – 3.x |
33+
2934
## Example Usage
3035

3136
See the [Developer Guide](DEVELOPER.md) for a full, example-driven walkthrough of redacting text and documents,

src/test/java/ai/philterd/PhilterClientMockTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import ai.philterd.philter.model.exceptions.ServiceUnavailableException;
3232
import ai.philterd.philter.model.exceptions.UnauthorizedException;
3333
import okhttp3.HttpUrl;
34+
import okhttp3.OkHttpClient;
3435
import okhttp3.mockwebserver.MockResponse;
3536
import okhttp3.mockwebserver.MockWebServer;
3637
import okhttp3.mockwebserver.RecordedRequest;
@@ -177,6 +178,28 @@ public void noAuthorizationHeaderWhenApiKeyAbsent() throws Exception {
177178
Assert.assertNull(request.getHeader("Authorization"));
178179
}
179180

181+
@Test
182+
public void suppliedOkHttpClientBuilderIsUsedAndAuthIsLayeredOnTop() throws Exception {
183+
184+
server.enqueue(new MockResponse().setResponseCode(200).setBody("[]"));
185+
186+
// An interceptor on the supplied builder proves the builder is actually used; the API key
187+
// proves the Authorization interceptor is still layered on top of the supplied builder.
188+
final OkHttpClient.Builder supplied = new OkHttpClient.Builder()
189+
.addInterceptor(chain -> chain.proceed(
190+
chain.request().newBuilder().header("X-Custom", "custom-value").build()));
191+
192+
final PhilterClient client = clientBuilder()
193+
.withOkHttpClientBuilder(supplied)
194+
.withApiKey("secret-key")
195+
.build();
196+
client.getPolicies();
197+
198+
final RecordedRequest request = server.takeRequest();
199+
Assert.assertEquals("custom-value", request.getHeader("X-Custom"));
200+
Assert.assertEquals("secret-key", request.getHeader("Authorization"));
201+
}
202+
180203
// Status.
181204

182205
@Test
@@ -398,6 +421,7 @@ public void wireContract() throws Exception {
398421

399422
// Contexts.
400423
verify(c, "GET", "/api/contexts", Map.of(), "[]", c::getContexts);
424+
verify(c, "GET", "/api/contexts/c1", Map.of(), "{}", () -> c.getContext("c1"));
401425
verify(c, "PUT", "/api/contexts/c1", Map.of("entity_type_disambiguation", "true", "ledger", "false"), "{}",
402426
() -> c.updateContext("c1", true, false));
403427
verify(c, "DELETE", "/api/contexts/c1", Map.of(), "{}", () -> c.deleteContext("c1"));
@@ -426,6 +450,7 @@ public void wireContract() throws Exception {
426450
verify(c, "GET", "/api/ledger/d1/valid", Map.of(), "true", () -> c.isLedgerValid("d1"));
427451

428452
// Custom lists.
453+
verify(c, "GET", "/api/lists", Map.of(), "[]", c::getLists);
429454
verify(c, "DELETE", "/api/lists/l1", Map.of(), "", () -> c.deleteList("l1"));
430455

431456
// Redact lists.

0 commit comments

Comments
 (0)