|
7 | 7 | import io.getstream.core.models.Activity; |
8 | 8 | import io.getstream.core.models.Data; |
9 | 9 | import io.getstream.core.models.EnrichedActivity; |
| 10 | +import io.getstream.core.options.DiscardActors; |
10 | 11 | import io.getstream.core.options.EnrichmentFlags; |
| 12 | +import io.getstream.core.options.Filter; |
| 13 | +import io.getstream.core.options.Limit; |
| 14 | +import io.getstream.core.options.Offset; |
11 | 15 | import java.util.Collections; |
12 | 16 | import java.util.List; |
13 | 17 | import java8.util.concurrent.CompletionException; |
14 | 18 | import okhttp3.OkHttpClient; |
15 | 19 | import org.junit.Test; |
| 20 | +import java.util.concurrent.atomic.AtomicReference; |
16 | 21 |
|
17 | 22 | public class FlatFeedTest { |
18 | 23 | private static final String apiKey = |
@@ -101,6 +106,118 @@ public void invalidFeedType() throws Exception { |
101 | 106 | .build(); |
102 | 107 |
|
103 | 108 | FlatFeed feed = client.flatFeed("aggregated", "1"); |
104 | | - List<Activity> result = feed.getActivities().join(); |
| 109 | + feed.getActivities().join(); |
| 110 | + } |
| 111 | + |
| 112 | + |
| 113 | + @Test |
| 114 | + public void testDiscardActorsOptions() { |
| 115 | + // Test DiscardActors with array |
| 116 | + DiscardActors discardActors1 = new DiscardActors("user1", "user2", "user3"); |
| 117 | + |
| 118 | + // Test DiscardActors with List |
| 119 | + List<String> actors = java.util.Arrays.asList("user4", "user5"); |
| 120 | + DiscardActors discardActors2 = new DiscardActors(actors); |
| 121 | + |
| 122 | + // Test DiscardActors with custom separator |
| 123 | + DiscardActors discardActors3 = new DiscardActors(new String[]{"user6", "user7"}, ";"); |
| 124 | + |
| 125 | + // Test DiscardActors with List and custom separator |
| 126 | + DiscardActors discardActors4 = new DiscardActors(actors, "|"); |
| 127 | + |
| 128 | + // Basic validation that objects were created |
| 129 | + assert discardActors1 != null; |
| 130 | + assert discardActors2 != null; |
| 131 | + assert discardActors3 != null; |
| 132 | + assert discardActors4 != null; |
| 133 | + } |
| 134 | + |
| 135 | + @Test |
| 136 | + public void testGetActivitiesWithRequestOptions() throws Exception { |
| 137 | + Client client = |
| 138 | + Client.builder(apiKey, secret) |
| 139 | + .httpClient(new OKHTTPClientAdapter(new OkHttpClient())) |
| 140 | + .build(); |
| 141 | + |
| 142 | + FlatFeed feed = client.flatFeed("flat", "test-request-options"); |
| 143 | + |
| 144 | + // Test with just DiscardActors |
| 145 | + DiscardActors discardActors = new DiscardActors("actor1", "actor2", "actor3"); |
| 146 | + List<Activity> result1 = feed.getActivities(discardActors).join(); |
| 147 | + assert result1 != null; |
| 148 | + |
| 149 | + // Test with DiscardActors + Limit + Filter |
| 150 | + List<String> actors = java.util.Arrays.asList("actor4", "actor5"); |
| 151 | + DiscardActors discardActors2 = new DiscardActors(actors); |
| 152 | + Filter filter = new Filter().refresh(); |
| 153 | + List<Activity> result2 = feed.getActivities(new Limit(10), filter, discardActors2).join(); |
| 154 | + assert result2 != null; |
| 155 | + |
| 156 | + // Test with all parameters |
| 157 | + List<Activity> result3 = feed.getActivities( |
| 158 | + new Limit(20), |
| 159 | + new Offset(5), |
| 160 | + new Filter().refresh(), |
| 161 | + new DiscardActors("actor6", "actor7") |
| 162 | + ).join(); |
| 163 | + assert result3 != null; |
| 164 | + } |
| 165 | + |
| 166 | + @Test |
| 167 | + public void testGetActivitiesUrlParameters() throws Exception { |
| 168 | + // Create a mock HTTP client that captures the request URL |
| 169 | + AtomicReference<String> capturedUrl = new AtomicReference<>(); |
| 170 | + |
| 171 | + // Create a custom OkHttpClient that intercepts requests |
| 172 | + OkHttpClient mockClient = new OkHttpClient.Builder() |
| 173 | + .addInterceptor(chain -> { |
| 174 | + capturedUrl.set(chain.request().url().toString()); |
| 175 | + // Return a mock response |
| 176 | + return new okhttp3.Response.Builder() |
| 177 | + .request(chain.request()) |
| 178 | + .protocol(okhttp3.Protocol.HTTP_1_1) |
| 179 | + .code(200) |
| 180 | + .message("OK") |
| 181 | + .body(okhttp3.ResponseBody.create( |
| 182 | + okhttp3.MediaType.parse("application/json"), |
| 183 | + "{\"results\":[],\"next\":\"\",\"duration\":\"0ms\"}" |
| 184 | + )) |
| 185 | + .build(); |
| 186 | + }) |
| 187 | + .build(); |
| 188 | + |
| 189 | + Client client = Client.builder("test-key", "test-secret") |
| 190 | + .httpClient(new OKHTTPClientAdapter(mockClient)) |
| 191 | + .build(); |
| 192 | + |
| 193 | + FlatFeed feed = client.flatFeed("flat", "test-url-params"); |
| 194 | + |
| 195 | + // Test with multiple RequestOptions |
| 196 | + feed.getActivities( |
| 197 | + new Limit(20), |
| 198 | + new Offset(5), |
| 199 | + new Filter().refresh(), |
| 200 | + new DiscardActors("actor1", "actor2", "actor3") |
| 201 | + ).join(); |
| 202 | + |
| 203 | + String url = capturedUrl.get(); |
| 204 | + assert url != null; |
| 205 | + |
| 206 | + // Verify URL contains expected parameters |
| 207 | + assert url.contains("limit=20") : "URL should contain limit=20, got: " + url; |
| 208 | + assert url.contains("offset=5") : "URL should contain offset=5, got: " + url; |
| 209 | + assert url.contains("refresh=1") : "URL should contain refresh=1, got: " + url; |
| 210 | + assert url.contains("discard_actors=actor1,actor2,actor3") : "URL should contain discard_actors, got: " + url; |
| 211 | + |
| 212 | + // Test with custom separator |
| 213 | + capturedUrl.set(null); |
| 214 | + feed.getActivities( |
| 215 | + new DiscardActors(new String[]{"actor4", "actor5"}, "|") |
| 216 | + ).join(); |
| 217 | + |
| 218 | + url = capturedUrl.get(); |
| 219 | + assert url != null; |
| 220 | + assert url.contains("discard_actors=actor4%7Cactor5") : "URL should contain pipe-separated actors, got: " + url; |
| 221 | + assert url.contains("discard_actors_sep=%7C") : "URL should contain discard_actors_sep, got: " + url; |
105 | 222 | } |
106 | 223 | } |
0 commit comments