Search in sources :

Example 26 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.

the class AlertServiceImplTest method loadRecentOfStreamsFiltersByStream.

@Test
@MongoDBFixtures("multiple-alerts.json")
public void loadRecentOfStreamsFiltersByStream() throws Exception {
    final List<Alert> alerts = alertService.loadRecentOfStreams(ImmutableList.of("5666df42bee80072613ce14d", "5666df42bee80072613ce14f"), new DateTime(0L, DateTimeZone.UTC), 300);
    assertThat(alerts.size()).isEqualTo(2);
    assertThat(alerts.get(0).getStreamId()).isNotEqualTo(STREAM_ID);
    assertThat(alerts.get(1).getStreamId()).isNotEqualTo(STREAM_ID);
}
Also used : DateTime(org.joda.time.DateTime) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) MongoDBServiceTest(org.graylog2.database.MongoDBServiceTest) Test(org.junit.Test)

Example 27 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.

the class AlertServiceImplTest method nonIntervalAlertShouldNotRepeatNotifications.

@Test
@MongoDBFixtures("non-interval-alert.json")
public void nonIntervalAlertShouldNotRepeatNotifications() throws Exception {
    final AlertCondition alertCondition = mock(AlertCondition.class);
    when(alertCondition.shouldRepeatNotifications()).thenReturn(true);
    final Alert alert = alertService.load(ALERT_ID, STREAM_ID);
    assertThat(alertService.shouldRepeatNotifications(alertCondition, alert)).isFalse();
}
Also used : AlertCondition(org.graylog2.plugin.alarms.AlertCondition) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) MongoDBServiceTest(org.graylog2.database.MongoDBServiceTest) Test(org.junit.Test)

Example 28 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.

the class AlertServiceImplTest method loadRecentOfStreamsLimitsResults.

@Test
@MongoDBFixtures("multiple-alerts.json")
public void loadRecentOfStreamsLimitsResults() throws Exception {
    final List<Alert> alerts = alertService.loadRecentOfStreams(ImmutableList.of("5666df42bee80072613ce14d", "5666df42bee80072613ce14e", "5666df42bee80072613ce14f"), new DateTime(0L, DateTimeZone.UTC), 1);
    assertThat(alerts.size()).isEqualTo(1);
}
Also used : DateTime(org.joda.time.DateTime) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) MongoDBServiceTest(org.graylog2.database.MongoDBServiceTest) Test(org.junit.Test)

Example 29 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.

the class AlertServiceImplTest method shouldRepeatNotificationsWhenOptionIsEnabled.

@Test
@MongoDBFixtures("unresolved-alert.json")
public void shouldRepeatNotificationsWhenOptionIsEnabled() throws Exception {
    final AlertCondition alertCondition = mock(AlertCondition.class);
    when(alertCondition.shouldRepeatNotifications()).thenReturn(true);
    final Alert alert = alertService.load(ALERT_ID, STREAM_ID);
    assertThat(alertService.shouldRepeatNotifications(alertCondition, alert)).isTrue();
}
Also used : AlertCondition(org.graylog2.plugin.alarms.AlertCondition) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) MongoDBServiceTest(org.graylog2.database.MongoDBServiceTest) Test(org.junit.Test)

Example 30 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.

the class NodeServiceImplTest method testRegisterServerWithExistingNode.

@Test
@MongoDBFixtures("NodeServiceImplTest-one-node.json")
public void testRegisterServerWithExistingNode() throws Exception {
    final Node node1 = nodeService.byNodeId(nodeId);
    assertThat(node1.getNodeId()).describedAs("There should be one existing node").isEqualTo(NODE_ID);
    nodeService.registerServer(nodeId.toString(), true, TRANSPORT_URI, LOCAL_CANONICAL_HOSTNAME);
    @SuppressWarnings("deprecation") final DBCollection collection = mongodb.mongoConnection().getDatabase().getCollection("nodes");
    assertThat(collection.count()).describedAs("There should only be one node").isEqualTo(1);
    final Node node2 = nodeService.byNodeId(nodeId);
    assertThat(node2).isNotNull();
    assertThat(node2.getHostname()).isEqualTo(LOCAL_CANONICAL_HOSTNAME);
    assertThat(node2.getTransportAddress()).isEqualTo(TRANSPORT_URI.toString());
    assertThat(node2.isLeader()).isTrue();
}
Also used : DBCollection(com.mongodb.DBCollection) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)167 Test (org.junit.Test)167 Entity (org.graylog2.contentpacks.model.entities.Entity)47 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)47 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)42 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)24 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)23 DateTime (org.joda.time.DateTime)17 ObjectId (org.bson.types.ObjectId)15 EntityExcerpt (org.graylog2.contentpacks.model.entities.EntityExcerpt)15 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)15 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)11 AbstractMap (java.util.AbstractMap)10 MigrationCompleted (org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.V20191203120602_MigrateSavedSearchesToViews.MigrationCompleted)10 LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)10 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)10 MongoDBServiceTest (org.graylog2.database.MongoDBServiceTest)10 GRN (org.graylog.grn.GRN)9 PipelineEntity (org.graylog2.contentpacks.model.entities.PipelineEntity)9 Document (org.bson.Document)8