RangerValidator { boolean isUnique(Long value, Set<Long> alreadySeen, String valueName, String collectionName, List<ValidationFailureDetails> failures) { return isUnique(value, null, alreadySeen, valueName, collectionName, failures); } protected  RangerValidator(ServiceStore store); protected  RangerValidator(RoleStore roleStore); void validate(Long id, Action action); void validate(String name, Action action); static String serializeFailures(List<ValidationFailureDetails> failures);  }
@Test public void test_isValid_string() { String fieldName = "value-field-Name"; String collectionName = "value-collection-Name"; Set<String> alreadySeen = new HashSet<>(); for (String value : new String[] { null, "", " " }) { Assert.assertFalse(_validator.isUnique(value, alreadySeen, fieldName, collectionName, _failures)); _utils.checkFailureForMissingValue(_failures, fieldName); } String value = "blah"; _failures.clear(); Assert.assertTrue(_validator.isUnique(value, alreadySeen, fieldName, collectionName, _failures)); Assert.assertTrue(_failures.isEmpty()); Assert.assertTrue(alreadySeen.contains(value)); _failures.clear(); Assert.assertFalse(_validator.isUnique(value, alreadySeen, fieldName, collectionName, _failures)); _utils.checkFailureForSemanticError(_failures, fieldName, value); value = "bLaH"; _failures.clear(); Assert.assertFalse(_validator.isUnique(value, alreadySeen, fieldName, collectionName, _failures)); _utils.checkFailureForSemanticError(_failures, fieldName, value); }
@Test public void test_isValid_long() { String fieldName = "field-Name"; String collectionName = "field-collection-Name"; Set<Long> alreadySeen = new HashSet<>(); Long value = null; Assert.assertFalse(_validator.isUnique(value, alreadySeen, fieldName, collectionName, _failures)); _utils.checkFailureForMissingValue(_failures, fieldName); value = 7L; _failures.clear(); Assert.assertTrue(_validator.isUnique(value, alreadySeen, fieldName, collectionName, _failures)); Assert.assertTrue(_failures.isEmpty()); Assert.assertTrue(alreadySeen.contains(value)); _failures.clear(); Assert.assertFalse(_validator.isUnique(value, alreadySeen, fieldName, collectionName, _failures)); _utils.checkFailureForSemanticError(_failures, fieldName, value.toString()); }
@Test public void test_isValid_integer() { String fieldName = "field-Name"; String collectionName = "field-collection-Name"; Set<Integer> alreadySeen = new HashSet<>(); Integer value = null; Assert.assertFalse(_validator.isUnique(value, alreadySeen, fieldName, collectionName, _failures)); _utils.checkFailureForMissingValue(_failures, fieldName); value = 49; _failures.clear(); Assert.assertTrue(_validator.isUnique(value, alreadySeen, fieldName, collectionName, _failures)); Assert.assertTrue(_failures.isEmpty()); Assert.assertTrue(alreadySeen.contains(value)); _failures.clear(); Assert.assertFalse(_validator.isUnique(value, alreadySeen, fieldName, collectionName, _failures)); _utils.checkFailureForSemanticError(_failures, fieldName, value.toString()); }