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);
}
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);
}
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);
}
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);
}
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"));
}
Aggregations