Search in sources :

Example 46 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.

the class SidecarCollectorFacadeTest method resolveEntityDescriptor.

@Test
@MongoDBFixtures("SidecarCollectorFacadeTest.json")
public void resolveEntityDescriptor() {
    final EntityDescriptor descriptor = EntityDescriptor.create("5b4c920b4b900a0024af0001", ModelTypes.SIDECAR_COLLECTOR_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) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 47 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.

the class SidecarCollectorFacadeTest method resolveEntity.

@Test
@MongoDBFixtures("SidecarCollectorFacadeTest.json")
public void resolveEntity() {
    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 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) SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 48 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.

the class SidecarCollectorFacadeTest method exportEntity.

@Test
@MongoDBFixtures("SidecarCollectorFacadeTest.json")
public void exportEntity() {
    final EntityDescriptor descriptor = EntityDescriptor.create("5b4c920b4b900a0024af0001", ModelTypes.SIDECAR_COLLECTOR_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportEntity(descriptor, entityDescriptorIds).orElseThrow(AssertionError::new);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.SIDECAR_COLLECTOR_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final SidecarCollectorEntity collectorEntity = objectMapper.convertValue(entityV1.data(), SidecarCollectorEntity.class);
    assertThat(collectorEntity.name()).isEqualTo(ValueReference.of("filebeat"));
    assertThat(collectorEntity.serviceType()).isEqualTo(ValueReference.of("exec"));
    assertThat(collectorEntity.nodeOperatingSystem()).isEqualTo(ValueReference.of("linux"));
    assertThat(collectorEntity.executablePath()).isEqualTo(ValueReference.of("/usr/lib/graylog-sidecar/filebeat"));
    assertThat(collectorEntity.executeParameters()).isEqualTo(ValueReference.of("-c %s"));
    assertThat(collectorEntity.validationParameters()).isEqualTo(ValueReference.of("test config -c %s"));
    assertThat(collectorEntity.defaultTemplate()).isEqualTo(ValueReference.of(""));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) 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) SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 49 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures 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 50 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures 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

MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)167 Test (org.junit.Test)167 Entity (org.graylog2.contentpacks.model.entities.Entity)47 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)47 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)42 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)24 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)23 DateTime (org.joda.time.DateTime)17 ObjectId (org.bson.types.ObjectId)15 EntityExcerpt (org.graylog2.contentpacks.model.entities.EntityExcerpt)15 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)15 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)11 AbstractMap (java.util.AbstractMap)10 MigrationCompleted (org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.V20191203120602_MigrateSavedSearchesToViews.MigrationCompleted)10 LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)10 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)10 MongoDBServiceTest (org.graylog2.database.MongoDBServiceTest)10 GRN (org.graylog.grn.GRN)9 PipelineEntity (org.graylog2.contentpacks.model.entities.PipelineEntity)9 Document (org.bson.Document)8