Search in sources :

Example 21 with NativeEntity

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

the class LookupTableFacadeTest method findExistingWithNoExistingEntity.

@Test
@MongoDBFixtures("LookupTableFacadeTest.json")
public void findExistingWithNoExistingEntity() {
    final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.LOOKUP_TABLE_V1).data(objectMapper.convertValue(LookupTableEntity.create(ValueReference.of("some-name"), ValueReference.of("Title"), ValueReference.of("Description"), ValueReference.of("cache-id"), ValueReference.of("data-adapter-id"), ValueReference.of("Default single value"), ValueReference.of(LookupDefaultValue.Type.STRING), ValueReference.of("Default multi value"), ValueReference.of(LookupDefaultValue.Type.OBJECT)), JsonNode.class)).build();
    final Optional<NativeEntity<LookupTableDto>> existingEntity = facade.findExisting(entity, Collections.emptyMap());
    assertThat(existingEntity).isEmpty();
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 22 with NativeEntity

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

the class LookupTableFacadeTest method findExisting.

@Test
@MongoDBFixtures("LookupTableFacadeTest.json")
public void findExisting() {
    final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.LOOKUP_TABLE_V1).data(objectMapper.convertValue(LookupTableEntity.create(ValueReference.of("http-dsv-no-cache"), ValueReference.of("HTTP DSV without Cache"), ValueReference.of("HTTP DSV without Cache"), ValueReference.of("cache-id"), ValueReference.of("data-adapter-id"), ValueReference.of("Default single value"), ValueReference.of(LookupDefaultValue.Type.STRING), ValueReference.of("Default multi value"), ValueReference.of(LookupDefaultValue.Type.OBJECT)), JsonNode.class)).build();
    final NativeEntity<LookupTableDto> existingEntity = facade.findExisting(entity, Collections.emptyMap()).orElseThrow(AssertionError::new);
    assertThat(existingEntity.descriptor().id()).isEqualTo(ModelId.of("5adf24dd4b900a0fdb4e530d"));
    assertThat(existingEntity.descriptor().type()).isEqualTo(ModelTypes.LOOKUP_TABLE_V1);
    assertThat(existingEntity.entity().name()).isEqualTo("http-dsv-no-cache");
    assertThat(existingEntity.entity().title()).isEqualTo("HTTP DSV without Cache");
    assertThat(existingEntity.entity().description()).isEqualTo("HTTP DSV without Cache");
    assertThat(existingEntity.entity().dataAdapterId()).isEqualTo("5adf24a04b900a0fdb4e52c8");
    assertThat(existingEntity.entity().cacheId()).isEqualTo("5adf24b24b900a0fdb4e52dd");
    assertThat(existingEntity.entity().defaultSingleValue()).isEqualTo("Default single value");
    assertThat(existingEntity.entity().defaultSingleValueType()).isEqualTo(LookupDefaultValue.Type.STRING);
    assertThat(existingEntity.entity().defaultMultiValue()).isEqualTo("Default multi value");
    assertThat(existingEntity.entity().defaultMultiValueType()).isEqualTo(LookupDefaultValue.Type.OBJECT);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) LookupTableDto(org.graylog2.lookup.dto.LookupTableDto) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 23 with NativeEntity

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

the class SidecarCollectorFacadeTest method createNativeEntity.

@Test
public void createNativeEntity() {
    final Entity entity = EntityV1.builder().id(ModelId.of("0")).type(ModelTypes.SIDECAR_COLLECTOR_V1).data(objectMapper.convertValue(SidecarCollectorEntity.create(ValueReference.of("filebeat"), ValueReference.of("exec"), ValueReference.of("linux"), ValueReference.of("/usr/lib/graylog-sidecar/filebeat"), ValueReference.of("-c %s"), ValueReference.of("test config -c %s"), ValueReference.of("")), JsonNode.class)).build();
    assertThat(collectorService.count()).isEqualTo(0L);
    final NativeEntity<Collector> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), Collections.emptyMap(), "username");
    assertThat(collectorService.count()).isEqualTo(1L);
    final Collector collector = collectorService.findByName("filebeat");
    assertThat(collector).isNotNull();
    final NativeEntityDescriptor expectedDescriptor = NativeEntityDescriptor.create(entity.id(), collector.id(), ModelTypes.SIDECAR_COLLECTOR_V1, collector.name(), false);
    assertThat(nativeEntity.descriptor()).isEqualTo(expectedDescriptor);
    assertThat(nativeEntity.entity()).isEqualTo(collector);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) Collector(org.graylog.plugins.sidecar.rest.models.Collector) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) Test(org.junit.Test)

Example 24 with NativeEntity

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

the class SidecarCollectorFacadeTest method findExisting.

@Test
@MongoDBFixtures("SidecarCollectorFacadeTest.json")
public void findExisting() {
    final Entity entity = EntityV1.builder().id(ModelId.of("0")).type(ModelTypes.SIDECAR_COLLECTOR_V1).data(objectMapper.convertValue(SidecarCollectorEntity.create(ValueReference.of("filebeat"), ValueReference.of("exec"), ValueReference.of("linux"), ValueReference.of("/usr/lib/graylog-sidecar/filebeat"), ValueReference.of("-c %s"), ValueReference.of("test config -c %s"), ValueReference.of("")), JsonNode.class)).build();
    final NativeEntity<Collector> existingCollector = facade.findExisting(entity, Collections.emptyMap()).orElseThrow(AssertionError::new);
    final Collector collector = collectorService.findByName("filebeat");
    assertThat(collector).isNotNull();
    final NativeEntityDescriptor expectedDescriptor = NativeEntityDescriptor.create(entity.id(), collector.id(), ModelTypes.SIDECAR_COLLECTOR_V1, collector.name(), false);
    assertThat(existingCollector.descriptor()).isEqualTo(expectedDescriptor);
    assertThat(existingCollector.entity()).isEqualTo(collector);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) Collector(org.graylog.plugins.sidecar.rest.models.Collector) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 25 with NativeEntity

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

the class ViewFacadeTest method itShouldCreateADTOFromAnEntity.

@Test
@MongoDBFixtures("ViewFacadeTest.json")
public void itShouldCreateADTOFromAnEntity() throws Exception {
    final StreamImpl stream = new StreamImpl(Collections.emptyMap());
    final Entity viewEntity = createViewEntity();
    final Map<EntityDescriptor, Object> nativeEntities = new HashMap<>(1);
    nativeEntities.put(EntityDescriptor.create(newStreamId, ModelTypes.STREAM_V1), stream);
    final UserImpl fakeUser = new UserImpl(mock(PasswordAlgorithmFactory.class), new Permissions(ImmutableSet.of()), ImmutableMap.of("username", "testuser"));
    when(userService.load("testuser")).thenReturn(fakeUser);
    final NativeEntity<ViewDTO> nativeEntity = facade.createNativeEntity(viewEntity, Collections.emptyMap(), nativeEntities, "testuser");
    assertThat(nativeEntity.descriptor().title()).isEqualTo("title");
    assertThat(nativeEntity.descriptor().type()).isEqualTo(ModelTypes.SEARCH_V1);
    Optional<ViewDTO> resultedView = viewService.get(nativeEntity.descriptor().id().id());
    assertThat(resultedView).isPresent();
    Optional<Search> search = searchDbService.get(resultedView.get().searchId());
    assertThat(search).isPresent();
    final Query query = search.get().queries().iterator().next();
    assertThat(query.filter()).isNotNull();
    assertThat(query.filter().filters()).isNotEmpty();
    final StreamFilter streamFilter = (StreamFilter) query.filter().filters().iterator().next();
    assertThat(streamFilter.streamId()).doesNotMatch(newStreamId);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) PivotEntity(org.graylog2.contentpacks.model.entities.PivotEntity) QueryEntity(org.graylog2.contentpacks.model.entities.QueryEntity) EventListEntity(org.graylog2.contentpacks.model.entities.EventListEntity) ViewEntity(org.graylog2.contentpacks.model.entities.ViewEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) SearchEntity(org.graylog2.contentpacks.model.entities.SearchEntity) ViewStateEntity(org.graylog2.contentpacks.model.entities.ViewStateEntity) StreamEntity(org.graylog2.contentpacks.model.entities.StreamEntity) MessageListEntity(org.graylog2.contentpacks.model.entities.MessageListEntity) Query(org.graylog.plugins.views.search.Query) HashMap(java.util.HashMap) StreamFilter(org.graylog.plugins.views.search.filter.StreamFilter) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) ViewDTO(org.graylog.plugins.views.search.views.ViewDTO) PasswordAlgorithmFactory(org.graylog2.security.PasswordAlgorithmFactory) StreamImpl(org.graylog2.streams.StreamImpl) Search(org.graylog.plugins.views.search.Search) UserImpl(org.graylog2.users.UserImpl) Permissions(org.graylog2.shared.security.Permissions) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)30 Entity (org.graylog2.contentpacks.model.entities.Entity)28 Test (org.junit.Test)26 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)15 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)14 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)12 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)7 LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)7 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)7 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)7 HashMap (java.util.HashMap)6 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)6 CacheDto (org.graylog2.lookup.dto.CacheDto)6 Map (java.util.Map)5 RuleDao (org.graylog.plugins.pipelineprocessor.db.RuleDao)5 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)5 DataAdapterDto (org.graylog2.lookup.dto.DataAdapterDto)5 Graph (com.google.common.graph.Graph)4 GraphBuilder (com.google.common.graph.GraphBuilder)4 ImmutableGraph (com.google.common.graph.ImmutableGraph)4