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));
}
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));
}
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;
}
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;
}
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();
}
Aggregations