Search in sources :

Example 86 with MongoDBFixtures

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

the class MongoIndexRangeServiceTest method findIgnoresLegacyIndexRanges.

@Test
@MongoDBFixtures("MongoIndexRangeServiceTest-LegacyIndexRanges.json")
public void findIgnoresLegacyIndexRanges() throws Exception {
    when(indices.waitForRecovery("graylog_1")).thenReturn(HealthStatus.Green);
    final DateTime begin = new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC);
    final DateTime end = new DateTime(2015, 2, 1, 0, 0, DateTimeZone.UTC);
    final SortedSet<IndexRange> indexRanges = indexRangeService.find(begin, end);
    assertThat(indexRanges).containsOnly(MongoIndexRange.create(new ObjectId("55e0261a0cc6980000000003"), "graylog_1", new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC), 42));
}
Also used : ObjectId(org.bson.types.ObjectId) DateTime(org.joda.time.DateTime) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 87 with MongoDBFixtures

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

the class MongoIndexRangeServiceTest method findReturnsIndexRangesWithinGivenRange.

/**
 * Test the following constellation:
 * <pre>
 *                        [-        index range       -]
 * [- graylog_1 -][- graylog_2 -][- graylog_3 -][- graylog_4 -][- graylog_5 -]
 * </pre>
 */
@Test
@MongoDBFixtures("MongoIndexRangeServiceTest-distinct.json")
public void findReturnsIndexRangesWithinGivenRange() throws Exception {
    final DateTime begin = new DateTime(2015, 1, 2, 12, 0, DateTimeZone.UTC);
    final DateTime end = new DateTime(2015, 1, 4, 12, 0, DateTimeZone.UTC);
    final SortedSet<IndexRange> indexRanges = indexRangeService.find(begin, end);
    assertThat(indexRanges).containsExactly(MongoIndexRange.create(new ObjectId("55e0261a0cc6980000000002"), "graylog_2", new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 3, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 3, 0, 0, DateTimeZone.UTC), 42), MongoIndexRange.create(new ObjectId("55e0261a0cc6980000000003"), "graylog_3", new DateTime(2015, 1, 3, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 4, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 4, 0, 0, DateTimeZone.UTC), 42), MongoIndexRange.create(new ObjectId("55e0261a0cc6980000000004"), "graylog_4", new DateTime(2015, 1, 4, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 5, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 5, 0, 0, DateTimeZone.UTC), 42));
}
Also used : ObjectId(org.bson.types.ObjectId) DateTime(org.joda.time.DateTime) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 88 with MongoDBFixtures

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

the class UserServiceImplTest method testLoad.

@Test
@MongoDBFixtures("UserServiceImplTest.json")
public void testLoad() throws Exception {
    final User user = userService.load("user1");
    assertThat(user).isNotNull();
    assertThat(user.getName()).isEqualTo("user1");
    assertThat(user.getEmail()).isEqualTo("user1@example.com");
}
Also used : User(org.graylog2.plugin.database.users.User) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 89 with MongoDBFixtures

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

the class MongoIndexRangeServiceTest method calculateRangeReturnsIndexRange.

@Test
@MongoDBFixtures("MongoIndexRangeServiceTest.json")
public void calculateRangeReturnsIndexRange() throws Exception {
    final String index = "graylog";
    final DateTime min = new DateTime(2015, 1, 1, 1, 0, DateTimeZone.UTC);
    final DateTime max = new DateTime(2015, 1, 1, 5, 0, DateTimeZone.UTC);
    when(indices.waitForRecovery(index)).thenReturn(HealthStatus.Green);
    when(indices.indexRangeStatsOfIndex(index)).thenReturn(IndexRangeStats.create(min, max));
    final IndexRange indexRange = indexRangeService.calculateRange(index);
    assertThat(indexRange.indexName()).isEqualTo(index);
    assertThat(indexRange.begin()).isEqualTo(min);
    assertThat(indexRange.end()).isEqualTo(max);
    Assertions.assertThat(indexRange.calculatedAt()).isEqualToIgnoringHours(DateTime.now(DateTimeZone.UTC));
}
Also used : DateTime(org.joda.time.DateTime) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 90 with MongoDBFixtures

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

the class MongoIndexRangeServiceTest method getReturnsExistingIndexRange.

@Test
@MongoDBFixtures("MongoIndexRangeServiceTest.json")
public void getReturnsExistingIndexRange() throws Exception {
    IndexRange indexRange = indexRangeService.get("graylog_1");
    assertThat(indexRange.indexName()).isEqualTo("graylog_1");
    assertThat(indexRange.begin()).isEqualTo(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC));
    assertThat(indexRange.end()).isEqualTo(new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC));
    assertThat(indexRange.calculatedAt()).isEqualTo(new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC));
    assertThat(indexRange.calculationDuration()).isEqualTo(23);
}
Also used : DateTime(org.joda.time.DateTime) 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