ChannelRegistrationPayload implements JsonSerializable { @NonNull public ChannelRegistrationPayload minimizedPayload(@Nullable ChannelRegistrationPayload last) { if (last == null) { return this; } Builder builder = new Builder(this); builder.setApid(null); builder.setUserId(null); builder.setAccengageDeviceId(null); if (last.setTags && setTags) { if (last.tags != null && last.tags.equals(tags)) { builder.setTags(false, null); } } if (namedUserId == null || UAStringUtil.equals(last.namedUserId, namedUserId)) { if (UAStringUtil.equals(last.country, country)) { builder.setCountry(null); } if (UAStringUtil.equals(last.language, language)) { builder.setLanguage(null); } if (UAStringUtil.equals(last.timezone, timezone)) { builder.setTimezone(null); } if (last.locationSettings != null && last.locationSettings.equals(locationSettings)) { builder.setLocationSettings(null); } if (UAStringUtil.equals(last.appVersion, appVersion)) { builder.setAppVersion(null); } if (UAStringUtil.equals(last.sdkVersion, sdkVersion)) { builder.setSdkVersion(null); } if (UAStringUtil.equals(last.deviceModel, deviceModel)) { builder.setDeviceModel(null); } if (UAStringUtil.equals(last.carrier, carrier)) { builder.setCarrier(null); } if (last.apiVersion != null && last.apiVersion.equals(apiVersion)) { builder.setApiVersion(null); } } return builder.build(); } private  ChannelRegistrationPayload(Builder builder); @NonNull ChannelRegistrationPayload minimizedPayload(@Nullable ChannelRegistrationPayload last); @NonNull @Override JsonValue toJsonValue(); @NonNull @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); @NonNull
    static final String ANDROID_DEVICE_TYPE; @NonNull
    static final String AMAZON_DEVICE_TYPE; final boolean optIn; final boolean backgroundEnabled; final String deviceType; final String pushAddress; final boolean setTags; final Set<String> tags; final String userId; final String apid; final String timezone; final String language; final String country; final Boolean locationSettings; final String appVersion; final String sdkVersion; final String deviceModel; final Integer apiVersion; final String carrier; final String accengageDeviceId; final String deliveryType; final String namedUserId; }
@Test public void testMinimizedPayloadIgnoresCreationSpecificData() { payload = new ChannelRegistrationPayload.Builder() .setUserId(testUserId) .setApid(testApid) .setAccengageDeviceId(testAccengageDeviceId) .build(); ChannelRegistrationPayload newPayload = new ChannelRegistrationPayload.Builder(payload).build(); ChannelRegistrationPayload minPayload = newPayload.minimizedPayload(payload); assertNull(minPayload.apid); assertNull(minPayload.userId); assertNull(minPayload.accengageDeviceId); }
@Test public void testMinimizedPayloadIncludesOptionalFieldsIfChanged() { payload = new ChannelRegistrationPayload.Builder() .setTags(testSetTags, testTags) .setLanguage(testLanguage) .setTimezone(testTimezone) .setCountry(testCountry) .setLocationSettings(true) .setAppVersion("123") .setApiVersion(123) .setSdkVersion("1.2.3") .setDeviceModel("Device model") .setCarrier("Carrier") .build(); ChannelRegistrationPayload newPayload = new ChannelRegistrationPayload.Builder(payload) .setLanguage("newLanguage") .setTimezone("newTimezone") .setCountry("newCountry") .setTags(true, new HashSet<>(Arrays.asList("new", "tags"))) .setLocationSettings(false) .setAppVersion("234") .setApiVersion(234) .setSdkVersion("2.3.4") .setDeviceModel("Other device model") .setCarrier("Other carrier") .build(); ChannelRegistrationPayload minPayload = newPayload.minimizedPayload(payload); assertEquals(minPayload.language, "newLanguage"); assertEquals(minPayload.timezone, "newTimezone"); assertEquals(minPayload.country, "newCountry"); assertTrue(minPayload.setTags); assertEquals(minPayload.tags, new HashSet<>(Arrays.asList("new", "tags"))); assertEquals(minPayload.locationSettings, false); assertEquals(minPayload.appVersion, "234"); assertEquals((Object) minPayload.apiVersion, 234); assertEquals(minPayload.sdkVersion, "2.3.4"); assertEquals(minPayload.deviceModel, "Other device model"); assertEquals(minPayload.carrier, "Other carrier"); }
@Test public void testMinimizedPayloadIgnoresOptionalFieldsIfUnchanged() { payload = new ChannelRegistrationPayload.Builder() .setTags(testSetTags, testTags) .setLanguage(testLanguage) .setTimezone(testTimezone) .setCountry(testCountry) .setLocationSettings(true) .setAppVersion("123") .setApiVersion(123) .setSdkVersion("1.2.3") .setDeviceModel("Device model") .setCarrier("Carrier") .build(); ChannelRegistrationPayload newPayload = new ChannelRegistrationPayload.Builder(payload) .build(); ChannelRegistrationPayload minPayload = newPayload.minimizedPayload(payload); assertNull(minPayload.language); assertNull(minPayload.timezone); assertNull(minPayload.country); assertFalse(minPayload.setTags); assertNull(minPayload.tags); assertNull(minPayload.locationSettings); assertNull(minPayload.appVersion); assertNull(minPayload.sdkVersion); assertNull(minPayload.apiVersion); assertNull(minPayload.deviceModel); assertNull(minPayload.carrier); }
@Test public void testMinimizedPayloadContainsRequiredFields() { payload = new ChannelRegistrationPayload.Builder() .setOptIn(testOptIn) .setBackgroundEnabled(testBackgroundEnabled) .setDeviceType(testDeviceType) .setPushAddress(testPushAddress) .build(); ChannelRegistrationPayload newPayload = new ChannelRegistrationPayload.Builder(payload) .setOptIn(!payload.optIn) .setBackgroundEnabled(!payload.backgroundEnabled) .build(); ChannelRegistrationPayload minPayload = newPayload.minimizedPayload(payload); assertEquals(minPayload.optIn, newPayload.optIn); assertEquals(minPayload.backgroundEnabled, newPayload.backgroundEnabled); assertEquals(minPayload.deviceType, newPayload.deviceType); assertEquals(minPayload.pushAddress, newPayload.pushAddress); }
@Test public void testMinimizedPayloadWhenLastIsNull() { payload = new ChannelRegistrationPayload.Builder() .setOptIn(testOptIn) .setBackgroundEnabled(testBackgroundEnabled) .setDeviceType(testDeviceType) .setPushAddress(testPushAddress) .setTags(testSetTags, testTags) .setUserId(testUserId) .setApid(testApid) .setAccengageDeviceId(testAccengageDeviceId) .setLanguage(testLanguage) .setTimezone(testTimezone) .setCountry(testCountry) .setLocationSettings(true) .setAppVersion("123") .setApiVersion(123) .setSdkVersion("1.2.3") .setDeviceModel("Device model") .setCarrier("Carrier") .build(); ChannelRegistrationPayload minPayload = payload.minimizedPayload(null); assertEquals(payload, minPayload); }
@Test public void testMinimizedPayloadNamedUserChanges() { payload = new ChannelRegistrationPayload.Builder() .setTags(true, testTags) .setLanguage(testLanguage) .setTimezone(testTimezone) .setCountry(testCountry) .setLocationSettings(true) .setAppVersion("123") .setApiVersion(123) .setSdkVersion("1.2.3") .setDeviceModel("Device model") .setCarrier("Carrier") .setNamedUserId("named user") .setAccengageDeviceId("accengage ID") .build(); ChannelRegistrationPayload newPayload = new ChannelRegistrationPayload.Builder(payload) .setNamedUserId("different named user") .build(); ChannelRegistrationPayload minPayload = newPayload.minimizedPayload(payload); ChannelRegistrationPayload expected = new ChannelRegistrationPayload.Builder(payload) .setTags(false, null) .setAccengageDeviceId(null) .setNamedUserId("different named user") .build(); assertEquals(expected, minPayload); }
@Test public void testMinimizePayloadIfNamedUserIsNull() { payload = new ChannelRegistrationPayload.Builder() .setTags(true, testTags) .setLanguage(testLanguage) .setTimezone(testTimezone) .setCountry(testCountry) .setLocationSettings(true) .setAppVersion("123") .setApiVersion(123) .setSdkVersion("1.2.3") .setDeviceModel("Device model") .setCarrier("Carrier") .setNamedUserId("named user") .setApid("some-apid") .setUserId("some-user") .build(); ChannelRegistrationPayload newPayload = new ChannelRegistrationPayload.Builder(payload) .setNamedUserId(null) .build(); ChannelRegistrationPayload minPayload = newPayload.minimizedPayload(payload); ChannelRegistrationPayload expected = new ChannelRegistrationPayload.Builder(payload) .setTags(false, null) .setAccengageDeviceId(null) .setNamedUserId(null) .setDeviceType(null) .setLanguage(null) .setTimezone(null) .setCountry(null) .setLocationSettings(null) .setAppVersion(null) .setApiVersion(null) .setSdkVersion(null) .setDeviceModel(null) .setCarrier(null) .setUserId(null) .setApid(null) .build(); assertEquals(expected, minPayload); }