@Test public void isvalid() { KeyConfiguration keyConfiguration = new KeyConfiguration(); KeyData keyData = new KeyData(); keyConfiguration.setKeyData(Collections.singletonList(keyData)); boolean result = validator.isValid(keyConfiguration, constraintValidatorContext); assertThat(result).isTrue(); }
@Override public boolean isValid(KeyConfiguration keyConfiguration, ConstraintValidatorContext cvc) { if (keyConfiguration == null) { return true; } List<Boolean> outcomes = Stream.of(KeyVaultType.values()) .filter(k -> { if (Optional.ofNullable(keyConfiguration.getKeyData()).isPresent()) { return keyConfiguration.getKeyData().stream() .map(KeyDataUtil::getKeyPairTypeFor) .anyMatch(keyType -> Objects.equals(k.getKeyPairType(),keyType)); } return false; }) .filter(k -> !keyConfiguration.getKeyVaultConfig(k).isPresent()) .map( k -> { cvc.disableDefaultConstraintViolation(); String messageKey = String.format( "{MatchingKeyVaultConfigsForKeyData.%s.message}", k.name().toLowerCase()); cvc.buildConstraintViolationWithTemplate(messageKey).addConstraintViolation(); return false; }) .collect(Collectors.toList()); return outcomes.isEmpty(); }
MatchingKeyVaultConfigsForKeyDataValidator implements ConstraintValidator<MatchingKeyVaultConfigsForKeyData, KeyConfiguration> { @Override public boolean isValid(KeyConfiguration keyConfiguration, ConstraintValidatorContext cvc) { if (keyConfiguration == null) { return true; } List<Boolean> outcomes = Stream.of(KeyVaultType.values()) .filter(k -> { if (Optional.ofNullable(keyConfiguration.getKeyData()).isPresent()) { return keyConfiguration.getKeyData().stream() .map(KeyDataUtil::getKeyPairTypeFor) .anyMatch(keyType -> Objects.equals(k.getKeyPairType(),keyType)); } return false; }) .filter(k -> !keyConfiguration.getKeyVaultConfig(k).isPresent()) .map( k -> { cvc.disableDefaultConstraintViolation(); String messageKey = String.format( "{MatchingKeyVaultConfigsForKeyData.%s.message}", k.name().toLowerCase()); cvc.buildConstraintViolationWithTemplate(messageKey).addConstraintViolation(); return false; }) .collect(Collectors.toList()); return outcomes.isEmpty(); } }
MatchingKeyVaultConfigsForKeyDataValidator implements ConstraintValidator<MatchingKeyVaultConfigsForKeyData, KeyConfiguration> { @Override public boolean isValid(KeyConfiguration keyConfiguration, ConstraintValidatorContext cvc) { if (keyConfiguration == null) { return true; } List<Boolean> outcomes = Stream.of(KeyVaultType.values()) .filter(k -> { if (Optional.ofNullable(keyConfiguration.getKeyData()).isPresent()) { return keyConfiguration.getKeyData().stream() .map(KeyDataUtil::getKeyPairTypeFor) .anyMatch(keyType -> Objects.equals(k.getKeyPairType(),keyType)); } return false; }) .filter(k -> !keyConfiguration.getKeyVaultConfig(k).isPresent()) .map( k -> { cvc.disableDefaultConstraintViolation(); String messageKey = String.format( "{MatchingKeyVaultConfigsForKeyData.%s.message}", k.name().toLowerCase()); cvc.buildConstraintViolationWithTemplate(messageKey).addConstraintViolation(); return false; }) .collect(Collectors.toList()); return outcomes.isEmpty(); }  }
MatchingKeyVaultConfigsForKeyDataValidator implements ConstraintValidator<MatchingKeyVaultConfigsForKeyData, KeyConfiguration> { @Override public boolean isValid(KeyConfiguration keyConfiguration, ConstraintValidatorContext cvc) { if (keyConfiguration == null) { return true; } List<Boolean> outcomes = Stream.of(KeyVaultType.values()) .filter(k -> { if (Optional.ofNullable(keyConfiguration.getKeyData()).isPresent()) { return keyConfiguration.getKeyData().stream() .map(KeyDataUtil::getKeyPairTypeFor) .anyMatch(keyType -> Objects.equals(k.getKeyPairType(),keyType)); } return false; }) .filter(k -> !keyConfiguration.getKeyVaultConfig(k).isPresent()) .map( k -> { cvc.disableDefaultConstraintViolation(); String messageKey = String.format( "{MatchingKeyVaultConfigsForKeyData.%s.message}", k.name().toLowerCase()); cvc.buildConstraintViolationWithTemplate(messageKey).addConstraintViolation(); return false; }) .collect(Collectors.toList()); return outcomes.isEmpty(); }  @Override boolean isValid(KeyConfiguration keyConfiguration, ConstraintValidatorContext cvc); }
MatchingKeyVaultConfigsForKeyDataValidator implements ConstraintValidator<MatchingKeyVaultConfigsForKeyData, KeyConfiguration> { @Override public boolean isValid(KeyConfiguration keyConfiguration, ConstraintValidatorContext cvc) { if (keyConfiguration == null) { return true; } List<Boolean> outcomes = Stream.of(KeyVaultType.values()) .filter(k -> { if (Optional.ofNullable(keyConfiguration.getKeyData()).isPresent()) { return keyConfiguration.getKeyData().stream() .map(KeyDataUtil::getKeyPairTypeFor) .anyMatch(keyType -> Objects.equals(k.getKeyPairType(),keyType)); } return false; }) .filter(k -> !keyConfiguration.getKeyVaultConfig(k).isPresent()) .map( k -> { cvc.disableDefaultConstraintViolation(); String messageKey = String.format( "{MatchingKeyVaultConfigsForKeyData.%s.message}", k.name().toLowerCase()); cvc.buildConstraintViolationWithTemplate(messageKey).addConstraintViolation(); return false; }) .collect(Collectors.toList()); return outcomes.isEmpty(); }  @Override boolean isValid(KeyConfiguration keyConfiguration, ConstraintValidatorContext cvc);  }