Search in sources :

Example 76 with MongoDBFixtures

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

the class MongoIndexSetServiceTest method deleteRemovesExistingIndexSetConfig.

@Test
@MongoDBFixtures("MongoIndexSetServiceTest.json")
public void deleteRemovesExistingIndexSetConfig() throws Exception {
    final IndexSetDeletedSubscriber subscriber = new IndexSetDeletedSubscriber();
    clusterEventBus.registerClusterEventSubscriber(subscriber);
    final int deletedEntries = indexSetService.delete(new ObjectId("57f3d721a43c2d59cb750001"));
    assertThat(deletedEntries).isEqualTo(1);
    assertThat(indexSetService.get("57f3d721a43c2d59cb750001")).isEmpty();
    assertThat(subscriber.getEvents()).hasSize(1).containsExactly(IndexSetDeletedEvent.create("57f3d721a43c2d59cb750001"));
}
Also used : ObjectId(org.bson.types.ObjectId) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 77 with MongoDBFixtures

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

the class V20161215163900_MoveIndexSetDefaultConfigTest method upgrade.

@Test
@MongoDBFixtures("V20161215163900_MoveIndexSetDefaultConfigTest.json")
public void upgrade() throws Exception {
    final long count = collection.count();
    migration.upgrade();
    final MigrationCompleted migrationCompleted = clusterConfigService.get(MigrationCompleted.class);
    assertThat(collection.count()).withFailMessage("No document should be deleted by the migration!").isEqualTo(count);
    assertThat(collection.count(Filters.exists("default"))).withFailMessage("The migration should have deleted the \"default\" field from the documents!").isEqualTo(0L);
    assertThat(clusterConfigService.get(DefaultIndexSetConfig.class)).withFailMessage("The DefaultIndexSetConfig should have been written to cluster config!").isNotNull();
    assertThat(clusterConfigService.get(DefaultIndexSetConfig.class).defaultIndexSetId()).isEqualTo("57f3d721a43c2d59cb750001");
    assertThat(migrationCompleted).isNotNull();
    assertThat(migrationCompleted.indexSetIds()).containsExactlyInAnyOrder("57f3d721a43c2d59cb750001", "57f3d721a43c2d59cb750003");
}
Also used : DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) MigrationCompleted(org.graylog2.migrations.V20161215163900_MoveIndexSetDefaultConfig.MigrationCompleted) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 78 with MongoDBFixtures

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

the class MongoInputStatusServiceTest method handleDeleteEvent_WhenDeletingInputRemovesState.

@Test
@MongoDBFixtures("input-status.json")
public void handleDeleteEvent_WhenDeletingInputRemovesState() throws Exception {
    final String deletedInput = "54e3deadbeefdeadbeef0001";
    final InputDeleted inputDeletedEvent = new InputDeleted() {

        @Override
        public String id() {
            return deletedInput;
        }
    };
    // Simulate that the input has actually been deleted
    // TODO: This will change once we fix https://github.com/Graylog2/graylog2-server/issues/7812
    when(inputService.find(deletedInput)).thenThrow(new NotFoundException());
    cut.handleInputDeleted(inputDeletedEvent);
    // The record should be removed from the DB
    assertThat(cut.get(deletedInput).isPresent(), is(false));
}
Also used : NotFoundException(org.graylog2.database.NotFoundException) InputDeleted(org.graylog2.rest.models.system.inputs.responses.InputDeleted) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 79 with MongoDBFixtures

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

the class OutputServiceImplTest method loadReturnsExistingOutput.

@Test
@MongoDBFixtures("OutputServiceImplTest.json")
public void loadReturnsExistingOutput() throws NotFoundException {
    final Output output = outputService.load("54e3deadbeefdeadbeef0001");
    assertThat(output.getId()).isEqualTo("54e3deadbeefdeadbeef0001");
}
Also used : Output(org.graylog2.plugin.streams.Output) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 80 with MongoDBFixtures

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

the class OutputServiceImplTest method updatingOutputIsPersistent.

@Test
@MongoDBFixtures("single-output.json")
public void updatingOutputIsPersistent() throws Exception {
    final String outputId = "5b927d32a7c8644ed44576ed";
    final Output newOutput = outputService.update(outputId, Collections.singletonMap("title", "Some other Title"));
    assertThat(newOutput.getTitle()).isEqualTo("Some other Title");
    final Output retrievedOutput = outputService.load(outputId);
    assertThat(retrievedOutput.getTitle()).isEqualTo("Some other Title");
}
Also used : Output(org.graylog2.plugin.streams.Output) 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