Search in sources :

Example 81 with UsingDataSet

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

the class MongoIndexRangeServiceTest method testHandleIndexReopening.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testHandleIndexReopening() throws Exception {
    final DateTime begin = new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC);
    final DateTime end = new DateTime(2016, 1, 15, 0, 0, DateTimeZone.UTC);
    when(indices.indexRangeStatsOfIndex("graylog_3")).thenReturn(IndexRangeStats.create(begin, end));
    when(indexSetRegistry.isManagedIndex("graylog_3")).thenReturn(true);
    localEventBus.post(IndicesReopenedEvent.create(Collections.singleton("graylog_3")));
    final SortedSet<IndexRange> indexRanges = indexRangeService.find(begin, end);
    assertThat(indexRanges).hasSize(1);
    assertThat(indexRanges.first().indexName()).isEqualTo("graylog_3");
    assertThat(indexRanges.first().begin()).isEqualTo(begin);
    assertThat(indexRanges.first().end()).isEqualTo(end);
}
Also used : DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 82 with UsingDataSet

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

the class ClusterConfigServiceImplTest method listIgnoresInvalidClasses.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void listIgnoresInvalidClasses() throws Exception {
    final DBCollection collection = mongoConnection.getDatabase().getCollection(COLLECTION_NAME);
    collection.save(new BasicDBObjectBuilder().add("type", CustomConfig.class.getCanonicalName()).add("payload", Collections.singletonMap("text", "TEST")).add("last_updated", TIME.toString()).add("last_updated_by", "ID").get());
    collection.save(new BasicDBObjectBuilder().add("type", "invalid.ClassName").add("payload", Collections.emptyMap()).add("last_updated", TIME.toString()).add("last_updated_by", "ID").get());
    assertThat(collection.count()).isEqualTo(2L);
    assertThat(clusterConfigService.list()).hasSize(1).containsOnly(CustomConfig.class);
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 83 with UsingDataSet

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

the class ClusterConfigServiceImplTest method writePersistsClusterConfig.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void writePersistsClusterConfig() throws Exception {
    CustomConfig customConfig = new CustomConfig();
    customConfig.text = "TEST";
    final DBCollection collection = mongoConnection.getDatabase().getCollection(COLLECTION_NAME);
    assertThat(collection.count()).isEqualTo(0L);
    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");
}
Also used : DBCollection(com.mongodb.DBCollection) DBObject(com.mongodb.DBObject) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 84 with UsingDataSet

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

the class ClusterConfigServiceImplTest method writeIgnoresNull.

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

Example 85 with UsingDataSet

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

the class ClusterConfigServiceImplTest method prepareCollectionCreatesCollectionIfItDoesNotExist.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void prepareCollectionCreatesCollectionIfItDoesNotExist() throws Exception {
    assertThat(mongoConnection.getDatabase().collectionExists(COLLECTION_NAME)).isFalse();
    DBCollection collection = ClusterConfigServiceImpl.prepareCollection(mongoConnection);
    assertThat(collection.getName()).isEqualTo(COLLECTION_NAME);
    assertThat(collection.getIndexInfo()).hasSize(2);
    assertThat(collection.getWriteConcern()).isEqualTo(WriteConcern.JOURNALED);
}
Also used : DBCollection(com.mongodb.DBCollection) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) 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