use of org.graylog2.plugin.configuration.ConfigurationRequest in project graylog2-server by Graylog2.
the class HTTPAlarmCallbackTest method getRequestedConfigurationContainsURLField.
@Test
public void getRequestedConfigurationContainsURLField() throws Exception {
final ConfigurationRequest requestedConfiguration = alarmCallback.getRequestedConfiguration();
final ConfigurationField field = requestedConfiguration.getField("url");
assertThat(field).isNotNull();
assertThat(field.getHumanName()).isEqualTo("URL");
assertThat(field.isOptional()).isEqualTo(ConfigurationField.Optional.NOT_OPTIONAL);
}
use of org.graylog2.plugin.configuration.ConfigurationRequest in project graylog2-server by Graylog2.
the class ConfigurationMapConverterTest method convertValuesThrowsIllegalArgumentExceptionOnEmptyFieldDescription.
@Test
public void convertValuesThrowsIllegalArgumentExceptionOnEmptyFieldDescription() throws Exception {
thrown.expect(ValidationException.class);
thrown.expectMessage("Unknown configuration field description for field \"string\"");
final ConfigurationRequest cr = new ConfigurationRequest();
final Map<String, Object> data = new HashMap<>();
data.put("string", "foo");
ConfigurationMapConverter.convertValues(data, cr);
}
use of org.graylog2.plugin.configuration.ConfigurationRequest in project graylog2-server by Graylog2.
the class V20161125142400_EmailAlarmCallbackMigrationTest method doMigrateMultipleQualifyingStreams.
@Test
public void doMigrateMultipleQualifyingStreams() throws Exception {
final String matchingStreamId1 = "matchingStreamId1";
final String matchingStreamId2 = "matchingStreamId2";
final Stream stream1 = mock(Stream.class);
when(stream1.getAlertReceivers()).thenReturn(Collections.emptyMap());
final Stream stream2 = mock(Stream.class);
when(stream2.getAlertReceivers()).thenReturn(ImmutableMap.of("users", ImmutableList.of("foouser"), "emails", ImmutableList.of("foo@bar.com")));
when(stream2.getId()).thenReturn(matchingStreamId1);
final Stream stream3 = mock(Stream.class);
when(stream3.getAlertReceivers()).thenReturn(ImmutableMap.of("users", ImmutableList.of("foouser2")));
when(stream3.getId()).thenReturn(matchingStreamId2);
when(this.streamService.loadAll()).thenReturn(ImmutableList.of(stream1, stream2, stream3));
final AlertCondition alertCondition1 = mock(AlertCondition.class);
final AlertCondition alertCondition2 = mock(AlertCondition.class);
when(this.streamService.getAlertConditions(eq(stream2))).thenReturn(ImmutableList.of(alertCondition1));
when(this.streamService.getAlertConditions(eq(stream3))).thenReturn(ImmutableList.of(alertCondition2));
final ConfigurationRequest configurationRequest = mock(ConfigurationRequest.class);
when(emailAlarmCallback.getRequestedConfiguration()).thenReturn(configurationRequest);
when(configurationRequest.getFields()).thenReturn(Collections.emptyMap());
final AlarmCallbackConfiguration newAlarmCallback1 = mock(AlarmCallbackConfiguration.class);
final String newAlarmCallbackId1 = "newAlarmCallbackId1";
final AlarmCallbackConfiguration newAlarmCallback2 = mock(AlarmCallbackConfiguration.class);
final String newAlarmCallbackId2 = "newAlarmCallbackId2";
when(alarmCallbackConfigurationService.create(eq(matchingStreamId1), any(CreateAlarmCallbackRequest.class), eq(localAdminId))).thenReturn(newAlarmCallback1);
when(alarmCallbackConfigurationService.create(eq(matchingStreamId2), any(CreateAlarmCallbackRequest.class), eq(localAdminId))).thenReturn(newAlarmCallback2);
when(alarmCallbackConfigurationService.save(eq(newAlarmCallback1))).thenReturn(newAlarmCallbackId1);
when(alarmCallbackConfigurationService.save(eq(newAlarmCallback2))).thenReturn(newAlarmCallbackId2);
this.emailAlarmCallbackMigrationPeriodical.upgrade();
final ArgumentCaptor<String> streamIdCaptor = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<CreateAlarmCallbackRequest> createAlarmCallbackRequestCaptor = ArgumentCaptor.forClass(CreateAlarmCallbackRequest.class);
final ArgumentCaptor<String> userIdCaptor = ArgumentCaptor.forClass(String.class);
verify(this.alarmCallbackConfigurationService, times(2)).create(streamIdCaptor.capture(), createAlarmCallbackRequestCaptor.capture(), userIdCaptor.capture());
assertThat(streamIdCaptor.getAllValues()).isNotNull().isNotEmpty().contains(matchingStreamId1).contains(matchingStreamId2);
createAlarmCallbackRequestCaptor.getAllValues().forEach(createAlarmCallbackRequest -> assertThat(createAlarmCallbackRequest.type()).isEqualTo(EmailAlarmCallback.class.getCanonicalName()));
final ArgumentCaptor<AlarmCallbackConfiguration> alarmCallbackConfigurationCaptor = ArgumentCaptor.forClass(AlarmCallbackConfiguration.class);
verify(this.alarmCallbackConfigurationService, times(2)).save(alarmCallbackConfigurationCaptor.capture());
assertThat(alarmCallbackConfigurationCaptor.getAllValues()).isNotNull().isNotEmpty().hasSize(2).contains(newAlarmCallback1).contains(newAlarmCallback2);
verifyMigrationCompletedWasPosted(ImmutableMap.of(matchingStreamId1, Optional.of(newAlarmCallbackId1), matchingStreamId2, Optional.of(newAlarmCallbackId2)));
}
use of org.graylog2.plugin.configuration.ConfigurationRequest in project graylog2-server by Graylog2.
the class V20161125142400_EmailAlarmCallbackMigrationTest method extractDefaultValuesFromEmailAlarmCallbackConfiguration.
@Test
public void extractDefaultValuesFromEmailAlarmCallbackConfiguration() throws Exception {
final ConfigurationRequest configurationRequest = mock(ConfigurationRequest.class);
when(emailAlarmCallback.getRequestedConfiguration()).thenReturn(configurationRequest);
final ConfigurationField configurationField1 = mock(ConfigurationField.class);
when(configurationField1.getDefaultValue()).thenReturn(42);
final ConfigurationField configurationField2 = mock(ConfigurationField.class);
when(configurationField2.getDefaultValue()).thenReturn("foobar");
final ConfigurationField configurationField3 = mock(ConfigurationField.class);
when(configurationField3.getDefaultValue()).thenReturn(true);
final Map<String, ConfigurationField> configurationFields = ImmutableMap.of("field1", configurationField1, "field2", configurationField2, "field3", configurationField3);
when(configurationRequest.getFields()).thenReturn(configurationFields);
final Map<String, Object> defaultConfig = this.emailAlarmCallbackMigrationPeriodical.getDefaultEmailAlarmCallbackConfig();
assertThat(defaultConfig).isNotNull().isNotEmpty().hasSize(3).isEqualTo(ImmutableMap.of("field1", 42, "field2", "foobar", "field3", true));
}
use of org.graylog2.plugin.configuration.ConfigurationRequest in project graylog2-server by Graylog2.
the class V20161125142400_EmailAlarmCallbackMigrationTest method doMigrateSingleQualifyingStream.
@Test
public void doMigrateSingleQualifyingStream() throws Exception {
final String matchingStreamId = "matchingStreamId";
final Stream stream1 = mock(Stream.class);
when(stream1.getAlertReceivers()).thenReturn(Collections.emptyMap());
final Stream stream2 = mock(Stream.class);
when(stream2.getAlertReceivers()).thenReturn(ImmutableMap.of("users", ImmutableList.of("foouser"), "emails", ImmutableList.of("foo@bar.com")));
when(stream2.getId()).thenReturn(matchingStreamId);
when(this.streamService.loadAll()).thenReturn(ImmutableList.of(stream1, stream2));
final AlertCondition alertCondition = mock(AlertCondition.class);
when(this.streamService.getAlertConditions(eq(stream2))).thenReturn(ImmutableList.of(alertCondition));
final ConfigurationRequest configurationRequest = mock(ConfigurationRequest.class);
when(emailAlarmCallback.getRequestedConfiguration()).thenReturn(configurationRequest);
when(configurationRequest.getFields()).thenReturn(Collections.emptyMap());
final AlarmCallbackConfiguration newAlarmCallback = mock(AlarmCallbackConfiguration.class);
final String newAlarmCallbackId = "newAlarmCallbackId";
when(alarmCallbackConfigurationService.create(eq(matchingStreamId), any(CreateAlarmCallbackRequest.class), eq(localAdminId))).thenReturn(newAlarmCallback);
when(alarmCallbackConfigurationService.save(eq(newAlarmCallback))).thenReturn(newAlarmCallbackId);
this.emailAlarmCallbackMigrationPeriodical.upgrade();
final ArgumentCaptor<String> streamIdCaptor = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<CreateAlarmCallbackRequest> createAlarmCallbackRequestCaptor = ArgumentCaptor.forClass(CreateAlarmCallbackRequest.class);
final ArgumentCaptor<String> userIdCaptor = ArgumentCaptor.forClass(String.class);
verify(this.alarmCallbackConfigurationService, times(1)).create(streamIdCaptor.capture(), createAlarmCallbackRequestCaptor.capture(), userIdCaptor.capture());
assertThat(streamIdCaptor.getValue()).isNotNull().isNotEmpty().isEqualTo(matchingStreamId);
final CreateAlarmCallbackRequest createAlarmCallbackRequest = createAlarmCallbackRequestCaptor.getValue();
assertThat(createAlarmCallbackRequest.type()).isEqualTo(EmailAlarmCallback.class.getCanonicalName());
final ArgumentCaptor<AlarmCallbackConfiguration> alarmCallbackConfigurationCaptor = ArgumentCaptor.forClass(AlarmCallbackConfiguration.class);
verify(this.alarmCallbackConfigurationService, times(1)).save(alarmCallbackConfigurationCaptor.capture());
assertThat(alarmCallbackConfigurationCaptor.getValue()).isEqualTo(newAlarmCallback);
verifyMigrationCompletedWasPosted(ImmutableMap.of(matchingStreamId, Optional.of(newAlarmCallbackId)));
}
Aggregations