use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.
the class PipelineFacadeTest method exportNativeEntity.
@Test
@MongoDBFixtures("PipelineFacadeTest/pipelines.json")
public void exportNativeEntity() {
final EntityDescriptor descriptor = EntityDescriptor.create("5a85c4854b900afd5d662be3", ModelTypes.PIPELINE_V1);
final EntityDescriptor streamDescriptor = EntityDescriptor.create("5adf23894b900a0fdb4e517d", ModelTypes.STREAM_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor, streamDescriptor);
final Entity entity = facade.exportEntity(descriptor, entityDescriptorIds).orElseThrow(AssertionError::new);
assertThat(entity).isInstanceOf(EntityV1.class);
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.PIPELINE_V1);
final EntityV1 entityV1 = (EntityV1) entity;
final PipelineEntity pipelineEntity = objectMapper.convertValue(entityV1.data(), PipelineEntity.class);
assertThat(pipelineEntity.title()).isEqualTo(ValueReference.of("Test"));
assertThat(pipelineEntity.description()).isEqualTo(ValueReference.of("Description"));
assertThat(pipelineEntity.source().asString(Collections.emptyMap())).startsWith("pipeline \"Test\"");
assertThat(pipelineEntity.connectedStreams()).containsOnly(ValueReference.of(entityDescriptorIds.get(streamDescriptor).orElse(null)));
}
use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.
the class PipelineFacadeTest method resolve.
@Test
@MongoDBFixtures("PipelineFacadeTest/pipelines.json")
public void resolve() {
final Stage stage = Stage.builder().stage(0).match(Stage.Match.EITHER).ruleReferences(ImmutableList.of("debug", "no-op")).build();
RuleDao ruleDao1 = RuleDao.builder().id("2342353045938450345").title("debug").source("rule \\\"debug\\\"\\nrule \\\"no-op\\\"\\nend\"").build();
org.graylog.plugins.pipelineprocessor.ast.Rule rule1 = org.graylog.plugins.pipelineprocessor.ast.Rule.builder().id("1").name("debug").when(mock(LogicalExpression.class)).then(Collections.emptyList()).build();
RuleDao ruleDao2 = RuleDao.builder().id("2342353045938450346").title("no-op").source("rule \\\"debug\\\"\\nrule \\\"no-op\\\"\\nend\"").build();
org.graylog.plugins.pipelineprocessor.ast.Rule rule2 = org.graylog.plugins.pipelineprocessor.ast.Rule.builder().id("2").name("no-op").when(mock(LogicalExpression.class)).then(Collections.emptyList()).build();
stage.setRules(ImmutableList.of(rule1, rule2));
final Pipeline pipeline = Pipeline.builder().id("5a85c4854b900afd5d662be3").name("Test").stages(ImmutableSortedSet.of(stage)).build();
when(pipelineRuleParser.parsePipeline(eq("dummy"), anyString())).thenReturn(pipeline);
when(ruleService.findByName("no-op")).thenReturn(Optional.of(ruleDao1));
when(ruleService.findByName("debug")).thenReturn(Optional.of(ruleDao2));
final EntityDescriptor pipelineEntity = EntityDescriptor.create("5a85c4854b900afd5d662be3", ModelTypes.PIPELINE_V1);
final Graph<EntityDescriptor> graph = facade.resolveNativeEntity(pipelineEntity);
final EntityDescriptor streamEntity = EntityDescriptor.create("5adf23894b900a0fdb4e517d", ModelTypes.STREAM_V1);
final EntityDescriptor ruleEntity1 = EntityDescriptor.create("2342353045938450345", ModelTypes.PIPELINE_RULE_V1);
final EntityDescriptor ruleEntity2 = EntityDescriptor.create("2342353045938450346", ModelTypes.PIPELINE_RULE_V1);
assertThat(graph.nodes()).containsOnly(pipelineEntity, streamEntity, ruleEntity1, ruleEntity2);
}
use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.
the class PipelineFacadeTest method exportNativeEntityWithDefaultStream.
@Test
@MongoDBFixtures("PipelineFacadeTest/pipelines_default_stream.json")
public void exportNativeEntityWithDefaultStream() {
final EntityDescriptor descriptor = EntityDescriptor.create("5a85c4854b900afd5d662be3", ModelTypes.PIPELINE_V1);
final EntityDescriptor defaultStreamDescriptor = EntityDescriptor.create(Stream.DEFAULT_STREAM_ID, ModelTypes.STREAM_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor, defaultStreamDescriptor);
assertThat(entityDescriptorIds.get(defaultStreamDescriptor)).isEqualTo(Optional.of(Stream.DEFAULT_STREAM_ID));
final Entity entity = facade.exportEntity(descriptor, entityDescriptorIds).orElseThrow(AssertionError::new);
assertThat(entity).isInstanceOf(EntityV1.class);
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.PIPELINE_V1);
final EntityV1 entityV1 = (EntityV1) entity;
final PipelineEntity pipelineEntity = objectMapper.convertValue(entityV1.data(), PipelineEntity.class);
assertThat(pipelineEntity.title()).isEqualTo(ValueReference.of("Test"));
assertThat(pipelineEntity.description()).isEqualTo(ValueReference.of("Description"));
assertThat(pipelineEntity.source().asString(Collections.emptyMap())).startsWith("pipeline \"Test\"");
assertThat(pipelineEntity.connectedStreams()).containsOnly(ValueReference.of(entityDescriptorIds.get(defaultStreamDescriptor).orElse(null)));
}
use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.
the class PipelineFacadeTest method findExisting.
@Test
@MongoDBFixtures("PipelineFacadeTest/pipelines.json")
public void findExisting() {
final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.PIPELINE_V1).data(objectMapper.convertValue(PipelineEntity.create(ValueReference.of("Title"), ValueReference.of("Description"), ValueReference.of("pipeline \"Title\"\nstage 0 match either\nrule \"debug\"\nrule \"no-op\"\nend"), Collections.singleton(ValueReference.of("5adf23894b900a0f00000001"))), JsonNode.class)).build();
final Optional<NativeEntity<PipelineDao>> existingEntity = facade.findExisting(entity, Collections.emptyMap());
assertThat(existingEntity).isEmpty();
}
use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.
the class PipelineFacadeTest method listEntityExcerpts.
@Test
@MongoDBFixtures("PipelineFacadeTest/pipelines.json")
public void listEntityExcerpts() {
final EntityExcerpt expectedEntityExcerpt = EntityExcerpt.builder().id(ModelId.of("5a85c4854b900afd5d662be3")).type(ModelTypes.PIPELINE_V1).title("Test").build();
final Set<EntityExcerpt> entityExcerpts = facade.listEntityExcerpts();
assertThat(entityExcerpts).containsOnly(expectedEntityExcerpt);
}
Aggregations