Search in sources :

Example 1 with DateValidator

use of org.graylog2.database.validators.DateValidator in project graylog2-server by Graylog2.

the class InputImpl method getValidations.

@Override
public Map<String, Validator> getValidations() {
    final ImmutableMap.Builder<String, Validator> validations = ImmutableMap.builder();
    //validations.put(MessageInput.FIELD_INPUT_ID, new FilledStringValidator());
    validations.put(MessageInput.FIELD_TITLE, new FilledStringValidator());
    validations.put(MessageInput.FIELD_TYPE, new FilledStringValidator());
    validations.put(MessageInput.FIELD_CONFIGURATION, new MapValidator());
    validations.put(MessageInput.FIELD_CREATOR_USER_ID, new FilledStringValidator());
    validations.put(MessageInput.FIELD_CREATED_AT, new DateValidator());
    validations.put(MessageInput.FIELD_CONTENT_PACK, new OptionalStringValidator());
    return validations.build();
}
Also used : DateValidator(org.graylog2.database.validators.DateValidator) MapValidator(org.graylog2.database.validators.MapValidator) FilledStringValidator(org.graylog2.database.validators.FilledStringValidator) OptionalStringValidator(org.graylog2.database.validators.OptionalStringValidator) ImmutableMap(com.google.common.collect.ImmutableMap) OptionalStringValidator(org.graylog2.database.validators.OptionalStringValidator) Validator(org.graylog2.plugin.database.validators.Validator) MapValidator(org.graylog2.database.validators.MapValidator) DateValidator(org.graylog2.database.validators.DateValidator) FilledStringValidator(org.graylog2.database.validators.FilledStringValidator)

Example 2 with DateValidator

use of org.graylog2.database.validators.DateValidator in project graylog2-server by Graylog2.

the class DateValidatorTest method testValidate.

@Test
public void testValidate() throws Exception {
    Validator v = new DateValidator();
    assertFalse(v.validate(null).passed());
    assertFalse(v.validate(9001).passed());
    assertFalse(v.validate("").passed());
    assertFalse(v.validate(new java.util.Date()).passed());
    // Only joda datetime.
    assertTrue(v.validate(new org.joda.time.DateTime(DateTimeZone.UTC)).passed());
    // Only accepts UTC.
    assertFalse(v.validate(new org.joda.time.DateTime(DateTimeZone.forID("+09:00"))).passed());
}
Also used : Validator(org.graylog2.plugin.database.validators.Validator) Test(org.junit.Test)

Aggregations

Validator (org.graylog2.plugin.database.validators.Validator)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 DateValidator (org.graylog2.database.validators.DateValidator)1 FilledStringValidator (org.graylog2.database.validators.FilledStringValidator)1 MapValidator (org.graylog2.database.validators.MapValidator)1 OptionalStringValidator (org.graylog2.database.validators.OptionalStringValidator)1 Test (org.junit.Test)1