use of org.graylog.plugins.pipelineprocessor.db.RuleDao in project graylog2-server by Graylog2.
the class InMemoryRuleServiceTest method storeRetrieve.
@Test
public void storeRetrieve() {
RuleDao rule = RuleDao.create(null, "test", "description", "rule \"test\" when true then end", null, null);
final RuleDao savedRule = service.save(rule);
// saving should create a copy with an id
assertThat(savedRule).isNotEqualTo(rule);
assertThat(savedRule.id()).isNotNull();
RuleDao loaded;
try {
loaded = service.load(savedRule.id());
} catch (NotFoundException e) {
fail("The rule should be found");
loaded = null;
}
assertThat(loaded).isNotNull();
assertThat(loaded).isEqualTo(savedRule);
service.delete(loaded.id());
try {
service.load(loaded.id());
fail("Deleted rules should not be found anymore");
} catch (NotFoundException ignored) {
}
}
use of org.graylog.plugins.pipelineprocessor.db.RuleDao in project graylog2-server by Graylog2.
the class InMemoryRuleServiceTest method uniqueTitles.
@Test
public void uniqueTitles() {
RuleDao rule = RuleDao.create(null, "test", "description", "rule \"test\" when true then end", null, null);
RuleDao rule2 = RuleDao.create(null, "test", "some other description", "rule \"test\" when false then end", null, null);
final RuleDao saved = service.save(rule);
try {
service.save(rule2);
fail("Titles must be unique for two different rules");
} catch (IllegalArgumentException ignored) {
}
try {
service.save(saved.toBuilder().createdAt(DateTime.now(DateTimeZone.UTC)).build());
} catch (IllegalArgumentException e) {
fail("Updating an existing rule should be possible");
}
service.delete(saved.id());
try {
service.save(rule);
} catch (IllegalArgumentException e) {
fail("Removing a rule should clean up the title index.");
}
}
use of org.graylog.plugins.pipelineprocessor.db.RuleDao in project graylog2-server by Graylog2.
the class InMemoryRuleServiceTest method loadMultiple.
@Test
public void loadMultiple() {
RuleDao rule1 = service.save(RuleDao.create(null, "test1", "description", "rule \"test1\" when true then end", null, null));
RuleDao rule2 = service.save(RuleDao.create(null, "test2", "description", "rule \"test2\" when true then end", null, null));
RuleDao rule3 = service.save(RuleDao.create(null, "test3", "description", "rule \"test3\" when true then end", null, null));
RuleDao rule4 = service.save(RuleDao.create(null, "test4", "description", "rule \"test4\" when true then end", null, null));
assertThat(service.loadAll()).containsExactlyInAnyOrder(rule1, rule2, rule3, rule4);
assertThat(service.loadNamed(ImmutableList.of("test3", "test2"))).containsExactlyInAnyOrder(rule2, rule3);
}
use of org.graylog.plugins.pipelineprocessor.db.RuleDao in project graylog2-server by Graylog2.
the class InMemoryRuleServiceTest method loadByName.
@Test
public void loadByName() throws NotFoundException {
RuleDao rule = RuleDao.create(null, "test", "description", "rule \"test\" when true then end", null, null);
final RuleDao savedRule = service.save(rule);
final RuleDao loadedRule = service.loadByName(savedRule.title());
assertThat(loadedRule).isEqualTo(savedRule);
}
use of org.graylog.plugins.pipelineprocessor.db.RuleDao in project graylog2-server by Graylog2.
the class PipelineRuleFacadeTest method createExcerpt.
@Test
public void createExcerpt() {
final RuleDao pipelineRule = RuleDao.builder().id("id").title("title").description("description").source("rule \"debug\"\nwhen\n true\nthen\n debug($message.message);\nend").build();
final EntityExcerpt excerpt = facade.createExcerpt(pipelineRule);
assertThat(excerpt.id()).isEqualTo(ModelId.of("id"));
assertThat(excerpt.type()).isEqualTo(ModelTypes.PIPELINE_RULE_V1);
assertThat(excerpt.title()).isEqualTo("title");
}
Aggregations