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);
}
}
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);
}
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);
}
}
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));
}
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();
}
Aggregations