Search in sources :

Example 81 with ObjectId

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

the class MongoIndexRangeServiceTest method findReturnsIndexRangesWithinGivenRange.

/**
     * Test the following constellation:
     * <pre>
     *                        [-        index range       -]
     * [- graylog_1 -][- graylog_2 -][- graylog_3 -][- graylog_4 -][- graylog_5 -]
     * </pre>
     */
@Test
@UsingDataSet(locations = "MongoIndexRangeServiceTest-distinct.json", loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void findReturnsIndexRangesWithinGivenRange() throws Exception {
    final DateTime begin = new DateTime(2015, 1, 2, 12, 0, DateTimeZone.UTC);
    final DateTime end = new DateTime(2015, 1, 4, 12, 0, DateTimeZone.UTC);
    final SortedSet<IndexRange> indexRanges = indexRangeService.find(begin, end);
    assertThat(indexRanges).containsExactly(MongoIndexRange.create(new ObjectId("55e0261a0cc6980000000002"), "graylog_2", new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 3, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 3, 0, 0, DateTimeZone.UTC), 42), MongoIndexRange.create(new ObjectId("55e0261a0cc6980000000003"), "graylog_3", new DateTime(2015, 1, 3, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 4, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 4, 0, 0, DateTimeZone.UTC), 42), MongoIndexRange.create(new ObjectId("55e0261a0cc6980000000004"), "graylog_4", new DateTime(2015, 1, 4, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 5, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 5, 0, 0, DateTimeZone.UTC), 42));
}
Also used : ObjectId(org.bson.types.ObjectId) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 82 with ObjectId

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

the class MongoIndexRangeServiceTest method findIgnoresLegacyIndexRanges.

@Test
@UsingDataSet(locations = "MongoIndexRangeServiceTest-LegacyIndexRanges.json", loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void findIgnoresLegacyIndexRanges() throws Exception {
    final DateTime begin = new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC);
    final DateTime end = new DateTime(2015, 2, 1, 0, 0, DateTimeZone.UTC);
    final SortedSet<IndexRange> indexRanges = indexRangeService.find(begin, end);
    assertThat(indexRanges).containsOnly(MongoIndexRange.create(new ObjectId("55e0261a0cc6980000000003"), "graylog_1", new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC), 42));
}
Also used : ObjectId(org.bson.types.ObjectId) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 83 with ObjectId

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

the class MongoDBSessionServiceImpl method loadAll.

@Override
public Collection<MongoDbSession> loadAll() {
    DBObject query = new BasicDBObject();
    List<MongoDbSession> dbSessions = Lists.newArrayList();
    final List<DBObject> sessions = query(MongoDbSession.class, query);
    for (DBObject session : sessions) {
        dbSessions.add(new MongoDbSession((ObjectId) session.get("_id"), session.toMap()));
    }
    return dbSessions;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) ObjectId(org.bson.types.ObjectId) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 84 with ObjectId

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

the class UserServiceImpl method loadAll.

@Override
public List<User> loadAll() {
    final DBObject query = new BasicDBObject();
    final List<DBObject> result = query(UserImpl.class, query);
    final List<User> users = Lists.newArrayList();
    for (DBObject dbObject : result) {
        users.add(userFactory.create((ObjectId) dbObject.get("_id"), dbObject.toMap()));
    }
    return users;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) User(org.graylog2.plugin.database.users.User) ObjectId(org.bson.types.ObjectId) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 85 with ObjectId

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

the class UserServiceImplTest method testSave.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void testSave() throws Exception {
    final User user = userService.create();
    user.setName("TEST");
    user.setFullName("TEST");
    user.setEmail("test@example.com");
    user.setTimeZone(DateTimeZone.UTC);
    user.setPassword("TEST");
    user.setPermissions(Collections.<String>emptyList());
    final String id = userService.save(user);
    final DBObject query = BasicDBObjectBuilder.start("_id", new ObjectId(id)).get();
    final DBObject dbObject = mongoConnection.getDatabase().getCollection(UserImpl.COLLECTION_NAME).findOne(query);
    assertThat(dbObject.get("username")).isEqualTo("TEST");
    assertThat(dbObject.get("full_name")).isEqualTo("TEST");
    assertThat(dbObject.get("email")).isEqualTo("test@example.com");
    assertThat(dbObject.get("timezone")).isEqualTo("UTC");
    assertThat((String) dbObject.get("password")).isNotEmpty();
}
Also used : User(org.graylog2.plugin.database.users.User) ObjectId(org.bson.types.ObjectId) DBObject(com.mongodb.DBObject) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) 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