Search in sources :

Example 1 with MongoDBFixtures

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

the class V20191203120602_MigrateSavedSearchesToViewsTest method migrateSavedSearchRelativeWithIntervalField.

@Test
@MongoDBFixtures("sample_saved_search_relative_with_interval_field.json")
public void migrateSavedSearchRelativeWithIntervalField() throws Exception {
    this.migration.upgrade();
    final MigrationCompleted migrationCompleted = captureMigrationCompleted();
    assertThat(migrationCompleted.savedSearchIds()).containsExactly(new AbstractMap.SimpleEntry<>("5c7e5499f38ed7e1d8d6a613", "5de0e98900002a0017000002"));
    assertViewServiceCreatedViews(1, resourceFile("sample_saved_search_relative_with_interval_field-expected_views.json"));
    assertSearchServiceCreated(1, resourceFile("sample_saved_search_relative_with_interval_field-expected_searches.json"));
}
Also used : AbstractMap(java.util.AbstractMap) MigrationCompleted(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.V20191203120602_MigrateSavedSearchesToViews.MigrationCompleted) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 2 with MongoDBFixtures

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

the class V20191203120602_MigrateSavedSearchesToViewsTest method migrateSavedSearchWithRelativeTimerange.

@Test
@MongoDBFixtures("sample_saved_search_relative.json")
public void migrateSavedSearchWithRelativeTimerange() throws Exception {
    this.migration.upgrade();
    final MigrationCompleted migrationCompleted = captureMigrationCompleted();
    assertThat(migrationCompleted.savedSearchIds()).containsExactly(new AbstractMap.SimpleEntry<>("5c7e5499f38ed7e1d8d6a613", "5de0e98900002a0017000002"));
    assertViewServiceCreatedViews(1, resourceFile("sample_saved_search_relative-expected_views.json"));
    assertSearchServiceCreated(1, resourceFile("sample_saved_search_relative-expected_searches.json"));
}
Also used : AbstractMap(java.util.AbstractMap) MigrationCompleted(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.V20191203120602_MigrateSavedSearchesToViews.MigrationCompleted) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 3 with MongoDBFixtures

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

the class V20191203120602_MigrateSavedSearchesToViewsTest method migrateSavedSearchWithMissingFields.

@Test
@MongoDBFixtures("sample_saved_search_with_missing_fields.json")
public void migrateSavedSearchWithMissingFields() throws Exception {
    this.migration.upgrade();
    final MigrationCompleted migrationCompleted = captureMigrationCompleted();
    assertThat(migrationCompleted.savedSearchIds()).containsExactly(new AbstractMap.SimpleEntry<>("5de660b7b2d44b5813c1d7f6", "5de0e98900002a0017000002"));
    assertViewServiceCreatedViews(1, resourceFile("sample_saved_search_with_missing_fields-expected_views.json"));
    assertSearchServiceCreated(1, resourceFile("sample_saved_search_with_missing_fields-expected_searches.json"));
}
Also used : AbstractMap(java.util.AbstractMap) MigrationCompleted(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.V20191203120602_MigrateSavedSearchesToViews.MigrationCompleted) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 4 with MongoDBFixtures

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

the class V20191203120602_MigrateSavedSearchesToViewsTest method migrateSavedSearchWithoutMessageRow.

@Test
@MongoDBFixtures("sample_saved_search_without_message_row.json")
public void migrateSavedSearchWithoutMessageRow() throws Exception {
    this.migration.upgrade();
    final MigrationCompleted migrationCompleted = captureMigrationCompleted();
    assertThat(migrationCompleted.savedSearchIds()).containsExactly(new AbstractMap.SimpleEntry<>("5c7e5499f38ed7e1d8d6a613", "5de0e98900002a0017000002"));
    assertViewServiceCreatedViews(1, resourceFile("sample_saved_search_without_message_row-expected_views.json"));
    assertSearchServiceCreated(1, resourceFile("sample_saved_search_without_message_row-expected_searches.json"));
}
Also used : AbstractMap(java.util.AbstractMap) MigrationCompleted(org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.V20191203120602_MigrateSavedSearchesToViews.MigrationCompleted) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 5 with MongoDBFixtures

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

the class V20190127111728_MigrateWidgetFormatSettingsTest method testMigrationWithOneChartColorMapping.

@Test
@MongoDBFixtures("V20190127111728_MigrateWidgetFormatSettings.json")
public void testMigrationWithOneChartColorMapping() {
    final BasicDBObject dbQuery1 = new BasicDBObject();
    dbQuery1.put("_id", new ObjectId("5e2ee372b22d7970576b2eb3"));
    final MongoCollection<Document> collection = mongoDB.mongoConnection().getMongoDatabase().getCollection("views");
    migration.upgrade();
    final FindIterable<Document> views = collection.find(dbQuery1);
    final Document view1 = views.first();
    @SuppressWarnings("unchecked") final List<Document> widgets1 = (List) view1.get("state", Document.class).get("2c67cc0f-c62e-47c1-8b70-e3198925e6bc", Document.class).get("widgets");
    assertThat(widgets1.size()).isEqualTo(2);
    Set<Document> aggregationWidgets = widgets1.stream().filter(w -> w.getString("type").equals("aggregation")).collect(Collectors.toSet());
    assertThat(aggregationWidgets.size()).isEqualTo(1);
    final Document aggregationWidget = aggregationWidgets.iterator().next();
    final Document config = aggregationWidget.get("config", Document.class);
    final Document formattingSettings = config.get("formatting_settings", Document.class);
    @SuppressWarnings("unchecked") final List<Document> chartColors = (List) formattingSettings.get("chart_colors", List.class);
    assertThat(chartColors.size()).isEqualTo(1);
    final Document chartColor = chartColors.get(0);
    assertThat(chartColor.getString("field_name")).isEqualTo("count()");
    assertThat(chartColor.getString("chart_color")).isEqualTo("#e91e63");
}
Also used : Document(org.bson.Document) MongoCollection(com.mongodb.client.MongoCollection) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BasicDBObject(com.mongodb.BasicDBObject) Set(java.util.Set) Test(org.junit.Test) Collectors(java.util.stream.Collectors) List(java.util.List) Rule(org.junit.Rule) ClusterConfigService(org.graylog2.plugin.cluster.ClusterConfigService) FindIterable(com.mongodb.client.FindIterable) MongoDBInstance(org.graylog.testing.mongodb.MongoDBInstance) ObjectId(org.bson.types.ObjectId) MockitoJUnit(org.mockito.junit.MockitoJUnit) MockitoRule(org.mockito.junit.MockitoRule) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Before(org.junit.Before) BasicDBObject(com.mongodb.BasicDBObject) ObjectId(org.bson.types.ObjectId) List(java.util.List) Document(org.bson.Document) 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