use of org.graylog2.plugin.rest.ValidationResult in project graylog2-server by Graylog2.
the class EventDefinitionDtoTest method testValidateWithInvalidFieldName.
@Test
public void testValidateWithInvalidFieldName() {
final EventFieldSpec fieldSpecMock = mock(EventFieldSpec.class);
final EventDefinitionDto invalidEventDefinition = testSubject.toBuilder().fieldSpec(ImmutableMap.of("foo\\bar", fieldSpecMock, "$yo&^a", fieldSpecMock)).build();
final ValidationResult validationResult = invalidEventDefinition.validate();
assertThat(validationResult.failed()).isTrue();
assertThat(validationResult.getErrors()).containsOnlyKeys("field_spec");
final List<String> fieldValidation = (List<String>) validationResult.getErrors().get("field_spec");
assertThat(fieldValidation.size()).isEqualTo(2);
assertThat(fieldValidation.get(0)).contains("foo\\bar");
assertThat(fieldValidation.get(1)).contains("$yo&^a");
}
use of org.graylog2.plugin.rest.ValidationResult in project graylog2-server by Graylog2.
the class AggregationEventProcessorConfigTest method testValidFilterConfiguration.
@Test
public void testValidFilterConfiguration() {
final AggregationEventProcessorConfig config = getConfig().toBuilder().query("foo").streams(ImmutableSet.of("1", "2")).build();
final ValidationResult validationResult = config.validate();
assertThat(validationResult.failed()).isFalse();
assertThat(validationResult.getErrors().size()).isEqualTo(0);
}
use of org.graylog2.plugin.rest.ValidationResult in project graylog2-server by Graylog2.
the class AggregationEventProcessorConfigTest method testValidateWithInvalidExecutionTime.
@Test
public void testValidateWithInvalidExecutionTime() {
final AggregationEventProcessorConfig invalidConfig1 = getConfig().toBuilder().executeEveryMs(-1).build();
final ValidationResult validationResult1 = invalidConfig1.validate();
assertThat(validationResult1.failed()).isTrue();
assertThat(validationResult1.getErrors()).containsOnlyKeys("execute_every_ms");
final AggregationEventProcessorConfig invalidConfig2 = invalidConfig1.toBuilder().executeEveryMs(0).build();
final ValidationResult validationResult2 = invalidConfig2.validate();
assertThat(validationResult2.failed()).isTrue();
assertThat(validationResult2.getErrors()).containsOnlyKeys("execute_every_ms");
}
use of org.graylog2.plugin.rest.ValidationResult in project graylog2-server by Graylog2.
the class AggregationEventProcessorConfigTest method testValidAggregationConfiguration.
@Test
public void testValidAggregationConfiguration() {
final AggregationEventProcessorConfig config = getConfig().toBuilder().groupBy(ImmutableList.of("bar")).series(ImmutableList.of(this.getSeries())).conditions(this.getConditions()).build();
final ValidationResult validationResult = config.validate();
assertThat(validationResult.failed()).isFalse();
assertThat(validationResult.getErrors().size()).isEqualTo(0);
}
use of org.graylog2.plugin.rest.ValidationResult in project graylog2-server by Graylog2.
the class AggregationEventProcessorConfig method validate.
@Override
public ValidationResult validate() {
final ValidationResult validationResult = new ValidationResult();
if (searchWithinMs() <= 0) {
validationResult.addError(FIELD_SEARCH_WITHIN_MS, "Filter & Aggregation search_within_ms must be greater than 0.");
}
if (executeEveryMs() <= 0) {
validationResult.addError(FIELD_EXECUTE_EVERY_MS, "Filter & Aggregation execute_every_ms must be greater than 0.");
}
if (!groupBy().isEmpty() && (series().isEmpty() || isConditionsEmpty())) {
validationResult.addError(FIELD_SERIES, "Aggregation with group_by must also contain series");
validationResult.addError(FIELD_CONDITIONS, "Aggregation with group_by must also contain conditions");
}
if (series().isEmpty() && !isConditionsEmpty()) {
validationResult.addError(FIELD_SERIES, "Aggregation with conditions must also contain series");
}
if (!series().isEmpty() && isConditionsEmpty()) {
validationResult.addError(FIELD_CONDITIONS, "Aggregation with series must also contain conditions");
}
return validationResult;
}
Aggregations