Search in sources :

Example 6 with ReferenceMapUtils.toReferenceMap

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

the class LookupDataAdapterFacadeTest method resolveEntity.

@Test
@MongoDBFixtures("LookupDataAdapterFacadeTest.json")
public void resolveEntity() {
    final Entity entity = 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 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) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 7 with ReferenceMapUtils.toReferenceMap

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

the class LookupDataAdapterFacadeTest method createNativeEntity.

@Test
public void createNativeEntity() {
    final Entity entity = EntityV1.builder().id(ModelId.of("1")).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();
    assertThat(dataAdapterService.findAll()).isEmpty();
    final NativeEntity<DataAdapterDto> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), Collections.emptyMap(), "username");
    assertThat(nativeEntity.descriptor().id()).isNotNull();
    assertThat(nativeEntity.descriptor().type()).isEqualTo(ModelTypes.LOOKUP_ADAPTER_V1);
    assertThat(nativeEntity.entity().name()).isEqualTo("http-dsv");
    assertThat(nativeEntity.entity().title()).isEqualTo("HTTP DSV");
    assertThat(nativeEntity.entity().description()).isEqualTo("HTTP DSV");
    assertThat(dataAdapterService.findAll()).hasSize(1);
}
Also used : 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) Test(org.junit.Test)

Example 8 with ReferenceMapUtils.toReferenceMap

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

the class OutputFacadeTest method findExisting.

@Test
@MongoDBFixtures("OutputFacadeTest.json")
public void findExisting() {
    final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.OUTPUT_V1).data(objectMapper.convertValue(OutputEntity.create(ValueReference.of("STDOUT"), ValueReference.of("org.graylog2.outputs.LoggingOutput"), ReferenceMapUtils.toReferenceMap(ImmutableMap.of("prefix", "Writing message: "))), JsonNode.class)).build();
    final Optional<NativeEntity<Output>> existingOutput = facade.findExisting(entity, Collections.emptyMap());
    assertThat(existingOutput).isEmpty();
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) OutputEntity(org.graylog2.contentpacks.model.entities.OutputEntity) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 9 with ReferenceMapUtils.toReferenceMap

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

the class OutputFacadeTest method createNativeEntity.

@Test
public void createNativeEntity() {
    final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.OUTPUT_V1).data(objectMapper.convertValue(OutputEntity.create(ValueReference.of("STDOUT"), ValueReference.of("org.graylog2.outputs.LoggingOutput"), ReferenceMapUtils.toReferenceMap(ImmutableMap.of("prefix", "Writing message: "))), JsonNode.class)).build();
    final NativeEntity<Output> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), Collections.emptyMap(), "username");
    assertThat(nativeEntity.descriptor().type()).isEqualTo(ModelTypes.OUTPUT_V1);
    assertThat(nativeEntity.entity().getTitle()).isEqualTo("STDOUT");
    assertThat(nativeEntity.entity().getType()).isEqualTo("org.graylog2.outputs.LoggingOutput");
    assertThat(nativeEntity.entity().getCreatorUserId()).isEqualTo("username");
    assertThat(nativeEntity.entity().getConfiguration()).containsEntry("prefix", "Writing message: ");
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) OutputEntity(org.graylog2.contentpacks.model.entities.OutputEntity) MessageOutput(org.graylog2.plugin.outputs.MessageOutput) LoggingOutput(org.graylog2.outputs.LoggingOutput) Output(org.graylog2.plugin.streams.Output) Test(org.junit.Test)

Example 10 with ReferenceMapUtils.toReferenceMap

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

the class InputFacadeTest method createNativeEntity.

@Test
@Ignore("Doesn't work without massive amount of mocks")
public void createNativeEntity() {
    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 NativeEntity<InputWithExtractors> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), Collections.emptyMap(), "username");
    final InputWithExtractors inputWithExtractors = nativeEntity.entity();
    final Input savedInput = inputWithExtractors.input();
    final String savedId = savedInput.getId();
    assertThat(nativeEntity.descriptor()).isEqualTo(EntityDescriptor.create(savedId, ModelTypes.INPUT_V1));
    assertThat(savedInput.getTitle()).isEqualTo("Local Raw UDP");
    assertThat(savedInput.getType()).isEqualTo("org.graylog2.inputs.raw.udp.RawUDPInput");
    assertThat(savedInput.isGlobal()).isFalse();
    assertThat(savedInput.getContentPack()).isNull();
}
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) RawUDPInput(org.graylog2.inputs.raw.udp.RawUDPInput) Input(org.graylog2.inputs.Input) FakeHttpMessageInput(org.graylog2.inputs.random.FakeHttpMessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) HashMap(java.util.HashMap) Ignore(org.junit.Ignore) 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