use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method findExisting.
@Test
public void findExisting() throws ValidationException {
final GrokPattern grokPattern = grokPatternService.save(GrokPattern.create("Test", "[a-z]+"));
final Entity grokPatternEntity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("Test", "[a-z]+"), JsonNode.class)).build();
final Optional<NativeEntity<GrokPattern>> existingGrokPattern = facade.findExisting(grokPatternEntity, Collections.emptyMap());
final NativeEntityDescriptor expectedDescriptor = NativeEntityDescriptor.create(grokPatternEntity.id(), "1", ModelTypes.GROK_PATTERN_V1, grokPattern.name(), false);
assertThat(existingGrokPattern).isPresent().get().satisfies(nativeEntity -> {
assertThat(nativeEntity.descriptor()).isEqualTo(expectedDescriptor);
assertThat(nativeEntity.entity()).isEqualTo(grokPattern);
});
}
use of org.graylog2.contentpacks.model.entities.EntityV1 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.EntityV1 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"));
}
use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class LookupCacheFacadeTest method createNativeEntity.
@Test
public void createNativeEntity() {
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();
assertThat(cacheService.findAll()).isEmpty();
final NativeEntity<CacheDto> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), Collections.emptyMap(), "username");
final NativeEntityDescriptor descriptor = nativeEntity.descriptor();
final CacheDto cacheDto = nativeEntity.entity();
assertThat(nativeEntity.descriptor().id()).isNotNull();
assertThat(descriptor.type()).isEqualTo(ModelTypes.LOOKUP_CACHE_V1);
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");
assertThat(cacheService.findAll()).hasSize(1);
}
use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class LookupCacheFacadeTest method exportNativeEntity.
@Test
public void exportNativeEntity() {
final CacheDto cacheDto = CacheDto.builder().id("1234567890").name("cache-name").title("Cache Title").description("Cache Description").config(new FallbackCacheConfig()).build();
final EntityDescriptor descriptor = EntityDescriptor.create(cacheDto.id(), ModelTypes.LOOKUP_CACHE_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Entity entity = facade.exportNativeEntity(cacheDto, entityDescriptorIds);
assertThat(entity).isInstanceOf(EntityV1.class);
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.LOOKUP_CACHE_V1);
final EntityV1 entityV1 = (EntityV1) entity;
final LookupCacheEntity lookupCacheEntity = objectMapper.convertValue(entityV1.data(), LookupCacheEntity.class);
assertThat(lookupCacheEntity.name()).isEqualTo(ValueReference.of("cache-name"));
assertThat(lookupCacheEntity.title()).isEqualTo(ValueReference.of("Cache Title"));
assertThat(lookupCacheEntity.description()).isEqualTo(ValueReference.of("Cache Description"));
assertThat(lookupCacheEntity.configuration()).containsEntry("type", ValueReference.of("FallbackCacheConfig"));
}
Aggregations