Skip to content

Commit 8271d95

Browse files
committed
Clean up
1 parent badd72f commit 8271d95

3 files changed

Lines changed: 157 additions & 200 deletions

File tree

build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import com.vanniktech.maven.publish.AndroidFusedLibrary
2-
import org.gradle.api.publish.maven.MavenPublication
3-
41
buildscript {
52
repositories {
63
google()

main/src/androidTest/java/helper/IntegrationHelper.java

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,68 @@ public static String dummySingleSegment(String segment) {
194194
return "{\"ms\":{\"k\":[{\"n\":\"" + segment + "\"}],\"cn\":null},\"ls\":{\"k\":[],\"cn\":1702507130121}}";
195195
}
196196

197+
/**
198+
* Builds a memberships response with custom segments and change number.
199+
* @param segments Array of segment names for my segments
200+
* @param msCn Change number for my segments (null if not needed)
201+
* @param largeSegments Array of segment names for large segments
202+
* @param lsCn Change number for large segments
203+
*/
204+
public static String membershipsResponse(String[] segments, Long msCn, String[] largeSegments, Long lsCn) {
205+
StringBuilder msSegments = new StringBuilder();
206+
for (int i = 0; i < segments.length; i++) {
207+
if (i > 0) msSegments.append(",");
208+
msSegments.append("{\"n\":\"").append(segments[i]).append("\"}");
209+
}
210+
211+
StringBuilder lsSegments = new StringBuilder();
212+
for (int i = 0; i < largeSegments.length; i++) {
213+
if (i > 0) lsSegments.append(",");
214+
lsSegments.append("{\"n\":\"").append(largeSegments[i]).append("\"}");
215+
}
216+
217+
return String.format("{\"ms\":{\"k\":[%s],\"cn\":%s},\"ls\":{\"k\":[%s],\"cn\":%d}}",
218+
msSegments, msCn, lsSegments, lsCn);
219+
}
220+
221+
/**
222+
* Simplified memberships response with only my segments.
223+
*/
224+
public static String membershipsResponse(String[] segments, long cn) {
225+
return membershipsResponse(segments, cn, new String[]{}, cn);
226+
}
227+
228+
/**
229+
* Builds a targeting rules changes response with a simple flag.
230+
*/
231+
public static String targetingRulesChangesWithFlag(String flagName, long till) {
232+
return String.format("{\"ff\":{\"s\":%d,\"t\":%d,\"d\":[" +
233+
"{\"trafficTypeName\":\"user\",\"name\":\"%s\",\"status\":\"ACTIVE\"," +
234+
"\"killed\":false,\"defaultTreatment\":\"off\",\"changeNumber\":%d," +
235+
"\"conditions\":[{\"conditionType\":\"ROLLOUT\",\"matcherGroup\":{\"combiner\":\"AND\"," +
236+
"\"matchers\":[{\"keySelector\":{\"trafficType\":\"user\"},\"matcherType\":\"ALL_KEYS\",\"negate\":false}]}," +
237+
"\"partitions\":[{\"treatment\":\"on\",\"size\":100}]}]}" +
238+
"]},\"rbs\":{\"s\":%d,\"t\":%d,\"d\":[]}}", till, till, flagName, till, till, till);
239+
}
240+
241+
/**
242+
* Builds a targeting rules changes response with both a flag and an RBS.
243+
*/
244+
public static String targetingRulesChangesWithFlagAndRbs(String flagName, String rbsName, long till) {
245+
return String.format("{\"ff\":{\"s\":%d,\"t\":%d,\"d\":[" +
246+
"{\"trafficTypeName\":\"user\",\"name\":\"%s\",\"status\":\"ACTIVE\"," +
247+
"\"killed\":false,\"defaultTreatment\":\"off\",\"changeNumber\":%d," +
248+
"\"conditions\":[{\"conditionType\":\"ROLLOUT\",\"matcherGroup\":{\"combiner\":\"AND\"," +
249+
"\"matchers\":[{\"keySelector\":{\"trafficType\":\"user\"},\"matcherType\":\"ALL_KEYS\",\"negate\":false}]}," +
250+
"\"partitions\":[{\"treatment\":\"on\",\"size\":100}]}]}" +
251+
"]},\"rbs\":{\"s\":%d,\"t\":%d,\"d\":[" +
252+
"{\"name\":\"%s\",\"status\":\"ACTIVE\",\"trafficTypeName\":\"user\"," +
253+
"\"excluded\":{\"keys\":[],\"segments\":[]}," +
254+
"\"conditions\":[{\"matcherGroup\":{\"combiner\":\"AND\"," +
255+
"\"matchers\":[{\"keySelector\":{\"trafficType\":\"user\"},\"matcherType\":\"ALL_KEYS\",\"negate\":false}]}}]}" +
256+
"]}}", till, till, flagName, till, till, till, rbsName);
257+
}
258+
197259
public static String dummyApiKey() {
198260
return "99049fd8653247c5ea42bc3c1ae2c6a42bc3";
199261
}
@@ -509,4 +571,46 @@ public static class ServicePath {
509571
public static final String IMPRESSIONS = "testImpressions/bulk";
510572
public static final String AUTH = "v2/auth";
511573
}
574+
575+
/**
576+
* Creates a simple split entity JSON body for database population.
577+
*/
578+
public static String splitEntityBody(String name, long changeNumber) {
579+
return String.format("{\"name\":\"%s\", \"changeNumber\": %d}", name, changeNumber);
580+
}
581+
582+
/**
583+
* Creates a segment list JSON for database population (my segments format).
584+
* @param segments Array of segment names
585+
*/
586+
public static String segmentListJson(String... segments) {
587+
StringBuilder sb = new StringBuilder("{\"k\":[");
588+
for (int i = 0; i < segments.length; i++) {
589+
if (i > 0) sb.append(",");
590+
sb.append("{\"n\":\"").append(segments[i]).append("\"}");
591+
}
592+
sb.append("],\"cn\":null}");
593+
return sb.toString();
594+
}
595+
596+
public static String membershipKeyListUpdate(java.math.BigInteger hashedKey, String segmentName, long changeNumber) {
597+
String keyListJson = "{\"a\":[" + hashedKey.toString() + "],\"r\":[]}";
598+
String encodedKeyList = Base64.encodeToString(
599+
keyListJson.getBytes(java.nio.charset.StandardCharsets.UTF_8),
600+
Base64.NO_WRAP);
601+
602+
String notificationJson = "{" +
603+
"\\\"type\\\":\\\"MEMBERSHIPS_MS_UPDATE\\\"," +
604+
"\\\"cn\\\":" + changeNumber + "," +
605+
"\\\"n\\\":[\\\"" + segmentName + "\\\"]," +
606+
"\\\"c\\\":0," +
607+
"\\\"u\\\":2," +
608+
"\\\"d\\\":\\\"" + encodedKeyList + "\\\"" +
609+
"}";
610+
611+
return "id: 1\n" +
612+
"event: message\n" +
613+
"data: {\"id\":\"m1\",\"clientId\":\"pri:test\",\"timestamp\":" + System.currentTimeMillis() +
614+
",\"encoding\":\"json\",\"channel\":\"test_channel\",\"data\":\"" + notificationJson + "\"}\n";
615+
}
512616
}

0 commit comments

Comments
 (0)