Search in sources :

Example 51 with ValidationResult

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");
}
Also used : EventFieldSpec(org.graylog.events.fields.EventFieldSpec) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ValidationResult(org.graylog2.plugin.rest.ValidationResult) Test(org.junit.Test)

Example 52 with ValidationResult

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);
}
Also used : ValidationResult(org.graylog2.plugin.rest.ValidationResult) Test(org.junit.Test)

Example 53 with ValidationResult

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");
}
Also used : ValidationResult(org.graylog2.plugin.rest.ValidationResult) Test(org.junit.Test)

Example 54 with ValidationResult

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);
}
Also used : ValidationResult(org.graylog2.plugin.rest.ValidationResult) Test(org.junit.Test)

Example 55 with ValidationResult

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;
}
Also used : ValidationResult(org.graylog2.plugin.rest.ValidationResult)

Aggregations

ValidationResult (org.graylog2.plugin.rest.ValidationResult)43 Test (org.junit.Test)24 ApiOperation (io.swagger.annotations.ApiOperation)16 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)16 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)14 Path (javax.ws.rs.Path)12 AuditEvent (org.graylog2.audit.jersey.AuditEvent)12 POST (javax.ws.rs.POST)11 List (java.util.List)10 Subject (org.apache.shiro.subject.Subject)8 GRN (org.graylog.grn.GRN)8 User (org.graylog2.plugin.database.users.User)8 ArrayList (java.util.ArrayList)7 Produces (javax.ws.rs.Produces)7 ValidationException (org.graylog2.plugin.database.ValidationException)6 DisplayName (org.junit.jupiter.api.DisplayName)6 Test (org.junit.jupiter.api.Test)6 BasicDBObject (com.mongodb.BasicDBObject)5 Collectors (java.util.stream.Collectors)5 NotFoundException (javax.ws.rs.NotFoundException)5