use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class HTTPAlarmCallbackTest method callThrowsAlarmCallbackExceptionIfRemoteServerReturnsError.
@Test
public void callThrowsAlarmCallbackExceptionIfRemoteServerReturnsError() throws Exception {
server.enqueue(new MockResponse().setResponseCode(500));
server.start();
final Configuration configuration = new Configuration(ImmutableMap.of("url", server.url("/").toString()));
alarmCallback.initialize(configuration);
alarmCallback.checkConfiguration();
final Stream stream = mock(Stream.class);
final AlertCondition alertCondition = mock(AlertCondition.class);
final List<MessageSummary> messageSummaries = ImmutableList.of();
final AlertCondition.CheckResult checkResult = new AbstractAlertCondition.CheckResult(true, alertCondition, "Result Description", new DateTime(2016, 9, 6, 17, 0, DateTimeZone.UTC), messageSummaries);
expectedException.expect(AlarmCallbackException.class);
expectedException.expectMessage("Expected successful HTTP response [2xx] but got [500].");
alarmCallback.call(stream, checkResult);
final RecordedRequest request = server.takeRequest();
assertThat(request.getPath()).isEqualTo("/");
assertThat(request.getHeader("Content-Type")).isEqualTo("application/json");
assertThat(request.getBodySize()).isPositive();
}
use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class EmailAlarmCallbackTest method checkConfigurationFailsWithoutSubject.
@Test
public void checkConfigurationFailsWithoutSubject() throws Exception {
final Map<String, Object> configMap = ImmutableMap.of("sender", "graylog@example.org", "body", "foobar", "user_receivers", Collections.emptyList(), "email_receivers", Collections.emptyList());
final Configuration configuration = new Configuration(configMap);
alarmCallback.initialize(configuration);
expectedException.expect(ConfigurationException.class);
expectedException.expectMessage("Sender or subject are missing or invalid.");
alarmCallback.checkConfiguration();
}
use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class EmailAlarmCallbackTest method checkConfigurationSucceedsWithFallbackSender.
@Test
public void checkConfigurationSucceedsWithFallbackSender() throws Exception {
final Map<String, Object> configMap = ImmutableMap.of("subject", "Graylog alert", "body", "foobar", "user_receivers", Collections.emptyList(), "email_receivers", Collections.emptyList());
final Configuration configuration = new Configuration(configMap);
when(emailConfiguration.getFromEmail()).thenReturn("default@sender.org");
alarmCallback.initialize(configuration);
alarmCallback.checkConfiguration();
}
use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class UserServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
this.mongoConnection = mongoRule.getMongoConnection();
this.configuration = new Configuration();
this.userFactory = new UserImplFactory(configuration);
this.permissions = new Permissions(ImmutableSet.of(new RestPermissions()));
this.userService = new UserServiceImpl(mongoConnection, configuration, roleService, userFactory, permissionsResolver);
when(roleService.getAdminRoleObjectId()).thenReturn("deadbeef");
}
use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class ConfigurationMapConverterTest method convertValuesThrowsIllegalArgumentExceptionOnUnknwonType.
@Test
public void convertValuesThrowsIllegalArgumentExceptionOnUnknwonType() throws Exception {
thrown.expect(ValidationException.class);
thrown.expectMessage("Unknown configuration field type \"dummy\"");
final ConfigurationRequest cr = new ConfigurationRequest();
cr.addField(new DummyField());
final Map<String, Object> data = new HashMap<>();
data.put("dummy", "foo");
ConfigurationMapConverter.convertValues(data, cr);
}
Aggregations