Search in sources :

Example 21 with MongoDBFixtures

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

the class EventDefinitionFacadeTest method resolveNativeEntity.

@Test
@MongoDBFixtures("EventDefinitionFacadeTest.json")
public void resolveNativeEntity() {
    EntityDescriptor eventDescriptor = EntityDescriptor.create("5d4032513d2746703d1467f6", ModelTypes.EVENT_DEFINITION_V1);
    EntityDescriptor streamDescriptor = EntityDescriptor.create("5cdab2293d27467fbe9e8a72", ModelTypes.STREAM_V1);
    Set<EntityDescriptor> expectedNodes = ImmutableSet.of(eventDescriptor, streamDescriptor);
    Graph<EntityDescriptor> graph = facade.resolveNativeEntity(eventDescriptor);
    assertThat(graph).isNotNull();
    Set<EntityDescriptor> nodes = graph.nodes();
    assertThat(nodes).isEqualTo(expectedNodes);
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 22 with MongoDBFixtures

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

the class EventDefinitionFacadeTest method resolveForInstallation.

@Test
@MongoDBFixtures("EventDefinitionFacadeTest.json")
public void resolveForInstallation() {
    EntityV1 eventEntityV1 = createTestEntity();
    final NotificationEntity notificationEntity = NotificationEntity.builder().title(ValueReference.of("title")).description(ValueReference.of("description")).config(HttpEventNotificationConfigEntity.builder().url(ValueReference.of("http://url")).build()).build();
    final JsonNode data = objectMapper.convertValue(notificationEntity, JsonNode.class);
    final EntityV1 notificationV1 = EntityV1.builder().data(data).id(ModelId.of("123123")).type(ModelTypes.EVENT_DEFINITION_V1).build();
    final EntityDescriptor entityDescriptor = EntityDescriptor.create("123123", ModelTypes.NOTIFICATION_V1);
    Map<String, ValueReference> parameters = ImmutableMap.of();
    Map<EntityDescriptor, Entity> entities = ImmutableMap.of(entityDescriptor, notificationV1);
    Graph<Entity> graph = facade.resolveForInstallation(eventEntityV1, parameters, entities);
    assertThat(graph).isNotNull();
    Set<Entity> expectedNodes = ImmutableSet.of(eventEntityV1, notificationV1);
    assertThat(graph.nodes()).isEqualTo(expectedNodes);
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) EventNotificationHandlerConfigEntity(org.graylog.events.contentpack.entities.EventNotificationHandlerConfigEntity) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) HttpEventNotificationConfigEntity(org.graylog.events.contentpack.entities.HttpEventNotificationConfigEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) AggregationEventProcessorConfigEntity(org.graylog.events.contentpack.entities.AggregationEventProcessorConfigEntity) EventDefinitionEntity(org.graylog.events.contentpack.entities.EventDefinitionEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 23 with MongoDBFixtures

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

the class AggregationEventProcessorConfigTest method toJobSchedulerConfig.

@Test
@MongoDBFixtures("aggregation-processors.json")
public void toJobSchedulerConfig() {
    final EventDefinitionDto dto = dbService.get("54e3deadbeefdeadbeefaffe").orElse(null);
    assertThat(dto).isNotNull();
    assertThat(dto.config().toJobSchedulerConfig(dto, clock)).isPresent().get().satisfies(schedulerConfig -> {
        assertThat(schedulerConfig.jobDefinitionConfig()).satisfies(jobDefinitionConfig -> {
            assertThat(jobDefinitionConfig).isInstanceOf(EventProcessorExecutionJob.Config.class);
            final EventProcessorExecutionJob.Config config = (EventProcessorExecutionJob.Config) jobDefinitionConfig;
            assertThat(config.eventDefinitionId()).isEqualTo(dto.id());
            assertThat(config.processingWindowSize()).isEqualTo(300000);
            assertThat(config.processingHopSize()).isEqualTo(300000);
            assertThat(config.parameters()).isEqualTo(AggregationEventProcessorParameters.builder().timerange(AbsoluteRange.create(clock.nowUTC().minus(300000), clock.nowUTC())).build());
        });
        assertThat(schedulerConfig.schedule()).satisfies(schedule -> {
            assertThat(schedule).isInstanceOf(IntervalJobSchedule.class);
            final IntervalJobSchedule config = (IntervalJobSchedule) schedule;
            assertThat(config.interval()).isEqualTo(300000);
            assertThat(config.unit()).isEqualTo(TimeUnit.MILLISECONDS);
        });
    });
}
Also used : EventDefinitionDto(org.graylog.events.processor.EventDefinitionDto) IntervalJobSchedule(org.graylog.scheduler.schedule.IntervalJobSchedule) EventProcessorExecutionJob(org.graylog.events.processor.EventProcessorExecutionJob) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 24 with MongoDBFixtures

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

the class AlarmCallbackConfigurationServiceImplTest method testGetForStreamSingleDocument.

@Test
@MongoDBFixtures("alarmCallbackConfigurationsSingleDocument.json")
public void testGetForStreamSingleDocument() throws Exception {
    final Stream stream = mock(StreamImpl.class);
    final String streamId = "5400deadbeefdeadbeefaffe";
    when(stream.getId()).thenReturn(streamId);
    final List<AlarmCallbackConfiguration> configs = alarmCallbackConfigurationService.getForStream(stream);
    final AlarmCallbackConfiguration alarmCallback = configs.get(0);
    assertNotNull("Returned list should not be null", configs);
    assertEquals("Returned list should contain a single document", 1, configs.size());
    assertNotNull("Returned Alarm Callback should not be null", alarmCallback);
}
Also used : Stream(org.graylog2.plugin.streams.Stream) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) MongoDBServiceTest(org.graylog2.database.MongoDBServiceTest) Test(org.junit.Test)

Example 25 with MongoDBFixtures

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

the class AlertServiceImplTest method loadRecentOfStreamQueriesByDate.

@Test
@MongoDBFixtures("multiple-alerts.json")
public void loadRecentOfStreamQueriesByDate() throws Exception {
    final List<Alert> alerts = alertService.loadRecentOfStream(STREAM_ID, new DateTime(0L, DateTimeZone.UTC), 300);
    assertThat(alerts.size()).isEqualTo(2);
}
Also used : DateTime(org.joda.time.DateTime) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) MongoDBServiceTest(org.graylog2.database.MongoDBServiceTest) 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