-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathSiftRequestTest.java
More file actions
70 lines (56 loc) · 2.43 KB
/
SiftRequestTest.java
File metadata and controls
70 lines (56 loc) · 2.43 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 com.siftscience;
import com.siftscience.model.ApplyDecisionFieldSet;
import okhttp3.OkHttpClient;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.junit.Assert;
import org.junit.Test;
import static java.net.HttpURLConnection.HTTP_OK;
public class SiftRequestTest {
@Test
public void testUserAgentHeader() throws Exception {
MockWebServer server = new MockWebServer();
MockResponse response = new MockResponse();
response.setResponseCode(HTTP_OK);
server.enqueue(response);
server.start();
String userId = "a_user_id";
// Create a new client and link it to the mock server.
SiftClient client = new SiftClient("YOUR_API_KEY", "YOUR_ACCOUNT_ID",
new OkHttpClient.Builder()
.addInterceptor(OkHttpUtils.urlRewritingInterceptor(server))
.build());
// Build and execute the request against the mock server.
ApplyDecisionRequest request = client.buildRequest(
new ApplyDecisionFieldSet()
.setUserId(userId)
.setTime(System.currentTimeMillis()));
request.send();
// Verify the request.
RecordedRequest recordedRequest = server.takeRequest();
Assert.assertEquals("SiftScience/v205 sift-java/3.17.0", recordedRequest.getHeader("User-Agent"));
}
@Test
public void testEnqueueRequests() throws Exception {
MockWebServer server = new MockWebServer();
MockResponse response = new MockResponse();
response.setResponseCode(HTTP_OK);
server.enqueue(response);
server.start();
// Create a new client and link it to the mock server.
SiftClient client = new SiftClient("YOUR_API_KEY", "YOUR_ACCOUNT_ID",
new OkHttpClient.Builder()
.addInterceptor(OkHttpUtils.urlRewritingInterceptor(server))
.build());
client.enqueueRequests();
// Build and execute the request against the mock server.
ApplyDecisionRequest request = client.buildRequest(
new ApplyDecisionFieldSet()
.setUserId("a_user_id")
.setTime(System.currentTimeMillis()));
ApplyDecisionResponse receivedResponse = request.send();
// verify
Assert.assertNotNull(receivedResponse);
}
}