use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class PipelineRuleFacadeTest method findExisting.
@Test
@MongoDBFixtures("PipelineRuleFacadeTest.json")
public void findExisting() {
final Entity entity = EntityV1.builder().id(ModelId.of("debug")).type(ModelTypes.PIPELINE_RULE_V1).data(objectMapper.convertValue(PipelineRuleEntity.create(ValueReference.of("debug"), ValueReference.of("Debug"), ValueReference.of("rule \"debug\"\nwhen\n true\nthen\n debug($message.message);\nend")), JsonNode.class)).build();
final NativeEntity<RuleDao> existingRule = facade.findExisting(entity, Collections.emptyMap()).orElseThrow(AssertionError::new);
assertThat(existingRule.descriptor().id()).isEqualTo(ModelId.of("5adf25034b900a0fdb4e5338"));
assertThat(existingRule.descriptor().type()).isEqualTo(ModelTypes.PIPELINE_RULE_V1);
assertThat(existingRule.entity().title()).isEqualTo("debug");
assertThat(existingRule.entity().description()).isEqualTo("Debug");
assertThat(existingRule.entity().source()).startsWith("rule \"debug\"\n");
}
use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class PipelineRuleFacadeTest method collectEntity.
@Test
@MongoDBFixtures("PipelineRuleFacadeTest.json")
public void collectEntity() {
final EntityDescriptor descriptor = EntityDescriptor.create("5adf25034b900a0fdb4e5338", ModelTypes.PIPELINE_RULE_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Optional<Entity> collectedEntity = facade.exportEntity(descriptor, entityDescriptorIds);
assertThat(collectedEntity).isPresent().containsInstanceOf(EntityV1.class);
final EntityV1 entity = (EntityV1) collectedEntity.orElseThrow(AssertionError::new);
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.PIPELINE_RULE_V1);
final PipelineRuleEntity pipelineRuleEntity = objectMapper.convertValue(entity.data(), PipelineRuleEntity.class);
assertThat(pipelineRuleEntity.title()).isEqualTo(ValueReference.of("debug"));
assertThat(pipelineRuleEntity.description()).isEqualTo(ValueReference.of("Debug"));
assertThat(pipelineRuleEntity.source().asString(Collections.emptyMap())).startsWith("rule \"debug\"\n");
}
use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class PipelineRuleFacadeTest method exportNativeEntity.
@Test
@MongoDBFixtures("PipelineRuleFacadeTest.json")
public void exportNativeEntity() {
final EntityDescriptor descriptor = EntityDescriptor.create("5adf25034b900a0fdb4e5338", ModelTypes.PIPELINE_RULE_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Entity entity = facade.exportEntity(descriptor, entityDescriptorIds).orElseThrow(AssertionError::new);
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.PIPELINE_RULE_V1);
final EntityV1 entityV1 = (EntityV1) entity;
final PipelineEntity pipelineEntity = objectMapper.convertValue(entityV1.data(), PipelineEntity.class);
assertThat(pipelineEntity.title()).isEqualTo(ValueReference.of("debug"));
assertThat(pipelineEntity.description()).isEqualTo(ValueReference.of("Debug"));
assertThat(pipelineEntity.source().asString(Collections.emptyMap())).startsWith("rule \"debug\"\n");
}
use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class SidecarCollectorFacadeTest method exportNativeEntity.
@Test
@MongoDBFixtures("SidecarCollectorFacadeTest.json")
public void exportNativeEntity() {
final Collector collector = collectorService.find("5b4c920b4b900a0024af0001");
final EntityDescriptor descriptor = EntityDescriptor.create(collector.id(), ModelTypes.SIDECAR_COLLECTOR_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Entity entity = facade.exportNativeEntity(collector, entityDescriptorIds);
assertThat(entity).isInstanceOf(EntityV1.class);
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.SIDECAR_COLLECTOR_V1);
final EntityV1 entityV1 = (EntityV1) entity;
final SidecarCollectorEntity collectorEntity = objectMapper.convertValue(entityV1.data(), SidecarCollectorEntity.class);
assertThat(collectorEntity.name()).isEqualTo(ValueReference.of("filebeat"));
assertThat(collectorEntity.serviceType()).isEqualTo(ValueReference.of("exec"));
assertThat(collectorEntity.nodeOperatingSystem()).isEqualTo(ValueReference.of("linux"));
assertThat(collectorEntity.executablePath()).isEqualTo(ValueReference.of("/usr/lib/graylog-sidecar/filebeat"));
assertThat(collectorEntity.executeParameters()).isEqualTo(ValueReference.of("-c %s"));
assertThat(collectorEntity.validationParameters()).isEqualTo(ValueReference.of("test config -c %s"));
assertThat(collectorEntity.defaultTemplate()).isEqualTo(ValueReference.of(""));
}
use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class ViewFacadeTest method createViewEntity.
private EntityV1 createViewEntity() throws Exception {
final QueryEntity query = QueryEntity.builder().id("dead-beef").timerange(KeywordRange.create("last 5 minutes", "Etc/UTC")).filter(OrFilter.or(StreamFilter.ofId(newStreamId))).query(ElasticsearchQueryString.of("author: Mara Jade")).build();
final SearchEntity searchEntity = SearchEntity.builder().queries(ImmutableSet.of(query)).parameters(ImmutableSet.of()).requires(ImmutableMap.of()).createdAt(DateTime.now(DateTimeZone.UTC)).build();
final ViewStateEntity viewStateEntity = ViewStateEntity.builder().fields(ImmutableSet.of()).titles(Titles.empty()).widgets(ImmutableSet.of()).widgetMapping(ImmutableMap.of()).widgetPositions(ImmutableMap.of()).formatting(FormattingSettings.builder().highlighting(ImmutableSet.of()).build()).displayModeSettings(DisplayModeSettings.empty()).build();
final ViewEntity entity = ViewEntity.builder().type(ViewEntity.Type.SEARCH).summary(ValueReference.of("summary")).title(ValueReference.of("title")).description(ValueReference.of("description")).search(searchEntity).properties(ImmutableSet.of()).requires(ImmutableMap.of()).state(ImmutableMap.of(newViewId, viewStateEntity)).createdAt(DateTime.now(DateTimeZone.UTC)).build();
return EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.SEARCH_V1).data(objectMapper.convertValue(entity, JsonNode.class)).build();
}
Aggregations