use of org.graylog2.indexer.indexset.IndexSetConfig in project graylog2-server by Graylog2.
the class IndexSetsResourceTest method setDefaultDoesNotDoAnythingIfIndexSetIsNotWritable.
@Test
public void setDefaultDoesNotDoAnythingIfIndexSetIsNotWritable() throws Exception {
final String readOnlyIndexSetId = "newDefaultIndexSetId";
final IndexSet readOnlyIndexSet = mock(IndexSet.class);
final IndexSetConfig readOnlyIndexSetConfig = IndexSetConfig.create(readOnlyIndexSetId, "title", "description", false, "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(readOnlyIndexSet.getConfig()).thenReturn(readOnlyIndexSetConfig);
when(indexSetService.get(readOnlyIndexSetId)).thenReturn(Optional.of(readOnlyIndexSetConfig));
expectedException.expect(ClientErrorException.class);
expectedException.expectMessage("Default index set must be writable.");
try {
indexSetsResource.setDefault(readOnlyIndexSetId);
} finally {
verifyZeroInteractions(clusterConfigService);
}
}
use of org.graylog2.indexer.indexset.IndexSetConfig 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.IndexSetConfig 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.IndexSetConfig 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.IndexSetConfig in project graylog2-server by Graylog2.
the class IndexSetsResourceTest method updateFailsWhenDefaultSetIsSetReadOnly.
@Test
public void updateFailsWhenDefaultSetIsSetReadOnly() throws Exception {
final String defaultIndexSetId = "defaultIndexSet";
final IndexSetConfig defaultIndexSetConfig = IndexSetConfig.create(defaultIndexSetId, "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.getDefault()).thenReturn(defaultIndexSetConfig);
when(indexSetService.get(defaultIndexSetId)).thenReturn(Optional.of(defaultIndexSetConfig));
final IndexSetConfig defaultIndexSetConfigSetReadOnly = defaultIndexSetConfig.toBuilder().isWritable(false).build();
expectedException.expect(ClientErrorException.class);
expectedException.expectMessage("Default index set must be writable.");
try {
indexSetsResource.update("defaultIndexSet", IndexSetUpdateRequest.fromIndexSetConfig(defaultIndexSetConfigSetReadOnly));
} finally {
verify(indexSetService, never()).save(any());
}
}
Aggregations