Search in sources :

Example 16 with ValidationResult

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

the class EventDefinitionDtoTest method testValidateWithInvalidConfig.

@Test
public void testValidateWithInvalidConfig() {
    final AggregationEventProcessorConfig configMock = mock(AggregationEventProcessorConfig.class);
    final ValidationResult mockedValidationResult = new ValidationResult();
    mockedValidationResult.addError("foo", "bar");
    when(configMock.validate()).thenReturn(mockedValidationResult);
    final EventDefinitionDto invalidEventDefinition = testSubject.toBuilder().config(configMock).build();
    final ValidationResult validationResult = invalidEventDefinition.validate();
    assertThat(validationResult.failed()).isTrue();
    assertThat(validationResult.getErrors()).containsOnlyKeys("foo");
}
Also used : AggregationEventProcessorConfig(org.graylog.events.processor.aggregation.AggregationEventProcessorConfig) ValidationResult(org.graylog2.plugin.rest.ValidationResult) Test(org.junit.Test)

Example 17 with ValidationResult

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

the class EventDefinitionDtoTest method testValidEventDefinitionWithKeySpecInFieldSpec.

@Test
public void testValidEventDefinitionWithKeySpecInFieldSpec() {
    final EventFieldSpec fieldSpecMock = mock(EventFieldSpec.class);
    final EventDefinitionDto invalidEventDefinition = testSubject.toBuilder().fieldSpec(ImmutableMap.of("foo", fieldSpecMock, "bar", fieldSpecMock)).keySpec(ImmutableList.of("foo", "bar")).build();
    final ValidationResult validationResult = invalidEventDefinition.validate();
    assertThat(validationResult.failed()).isFalse();
    assertThat(validationResult.getErrors().size()).isEqualTo(0);
}
Also used : EventFieldSpec(org.graylog.events.fields.EventFieldSpec) ValidationResult(org.graylog2.plugin.rest.ValidationResult) Test(org.junit.Test)

Example 18 with ValidationResult

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

the class EventDefinitionDtoTest method testValidateWithKeySpecNotInFieldSpec.

@Test
public void testValidateWithKeySpecNotInFieldSpec() {
    final EventFieldSpec fieldSpecMock = mock(EventFieldSpec.class);
    final EventDefinitionDto invalidEventDefinition = testSubject.toBuilder().fieldSpec(ImmutableMap.of("bar", fieldSpecMock, "baz", fieldSpecMock)).keySpec(ImmutableList.of("foo")).build();
    final ValidationResult validationResult = invalidEventDefinition.validate();
    assertThat(validationResult.failed()).isTrue();
    assertThat(validationResult.getErrors()).containsOnlyKeys("key_spec");
}
Also used : EventFieldSpec(org.graylog.events.fields.EventFieldSpec) ValidationResult(org.graylog2.plugin.rest.ValidationResult) Test(org.junit.Test)

Example 19 with ValidationResult

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

the class EventDefinitionDtoTest method testValidEventDefinition.

@Test
public void testValidEventDefinition() {
    final ValidationResult validationResult = testSubject.validate();
    assertThat(validationResult.failed()).isFalse();
    assertThat(validationResult.getErrors().size()).isEqualTo(0);
}
Also used : ValidationResult(org.graylog2.plugin.rest.ValidationResult) Test(org.junit.Test)

Example 20 with ValidationResult

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

the class AggregationEventProcessorConfigTest method testValidConfiguration.

@Test
public void testValidConfiguration() {
    final ValidationResult validationResult = getConfig().validate();
    assertThat(validationResult.failed()).isFalse();
    assertThat(validationResult.getErrors().size()).isEqualTo(0);
}
Also used : ValidationResult(org.graylog2.plugin.rest.ValidationResult) Test(org.junit.Test)

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