use of org.bson.types.ObjectId in project graylog2-server by Graylog2.
the class StreamRouterEngineTest method testRemoveFromAllMessages.
@Test
public void testRemoveFromAllMessages() throws Exception {
final StreamMock stream = getStreamMock("test");
final StreamRuleMock rule = new StreamRuleMock(ImmutableMap.of("_id", new ObjectId(), "field", "testfield", "type", StreamRuleType.PRESENCE.toInteger(), "stream_id", stream.getId()));
stream.setRemoveMatchesFromDefaultStream(true);
stream.setStreamRules(Collections.singletonList(rule));
final StreamRouterEngine engine = newEngine(Collections.singletonList(stream));
final Message message = getMessage();
message.addStream(defaultStream);
assertThat(message.getStreams()).containsExactly(defaultStream);
// Without testfield in the message.
assertThat(engine.match(message)).isEmpty();
// With field in the message.
message.addField("testfield", "testvalue");
assertThat(engine.match(message)).containsExactly(stream);
assertThat(message.getStreams()).doesNotContain(defaultStream);
}
use of org.bson.types.ObjectId in project graylog2-server by Graylog2.
the class StreamRouterEngineTest method testContainsMatch.
@Test
public void testContainsMatch() throws Exception {
final StreamMock stream = getStreamMock("test");
final StreamRuleMock rule = new StreamRuleMock(ImmutableMap.of("_id", new ObjectId(), "field", "testfield", "value", "testvalue", "type", StreamRuleType.CONTAINS.toInteger(), "stream_id", stream.getId()));
stream.setStreamRules(Lists.newArrayList(rule));
final StreamRouterEngine engine = newEngine(Lists.newArrayList(stream));
final Message message = getMessage();
// With wrong value for field.
message.addField("testfield", "no-foobar");
assertTrue(engine.match(message).isEmpty());
// With matching value for field.
message.addField("testfield", "hello testvalue");
assertEquals(engine.match(message), Lists.newArrayList(stream));
}
use of org.bson.types.ObjectId in project graylog2-server by Graylog2.
the class StreamRouterEngineTest method testSmallerMatch.
@Test
public void testSmallerMatch() throws Exception {
final StreamMock stream = getStreamMock("test");
final StreamRuleMock rule = new StreamRuleMock(ImmutableMap.of("_id", new ObjectId(), "field", "testfield", "value", "5", "type", StreamRuleType.SMALLER.toInteger(), "stream_id", stream.getId()));
stream.setStreamRules(Lists.newArrayList(rule));
final StreamRouterEngine engine = newEngine(Lists.newArrayList(stream));
final Message message = getMessage();
// With bigger value.
message.addField("testfield", "5");
assertTrue(engine.match(message).isEmpty());
// With smaller value.
message.addField("testfield", "2");
assertEquals(engine.match(message), Lists.newArrayList(stream));
}
use of org.bson.types.ObjectId in project graylog2-server by Graylog2.
the class MatcherTest method getSampleRule.
protected StreamRule getSampleRule() {
Map<String, Object> mongoRule = Maps.newHashMap();
mongoRule.put("_id", new ObjectId());
mongoRule.put("field", "something");
return new StreamRuleMock(mongoRule);
}
use of org.bson.types.ObjectId in project gora by apache.
the class MongoStore method fromMongoString.
private Object fromMongoString(final DocumentFieldType storeType, final String docf, final BSONDecorator easybson) {
Object result;
if (storeType == DocumentFieldType.OBJECTID) {
// Try auto-conversion of BSON data to ObjectId
// It will work if data is stored as String or as ObjectId
Object bin = easybson.get(docf);
if (bin instanceof String) {
ObjectId id = new ObjectId((String) bin);
result = new Utf8(id.toString());
} else {
result = new Utf8(bin.toString());
}
} else if (storeType == DocumentFieldType.DATE) {
Object bin = easybson.get(docf);
if (bin instanceof Date) {
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.getDefault());
calendar.setTime((Date) bin);
result = new Utf8(DatatypeConverter.printDateTime(calendar));
} else {
result = new Utf8(bin.toString());
}
} else {
result = easybson.getUtf8String(docf);
}
return result;
}
Aggregations