Search in sources :

Example 46 with Configuration

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();
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Configuration(org.graylog2.plugin.configuration.Configuration) DummyAlertCondition(org.graylog2.alerts.types.DummyAlertCondition) AbstractAlertCondition(org.graylog2.alerts.AbstractAlertCondition) AlertCondition(org.graylog2.plugin.alarms.AlertCondition) Stream(org.graylog2.plugin.streams.Stream) MessageSummary(org.graylog2.plugin.MessageSummary) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 47 with Configuration

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();
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) EmailConfiguration(org.graylog2.configuration.EmailConfiguration) Test(org.junit.Test)

Example 48 with Configuration

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();
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) EmailConfiguration(org.graylog2.configuration.EmailConfiguration) Test(org.junit.Test)

Example 49 with Configuration

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");
}
Also used : RestPermissions(org.graylog2.shared.security.RestPermissions) Configuration(org.graylog2.Configuration) RestPermissions(org.graylog2.shared.security.RestPermissions) Permissions(org.graylog2.shared.security.Permissions) Before(org.junit.Before)

Example 50 with Configuration

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);
}
Also used : HashMap(java.util.HashMap) ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)34 Configuration (org.graylog2.plugin.configuration.Configuration)29 ApiOperation (io.swagger.annotations.ApiOperation)24 Timed (com.codahale.metrics.annotation.Timed)23 BadRequestException (javax.ws.rs.BadRequestException)19 Path (javax.ws.rs.Path)18 AuditEvent (org.graylog2.audit.jersey.AuditEvent)17 Consumes (javax.ws.rs.Consumes)13 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)13 MessageInput (org.graylog2.plugin.inputs.MessageInput)13 Stream (org.graylog2.plugin.streams.Stream)13 ApiResponses (io.swagger.annotations.ApiResponses)12 PUT (javax.ws.rs.PUT)11 ValidationException (org.graylog2.plugin.database.ValidationException)11 DateTime (org.joda.time.DateTime)11 Produces (javax.ws.rs.Produces)10 Configuration (org.graylog2.Configuration)10 POST (javax.ws.rs.POST)9 EmailConfiguration (org.graylog2.configuration.EmailConfiguration)9 URI (java.net.URI)8