|
1 | 1 | package io.github.easy4j.hermes.security; |
2 | 2 |
|
3 | 3 | import io.github.easy4j.hermes.HermesHttpClientConfig; |
| 4 | +import io.github.easy4j.hermes.api.HermesHttpClient; |
4 | 5 | import okhttp3.mockwebserver.MockResponse; |
5 | 6 | import okhttp3.mockwebserver.MockWebServer; |
6 | 7 | import org.junit.jupiter.api.Test; |
7 | 8 |
|
8 | 9 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
| 10 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
9 | 11 | import static org.junit.jupiter.api.Assertions.assertThrows; |
10 | 12 |
|
11 | 13 | class EndpointPolicyContractTest { |
12 | 14 |
|
13 | 15 | @Test |
14 | 16 | void testEp001S1() throws Exception { |
15 | 17 | try (MockWebServer server = new MockWebServer()) { |
16 | | - server.enqueue(new MockResponse().setResponseCode(200).setBody("{}")); |
| 18 | + server.enqueue(new MockResponse() |
| 19 | + .setResponseCode(200) |
| 20 | + .setHeader("Content-Type", "application/json") |
| 21 | + .setBody("{}")); |
17 | 22 | server.start(); |
18 | 23 |
|
19 | 24 | int allowedPort = server.getPort(); |
20 | 25 | EndpointPolicy policy = EndpointPolicy.trustedLocal("127.0.0.1", allowedPort); |
21 | 26 |
|
22 | 27 | HermesHttpClientConfig allowed = new HermesHttpClientConfig() |
23 | | - .setEndpointPolicy(policy); |
24 | | - assertDoesNotThrow(() -> allowed.setBaseUrl( |
25 | | - "http://127.0.0.1:" + allowedPort)); |
| 28 | + .setEndpointPolicy(policy) |
| 29 | + .setBaseUrl("http://127.0.0.1:" + allowedPort); |
| 30 | + |
| 31 | + try (HermesHttpClient client = new HermesHttpClient(allowed)) { |
| 32 | + assertNotNull(client.health()); |
| 33 | + assertNotNull(server.takeRequest()); |
| 34 | + } |
26 | 35 |
|
27 | 36 | HermesHttpClientConfig differentPort = new HermesHttpClientConfig() |
28 | 37 | .setEndpointPolicy(policy); |
|
0 commit comments