Search in sources :

Example 76 with ObjectId

use of org.bson.types.ObjectId in project graylog2-server by Graylog2.

the class LegacyMongoIndexRangeServiceTest method testFindAll.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testFindAll() throws Exception {
    final SortedSet<IndexRange> indexRanges = indexRangeService.findAll();
    final DateTime end0 = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC);
    final DateTime end1 = new DateTime(2015, 1, 2, 0, 0, 0, 0, DateTimeZone.UTC);
    final DateTime end2 = new DateTime(2015, 1, 3, 0, 0, 0, 0, DateTimeZone.UTC);
    final DateTime end99 = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC);
    assertThat(indexRanges).containsExactly(MongoIndexRange.create(new ObjectId("56250da2d400000000000001"), "graylog_0", EPOCH, end0, end0, 0), MongoIndexRange.create(new ObjectId("56250da2d400000000000099"), "graylog_99", EPOCH, end99, EPOCH, 0), MongoIndexRange.create(new ObjectId("56250da2d400000000000002"), "graylog_1", EPOCH, end1, end1, 1), MongoIndexRange.create(new ObjectId("56250da2d400000000000003"), "graylog_2", EPOCH, end2, end2, 2));
}
Also used : ObjectId(org.bson.types.ObjectId) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 77 with ObjectId

use of org.bson.types.ObjectId in project graylog2-server by Graylog2.

the class MongoIndexSetServiceTest method getReturnsAbsentOptionalIfIndexSetConfigDoesNotExist.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void getReturnsAbsentOptionalIfIndexSetConfigDoesNotExist() throws Exception {
    final Optional<IndexSetConfig> indexSetConfig = indexSetService.get(new ObjectId("57f3d3f0a43c2d595eb0a348"));
    assertThat(indexSetConfig).isEmpty();
}
Also used : ObjectId(org.bson.types.ObjectId) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 78 with ObjectId

use of org.bson.types.ObjectId in project graylog2-server by Graylog2.

the class MongoIndexSetServiceTest method deleteRemovesExistingIndexSetConfig.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void deleteRemovesExistingIndexSetConfig() throws Exception {
    final IndexSetDeletedSubscriber subscriber = new IndexSetDeletedSubscriber();
    clusterEventBus.registerClusterEventSubscriber(subscriber);
    final int deletedEntries = indexSetService.delete(new ObjectId("57f3d721a43c2d59cb750001"));
    assertThat(deletedEntries).isEqualTo(1);
    assertThat(indexSetService.get("57f3d721a43c2d59cb750001")).isEmpty();
    assertThat(subscriber.getEvents()).hasSize(1).containsExactly(IndexSetDeletedEvent.create("57f3d721a43c2d59cb750001"));
}
Also used : ObjectId(org.bson.types.ObjectId) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 79 with ObjectId

use of org.bson.types.ObjectId in project graylog2-server by Graylog2.

the class PersistedImplTest method testConstructorWithFieldsAndId.

@Test
public void testConstructorWithFieldsAndId() throws Exception {
    Map<String, Object> fields = Maps.newHashMap();
    ObjectId id = new ObjectId();
    Persisted persisted = new PersistedImplSUT(id, fields);
    assertNotNull(persisted);
    assertNotNull(persisted.getId());
    assertFalse(persisted.getId().isEmpty());
    assertEquals(id.toString(), persisted.getId());
}
Also used : ObjectId(org.bson.types.ObjectId) Persisted(org.graylog2.plugin.database.Persisted) Test(org.junit.Test)

Example 80 with ObjectId

use of org.bson.types.ObjectId in project graylog2-server by Graylog2.

the class PersistedImplTest method testEqualityForSameRecord.

@Test
public void testEqualityForSameRecord() throws Exception {
    Map<String, Object> fields = Maps.newHashMap();
    fields.put("foo", "bar");
    fields.put("bar", 42);
    ObjectId id = new ObjectId();
    Persisted persisted1 = new PersistedImplSUT(id, fields);
    Persisted persisted2 = new PersistedImplSUT(id, fields);
    assertEquals(persisted1, persisted2);
}
Also used : ObjectId(org.bson.types.ObjectId) Persisted(org.graylog2.plugin.database.Persisted) Test(org.junit.Test)

Aggregations

ObjectId (org.bson.types.ObjectId)249 Test (org.junit.Test)157 BasicDBObject (com.mongodb.BasicDBObject)54 Document (org.bson.Document)38 DBObject (com.mongodb.DBObject)35 ArrayList (java.util.ArrayList)28 BsonObjectId (org.bson.BsonObjectId)27 Date (java.util.Date)24 DBRef (com.mongodb.DBRef)15 List (java.util.List)15 StreamRuleMock (org.graylog2.streams.matchers.StreamRuleMock)14 Message (org.graylog2.plugin.Message)13 BasicBSONObject (org.bson.BasicBSONObject)12 Query (org.springframework.data.mongodb.core.query.Query)11 GridFSFile (com.mongodb.client.gridfs.model.GridFSFile)10 Map (java.util.Map)10 Binary (org.bson.types.Binary)10 GridFSFindIterable (com.mongodb.client.gridfs.GridFSFindIterable)8 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)7 Code (org.bson.types.Code)7