This repository was archived by the owner on Dec 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathAIDataServiceTest.java
More file actions
70 lines (55 loc) · 2.53 KB
/
AIDataServiceTest.java
File metadata and controls
70 lines (55 loc) · 2.53 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
package ai.api;
import static org.junit.Assert.*;
import java.net.MalformedURLException;
import java.util.Calendar;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Test;
import ai.api.model.AIRequest;
public class AIDataServiceTest {
@Test
public void testCustomContext() throws AIServiceException {
AIConfiguration config = new AIConfiguration("");
final AtomicReference<String> endpointValue = new AtomicReference<>();
final AtomicReference<String> requestJsonValue = new AtomicReference<>();
AIDataService dataService = new AIDataService(config) {
@Override
protected String doTextRequest(String endpoint, String requestJson,
Map<String, String> additionalHeaders, String requestMethod) throws MalformedURLException, AIServiceException {
endpointValue.set(endpoint);
requestJsonValue.set(requestJson);
return "{}";
}
};
AIServiceContext customContext = new AIServiceContextBuilder()
.setSessionId("customSessionId")
.setSessionId(TimeZone.getTimeZone("Europe/London"))
.build();
String defaultTimeZoneID = Calendar.getInstance().getTimeZone().getID();
AIRequest request;
// Timezone is undefined
request = new AIRequest();
dataService.request(request);
assertTrue(endpointValue.get().indexOf("sessionId=customSessionId") == -1);
assertEquals(defaultTimeZoneID, request.getTimezone());
assertTrue(requestJsonValue.get().indexOf(defaultTimeZoneID) > 0);
assertTrue(requestJsonValue.get().indexOf("Europe/London") == -1);
// Timezone is defined in custom context
request = new AIRequest();
dataService.request(request, customContext);
assertTrue(endpointValue.get().indexOf("sessionId=customSessionId") > 0);
assertEquals("Europe/London", request.getTimezone());
assertTrue(requestJsonValue.get().indexOf("Europe/London") > 0);
assertTrue(requestJsonValue.get().indexOf(defaultTimeZoneID) == -1);
// Timezone is defined in request and custom context
request = new AIRequest();
request.setTimezone("GMT");
dataService.request(request, customContext);
assertTrue(endpointValue.get().indexOf("sessionId=customSessionId") > 0);
assertEquals("GMT", request.getTimezone());
assertTrue(requestJsonValue.get().indexOf("Europe/London") == -1);
assertTrue(requestJsonValue.get().indexOf(defaultTimeZoneID) == -1);
assertTrue(requestJsonValue.get().indexOf("GMT") > 0);
}
}