Search in sources :

Example 21 with ValidationResult

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

the class AggregationEventProcessorConfigTest method testValidateWithIncompleteAggregationOptions.

@Test
public void testValidateWithIncompleteAggregationOptions() {
    AggregationEventProcessorConfig invalidConfig = getConfig().toBuilder().groupBy(ImmutableList.of("foo")).build();
    ValidationResult validationResult = invalidConfig.validate();
    assertThat(validationResult.failed()).isTrue();
    assertThat(validationResult.getErrors()).containsOnlyKeys("series", "conditions");
    invalidConfig = getConfig().toBuilder().series(ImmutableList.of(this.getSeries())).build();
    validationResult = invalidConfig.validate();
    assertThat(validationResult.failed()).isTrue();
    assertThat(validationResult.getErrors()).containsOnlyKeys("conditions");
    invalidConfig = getConfig().toBuilder().conditions(this.getConditions()).build();
    validationResult = invalidConfig.validate();
    assertThat(validationResult.failed()).isTrue();
    assertThat(validationResult.getErrors()).containsOnlyKeys("series");
}
Also used : ValidationResult(org.graylog2.plugin.rest.ValidationResult) Test(org.junit.Test)

Example 22 with ValidationResult

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

the class AggregationEventProcessorConfigTest method testValidateWithInvalidTimeRange.

@Test
public void testValidateWithInvalidTimeRange() {
    final AggregationEventProcessorConfig invalidConfig1 = getConfig().toBuilder().searchWithinMs(-1).build();
    final ValidationResult validationResult1 = invalidConfig1.validate();
    assertThat(validationResult1.failed()).isTrue();
    assertThat(validationResult1.getErrors()).containsOnlyKeys("search_within_ms");
    final AggregationEventProcessorConfig invalidConfig2 = invalidConfig1.toBuilder().searchWithinMs(0).build();
    final ValidationResult validationResult2 = invalidConfig2.validate();
    assertThat(validationResult2.failed()).isTrue();
    assertThat(validationResult2.getErrors()).containsOnlyKeys("search_within_ms");
}
Also used : ValidationResult(org.graylog2.plugin.rest.ValidationResult) Test(org.junit.Test)

Example 23 with ValidationResult

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

the class NotificationDtoTest method testValidLegacyNotification.

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

Example 24 with ValidationResult

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

the class NotificationDtoTest method testValidEmailNotification.

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

Example 25 with ValidationResult

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

the class NotificationDtoTest method testValidateWithEmptyConfig.

@Test
public void testValidateWithEmptyConfig() {
    final NotificationDto invalidNotification = NotificationDto.builder().title("Foo").description("").config(new EventNotificationConfig.FallbackNotificationConfig()).build();
    final ValidationResult validationResult = invalidNotification.validate();
    assertThat(validationResult.failed()).isTrue();
    assertThat(validationResult.getErrors()).containsOnlyKeys("config");
}
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