Search in sources :

Example 81 with EntityV1

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

the class LookupDataAdapterFacadeTest method findExisting.

@Test
@MongoDBFixtures("LookupDataAdapterFacadeTest.json")
public void findExisting() {
    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();
    final NativeEntity<DataAdapterDto> nativeEntity = facade.findExisting(entity, Collections.emptyMap()).orElseThrow(AssertionError::new);
    assertThat(nativeEntity.descriptor().id()).isEqualTo(ModelId.of("5adf24a04b900a0fdb4e52c8"));
    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");
}
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) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 82 with EntityV1

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

the class LookupDataAdapterFacadeTest method collectEntity.

@Test
@MongoDBFixtures("LookupDataAdapterFacadeTest.json")
public void collectEntity() {
    final EntityDescriptor descriptor = EntityDescriptor.create("5adf24a04b900a0fdb4e52c8", ModelTypes.LOOKUP_ADAPTER_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_ADAPTER_V1);
    final LookupDataAdapterEntity lookupDataAdapterEntity = objectMapper.convertValue(entity.data(), LookupDataAdapterEntity.class);
    assertThat(lookupDataAdapterEntity.name()).isEqualTo(ValueReference.of("http-dsv"));
    assertThat(lookupDataAdapterEntity.title()).isEqualTo(ValueReference.of("HTTP DSV"));
    assertThat(lookupDataAdapterEntity.description()).isEqualTo(ValueReference.of("HTTP DSV"));
}
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) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 83 with EntityV1

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

the class OutputFacadeTest method resolveEntity.

@Test
@MongoDBFixtures("OutputFacadeTest.json")
public void resolveEntity() {
    final Entity entity = EntityV1.builder().id(ModelId.of("5adf239e4b900a0fdb4e5197")).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 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) OutputEntity(org.graylog2.contentpacks.model.entities.OutputEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 84 with EntityV1

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

the class OutputFacadeTest method collectEntity.

@Test
@MongoDBFixtures("OutputFacadeTest.json")
public void collectEntity() {
    final EntityDescriptor descriptor = EntityDescriptor.create("5adf239e4b900a0fdb4e5197", ModelTypes.OUTPUT_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.OUTPUT_V1);
    final OutputEntity outputEntity = objectMapper.convertValue(entity.data(), OutputEntity.class);
    assertThat(outputEntity.title()).isEqualTo(ValueReference.of("STDOUT"));
    assertThat(outputEntity.type()).isEqualTo(ValueReference.of("org.graylog2.outputs.LoggingOutput"));
    assertThat(outputEntity.configuration()).isNotEmpty();
}
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) OutputEntity(org.graylog2.contentpacks.model.entities.OutputEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) OutputEntity(org.graylog2.contentpacks.model.entities.OutputEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 85 with EntityV1

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

the class CatalogResourceTest method resolveEntities.

@Test
public void resolveEntities() {
    final EntityDescriptor entityDescriptor = EntityDescriptor.builder().id(ModelId.of("1234567890")).type(ModelType.of("test", "1")).build();
    final MutableGraph<EntityDescriptor> entityDescriptors = GraphBuilder.directed().build();
    entityDescriptors.addNode(entityDescriptor);
    final EntityV1 entity = EntityV1.builder().id(ModelId.of("1234567890")).type(ModelType.of("test", "1")).data(new ObjectNode(JsonNodeFactory.instance).put("test", "1234")).build();
    when(mockEntityFacade.resolveNativeEntity(entityDescriptor)).thenReturn(entityDescriptors);
    when(mockEntityFacade.exportEntity(eq(entityDescriptor), any(EntityDescriptorIds.class))).thenReturn(Optional.of(entity));
    final CatalogResolveRequest request = CatalogResolveRequest.create(entityDescriptors.nodes());
    final CatalogResolveResponse catalogResolveResponse = catalogResource.resolveEntities(request);
    assertThat(catalogResolveResponse.entities()).containsOnly(entity);
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) CatalogResolveRequest(org.graylog2.rest.models.system.contentpacks.responses.CatalogResolveRequest) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) CatalogResolveResponse(org.graylog2.rest.models.system.contentpacks.responses.CatalogResolveResponse) 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