use of org.graylog2.plugin.rest.ValidationResult in project graylog2-server by Graylog2.
the class LookupTableResource method validateAdapter.
@POST
@Path("adapters/validate")
@NoAuditEvent("Validation only")
@ApiOperation(value = "Validate the data adapter config")
@RequiresPermissions(RestPermissions.LOOKUP_TABLES_READ)
public ValidationResult validateAdapter(@Valid @ApiParam DataAdapterApi toValidate) {
final ValidationResult validation = new ValidationResult();
final Optional<DataAdapterDto> dtoOptional = dbDataAdapterService.get(toValidate.name());
if (dtoOptional.isPresent()) {
// an adapter exist with the given name, check that the IDs are the same, this might be an update
final DataAdapterDto adapterDto = dtoOptional.get();
// noinspection ConstantConditions
if (!adapterDto.id().equals(toValidate.id())) {
// an adapter exists with a different id, so the name is already in use, fail validation
validation.addError("name", "The data adapter name is already in use.");
}
}
final Optional<Multimap<String, String>> configValidations = toValidate.config().validate(lookupDataAdapterValidationContext);
configValidations.ifPresent(validation::addAll);
return validation;
}
use of org.graylog2.plugin.rest.ValidationResult in project graylog2-server by Graylog2.
the class NotificationDtoTest method testValidateHttpWithEmptyConfigParameters.
@Test
public void testValidateHttpWithEmptyConfigParameters() {
final HTTPEventNotificationConfig emptyConfig = HTTPEventNotificationConfig.Builder.create().url("").build();
final NotificationDto emptyNotification = getHttpNotification().toBuilder().config(emptyConfig).build();
final ValidationResult validationResult = emptyNotification.validate();
assertThat(validationResult.failed()).isTrue();
assertThat(validationResult.getErrors()).containsOnlyKeys("url");
}
use of org.graylog2.plugin.rest.ValidationResult in project graylog2-server by Graylog2.
the class NotificationDtoTest method testValidateWithEmptyTitle.
@Test
public void testValidateWithEmptyTitle() {
final NotificationDto invalidNotification = getHttpNotification().toBuilder().title("").build();
final ValidationResult validationResult = invalidNotification.validate();
assertThat(validationResult.failed()).isTrue();
assertThat(validationResult.getErrors()).containsOnlyKeys("title");
}
use of org.graylog2.plugin.rest.ValidationResult in project graylog2-server by Graylog2.
the class NotificationDtoTest method testValidateLegacyWithEmptyConfigParameters.
@Test
public void testValidateLegacyWithEmptyConfigParameters() {
final LegacyAlarmCallbackEventNotificationConfig emptyConfig = LegacyAlarmCallbackEventNotificationConfig.Builder.create().callbackType("").configuration(new HashMap<>()).build();
final NotificationDto emptyNotification = getLegacyNotification().toBuilder().config(emptyConfig).build();
final ValidationResult validationResult = emptyNotification.validate();
assertThat(validationResult.failed()).isTrue();
assertThat(validationResult.getErrors()).containsOnlyKeys("callback_type");
}
use of org.graylog2.plugin.rest.ValidationResult in project graylog2-server by Graylog2.
the class EventDefinitionDtoTest method testValidateWithEmptyConfigType.
@Test
public void testValidateWithEmptyConfigType() {
final EventDefinitionDto invalidEventDefinition = testSubject.toBuilder().config(new EventProcessorConfig.FallbackConfig()).build();
final ValidationResult validationResult = invalidEventDefinition.validate();
assertThat(validationResult.failed()).isTrue();
assertThat(validationResult.getErrors()).containsOnlyKeys("config");
}
Aggregations