Search in sources :

Example 21 with IndexSetService

use of org.graylog2.indexer.indexset.IndexSetService in project graylog2-server by Graylog2.

the class IndexSetsResourceTest method delete0.

@Test
public void delete0() throws Exception {
    final IndexSet indexSet = mock(IndexSet.class);
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    when(indexSet.getConfig()).thenReturn(indexSetConfig);
    when(indexSetRegistry.getDefault()).thenReturn(null);
    when(indexSetRegistry.get("id")).thenReturn(Optional.of(indexSet));
    when(indexSetService.delete("id")).thenReturn(0);
    expectedException.expect(NotFoundException.class);
    expectedException.expectMessage("Couldn't delete index set with ID <id>");
    try {
        indexSetsResource.delete("id", false);
    } finally {
        verify(indexSetRegistry, times(1)).getDefault();
        verify(indexSetService, times(1)).delete("id");
        verifyNoMoreInteractions(indexSetService);
    }
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) IndexSet(org.graylog2.indexer.IndexSet) Test(org.junit.Test)

Example 22 with IndexSetService

use of org.graylog2.indexer.indexset.IndexSetService in project graylog2-server by Graylog2.

the class IndexSetsResourceTest method update.

@Test
public void update() {
    final IndexSetConfig indexSetConfig = IndexSetConfig.create("id", "new title", "description", true, "prefix", 1, 0, MessageCountRotationStrategy.class.getCanonicalName(), MessageCountRotationStrategyConfig.create(1000), NoopRetentionStrategy.class.getCanonicalName(), NoopRetentionStrategyConfig.create(1), ZonedDateTime.of(2016, 10, 10, 12, 0, 0, 0, ZoneOffset.UTC), "standard", "index-template", 1, false);
    final IndexSetConfig updatedIndexSetConfig = indexSetConfig.toBuilder().title("new title").build();
    when(indexSetService.get("id")).thenReturn(Optional.of(indexSetConfig));
    when(indexSetService.save(indexSetConfig)).thenReturn(updatedIndexSetConfig);
    final IndexSetSummary summary = indexSetsResource.update("id", IndexSetUpdateRequest.fromIndexSetConfig(indexSetConfig));
    verify(indexSetService, times(1)).get("id");
    verify(indexSetService, times(1)).save(indexSetConfig);
    verify(indexSetService, times(1)).getDefault();
    verifyNoMoreInteractions(indexSetService);
    // The real update wouldn't replace the index template nameā€¦
    final IndexSetConfig actual = summary.toIndexSetConfig().toBuilder().indexTemplateName("index-template").build();
    assertThat(actual).isEqualTo(updatedIndexSetConfig);
}
Also used : NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) MessageCountRotationStrategy(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) IndexSetSummary(org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary) Test(org.junit.Test)

Example 23 with IndexSetService

use of org.graylog2.indexer.indexset.IndexSetService in project graylog2-server by Graylog2.

the class IndexSetsResourceTest method saveDenied.

@Test
@Ignore("Currently doesn't work with @RequiresPermissions")
public void saveDenied() {
    notPermitted();
    final IndexSetConfig indexSetConfig = IndexSetConfig.create("title", "description", true, "prefix", 1, 0, MessageCountRotationStrategy.class.getCanonicalName(), MessageCountRotationStrategyConfig.create(1000), NoopRetentionStrategy.class.getCanonicalName(), NoopRetentionStrategyConfig.create(1), ZonedDateTime.of(2016, 10, 10, 12, 0, 0, 0, ZoneOffset.UTC), "standard", "index-template", 1, false);
    expectedException.expect(ForbiddenException.class);
    expectedException.expectMessage("Not authorized to access resource id <id>");
    try {
        indexSetsResource.save(IndexSetSummary.fromIndexSetConfig(indexSetConfig, false));
    } finally {
        verifyZeroInteractions(indexSetService);
    }
}
Also used : NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) MessageCountRotationStrategy(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 24 with IndexSetService

use of org.graylog2.indexer.indexset.IndexSetService in project graylog2-server by Graylog2.

the class IndexSetsResourceTest method list.

@Test
public void list() {
    final IndexSetConfig indexSetConfig = IndexSetConfig.create("id", "title", "description", true, "prefix", 1, 0, MessageCountRotationStrategy.class.getCanonicalName(), MessageCountRotationStrategyConfig.create(1000), NoopRetentionStrategy.class.getCanonicalName(), NoopRetentionStrategyConfig.create(1), ZonedDateTime.of(2016, 10, 10, 12, 0, 0, 0, ZoneOffset.UTC), "standard", "index-template", 1, false);
    when(indexSetService.findAll()).thenReturn(Collections.singletonList(indexSetConfig));
    final IndexSetResponse list = indexSetsResource.list(0, 0, false);
    verify(indexSetService, times(1)).findAll();
    verify(indexSetService, times(1)).getDefault();
    verifyNoMoreInteractions(indexSetService);
    assertThat(list.total()).isEqualTo(1);
    assertThat(list.indexSets()).containsExactly(IndexSetSummary.fromIndexSetConfig(indexSetConfig, false));
}
Also used : NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) MessageCountRotationStrategy(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) IndexSetResponse(org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse) Test(org.junit.Test)

Example 25 with IndexSetService

use of org.graylog2.indexer.indexset.IndexSetService in project graylog2-server by Graylog2.

the class IndexSetsResourceTest method list0.

@Test
public void list0() {
    when(indexSetService.findAll()).thenReturn(Collections.emptyList());
    final IndexSetResponse list = indexSetsResource.list(0, 0, false);
    verify(indexSetService, times(1)).findAll();
    verify(indexSetService, times(1)).getDefault();
    verifyNoMoreInteractions(indexSetService);
    assertThat(list.total()).isEqualTo(0);
    assertThat(list.indexSets()).isEmpty();
}
Also used : IndexSetResponse(org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)25 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)24 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)12 NoopRetentionStrategy (org.graylog2.indexer.retention.strategies.NoopRetentionStrategy)8 MessageCountRotationStrategy (org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy)8 RetentionStrategyConfig (org.graylog2.plugin.indexer.retention.RetentionStrategyConfig)6 RotationStrategyConfig (org.graylog2.plugin.indexer.rotation.RotationStrategyConfig)6 DeletionRetentionStrategyConfig (org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig)5 MessageCountRotationStrategyConfig (org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig)5 IndexSet (org.graylog2.indexer.IndexSet)3 IndexSetResponse (org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse)3 IndexSetSummary (org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary)3 IndexSetCreatedEvent (org.graylog2.indexer.indexset.events.IndexSetCreatedEvent)2 IndexSetCleanupJob (org.graylog2.indexer.indices.jobs.IndexSetCleanupJob)2 ClusterConfigServiceImpl (org.graylog2.cluster.ClusterConfigServiceImpl)1 ClusterEventBus (org.graylog2.events.ClusterEventBus)1 IndexSetDeletedEvent (org.graylog2.indexer.indexset.events.IndexSetDeletedEvent)1 ChainingClassLoader (org.graylog2.shared.plugins.ChainingClassLoader)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1