Search in sources :

Example 71 with MongoDBFixtures

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

the class OutputFacadeTest method delete.

@Test
@MongoDBFixtures("OutputFacadeTest.json")
public void delete() throws NotFoundException {
    final Output output = outputService.load("5adf239e4b900a0fdb4e5197");
    assertThat(outputService.count()).isEqualTo(1L);
    facade.delete(output);
    assertThat(outputService.count()).isEqualTo(0L);
    assertThatThrownBy(() -> outputService.load("5adf239e4b900a0fdb4e5197")).isInstanceOf(NotFoundException.class);
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) LoggingOutput(org.graylog2.outputs.LoggingOutput) Output(org.graylog2.plugin.streams.Output) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 72 with MongoDBFixtures

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

the class V20180718155800_AddContentPackIdAndRevTest method upgrade.

@Test
@MongoDBFixtures("V20180718155800_AddContentPackIdAndRevTest.json")
public void upgrade() {
    final MongoCollection<Document> collection = mongodb.mongoConnection().getMongoDatabase().getCollection(ContentPackPersistenceService.COLLECTION_NAME);
    final Bson filter = and(exists(ContentPack.FIELD_META_ID), exists(ContentPack.FIELD_META_REVISION));
    assertThat(collection.count(filter)).isEqualTo(1L);
    migration.upgrade();
    assertThat(collection.count(filter)).isEqualTo(2L);
}
Also used : Document(org.bson.Document) Bson(org.bson.conversions.Bson) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 73 with MongoDBFixtures

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

the class DashboardV1FacadeTest method viewDTOShouldHaveACorrectViewState.

@Test
@MongoDBFixtures("DashboardV1FacadeTest.json")
public void viewDTOShouldHaveACorrectViewState() {
    assertThat(viewDTO.type()).isEqualByComparingTo(ViewDTO.Type.DASHBOARD);
    assertThat(viewDTO.state()).isNotNull();
    assertThat(viewDTO.state().size()).isEqualTo(1);
    ViewStateDTO viewState = viewDTO.state().values().iterator().next();
    assertThat(viewState.widgets().size()).isEqualTo(12);
    final Set<String> widgetIds = viewState.widgets().stream().map(WidgetDTO::id).collect(Collectors.toSet());
    final Set<String> widgetPositionIds = viewState.widgetPositions().keySet();
    assertThat(widgetIds).containsAll(widgetPositionIds);
    widgetIds.forEach(widgetId -> assertThat(viewState.titles().widgetTitle(widgetId)).isPresent());
    widgetIds.forEach(widgetId -> assertThat(viewState.widgetMapping().get(widgetId)).isNotEmpty());
}
Also used : ViewStateDTO(org.graylog.plugins.views.search.views.ViewStateDTO) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 74 with MongoDBFixtures

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

the class InputFacadeTest method resolveNativeEntityGrokPattern.

@Test
@MongoDBFixtures("InputFacadeTest.json")
public void resolveNativeEntityGrokPattern() throws NotFoundException {
    final Input input = inputService.find("5ae2ebbeef27464477f0fd8b");
    EntityDescriptor entityDescriptor = EntityDescriptor.create(ModelId.of(input.getId()), ModelTypes.INPUT_V1);
    EntityDescriptor expectedDescriptor = EntityDescriptor.create(ModelId.of("1"), ModelTypes.GROK_PATTERN_V1);
    Graph<EntityDescriptor> graph = facade.resolveNativeEntity(entityDescriptor);
    assertThat(graph.nodes()).contains(expectedDescriptor);
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) RawUDPInput(org.graylog2.inputs.raw.udp.RawUDPInput) Input(org.graylog2.inputs.Input) FakeHttpMessageInput(org.graylog2.inputs.random.FakeHttpMessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 75 with MongoDBFixtures

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

the class InputFacadeTest method exportEntity.

@Test
@MongoDBFixtures("InputFacadeTest.json")
public void exportEntity() {
    final ModelId id = ModelId.of("5acc84f84b900a4ff290d9a7");
    final EntityDescriptor descriptor = EntityDescriptor.create(id, ModelTypes.INPUT_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportEntity(descriptor, entityDescriptorIds).orElseThrow(AssertionError::new);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.INPUT_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final InputEntity inputEntity = objectMapper.convertValue(entityV1.data(), InputEntity.class);
    assertThat(inputEntity.title()).isEqualTo(ValueReference.of("Local Raw UDP"));
    assertThat(inputEntity.type()).isEqualTo(ValueReference.of("org.graylog2.inputs.raw.udp.RawUDPInput"));
    assertThat(inputEntity.global()).isEqualTo(ValueReference.of(false));
    assertThat(inputEntity.configuration()).containsEntry("bind_address", ValueReference.of("127.0.0.1")).containsEntry("port", ValueReference.of(5555));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) ConverterEntity(org.graylog2.contentpacks.model.entities.ConverterEntity) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) ModelId(org.graylog2.contentpacks.model.ModelId) 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