Repository navigation
Expand file tree
/
Copy pathFeedTest.java
More file actions
254 lines (220 loc) · 8.39 KB
/
Copy pathFeedTest.java
File metadata and controls
254 lines (220 loc) · 8.39 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
package io.getstream.client;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import com.google.common.collect.Lists;
import io.getstream.client.entities.FootballMatch;
import io.getstream.client.entities.Match;
import io.getstream.client.entities.VolleyballMatch;
import io.getstream.core.http.OKHTTPClientAdapter;
import io.getstream.core.models.Activity;
import io.getstream.core.models.FeedID;
import io.getstream.core.models.FollowStats;
import io.getstream.core.models.ModerationResponse;
import io.getstream.core.options.CustomQueryParameter;
import java.net.MalformedURLException;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import okhttp3.OkHttpClient;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public class FeedTest {
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");
private static Client client;
@Rule public ExpectedException expectedException = ExpectedException.none();
@BeforeClass
public static void setup() throws MalformedURLException {
client =
Client.builder(apiKey, secret)
.httpClient(new OKHTTPClientAdapter(new OkHttpClient()))
.build();
}
@Test
public void addActivity() throws Exception {
Activity activity = Activity.builder().actor("test").verb("test").object("test").build();
FlatFeed feed = client.flatFeed("flat", "1");
Activity result = feed.addActivity(activity).join();
}
@Test
public void addActivitySkipModeration() throws Exception {
FlatFeed feed = client.flatFeed("user", "1");
Activity blocked =
Activity.builder()
.actor("test")
.verb("test")
.object("test")
.moderationTemplate("moderation_template_activity")
.extraField("text", "pissoar")
.foreignID(UUID.randomUUID().toString())
.time(new Date())
.build();
Activity withModeration = feed.addActivity(blocked).join();
assertNotNull(withModeration.getModerationResponse());
assertEquals("remove", withModeration.getModerationResponse().getRecommendedAction());
Activity withoutModeration =
feed.addActivity(blocked, new CustomQueryParameter("skip_moderation", "true")).join();
assertNull(withoutModeration.getModerationResponse());
}
@Test
public void addActivitiesSkipModeration() throws Exception {
FlatFeed feed = client.flatFeed("user", "1");
Activity blocked =
Activity.builder()
.actor("test")
.verb("test")
.object("test")
.moderationTemplate("moderation_template_activity")
.extraField("text", "pissoar")
.foreignID(UUID.randomUUID().toString())
.time(new Date())
.build();
List<Activity> withoutModeration =
feed.addActivities(
new Activity[] {blocked},
new CustomQueryParameter("skip_moderation", "true"))
.join();
assertEquals(1, withoutModeration.size());
assertNull(withoutModeration.get(0).getModerationResponse());
}
@Test
public void addActivities() throws Exception {
Activity activity = Activity.builder().actor("test").verb("test").object("test").build();
FlatFeed feed = client.flatFeed("flat", "1");
List<Activity> result = feed.addActivities(activity).join();
}
@Test
public void addCustomActivities() throws Exception {
VolleyballMatch volley = new VolleyballMatch();
volley.actor = "Me";
volley.object = "Message";
volley.verb = "verb";
volley.setNrOfBlocked(1);
volley.setNrOfServed(1);
FootballMatch football = new FootballMatch();
football.actor = "Me";
football.object = "Message";
football.verb = "verb";
football.setNrOfPenalty(2);
football.setNrOfScore(3);
FlatFeed feed = client.flatFeed("flat", "1");
List<Match> result = feed.addCustomActivities(volley, football).join();
}
@Test
public void removeActivityByID() throws Exception {
FlatFeed feed = client.flatFeed("flat", "1");
feed.removeActivityByID("654e333e-d146-11e8-bd18-1231d51167b4").join();
}
@Test
public void removeActivityByForeignID() throws Exception {
FlatFeed feed = client.flatFeed("flat", "1");
feed.removeActivityByForeignID("654e333e-d146-11e8-bd18-1231d51167b4").join();
}
@Test
public void follow() throws Exception {
FlatFeed feed1 = client.flatFeed("flat", "1");
FlatFeed feed2 = client.flatFeed("flat", "2");
feed1.follow(feed2).join();
}
@Test
public void getFollowers() throws Exception {
FlatFeed feed = client.flatFeed("flat", "1");
feed.getFollowers().join();
}
@Test
public void getFollowed() throws Exception {
FlatFeed feed = client.flatFeed("flat", "1");
feed.getFollowed().join();
}
@Test
public void unfollow() throws Exception {
FlatFeed feed1 = client.flatFeed("flat", "1");
FlatFeed feed2 = client.flatFeed("flat", "2");
feed1.unfollow(feed2).join();
}
@Test
public void getFollowStats() throws Exception {
String uuid1 = UUID.randomUUID().toString().replace("-", "");
String uuid2 = UUID.randomUUID().toString().replace("-", "");
String feed1Id = "flat:" + uuid1;
FlatFeed feed1 = client.flatFeed("flat", uuid1);
FlatFeed feed2 = client.flatFeed("flat", uuid2);
feed1.follow(feed2).join();
FollowStats stats =
feed1.getFollowStats(Collections.emptyList(), Lists.newArrayList("timeline")).join();
assertEquals(0, stats.getFollowers().getCount());
assertEquals(feed1Id, stats.getFollowers().getFeed());
assertEquals(0, stats.getFollowing().getCount());
assertEquals(feed1Id, stats.getFollowing().getFeed());
stats = feed1.getFollowStats(Collections.emptyList(), Lists.newArrayList("flat")).join();
assertEquals(0, stats.getFollowers().getCount());
assertEquals(feed1Id, stats.getFollowers().getFeed());
assertEquals(1, stats.getFollowing().getCount());
assertEquals(feed1Id, stats.getFollowing().getFeed());
}
@Test
public void updateActivityToTargets() throws Exception {
FlatFeed feed = client.flatFeed("flat", "bob");
Activity activity =
Activity.builder()
.actor("shmest")
.verb("test")
.object("test")
.foreignID("foreignID-1-2-3-4")
.time(new Date())
.to(Lists.newArrayList(new FeedID("flat:alice")))
.build();
Activity result = feed.addActivity(activity).join();
feed.updateActivityToTargets(
result, new FeedID[] {new FeedID("flat", "claire")}, new FeedID[] {});
List<Activity> after = feed.getActivities().join();
}
@Test
public void replaceActivityToTargets() throws Exception {
FlatFeed feed = client.flatFeed("flat", "1");
Activity activity =
Activity.builder()
.actor("test")
.verb("test")
.object("test")
.foreignID("foreignID")
.time(new Date())
.to(Lists.newArrayList(new FeedID("feed:2")))
.build();
feed.replaceActivityToTargets(activity, new FeedID("feed:3"));
}
@Test
public void feedCanNotBeInitializedWithNullSlug() throws Exception {
expectedException.expect(NullPointerException.class);
expectedException.expectMessage("Feed slug can't be null");
client.flatFeed(null, "1");
}
@Test
public void feedCanNotBeInitializedWithEmptySlug() throws Exception {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Feed slug can't be empty");
client.flatFeed("", "1");
}
@Test
public void feedCanNotBeInitializedWithNullUserId() throws Exception {
expectedException.expect(NullPointerException.class);
expectedException.expectMessage("Feed user ID can't be null");
client.flatFeed("flat", null);
}
@Test
public void feedCanNotBeInitializedWithEmptyUserId() throws Exception {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("User ID can't be empty");
client.flatFeed("flat", "");
}
}