Search in sources :

Example 31 with MongoDBFixtures

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

Example 32 with MongoDBFixtures

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

the class LookupCacheFacadeTest method resolveEntityDescriptor.

@Test
@MongoDBFixtures("LookupCacheFacadeTest.json")
public void resolveEntityDescriptor() {
    final EntityDescriptor descriptor = EntityDescriptor.create("5adf24b24b900a0fdb4e52dd", ModelTypes.LOOKUP_CACHE_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 33 with MongoDBFixtures

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

the class LookupCacheFacadeTest method findExisting.

@Test
@MongoDBFixtures("LookupCacheFacadeTest.json")
public void findExisting() {
    final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.LOOKUP_CACHE_V1).data(objectMapper.convertValue(LookupCacheEntity.create(ValueReference.of("no-op-cache"), ValueReference.of("No-op cache"), ValueReference.of("No-op cache"), ReferenceMapUtils.toReferenceMap(ImmutableMap.of("type", "none"))), JsonNode.class)).build();
    final NativeEntity<CacheDto> existingCache = facade.findExisting(entity, Collections.emptyMap()).orElseThrow(AssertionError::new);
    final NativeEntityDescriptor descriptor = existingCache.descriptor();
    final CacheDto cacheDto = existingCache.entity();
    assertThat(descriptor.id()).isEqualTo(ModelId.of("5adf24b24b900a0fdb4e52dd"));
    assertThat(descriptor.type()).isEqualTo(ModelTypes.LOOKUP_CACHE_V1);
    assertThat(cacheDto.id()).isEqualTo("5adf24b24b900a0fdb4e52dd");
    assertThat(cacheDto.name()).isEqualTo("no-op-cache");
    assertThat(cacheDto.title()).isEqualTo("No-op cache");
    assertThat(cacheDto.description()).isEqualTo("No-op cache");
    assertThat(cacheDto.config().type()).isEqualTo("none");
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) CacheDto(org.graylog2.lookup.dto.CacheDto) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 34 with MongoDBFixtures

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

the class LookupCacheFacadeTest method resolveEntity.

@Test
@MongoDBFixtures("LookupCacheFacadeTest.json")
public void resolveEntity() {
    final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.LOOKUP_CACHE_V1).data(objectMapper.convertValue(LookupCacheEntity.create(ValueReference.of("no-op-cache"), ValueReference.of("No-op cache"), ValueReference.of("No-op cache"), ReferenceMapUtils.toReferenceMap(ImmutableMap.of("type", "none"))), 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) LookupCacheEntity(org.graylog2.contentpacks.model.entities.LookupCacheEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 35 with MongoDBFixtures

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

the class LookupCacheFacadeTest method listEntityExcerpts.

@Test
@MongoDBFixtures("LookupCacheFacadeTest.json")
public void listEntityExcerpts() {
    final EntityExcerpt expectedEntityExcerpt = EntityExcerpt.builder().id(ModelId.of("5adf24b24b900a0fdb4e52dd")).type(ModelTypes.LOOKUP_CACHE_V1).title("No-op cache").build();
    final Set<EntityExcerpt> entityExcerpts = facade.listEntityExcerpts();
    assertThat(entityExcerpts).containsOnly(expectedEntityExcerpt);
}
Also used : EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) 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