Search in sources :

Example 6 with RuleDao

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) {
    }
}
Also used : RuleDao(org.graylog.plugins.pipelineprocessor.db.RuleDao) NotFoundException(org.graylog2.database.NotFoundException) Test(org.junit.Test)

Example 7 with RuleDao

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.");
    }
}
Also used : RuleDao(org.graylog.plugins.pipelineprocessor.db.RuleDao) Test(org.junit.Test)

Example 8 with RuleDao

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);
}
Also used : RuleDao(org.graylog.plugins.pipelineprocessor.db.RuleDao) Test(org.junit.Test)

Example 9 with RuleDao

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);
}
Also used : RuleDao(org.graylog.plugins.pipelineprocessor.db.RuleDao) Test(org.junit.Test)

Example 10 with RuleDao

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");
}
Also used : RuleDao(org.graylog.plugins.pipelineprocessor.db.RuleDao) EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) Test(org.junit.Test)

Aggregations

RuleDao (org.graylog.plugins.pipelineprocessor.db.RuleDao)19 Test (org.junit.Test)10 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)4 PipelineRuleEntity (org.graylog2.contentpacks.model.entities.PipelineRuleEntity)4 NotFoundException (org.graylog2.database.NotFoundException)4 ApiOperation (io.swagger.annotations.ApiOperation)3 BadRequestException (javax.ws.rs.BadRequestException)3 Rule (org.graylog.plugins.pipelineprocessor.ast.Rule)3 ParseException (org.graylog.plugins.pipelineprocessor.parser.ParseException)3 AuditEvent (org.graylog2.audit.jersey.AuditEvent)3 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)3 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)3 DateTime (org.joda.time.DateTime)3 POST (javax.ws.rs.POST)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Api (io.swagger.annotations.Api)1