Search in sources :

Example 76 with EntityDescriptor

use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.

the class GrokPatternFacadeTest method notResolveNotMatchingDependecyForInstallation.

@Test
public void notResolveNotMatchingDependecyForInstallation() {
    final Entity grokPatternEntity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("Test", "%{DOOM}"), JsonNode.class)).build();
    final Entity grokPatternEntityDependency = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("PORTAL", "\\d\\d"), JsonNode.class)).build();
    final EntityDescriptor dependencyDescriptor = grokPatternEntityDependency.toEntityDescriptor();
    final Map<EntityDescriptor, Entity> entityDescriptorEntityMap = new HashMap(1);
    entityDescriptorEntityMap.put(dependencyDescriptor, grokPatternEntityDependency);
    final Map<String, ValueReference> parameters = Collections.emptyMap();
    Graph<Entity> graph = facade.resolveForInstallation(grokPatternEntity, parameters, entityDescriptorEntityMap);
    assertThat(graph.nodes().toArray()).doesNotContain(grokPatternEntityDependency);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) HashMap(java.util.HashMap) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) Test(org.junit.Test)

Example 77 with EntityDescriptor

use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.

the class LookupTableFacadeTest method collectEntity.

@Test
@MongoDBFixtures("LookupTableFacadeTest.json")
public void collectEntity() {
    final EntityDescriptor tableDescriptor = EntityDescriptor.create("5adf24dd4b900a0fdb4e530d", ModelTypes.LOOKUP_TABLE_V1);
    final EntityDescriptor adapterDescriptor = EntityDescriptor.create("5adf24a04b900a0fdb4e52c8", ModelTypes.LOOKUP_ADAPTER_V1);
    final EntityDescriptor cacheDescriptor = EntityDescriptor.create("5adf24b24b900a0fdb4e52dd", ModelTypes.LOOKUP_CACHE_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(tableDescriptor, adapterDescriptor, cacheDescriptor);
    final Optional<Entity> collectedEntity = facade.exportEntity(EntityDescriptor.create("http-dsv-no-cache", ModelTypes.LOOKUP_TABLE_V1), entityDescriptorIds);
    assertThat(collectedEntity).isPresent().containsInstanceOf(EntityV1.class);
    final EntityV1 entity = (EntityV1) collectedEntity.orElseThrow(AssertionError::new);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(tableDescriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.LOOKUP_TABLE_V1);
    final LookupTableEntity lookupTableEntity = objectMapper.convertValue(entity.data(), LookupTableEntity.class);
    assertThat(lookupTableEntity.name()).isEqualTo(ValueReference.of("http-dsv-no-cache"));
    assertThat(lookupTableEntity.title()).isEqualTo(ValueReference.of("HTTP DSV without Cache"));
    assertThat(lookupTableEntity.description()).isEqualTo(ValueReference.of("HTTP DSV without Cache"));
    assertThat(lookupTableEntity.dataAdapterName()).isEqualTo(ValueReference.of(entityDescriptorIds.get(adapterDescriptor).orElse(null)));
    assertThat(lookupTableEntity.cacheName()).isEqualTo(ValueReference.of(entityDescriptorIds.get(cacheDescriptor).orElse(null)));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 78 with EntityDescriptor

use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.

the class LookupTableFacadeTest method exportEntity.

@Test
public void exportEntity() {
    final EntityDescriptor tableDescriptor = EntityDescriptor.create("1234567890", ModelTypes.LOOKUP_TABLE_V1);
    final EntityDescriptor adapterDescriptor = EntityDescriptor.create("data-adapter-1234", ModelTypes.LOOKUP_ADAPTER_V1);
    final EntityDescriptor cacheDescriptor = EntityDescriptor.create("cache-1234", ModelTypes.LOOKUP_CACHE_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(tableDescriptor, adapterDescriptor, cacheDescriptor);
    final LookupTableDto lookupTableDto = LookupTableDto.builder().id("1234567890").name("lookup-table-name").title("Lookup Table Title").description("Lookup Table Description").dataAdapterId("data-adapter-1234").cacheId("cache-1234").defaultSingleValue("default-single").defaultSingleValueType(LookupDefaultValue.Type.STRING).defaultMultiValue("default-multi").defaultMultiValueType(LookupDefaultValue.Type.STRING).build();
    final Entity entity = facade.exportNativeEntity(lookupTableDto, entityDescriptorIds);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(tableDescriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.LOOKUP_TABLE_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final LookupTableEntity lookupTableEntity = objectMapper.convertValue(entityV1.data(), LookupTableEntity.class);
    assertThat(lookupTableEntity.name()).isEqualTo(ValueReference.of("lookup-table-name"));
    assertThat(lookupTableEntity.title()).isEqualTo(ValueReference.of("Lookup Table Title"));
    assertThat(lookupTableEntity.description()).isEqualTo(ValueReference.of("Lookup Table Description"));
    assertThat(lookupTableEntity.dataAdapterName()).isEqualTo(ValueReference.of(entityDescriptorIds.get(adapterDescriptor).orElse(null)));
    assertThat(lookupTableEntity.cacheName()).isEqualTo(ValueReference.of(entityDescriptorIds.get(cacheDescriptor).orElse(null)));
    assertThat(lookupTableEntity.defaultSingleValue()).isEqualTo(ValueReference.of("default-single"));
    assertThat(lookupTableEntity.defaultSingleValueType()).isEqualTo(ValueReference.of(LookupDefaultValue.Type.STRING));
    assertThat(lookupTableEntity.defaultMultiValue()).isEqualTo(ValueReference.of("default-multi"));
    assertThat(lookupTableEntity.defaultMultiValueType()).isEqualTo(ValueReference.of(LookupDefaultValue.Type.STRING));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) LookupTableDto(org.graylog2.lookup.dto.LookupTableDto) Test(org.junit.Test)

Example 79 with EntityDescriptor

use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.

the class LookupTableFacadeTest method resolveEntityDescriptor.

@Test
@MongoDBFixtures({ "LookupCacheFacadeTest.json", "LookupDataAdapterFacadeTest.json", "LookupTableFacadeTest.json" })
public void resolveEntityDescriptor() {
    final EntityDescriptor descriptor = EntityDescriptor.create("5adf24dd4b900a0fdb4e530d", ModelTypes.LOOKUP_TABLE_V1);
    final Graph<EntityDescriptor> graph = facade.resolveNativeEntity(descriptor);
    assertThat(graph.nodes()).hasSize(3).containsOnly(descriptor, EntityDescriptor.create("5adf24a04b900a0fdb4e52c8", ModelTypes.LOOKUP_ADAPTER_V1), EntityDescriptor.create("5adf24b24b900a0fdb4e52dd", ModelTypes.LOOKUP_CACHE_V1));
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 80 with EntityDescriptor

use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.

the class LookupTableFacadeTest method resolveEntity.

@Test
@MongoDBFixtures({ "LookupCacheFacadeTest.json", "LookupDataAdapterFacadeTest.json", "LookupTableFacadeTest.json" })
public void resolveEntity() {
    final Entity entity = EntityV1.builder().id(ModelId.of("5adf24dd4b900a0fdb4e530d")).type(ModelTypes.LOOKUP_TABLE_V1).data(objectMapper.convertValue(LookupTableEntity.create(ValueReference.of("http-dsv-no-cache"), ValueReference.of("HTTP DSV without Cache"), ValueReference.of("HTTP DSV without Cache"), ValueReference.of("5adf24b24b900a0fdb4e52dd"), ValueReference.of("5adf24a04b900a0fdb4e52c8"), ValueReference.of("Default single value"), ValueReference.of(LookupDefaultValue.Type.STRING), ValueReference.of("Default multi value"), ValueReference.of(LookupDefaultValue.Type.OBJECT)), JsonNode.class)).build();
    final Entity cacheEntity = EntityV1.builder().id(ModelId.of("5adf24b24b900a0fdb4e52dd")).type(ModelTypes.LOOKUP_CACHE_V1).data(objectMapper.convertValue(LookupCacheEntity.create(ValueReference.of("no-op-cache"), ValueReference.of("No-op cache"), ValueReference.of("No-op cache"), ReferenceMapUtils.toReferenceMap(ImmutableMap.of("type", "none"))), JsonNode.class)).build();
    final Entity dataAdapterEntity = EntityV1.builder().id(ModelId.of("5adf24a04b900a0fdb4e52c8")).type(ModelTypes.LOOKUP_ADAPTER_V1).data(objectMapper.convertValue(LookupDataAdapterEntity.create(ValueReference.of("http-dsv"), ValueReference.of("HTTP DSV"), ValueReference.of("HTTP DSV"), ReferenceMapUtils.toReferenceMap(Collections.emptyMap())), JsonNode.class)).build();
    final Map<EntityDescriptor, Entity> entities = ImmutableMap.of(cacheEntity.toEntityDescriptor(), cacheEntity, dataAdapterEntity.toEntityDescriptor(), dataAdapterEntity);
    final Graph<Entity> graph = facade.resolveForInstallation(entity, Collections.emptyMap(), entities);
    assertThat(graph.nodes()).hasSize(3).containsOnly(entity, cacheEntity, dataAdapterEntity);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)92 Test (org.junit.Test)63 Entity (org.graylog2.contentpacks.model.entities.Entity)62 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)59 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)48 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)44 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)44 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)42 ModelId (org.graylog2.contentpacks.model.ModelId)26 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)15 Map (java.util.Map)14 Graph (com.google.common.graph.Graph)13 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)13 Optional (java.util.Optional)12 Set (java.util.Set)12 Collectors (java.util.stream.Collectors)12 EntityExcerpt (org.graylog2.contentpacks.model.entities.EntityExcerpt)12 NotFoundException (org.graylog2.database.NotFoundException)12