-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathBatchClientTest.java
More file actions
196 lines (162 loc) · 6.33 KB
/
BatchClientTest.java
File metadata and controls
196 lines (162 loc) · 6.33 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package io.getstream.client;
import com.google.common.collect.ImmutableMap;
import io.getstream.core.KeepHistory;
import io.getstream.core.models.*;
import java.text.SimpleDateFormat;
import java.util.*;
import org.junit.Test;
public class BatchClientTest {
private static final String apiKey =
System.getenv("STREAM_KEY") != null
? System.getenv("STREAM_KEY")
: System.getProperty("STREAM_KEY");
private static final String secret =
System.getenv("STREAM_SECRET") != null
? System.getenv("STREAM_SECRET")
: System.getProperty("STREAM_SECRET");
@Test
public void addToMany() throws Exception {
Client client = Client.builder(apiKey, secret).build();
Activity activity = Activity.builder().actor("test").verb("test").object("test").build();
client
.batch()
.addToMany(activity, new FeedID[] {new FeedID("flat", "1"), new FeedID("flat", "2")})
.join();
}
@Test
public void followMany() throws Exception {
BatchClient client = Client.builder(apiKey, secret).build().batch();
client
.followMany(
0,
new FollowRelation[] {
new FollowRelation("flat:1", "flat:2"), new FollowRelation("aggregated:1", "flat:1")
})
.join();
List<FollowRelation> follows = new ArrayList<>();
follows.add(new FollowRelation("flat:1", "flat:2"));
client.followMany(follows.toArray(new FollowRelation[0])).join();
}
@Test
public void followManyWithPerRelationActivityCopyLimit() throws Exception {
BatchClient client = Client.builder(apiKey, secret).build().batch();
// Test per-relationship activity_copy_limit
client
.followMany(
new FollowRelation[] {
new FollowRelation("flat:1", "flat:2", 10),
new FollowRelation("aggregated:1", "flat:1", 20)
})
.join();
}
@Test
public void unfollowMany() throws Exception {
BatchClient client = Client.builder(apiKey, secret).build().batch();
client
.unfollowMany(
new FollowRelation[] {
new FollowRelation("flat:1", "flat:2"), new FollowRelation("aggregated:1", "flat:1")
})
.join();
client
.unfollowMany(
KeepHistory.NO,
new FollowRelation[] {
new FollowRelation("flat:1", "flat:2"), new FollowRelation("aggregated:1", "flat:1")
})
.join();
client
.unfollowMany(
new UnfollowOperation[] {
new UnfollowOperation("flat:1", "flat:2", KeepHistory.NO),
new UnfollowOperation("aggregated:1", "flat:1", KeepHistory.YES)
})
.join();
}
@Test
public void updateActivities() throws Exception {
Client client = Client.builder(apiKey, secret).build();
Activity activity =
Activity.builder()
.actor("test")
.verb("test")
.object("test")
.foreignID("foreignID")
.time(new Date())
.build();
FlatFeed feed = client.flatFeed("flat", "1");
Activity result = feed.addActivity(activity).join();
client.batch().updateActivities(Activity.builder().fromActivity(result).build()).join();
}
@Test
public void partiallyUpdateActivityByID() throws Exception {
Client client = Client.builder(apiKey, secret).build();
Map<String, Object> set = ImmutableMap.of("value", "message");
Iterable<String> unset = Collections.emptyList();
Activity result =
client.updateActivityByID("1657b300-a648-11d5-8080-800020fde6c3", set, unset).join();
}
@Test
public void partiallyUpdateActivityByForeignID() throws Exception {
Client client = Client.builder(apiKey, secret).build();
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S");
isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date time = isoFormat.parse("2001-09-11T00:01:02.000000");
Map<String, Object> set = ImmutableMap.of("value", "message");
Iterable<String> unset = Collections.emptyList();
Activity result =
client
.updateActivityByForeignID(new ForeignIDTimePair("foreignID", time), set, unset)
.join();
}
@Test
public void partiallyUpdateActivitiesByID() throws Exception {
Client client = Client.builder(apiKey, secret).build();
ActivityUpdate update =
ActivityUpdate.builder()
.id("1657b300-a648-11d5-8080-800020fde6c3")
.set(ImmutableMap.of("value", "message"))
.unset(Collections.emptyList())
.build();
List<Activity> result = client.updateActivitiesByID(update).join();
}
@Test
public void partiallyUpdateActivitiesByForeignID() throws Exception {
Client client = Client.builder(apiKey, secret).build();
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S");
isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
ActivityUpdate update =
ActivityUpdate.builder()
.foreignID("foreignID")
.time(isoFormat.parse("2001-09-11T00:01:02.000000"))
.set(ImmutableMap.of("value", "message"))
.unset(Collections.emptyList())
.build();
List<Activity> result = client.updateActivitiesByForeignID(update).join();
}
@Test
public void getActivitiesByID() throws Exception {
BatchClient client = Client.builder(apiKey, secret).build().batch();
List<Activity> result = client.getActivitiesByID("1657b300-a648-11d5-8080-800020fde6c3").join();
}
@Test
public void getEnrichedActivitiesByID() throws Exception {
BatchClient client = Client.builder(apiKey, secret).build().batch();
List<EnrichedActivity> result =
client.getEnrichedActivitiesByID("1657b300-a648-11d5-8080-800020fde6c3").join();
}
@Test
public void getActivitiesByForeignID() throws Exception {
BatchClient client = Client.builder(apiKey, secret).build().batch();
List<Activity> result =
client.getActivitiesByForeignID(new ForeignIDTimePair("foreignID", new Date())).join();
}
@Test
public void getEnrichedActivitiesByForeignID() throws Exception {
BatchClient client = Client.builder(apiKey, secret).build().batch();
List<EnrichedActivity> result =
client
.getEnrichedActivitiesByForeignID(new ForeignIDTimePair("foreignID", new Date()))
.join();
}
}