Search in sources :

Example 1 with ReferenceMapUtils.toReferenceMap

use of org.graylog2.contentpacks.model.entities.references.ReferenceMapUtils.toReferenceMap 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 2 with ReferenceMapUtils.toReferenceMap

use of org.graylog2.contentpacks.model.entities.references.ReferenceMapUtils.toReferenceMap in project graylog2-server by Graylog2.

the class LookupCacheFacadeTest method findExisting.

@Test
@MongoDBFixtures("LookupCacheFacadeTest.json")
public void findExisting() {
    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();
    final NativeEntity<CacheDto> existingCache = facade.findExisting(entity, Collections.emptyMap()).orElseThrow(AssertionError::new);
    final NativeEntityDescriptor descriptor = existingCache.descriptor();
    final CacheDto cacheDto = existingCache.entity();
    assertThat(descriptor.id()).isEqualTo(ModelId.of("5adf24b24b900a0fdb4e52dd"));
    assertThat(descriptor.type()).isEqualTo(ModelTypes.LOOKUP_CACHE_V1);
    assertThat(cacheDto.id()).isEqualTo("5adf24b24b900a0fdb4e52dd");
    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");
}
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) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 3 with ReferenceMapUtils.toReferenceMap

use of org.graylog2.contentpacks.model.entities.references.ReferenceMapUtils.toReferenceMap in project graylog2-server by Graylog2.

the class LookupCacheFacadeTest method resolveEntity.

@Test
@MongoDBFixtures("LookupCacheFacadeTest.json")
public void resolveEntity() {
    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();
    final Graph<Entity> graph = facade.resolveForInstallation(entity, Collections.emptyMap(), Collections.emptyMap());
    assertThat(graph.nodes()).containsOnly(entity);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 4 with ReferenceMapUtils.toReferenceMap

use of org.graylog2.contentpacks.model.entities.references.ReferenceMapUtils.toReferenceMap in project graylog2-server by Graylog2.

the class InputFacadeTest method findExisting.

@Test
@MongoDBFixtures("InputFacadeTest.json")
public void findExisting() {
    final Map<String, Object> configuration = new HashMap<>();
    configuration.put("override_source", null);
    configuration.put("recv_buffer_size", 262144);
    configuration.put("bind_address", "127.0.0.1");
    configuration.put("port", 5555);
    configuration.put("number_worker_threads", 8);
    final Entity entity = EntityV1.builder().id(ModelId.of("5acc84f84b900a4ff290d9a7")).type(ModelTypes.INPUT_V1).data(objectMapper.convertValue(InputEntity.create(ValueReference.of("Local Raw UDP"), ReferenceMapUtils.toReferenceMap(configuration), Collections.emptyMap(), ValueReference.of("org.graylog2.inputs.raw.udp.RawUDPInput"), ValueReference.of(false), Collections.emptyList()), JsonNode.class)).build();
    final Optional<NativeEntity<InputWithExtractors>> existingInput = facade.findExisting(entity, Collections.emptyMap());
    assertThat(existingInput).isEmpty();
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) ConverterEntity(org.graylog2.contentpacks.model.entities.ConverterEntity) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) HashMap(java.util.HashMap) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 5 with ReferenceMapUtils.toReferenceMap

use of org.graylog2.contentpacks.model.entities.references.ReferenceMapUtils.toReferenceMap in project graylog2-server by Graylog2.

the class InputFacadeTest method resolveEntity.

@Test
@MongoDBFixtures("InputFacadeTest.json")
public void resolveEntity() {
    final Map<String, Object> configuration = new HashMap<>();
    configuration.put("override_source", null);
    configuration.put("recv_buffer_size", 262144);
    configuration.put("bind_address", "127.0.0.1");
    configuration.put("port", 5555);
    configuration.put("number_worker_threads", 8);
    final Entity entity = EntityV1.builder().id(ModelId.of("5acc84f84b900a4ff290d9a7")).type(ModelTypes.INPUT_V1).data(objectMapper.convertValue(InputEntity.create(ValueReference.of("Local Raw UDP"), ReferenceMapUtils.toReferenceMap(configuration), Collections.emptyMap(), ValueReference.of("org.graylog2.inputs.raw.udp.RawUDPInput"), ValueReference.of(false), Collections.emptyList()), JsonNode.class)).build();
    final Graph<Entity> graph = facade.resolveForInstallation(entity, Collections.emptyMap(), Collections.emptyMap());
    assertThat(graph.nodes()).containsOnly(entity);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) ConverterEntity(org.graylog2.contentpacks.model.entities.ConverterEntity) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) HashMap(java.util.HashMap) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

Entity (org.graylog2.contentpacks.model.entities.Entity)17 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)17 Test (org.junit.Test)17 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)13 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)6 HashMap (java.util.HashMap)5 ConverterEntity (org.graylog2.contentpacks.model.entities.ConverterEntity)5 ExtractorEntity (org.graylog2.contentpacks.model.entities.ExtractorEntity)5 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)5 InputEntity (org.graylog2.contentpacks.model.entities.InputEntity)5 LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)5 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)5 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)3 OutputEntity (org.graylog2.contentpacks.model.entities.OutputEntity)3 Input (org.graylog2.inputs.Input)3 FakeHttpMessageInput (org.graylog2.inputs.random.FakeHttpMessageInput)3 RawUDPInput (org.graylog2.inputs.raw.udp.RawUDPInput)3 MessageInput (org.graylog2.plugin.inputs.MessageInput)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayList (java.util.ArrayList)2