Search in sources :

Example 86 with ObjectId

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

the class StreamListFingerprintTest method makeStreamRule.

private static StreamRule makeStreamRule(int id, String field) {
    final HashMap<String, Object> fields = Maps.newHashMap();
    fields.put(StreamRuleImpl.FIELD_FIELD, field);
    return new StreamRuleImpl(new ObjectId(String.format(Locale.ENGLISH, "%024d", id)), fields);
}
Also used : ObjectId(org.bson.types.ObjectId)

Example 87 with ObjectId

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

the class StreamListFingerprintTest method makeStream.

private static Stream makeStream(int id, String title, StreamRule[] rules, Output[] outputs) {
    final HashMap<String, Object> fields = Maps.newHashMap();
    fields.put(StreamImpl.FIELD_TITLE, title);
    return new StreamImpl(new ObjectId(String.format(Locale.ENGLISH, "%024d", id)), fields, Lists.newArrayList(rules), Sets.newHashSet(outputs), null);
}
Also used : ObjectId(org.bson.types.ObjectId)

Example 88 with ObjectId

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

the class StreamRouterEngineTest method testGetFingerprint.

@Test
public void testGetFingerprint() {
    final StreamMock stream1 = getStreamMock("test");
    final StreamRuleMock rule1 = new StreamRuleMock(ImmutableMap.of("_id", new ObjectId(), "field", "testfield1", "type", StreamRuleType.PRESENCE.toInteger(), "stream_id", stream1.getId()));
    final StreamRuleMock rule2 = new StreamRuleMock(ImmutableMap.of("_id", new ObjectId(), "field", "testfield2", "value", "^test", "type", StreamRuleType.REGEX.toInteger(), "stream_id", stream1.getId()));
    stream1.setStreamRules(Lists.newArrayList(rule1, rule2));
    final StreamMock stream2 = getStreamMock("test");
    final StreamRuleMock rule3 = new StreamRuleMock(ImmutableMap.of("_id", new ObjectId(), "field", "testfield", "value", "^test", "type", StreamRuleType.REGEX.toInteger(), "stream_id", stream2.getId()));
    stream2.setStreamRules(Lists.newArrayList(rule3));
    final StreamRouterEngine engine1 = newEngine(Lists.newArrayList(stream1));
    final StreamRouterEngine engine2 = newEngine(Lists.newArrayList(stream1));
    final StreamRouterEngine engine3 = newEngine(Lists.newArrayList(stream2));
    assertEquals(engine1.getFingerprint(), engine2.getFingerprint());
    assertNotEquals(engine1.getFingerprint(), engine3.getFingerprint());
}
Also used : ObjectId(org.bson.types.ObjectId) StreamRuleMock(org.graylog2.streams.matchers.StreamRuleMock) Test(org.junit.Test)

Example 89 with ObjectId

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

the class StreamRouterEngineTest method testOrTestMatch.

@Test
public void testOrTestMatch() throws Exception {
    final StreamMock stream = getStreamMock("test", Stream.MatchingType.OR);
    final StreamRuleMock rule1 = new StreamRuleMock(ImmutableMap.of("_id", new ObjectId(), "field", "testfield1", "type", StreamRuleType.PRESENCE.toInteger(), "stream_id", stream.getId()));
    final StreamRuleMock rule2 = new StreamRuleMock(ImmutableMap.of("_id", new ObjectId(), "field", "testfield2", "value", "^test", "type", StreamRuleType.REGEX.toInteger(), "stream_id", stream.getId()));
    stream.setStreamRules(Lists.newArrayList(rule1, rule2));
    final StreamRouterEngine engine = newEngine(Lists.newArrayList(stream));
    // Without testfield1 and testfield2 in the message.
    final Message message1 = getMessage();
    final StreamRouterEngine.StreamTestMatch testMatch1 = engine.testMatch(message1).get(0);
    final Map<StreamRule, Boolean> matches1 = testMatch1.getMatches();
    assertFalse(testMatch1.isMatched());
    assertFalse(matches1.get(rule1));
    assertFalse(matches1.get(rule2));
    // With testfield1 but no-matching testfield2 in the message.
    final Message message2 = getMessage();
    message2.addField("testfield1", "testvalue");
    message2.addField("testfield2", "no-testvalue");
    final StreamRouterEngine.StreamTestMatch testMatch2 = engine.testMatch(message2).get(0);
    final Map<StreamRule, Boolean> matches2 = testMatch2.getMatches();
    assertTrue(testMatch2.isMatched());
    assertTrue(matches2.get(rule1));
    assertFalse(matches2.get(rule2));
    // With testfield1 and matching testfield2 in the message.
    final Message message3 = getMessage();
    message3.addField("testfield1", "testvalue");
    message3.addField("testfield2", "testvalue2");
    final StreamRouterEngine.StreamTestMatch testMatch3 = engine.testMatch(message3).get(0);
    final Map<StreamRule, Boolean> matches3 = testMatch3.getMatches();
    assertTrue(testMatch3.isMatched());
    assertTrue(matches3.get(rule1));
    assertTrue(matches3.get(rule2));
}
Also used : Message(org.graylog2.plugin.Message) ObjectId(org.bson.types.ObjectId) StreamRule(org.graylog2.plugin.streams.StreamRule) StreamRuleMock(org.graylog2.streams.matchers.StreamRuleMock) Test(org.junit.Test)

Example 90 with ObjectId

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

the class StreamRouterEngineTest method testPresenceMatch.

@Test
public void testPresenceMatch() 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.setStreamRules(Lists.newArrayList(rule));
    final StreamRouterEngine engine = newEngine(Lists.newArrayList(stream));
    final Message message = getMessage();
    // Without testfield in the message.
    assertTrue(engine.match(message).isEmpty());
    // With field in the message.
    message.addField("testfield", "testvalue");
    assertEquals(engine.match(message), Lists.newArrayList(stream));
}
Also used : Message(org.graylog2.plugin.Message) ObjectId(org.bson.types.ObjectId) StreamRuleMock(org.graylog2.streams.matchers.StreamRuleMock) 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