Search in sources :

Example 26 with EntityDescriptor

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

the class EventDefinitionFacadeTest method createNativeEntity.

@Test
public void createNativeEntity() {
    final EntityV1 entityV1 = createTestEntity();
    final NotificationDto notificationDto = NotificationDto.builder().config(HTTPEventNotificationConfig.builder().url("https://hulud.net").build()).title("Notify me Senpai").description("A notification for senpai").id("dead-beef").build();
    final EntityDescriptor entityDescriptor = EntityDescriptor.create("123123", ModelTypes.NOTIFICATION_V1);
    final ImmutableMap<EntityDescriptor, Object> nativeEntities = ImmutableMap.of(entityDescriptor, notificationDto);
    final JobDefinitionDto jobDefinitionDto = mock(JobDefinitionDto.class);
    final JobTriggerDto jobTriggerDto = mock(JobTriggerDto.class);
    when(jobDefinitionDto.id()).thenReturn("job-123123");
    when(jobSchedulerClock.nowUTC()).thenReturn(DateTime.now(DateTimeZone.UTC));
    when(jobDefinitionService.save(any(JobDefinitionDto.class))).thenReturn(jobDefinitionDto);
    when(jobTriggerService.create(any(JobTriggerDto.class))).thenReturn(jobTriggerDto);
    final UserImpl kmerzUser = new UserImpl(mock(PasswordAlgorithmFactory.class), new Permissions(ImmutableSet.of()), ImmutableMap.of("username", "kmerz"));
    when(userService.load("kmerz")).thenReturn(kmerzUser);
    final NativeEntity<EventDefinitionDto> nativeEntity = facade.createNativeEntity(entityV1, ImmutableMap.of(), nativeEntities, "kmerz");
    assertThat(nativeEntity).isNotNull();
    final EventDefinitionDto eventDefinitionDto = nativeEntity.entity();
    assertThat(eventDefinitionDto.title()).isEqualTo("title");
    assertThat(eventDefinitionDto.description()).isEqualTo("description");
    assertThat(eventDefinitionDto.config().type()).isEqualTo("aggregation-v1");
    // verify that ownership was registered for this entity
    verify(entityOwnershipService, times(1)).registerNewEventDefinition(nativeEntity.entity().id(), kmerzUser);
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) PasswordAlgorithmFactory(org.graylog2.security.PasswordAlgorithmFactory) NotificationDto(org.graylog.events.notifications.NotificationDto) EventDefinitionDto(org.graylog.events.processor.EventDefinitionDto) JobDefinitionDto(org.graylog.scheduler.JobDefinitionDto) UserImpl(org.graylog2.users.UserImpl) Permissions(org.graylog2.shared.security.Permissions) JobTriggerDto(org.graylog.scheduler.JobTriggerDto) Test(org.junit.Test)

Example 27 with EntityDescriptor

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

the class EventDefinitionFacadeTest method resolveForInstallation.

@Test
@MongoDBFixtures("EventDefinitionFacadeTest.json")
public void resolveForInstallation() {
    EntityV1 eventEntityV1 = createTestEntity();
    final NotificationEntity notificationEntity = NotificationEntity.builder().title(ValueReference.of("title")).description(ValueReference.of("description")).config(HttpEventNotificationConfigEntity.builder().url(ValueReference.of("http://url")).build()).build();
    final JsonNode data = objectMapper.convertValue(notificationEntity, JsonNode.class);
    final EntityV1 notificationV1 = EntityV1.builder().data(data).id(ModelId.of("123123")).type(ModelTypes.EVENT_DEFINITION_V1).build();
    final EntityDescriptor entityDescriptor = EntityDescriptor.create("123123", ModelTypes.NOTIFICATION_V1);
    Map<String, ValueReference> parameters = ImmutableMap.of();
    Map<EntityDescriptor, Entity> entities = ImmutableMap.of(entityDescriptor, notificationV1);
    Graph<Entity> graph = facade.resolveForInstallation(eventEntityV1, parameters, entities);
    assertThat(graph).isNotNull();
    Set<Entity> expectedNodes = ImmutableSet.of(eventEntityV1, notificationV1);
    assertThat(graph.nodes()).isEqualTo(expectedNodes);
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) EventNotificationHandlerConfigEntity(org.graylog.events.contentpack.entities.EventNotificationHandlerConfigEntity) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) HttpEventNotificationConfigEntity(org.graylog.events.contentpack.entities.HttpEventNotificationConfigEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) AggregationEventProcessorConfigEntity(org.graylog.events.contentpack.entities.AggregationEventProcessorConfigEntity) EventDefinitionEntity(org.graylog.events.contentpack.entities.EventDefinitionEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 28 with EntityDescriptor

use of org.graylog2.contentpacks.model.entities.EntityDescriptor 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 29 with EntityDescriptor

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

the class GrokPatternFacadeTest method resolveEntityDescriptor.

@Test
public void resolveEntityDescriptor() throws ValidationException {
    final GrokPattern grokPattern = grokPatternService.save(GrokPattern.create("Test1", "[a-z]+"));
    final EntityDescriptor descriptor = EntityDescriptor.create(grokPattern.id(), ModelTypes.GROK_PATTERN_V1);
    final Graph<EntityDescriptor> graph = facade.resolveNativeEntity(descriptor);
    assertThat(graph.nodes()).containsOnly(descriptor);
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) GrokPattern(org.graylog2.grok.GrokPattern) Test(org.junit.Test)

Example 30 with EntityDescriptor

use of org.graylog2.contentpacks.model.entities.EntityDescriptor 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)

Aggregations

EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)92 Test (org.junit.Test)63 Entity (org.graylog2.contentpacks.model.entities.Entity)62 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)59 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)48 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)44 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)44 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)42 ModelId (org.graylog2.contentpacks.model.ModelId)26 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)15 Map (java.util.Map)14 Graph (com.google.common.graph.Graph)13 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)13 Optional (java.util.Optional)12 Set (java.util.Set)12 Collectors (java.util.stream.Collectors)12 EntityExcerpt (org.graylog2.contentpacks.model.entities.EntityExcerpt)12 NotFoundException (org.graylog2.database.NotFoundException)12