Search in sources :

Example 46 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class AlarmCallbackConfigurationServiceImplTest method testCreate.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void testCreate() throws Exception {
    final CreateAlarmCallbackRequest request = CreateAlarmCallbackRequest.create("", "", Collections.emptyMap());
    final String streamId = "54e3deadbeefdeadbeefaffe";
    final String userId = "someuser";
    final AlarmCallbackConfiguration alarmCallbackConfiguration = this.alarmCallbackConfigurationService.create(streamId, request, userId);
    assertNotNull(alarmCallbackConfiguration);
    assertEquals(alarmCallbackConfiguration.getStreamId(), streamId);
    assertEquals("Create should not save the object", 0, alarmCallbackConfigurationService.count());
}
Also used : CreateAlarmCallbackRequest(org.graylog2.rest.models.alarmcallbacks.requests.CreateAlarmCallbackRequest) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) MongoDBServiceTest(org.graylog2.database.MongoDBServiceTest) Test(org.junit.Test)

Example 47 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class AlarmCallbackHistoryServiceImplTest method testSaveForDummyError.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
@ShouldMatchDataSet
@IgnorePropertyValue(properties = { "created_at", "_id" })
public void testSaveForDummyError() throws Exception {
    final Date createdAt = DateTime.parse("2015-07-20T09:49:02.503Z").toDate();
    final AlarmCallbackConfiguration alarmCallbackConfiguration = mockAlarmCallbackConfiguration(createdAt);
    final Alert alert = mockAlert();
    final AlertCondition alertCondition = mockAlertCondition();
    final String errorMessage = "Dummy Error Message";
    final AlarmCallbackHistory error = this.alarmCallbackHistoryService.error(alarmCallbackConfiguration, alert, alertCondition, errorMessage);
    this.alarmCallbackHistoryService.save(error);
}
Also used : AlertCondition(org.graylog2.plugin.alarms.AlertCondition) Alert(org.graylog2.alerts.Alert) Date(java.util.Date) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) MongoDBServiceTest(org.graylog2.database.MongoDBServiceTest) Test(org.junit.Test) IgnorePropertyValue(com.lordofthejars.nosqlunit.annotation.IgnorePropertyValue) ShouldMatchDataSet(com.lordofthejars.nosqlunit.annotation.ShouldMatchDataSet)

Example 48 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class AlarmCallbackHistoryServiceImplTest method testSaveForDummySuccess.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
@ShouldMatchDataSet
@IgnorePropertyValue(properties = { "created_at", "_id" })
public void testSaveForDummySuccess() throws Exception {
    final Date createdAt = DateTime.parse("2015-07-20T09:49:02.503Z").toDate();
    final AlarmCallbackConfiguration alarmCallbackConfiguration = mockAlarmCallbackConfiguration(createdAt);
    final Alert alert = mockAlert();
    final AlertCondition alertCondition = mockAlertCondition();
    final AlarmCallbackHistory success = this.alarmCallbackHistoryService.success(alarmCallbackConfiguration, alert, alertCondition);
    this.alarmCallbackHistoryService.save(success);
}
Also used : AlertCondition(org.graylog2.plugin.alarms.AlertCondition) Alert(org.graylog2.alerts.Alert) Date(java.util.Date) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) MongoDBServiceTest(org.graylog2.database.MongoDBServiceTest) Test(org.junit.Test) IgnorePropertyValue(com.lordofthejars.nosqlunit.annotation.IgnorePropertyValue) ShouldMatchDataSet(com.lordofthejars.nosqlunit.annotation.ShouldMatchDataSet)

Example 49 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class AlertServiceImplTest method loadRecentOfStreamLimitResults.

@Test
@UsingDataSet(locations = "multiple-alerts.json")
public void loadRecentOfStreamLimitResults() throws Exception {
    final List<Alert> alerts = alertService.loadRecentOfStream(STREAM_ID, new DateTime(0L, DateTimeZone.UTC), 1);
    assertThat(alerts.size()).isEqualTo(1);
}
Also used : DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) MongoDBServiceTest(org.graylog2.database.MongoDBServiceTest) Test(org.junit.Test)

Example 50 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class AlertServiceImplTest method loadRecentOfStreamsIsEmptyIfNoStreams.

@Test
@UsingDataSet(locations = "multiple-alerts.json")
public void loadRecentOfStreamsIsEmptyIfNoStreams() throws Exception {
    final List<Alert> alerts = alertService.loadRecentOfStreams(ImmutableList.of(), new DateTime(0L, DateTimeZone.UTC), 300);
    assertThat(alerts.size()).isEqualTo(0);
}
Also used : DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) MongoDBServiceTest(org.graylog2.database.MongoDBServiceTest) Test(org.junit.Test)

Aggregations

UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)94 Test (org.junit.Test)94 DateTime (org.joda.time.DateTime)40 DBCollection (com.mongodb.DBCollection)29 ZonedDateTime (java.time.ZonedDateTime)19 DBObject (com.mongodb.DBObject)15 BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)13 ObjectId (org.bson.types.ObjectId)9 MongoDBServiceTest (org.graylog2.database.MongoDBServiceTest)9 Timer (com.codahale.metrics.Timer)6 Histogram (com.codahale.metrics.Histogram)5 JsonPath (com.jayway.restassured.path.json.JsonPath)5 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)5 HistogramResult (org.graylog2.indexer.results.HistogramResult)5 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)5 List (java.util.List)4 TermsResult (org.graylog2.indexer.results.TermsResult)4 User (org.graylog2.plugin.database.users.User)4 LdapSettings (org.graylog2.shared.security.ldap.LdapSettings)4 Map (java.util.Map)3