use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method createNativeEntity.
@Test
public void createNativeEntity() throws NotFoundException {
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 NativeEntity<GrokPattern> nativeEntity = facade.createNativeEntity(grokPatternEntity, Collections.emptyMap(), Collections.emptyMap(), "admin");
final GrokPattern expectedGrokPattern = GrokPattern.create("1", "Test", "[a-z]+", null);
final NativeEntityDescriptor expectedDescriptor = NativeEntityDescriptor.create("1", "1", ModelTypes.GROK_PATTERN_V1, "Test");
assertThat(nativeEntity.descriptor().title()).isEqualTo(expectedDescriptor.title());
assertThat(nativeEntity.descriptor().type()).isEqualTo(expectedDescriptor.type());
assertThat(nativeEntity.entity()).isEqualTo(expectedGrokPattern);
assertThat(grokPatternService.load("1")).isEqualTo(expectedGrokPattern);
}
use of org.graylog2.contentpacks.model.entities.NativeEntity 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.NativeEntity 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.NativeEntity 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");
}
use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.
the class LookupTableFacadeTest method createNativeEntity.
@Test
public void createNativeEntity() {
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("no-op-cache"), ValueReference.of("http-dsv"), ValueReference.of("Default single value"), ValueReference.of(LookupDefaultValue.Type.STRING), ValueReference.of("Default multi value"), ValueReference.of(LookupDefaultValue.Type.OBJECT)), JsonNode.class)).build();
final EntityDescriptor cacheDescriptor = EntityDescriptor.create("no-op-cache", ModelTypes.LOOKUP_CACHE_V1);
final CacheDto cacheDto = CacheDto.builder().id("5adf24b24b900a0fdb4e0001").name("no-op-cache").title("No-op cache").description("No-op cache").config(new FallbackCacheConfig()).build();
final EntityDescriptor dataAdapterDescriptor = EntityDescriptor.create("http-dsv", ModelTypes.LOOKUP_ADAPTER_V1);
final DataAdapterDto dataAdapterDto = DataAdapterDto.builder().id("5adf24a04b900a0fdb4e0002").name("http-dsv").title("HTTP DSV").description("HTTP DSV").config(new FallbackAdapterConfig()).build();
final Map<EntityDescriptor, Object> nativeEntities = ImmutableMap.of(cacheDescriptor, cacheDto, dataAdapterDescriptor, dataAdapterDto);
assertThat(lookupTableService.findAll()).isEmpty();
final NativeEntity<LookupTableDto> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), nativeEntities, "username");
assertThat(nativeEntity.descriptor().type()).isEqualTo(ModelTypes.LOOKUP_TABLE_V1);
assertThat(nativeEntity.entity().name()).isEqualTo("http-dsv-no-cache");
assertThat(nativeEntity.entity().title()).isEqualTo("HTTP DSV without Cache");
assertThat(nativeEntity.entity().description()).isEqualTo("HTTP DSV without Cache");
assertThat(nativeEntity.entity().cacheId()).isEqualTo("5adf24b24b900a0fdb4e0001");
assertThat(nativeEntity.entity().dataAdapterId()).isEqualTo("5adf24a04b900a0fdb4e0002");
assertThat(nativeEntity.entity().defaultSingleValue()).isEqualTo("Default single value");
assertThat(nativeEntity.entity().defaultSingleValueType()).isEqualTo(LookupDefaultValue.Type.STRING);
assertThat(nativeEntity.entity().defaultMultiValue()).isEqualTo("Default multi value");
assertThat(nativeEntity.entity().defaultMultiValueType()).isEqualTo(LookupDefaultValue.Type.OBJECT);
assertThat(lookupTableService.findAll()).hasSize(1);
}
Aggregations