Search in sources :

Example 36 with UsingDataSet

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

the class ClusterConfigServiceImplTest method removeDoesNothingIfConfigDoesNotExist.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void removeDoesNothingIfConfigDoesNotExist() throws Exception {
    final DBCollection collection = mongoConnection.getDatabase().getCollection(COLLECTION_NAME);
    assertThat(collection.count()).isEqualTo(0L);
    assertThat(clusterConfigService.remove(CustomConfig.class)).isEqualTo(0);
}
Also used : DBCollection(com.mongodb.DBCollection) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 37 with UsingDataSet

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

the class ClusterConfigServiceImplTest method writeUpdatesExistingClusterConfig.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void writeUpdatesExistingClusterConfig() throws Exception {
    CustomConfig customConfig = new CustomConfig();
    customConfig.text = "TEST";
    DBObject seedObject = new BasicDBObjectBuilder().add("type", CustomConfig.class.getCanonicalName()).add("payload", Collections.singletonMap("text", "ORIGINAL")).add("last_updated", TIME.toString()).add("last_updated_by", "NOT ID").get();
    final DBCollection collection = mongoConnection.getDatabase().getCollection(COLLECTION_NAME);
    collection.save(seedObject);
    assertThat(collection.count()).isEqualTo(1L);
    clusterConfigService.write(customConfig);
    assertThat(collection.count()).isEqualTo(1L);
    DBObject dbObject = collection.findOne();
    assertThat((String) dbObject.get("type")).isEqualTo(CustomConfig.class.getCanonicalName());
    assertThat((String) dbObject.get("last_updated_by")).isEqualTo("ID");
    @SuppressWarnings("unchecked") Map<String, Object> payload = (Map<String, Object>) dbObject.get("payload");
    assertThat(payload).containsEntry("text", "TEST");
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DBObject(com.mongodb.DBObject) DBObject(com.mongodb.DBObject) Map(java.util.Map) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 38 with UsingDataSet

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

the class AlarmCallbackConfigurationServiceImplTest method testGetForStreamSingleDocument.

@Test
@UsingDataSet(locations = "alarmCallbackConfigurationsSingleDocument.json", loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testGetForStreamSingleDocument() throws Exception {
    final Stream stream = mock(StreamImpl.class);
    final String streamId = "5400deadbeefdeadbeefaffe";
    when(stream.getId()).thenReturn(streamId);
    final List<AlarmCallbackConfiguration> configs = alarmCallbackConfigurationService.getForStream(stream);
    final AlarmCallbackConfiguration alarmCallback = configs.get(0);
    assertNotNull("Returned list should not be null", configs);
    assertEquals("Returned list should contain a single document", 1, configs.size());
    assertNotNull("Returned Alarm Callback should not be null", alarmCallback);
}
Also used : Stream(org.graylog2.plugin.streams.Stream) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) MongoDBServiceTest(org.graylog2.database.MongoDBServiceTest) Test(org.junit.Test)

Example 39 with UsingDataSet

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

the class AlertServiceImplTest method loadRecentOfStreamsLimitsResults.

@Test
@UsingDataSet(locations = "multiple-alerts.json")
public void loadRecentOfStreamsLimitsResults() throws Exception {
    final List<Alert> alerts = alertService.loadRecentOfStreams(ImmutableList.of("5666df42bee80072613ce14d", "5666df42bee80072613ce14e", "5666df42bee80072613ce14f"), 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 40 with UsingDataSet

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

the class AlertServiceImplTest method loadRecentOfStreamQueriesByDate.

@Test
@UsingDataSet(locations = "multiple-alerts.json")
public void loadRecentOfStreamQueriesByDate() throws Exception {
    final List<Alert> alerts = alertService.loadRecentOfStream(STREAM_ID, new DateTime(0L, DateTimeZone.UTC), 300);
    assertThat(alerts.size()).isEqualTo(2);
}
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