Search in sources :

Example 1 with FallbackAdapterConfig

use of org.graylog2.plugin.lookup.FallbackAdapterConfig in project graylog2-server by Graylog2.

the class LookupTableFacadeTest method createNativeEntity.

@Test
public void createNativeEntity() {
    final Entity entity = EntityV1.builder().id(ModelId.of("1")).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("no-op-cache"), ValueReference.of("http-dsv"), ValueReference.of("Default single value"), ValueReference.of(LookupDefaultValue.Type.STRING), ValueReference.of("Default multi value"), ValueReference.of(LookupDefaultValue.Type.OBJECT)), JsonNode.class)).build();
    final EntityDescriptor cacheDescriptor = EntityDescriptor.create("no-op-cache", ModelTypes.LOOKUP_CACHE_V1);
    final CacheDto cacheDto = CacheDto.builder().id("5adf24b24b900a0fdb4e0001").name("no-op-cache").title("No-op cache").description("No-op cache").config(new FallbackCacheConfig()).build();
    final EntityDescriptor dataAdapterDescriptor = EntityDescriptor.create("http-dsv", ModelTypes.LOOKUP_ADAPTER_V1);
    final DataAdapterDto dataAdapterDto = DataAdapterDto.builder().id("5adf24a04b900a0fdb4e0002").name("http-dsv").title("HTTP DSV").description("HTTP DSV").config(new FallbackAdapterConfig()).build();
    final Map<EntityDescriptor, Object> nativeEntities = ImmutableMap.of(cacheDescriptor, cacheDto, dataAdapterDescriptor, dataAdapterDto);
    assertThat(lookupTableService.findAll()).isEmpty();
    final NativeEntity<LookupTableDto> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), nativeEntities, "username");
    assertThat(nativeEntity.descriptor().type()).isEqualTo(ModelTypes.LOOKUP_TABLE_V1);
    assertThat(nativeEntity.entity().name()).isEqualTo("http-dsv-no-cache");
    assertThat(nativeEntity.entity().title()).isEqualTo("HTTP DSV without Cache");
    assertThat(nativeEntity.entity().description()).isEqualTo("HTTP DSV without Cache");
    assertThat(nativeEntity.entity().cacheId()).isEqualTo("5adf24b24b900a0fdb4e0001");
    assertThat(nativeEntity.entity().dataAdapterId()).isEqualTo("5adf24a04b900a0fdb4e0002");
    assertThat(nativeEntity.entity().defaultSingleValue()).isEqualTo("Default single value");
    assertThat(nativeEntity.entity().defaultSingleValueType()).isEqualTo(LookupDefaultValue.Type.STRING);
    assertThat(nativeEntity.entity().defaultMultiValue()).isEqualTo("Default multi value");
    assertThat(nativeEntity.entity().defaultMultiValueType()).isEqualTo(LookupDefaultValue.Type.OBJECT);
    assertThat(lookupTableService.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) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) LookupTableDto(org.graylog2.lookup.dto.LookupTableDto) CacheDto(org.graylog2.lookup.dto.CacheDto) FallbackAdapterConfig(org.graylog2.plugin.lookup.FallbackAdapterConfig) FallbackCacheConfig(org.graylog2.plugin.lookup.FallbackCacheConfig) Test(org.junit.Test)

Example 2 with FallbackAdapterConfig

use of org.graylog2.plugin.lookup.FallbackAdapterConfig in project graylog2-server by Graylog2.

the class LookupDataAdapterFacadeTest method exportNativeEntity.

@Test
public void exportNativeEntity() {
    final DataAdapterDto dataAdapterDto = DataAdapterDto.builder().id("1234567890").name("data-adapter-name").title("Data Adapter Title").description("Data Adapter Description").config(new FallbackAdapterConfig()).build();
    final EntityDescriptor descriptor = EntityDescriptor.create(dataAdapterDto.id(), ModelTypes.LOOKUP_ADAPTER_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportNativeEntity(dataAdapterDto, entityDescriptorIds);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.LOOKUP_ADAPTER_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final LookupDataAdapterEntity lookupDataAdapterEntity = objectMapper.convertValue(entityV1.data(), LookupDataAdapterEntity.class);
    assertThat(lookupDataAdapterEntity.name()).isEqualTo(ValueReference.of("data-adapter-name"));
    assertThat(lookupDataAdapterEntity.title()).isEqualTo(ValueReference.of("Data Adapter Title"));
    assertThat(lookupDataAdapterEntity.description()).isEqualTo(ValueReference.of("Data Adapter Description"));
    assertThat(lookupDataAdapterEntity.configuration()).containsEntry("type", ValueReference.of("FallbackAdapterConfig"));
}
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) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) FallbackAdapterConfig(org.graylog2.plugin.lookup.FallbackAdapterConfig) Test(org.junit.Test)

Example 3 with FallbackAdapterConfig

use of org.graylog2.plugin.lookup.FallbackAdapterConfig in project graylog2-server by Graylog2.

the class LookupDataAdapterFacadeTest method createExcerpt.

@Test
public void createExcerpt() {
    final DataAdapterDto dataAdapterDto = DataAdapterDto.builder().id("1234567890").name("data-adapter-name").title("Data Adapter Title").description("Data Adapter Description").config(new FallbackAdapterConfig()).build();
    final EntityExcerpt excerpt = facade.createExcerpt(dataAdapterDto);
    assertThat(excerpt.id()).isEqualTo(ModelId.of("1234567890"));
    assertThat(excerpt.type()).isEqualTo(ModelTypes.LOOKUP_ADAPTER_V1);
    assertThat(excerpt.title()).isEqualTo("Data Adapter Title");
}
Also used : DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) FallbackAdapterConfig(org.graylog2.plugin.lookup.FallbackAdapterConfig) Test(org.junit.Test)

Aggregations

DataAdapterDto (org.graylog2.lookup.dto.DataAdapterDto)3 FallbackAdapterConfig (org.graylog2.plugin.lookup.FallbackAdapterConfig)3 Test (org.junit.Test)3 Entity (org.graylog2.contentpacks.model.entities.Entity)2 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)2 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)2 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)2 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)1 EntityExcerpt (org.graylog2.contentpacks.model.entities.EntityExcerpt)1 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)1 LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)1 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)1 CacheDto (org.graylog2.lookup.dto.CacheDto)1 LookupTableDto (org.graylog2.lookup.dto.LookupTableDto)1 FallbackCacheConfig (org.graylog2.plugin.lookup.FallbackCacheConfig)1