@Test public void testValidWebPush() { final Gson gson = new Gson(); final VariantType webPushType = VariantType.WEB_PUSH; WebPushRegistration registration = new WebPushRegistration(); registration.setEndpoint("https: registration.getKeys().setAuth("authTokens"); registration.getKeys().setP256dh("devicePublicKey"); String registrationJson = Base64.getEncoder().encodeToString(gson.toJson(registration).getBytes()); assertThat(DeviceTokenValidator.isValidDeviceTokenForVariant(registrationJson, webPushType)).isTrue(); }
public static boolean isValidDeviceTokenForVariant(final String deviceToken, final VariantType type) { switch (type) { case IOS: case IOS_TOKEN: return IOS_DEVICE_TOKEN.matcher(deviceToken).matches(); case ANDROID: return ANDROID_DEVICE_TOKEN.matcher(deviceToken).matches(); case WEB_PUSH: return isWebPushRegistration(deviceToken); } return false; }
DeviceTokenValidator implements ConstraintValidator<DeviceTokenCheck, Installation> { public static boolean isValidDeviceTokenForVariant(final String deviceToken, final VariantType type) { switch (type) { case IOS: case IOS_TOKEN: return IOS_DEVICE_TOKEN.matcher(deviceToken).matches(); case ANDROID: return ANDROID_DEVICE_TOKEN.matcher(deviceToken).matches(); case WEB_PUSH: return isWebPushRegistration(deviceToken); } return false; } }
DeviceTokenValidator implements ConstraintValidator<DeviceTokenCheck, Installation> { public static boolean isValidDeviceTokenForVariant(final String deviceToken, final VariantType type) { switch (type) { case IOS: case IOS_TOKEN: return IOS_DEVICE_TOKEN.matcher(deviceToken).matches(); case ANDROID: return ANDROID_DEVICE_TOKEN.matcher(deviceToken).matches(); case WEB_PUSH: return isWebPushRegistration(deviceToken); } return false; }  }
DeviceTokenValidator implements ConstraintValidator<DeviceTokenCheck, Installation> { public static boolean isValidDeviceTokenForVariant(final String deviceToken, final VariantType type) { switch (type) { case IOS: case IOS_TOKEN: return IOS_DEVICE_TOKEN.matcher(deviceToken).matches(); case ANDROID: return ANDROID_DEVICE_TOKEN.matcher(deviceToken).matches(); case WEB_PUSH: return isWebPushRegistration(deviceToken); } return false; }  @Override void initialize(DeviceTokenCheck constraintAnnotation); @Override boolean isValid(Installation installation, ConstraintValidatorContext context); static boolean isValidDeviceTokenForVariant(final String deviceToken, final VariantType type); }
DeviceTokenValidator implements ConstraintValidator<DeviceTokenCheck, Installation> { public static boolean isValidDeviceTokenForVariant(final String deviceToken, final VariantType type) { switch (type) { case IOS: case IOS_TOKEN: return IOS_DEVICE_TOKEN.matcher(deviceToken).matches(); case ANDROID: return ANDROID_DEVICE_TOKEN.matcher(deviceToken).matches(); case WEB_PUSH: return isWebPushRegistration(deviceToken); } return false; }  @Override void initialize(DeviceTokenCheck constraintAnnotation); @Override boolean isValid(Installation installation, ConstraintValidatorContext context); static boolean isValidDeviceTokenForVariant(final String deviceToken, final VariantType type);  }