-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStreamHTTPClientTest.java
More file actions
103 lines (88 loc) · 3.35 KB
/
StreamHTTPClientTest.java
File metadata and controls
103 lines (88 loc) · 3.35 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package io.getstream;
import static org.junit.jupiter.api.Assertions.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.getstream.models.MessageResponse;
import io.getstream.services.framework.StreamHTTPClient;
import java.util.Date;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class StreamHTTPClientTest {
private static StreamHTTPClient client;
private static ObjectMapper objectMapper;
@BeforeAll
static void setup() {
// Initialize with test credentials (secret must be at least 32 characters for HS256)
client = new StreamHTTPClient();
objectMapper = client.getObjectMapper();
}
@Test
void testUnixNanosecondTimestampParsing() throws Exception {
long timestampInNanos = 1704542400000000000L;
long timestampInMillis = timestampInNanos / 1_000_000;
// Create a JSON response with unix microsecond timestamp
String json =
String.format(
"""
{
"id": "test-message-id",
"text": "Test message",
"type": "regular",
"created_at": %d,
"updated_at": %d
}
""",
timestampInNanos, timestampInNanos);
// Parse the JSON
MessageResponse message = objectMapper.readValue(json, MessageResponse.class);
// Expected date: 2024-01-06 12:00:00 UTC
Date expectedDate = new Date(timestampInMillis);
// Assert that the parsed date matches the expected date
assertEquals(
expectedDate.getTime(),
message.getCreatedAt().getTime(),
1000, // Allow 1 second tolerance
String.format(
"Expected timestamp %d (2024-01-06) but got %d (%s)",
expectedDate.getTime(), message.getCreatedAt().getTime(), message.getCreatedAt()));
assertEquals(
expectedDate.getTime(),
message.getUpdatedAt().getTime(),
1000, // Allow 1 second tolerance
String.format(
"Expected timestamp %d (2024-01-06) but got %d (%s)",
expectedDate.getTime(), message.getUpdatedAt().getTime(), message.getUpdatedAt()));
}
@Test
void testRFC3339TimestampParsing() throws Exception {
// Create a JSON response with RFC 3339 formatted timestamp
String json =
"""
{
"id": "test-message-id",
"text": "Test message",
"type": "regular",
"created_at": "2024-01-06T12:00:00.000Z",
"updated_at": "2024-01-06T12:00:00Z"
}
""";
// Parse the JSON
MessageResponse message = objectMapper.readValue(json, MessageResponse.class);
// Expected date: 2024-01-06 12:00:00 UTC
Date expectedDate = new Date(1704542400000L);
// Assert that the parsed date matches the expected date
assertEquals(
expectedDate.getTime(),
message.getCreatedAt().getTime(),
1000, // Allow 1 second tolerance
String.format(
"Expected timestamp %d (2024-01-06T12:00:00Z) but got %d (%s)",
expectedDate.getTime(), message.getCreatedAt().getTime(), message.getCreatedAt()));
assertEquals(
expectedDate.getTime(),
message.getUpdatedAt().getTime(),
1000, // Allow 1 second tolerance
String.format(
"Expected timestamp %d (2024-01-06T12:00:00Z) but got %d (%s)",
expectedDate.getTime(), message.getUpdatedAt().getTime(), message.getUpdatedAt()));
}
}