-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilitiesIntegrationTest.java
More file actions
88 lines (75 loc) · 3.3 KB
/
Copy pathUtilitiesIntegrationTest.java
File metadata and controls
88 lines (75 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.marketdata.sdk;
import static org.assertj.core.api.Assertions.assertThat;
import com.marketdata.sdk.utilities.ServiceStatus;
import com.marketdata.sdk.utilities.User;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
/**
* Integration tests for the {@code utilities} resource against the live Market Data API. Gated by
* the {@code MARKETDATA_RUN_INTEGRATION_TESTS=true} environment variable in {@code
* build.gradle.kts}; a valid {@code MARKETDATA_TOKEN} is also required.
*
* <p>These are the unversioned diagnostic endpoints ({@code /status/}, {@code /headers/}, {@code
* /user/}). Tests assert <strong>shape</strong> rather than specific values: the service list, the
* echoed header map, and the quota record all drift. Status is asserted as {@code 200 || 203} (203
* = cached/delayed data, which the SDK surfaces as success), matching the other resource suites.
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class UtilitiesIntegrationTest {
private MarketDataClient client;
@BeforeAll
void setUp() {
client = new MarketDataClient();
}
@AfterAll
void tearDown() {
if (client != null) {
client.close();
}
}
@Test
void statusReturnsPerServiceHealth() {
UtilitiesStatusResponse resp = client.utilities().status();
assertThat(resp.statusCode()).isIn(200, 203);
assertThat(resp.values()).as("the API always reports at least one service").isNotEmpty();
ServiceStatus first = resp.values().get(0);
assertThat(first.service()).isNotBlank();
assertThat(first.status()).isNotBlank();
// uptime is a percentage; assert it decodes into the valid range.
assertThat(first.uptimePct30d()).isBetween(0.0, 100.0);
}
@Test
void headersEchoesRequestHeadersWithRedactedAuth() {
UtilitiesHeadersResponse resp = client.utilities().headers();
assertThat(resp.statusCode()).isIn(200, 203);
Map<String, String> headers = resp.values();
assertThat(headers).as("the server echoes the request headers it received").isNotEmpty();
// The SDK's User-Agent (marketdata-sdk-java/{version}) is always echoed back, regardless of how
// the server cases the header key — a stable proof the round-trip carried the SDK's headers.
assertThat(headers.toString()).contains("marketdata-sdk-java");
}
@Test
void userReturnsQuotaSnapshot() {
// The client constructor already validated this token against /user/ on startup, so a 200 is
// expected here; assert the quota record decodes rather than pinning to plan-specific numbers.
UtilitiesUserResponse resp = client.utilities().user();
assertThat(resp.statusCode()).isIn(200, 203);
User user = resp.values();
assertThat(user).isNotNull();
assertThat(user.requestsLimit()).as("a real plan exposes a request limit").isGreaterThan(0);
assertThat(user.requestsRemaining()).isGreaterThanOrEqualTo(0);
}
@Test
void statusValuesDecodeEveryRow() {
// Defensive: iterate the whole list so a malformed row anywhere trips a ParseError, not just
// the first.
List<ServiceStatus> services = client.utilities().status().values();
for (ServiceStatus s : services) {
assertThat(s.service()).isNotBlank();
}
}
}