Search in sources :

Example 1 with StringValidator

use of org.apache.sling.validation.impl.util.examplevalidators.StringValidator in project sling by apache.

the class ValidatorMapTest method testPutValidatorWithSameValidatorIdAndHigherRanking.

@Test
public void testPutValidatorWithSameValidatorIdAndHigherRanking() {
    Map<String, Object> validatorProperties = new HashMap<>();
    validatorProperties.put(Validator.PROPERTY_VALIDATOR_ID, DATE_VALIDATOR_ID);
    validatorProperties.put(Validator.PROPERTY_VALIDATOR_SEVERITY, 2);
    Mockito.doReturn(1).when(newValidatorServiceReference).compareTo(Mockito.anyObject());
    Validator<String> stringValidator = new StringValidator();
    validatorMap.put(validatorProperties, stringValidator, newValidatorServiceReference);
    Assert.assertEquals(new ValidatorMetadata(stringValidator, newValidatorServiceReference, 2), validatorMap.get(DATE_VALIDATOR_ID));
}
Also used : HashMap(java.util.HashMap) StringValidator(org.apache.sling.validation.impl.util.examplevalidators.StringValidator) ValidatorMetadata(org.apache.sling.validation.impl.ValidatorMap.ValidatorMetadata) Test(org.junit.Test)

Example 2 with StringValidator

use of org.apache.sling.validation.impl.util.examplevalidators.StringValidator in project sling by apache.

the class ValidatorTypeUtilTest method testGetValidatorTypeOfDirectImplementations.

@SuppressWarnings("unchecked")
@Test
public void testGetValidatorTypeOfDirectImplementations() {
    Assert.assertThat((Class<String>) ValidatorTypeUtil.getValidatorType(new RegexValidator()), Matchers.equalTo(String.class));
    Assert.assertThat((Class<String>) ValidatorTypeUtil.getValidatorType(new StringValidator()), Matchers.equalTo(String.class));
    Assert.assertThat((Class<Integer>) ValidatorTypeUtil.getValidatorType(new IntegerValidator()), Matchers.equalTo(Integer.class));
}
Also used : IntegerValidator(org.apache.sling.validation.impl.util.examplevalidators.IntegerValidator) RegexValidator(org.apache.sling.validation.impl.validators.RegexValidator) ExtendedStringValidator(org.apache.sling.validation.impl.util.examplevalidators.ExtendedStringValidator) DerivedStringValidator(org.apache.sling.validation.impl.util.examplevalidators.DerivedStringValidator) StringValidator(org.apache.sling.validation.impl.util.examplevalidators.StringValidator) Test(org.junit.Test)

Example 3 with StringValidator

use of org.apache.sling.validation.impl.util.examplevalidators.StringValidator in project sling by apache.

the class ValidatorMapTest method testPutValidatorWithSameValidatorIdAndLowerRanking.

@Test
public void testPutValidatorWithSameValidatorIdAndLowerRanking() {
    Map<String, Object> validatorProperties = new HashMap<>();
    validatorProperties.put(Validator.PROPERTY_VALIDATOR_ID, DATE_VALIDATOR_ID);
    validatorProperties.put(Validator.PROPERTY_VALIDATOR_SEVERITY, 2);
    Mockito.doReturn(-1).when(newValidatorServiceReference).compareTo(Mockito.anyObject());
    Validator<String> stringValidator = new StringValidator();
    validatorMap.put(validatorProperties, stringValidator, newValidatorServiceReference);
    Assert.assertEquals(new ValidatorMetadata(dateValidator, validatorServiceReference, 10), validatorMap.get(DATE_VALIDATOR_ID));
}
Also used : HashMap(java.util.HashMap) StringValidator(org.apache.sling.validation.impl.util.examplevalidators.StringValidator) ValidatorMetadata(org.apache.sling.validation.impl.ValidatorMap.ValidatorMetadata) Test(org.junit.Test)

Aggregations

StringValidator (org.apache.sling.validation.impl.util.examplevalidators.StringValidator)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 ValidatorMetadata (org.apache.sling.validation.impl.ValidatorMap.ValidatorMetadata)2 DerivedStringValidator (org.apache.sling.validation.impl.util.examplevalidators.DerivedStringValidator)1 ExtendedStringValidator (org.apache.sling.validation.impl.util.examplevalidators.ExtendedStringValidator)1 IntegerValidator (org.apache.sling.validation.impl.util.examplevalidators.IntegerValidator)1 RegexValidator (org.apache.sling.validation.impl.validators.RegexValidator)1