Search in sources :

Example 36 with EntityV1

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

the class GrokPatternFacadeTest method findExisting.

@Test
public void findExisting() throws ValidationException {
    final GrokPattern grokPattern = grokPatternService.save(GrokPattern.create("Test", "[a-z]+"));
    final Entity grokPatternEntity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("Test", "[a-z]+"), JsonNode.class)).build();
    final Optional<NativeEntity<GrokPattern>> existingGrokPattern = facade.findExisting(grokPatternEntity, Collections.emptyMap());
    final NativeEntityDescriptor expectedDescriptor = NativeEntityDescriptor.create(grokPatternEntity.id(), "1", ModelTypes.GROK_PATTERN_V1, grokPattern.name(), false);
    assertThat(existingGrokPattern).isPresent().get().satisfies(nativeEntity -> {
        assertThat(nativeEntity.descriptor()).isEqualTo(expectedDescriptor);
        assertThat(nativeEntity.entity()).isEqualTo(grokPattern);
    });
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) GrokPattern(org.graylog2.grok.GrokPattern) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Test(org.junit.Test)

Example 37 with EntityV1

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

the class GrokPatternFacadeTest method exportEntity.

@Test
public void exportEntity() throws ValidationException {
    grokPatternService.save(GrokPattern.create("Test1", "[a-z]+"));
    grokPatternService.save(GrokPattern.create("Test2", "[a-z]+"));
    final EntityDescriptor descriptor = EntityDescriptor.create("1", ModelTypes.GROK_PATTERN_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Map<String, Object> entity = ImmutableMap.of("name", "Test1", "pattern", "[a-z]+");
    final JsonNode entityData = objectMapper.convertValue(entity, JsonNode.class);
    final Optional<Entity> collectedEntity = facade.exportEntity(descriptor, entityDescriptorIds);
    assertThat(collectedEntity).isPresent();
    final EntityV1 entityV1 = (EntityV1) collectedEntity.get();
    assertThat(entityV1.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entityV1.type()).isEqualTo(ModelTypes.GROK_PATTERN_V1);
    assertThat(entityV1.data()).isEqualTo(entityData);
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 38 with EntityV1

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

the class LookupCacheFacadeTest method collectEntity.

@Test
@MongoDBFixtures("LookupCacheFacadeTest.json")
public void collectEntity() {
    final EntityDescriptor descriptor = EntityDescriptor.create("5adf24b24b900a0fdb4e52dd", ModelTypes.LOOKUP_CACHE_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.LOOKUP_CACHE_V1);
    final LookupCacheEntity lookupCacheEntity = objectMapper.convertValue(entity.data(), LookupCacheEntity.class);
    assertThat(lookupCacheEntity.name()).isEqualTo(ValueReference.of("no-op-cache"));
    assertThat(lookupCacheEntity.title()).isEqualTo(ValueReference.of("No-op cache"));
    assertThat(lookupCacheEntity.description()).isEqualTo(ValueReference.of("No-op cache"));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 39 with EntityV1

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

the class LookupCacheFacadeTest method createNativeEntity.

@Test
public void createNativeEntity() {
    final Entity entity = EntityV1.builder().id(ModelId.of("1")).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();
    assertThat(cacheService.findAll()).isEmpty();
    final NativeEntity<CacheDto> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), Collections.emptyMap(), "username");
    final NativeEntityDescriptor descriptor = nativeEntity.descriptor();
    final CacheDto cacheDto = nativeEntity.entity();
    assertThat(nativeEntity.descriptor().id()).isNotNull();
    assertThat(descriptor.type()).isEqualTo(ModelTypes.LOOKUP_CACHE_V1);
    assertThat(cacheDto.name()).isEqualTo("no-op-cache");
    assertThat(cacheDto.title()).isEqualTo("No-op cache");
    assertThat(cacheDto.description()).isEqualTo("No-op cache");
    assertThat(cacheDto.config().type()).isEqualTo("none");
    assertThat(cacheService.findAll()).hasSize(1);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) CacheDto(org.graylog2.lookup.dto.CacheDto) Test(org.junit.Test)

Example 40 with EntityV1

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

the class LookupCacheFacadeTest method exportNativeEntity.

@Test
public void exportNativeEntity() {
    final CacheDto cacheDto = CacheDto.builder().id("1234567890").name("cache-name").title("Cache Title").description("Cache Description").config(new FallbackCacheConfig()).build();
    final EntityDescriptor descriptor = EntityDescriptor.create(cacheDto.id(), ModelTypes.LOOKUP_CACHE_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportNativeEntity(cacheDto, entityDescriptorIds);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.LOOKUP_CACHE_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final LookupCacheEntity lookupCacheEntity = objectMapper.convertValue(entityV1.data(), LookupCacheEntity.class);
    assertThat(lookupCacheEntity.name()).isEqualTo(ValueReference.of("cache-name"));
    assertThat(lookupCacheEntity.title()).isEqualTo(ValueReference.of("Cache Title"));
    assertThat(lookupCacheEntity.description()).isEqualTo(ValueReference.of("Cache Description"));
    assertThat(lookupCacheEntity.configuration()).containsEntry("type", ValueReference.of("FallbackCacheConfig"));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) CacheDto(org.graylog2.lookup.dto.CacheDto) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) FallbackCacheConfig(org.graylog2.plugin.lookup.FallbackCacheConfig) Test(org.junit.Test)

Aggregations

Entity (org.graylog2.contentpacks.model.entities.Entity)82 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)78 Test (org.junit.Test)71 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)56 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)48 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)45 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)40 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)33 JsonNode (com.fasterxml.jackson.databind.JsonNode)25 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)21 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)21 LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)17 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)17 VisibleForTesting (com.google.common.annotations.VisibleForTesting)16 PipelineEntity (org.graylog2.contentpacks.model.entities.PipelineEntity)16 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)16 ModelId (org.graylog2.contentpacks.model.ModelId)14 HashMap (java.util.HashMap)12 InputEntity (org.graylog2.contentpacks.model.entities.InputEntity)11 Map (java.util.Map)10