use of org.graylog2.lookup.dto.DataAdapterDto in project graylog2-server by Graylog2.
the class LookupDataAdapterFacadeTest method exportNativeEntity.
@Test
public void exportNativeEntity() {
final DataAdapterDto dataAdapterDto = DataAdapterDto.builder().id("1234567890").name("data-adapter-name").title("Data Adapter Title").description("Data Adapter Description").config(new FallbackAdapterConfig()).build();
final EntityDescriptor descriptor = EntityDescriptor.create(dataAdapterDto.id(), ModelTypes.LOOKUP_ADAPTER_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Entity entity = facade.exportNativeEntity(dataAdapterDto, entityDescriptorIds);
assertThat(entity).isInstanceOf(EntityV1.class);
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.LOOKUP_ADAPTER_V1);
final EntityV1 entityV1 = (EntityV1) entity;
final LookupDataAdapterEntity lookupDataAdapterEntity = objectMapper.convertValue(entityV1.data(), LookupDataAdapterEntity.class);
assertThat(lookupDataAdapterEntity.name()).isEqualTo(ValueReference.of("data-adapter-name"));
assertThat(lookupDataAdapterEntity.title()).isEqualTo(ValueReference.of("Data Adapter Title"));
assertThat(lookupDataAdapterEntity.description()).isEqualTo(ValueReference.of("Data Adapter Description"));
assertThat(lookupDataAdapterEntity.configuration()).containsEntry("type", ValueReference.of("FallbackAdapterConfig"));
}
use of org.graylog2.lookup.dto.DataAdapterDto in project graylog2-server by Graylog2.
the class V20191129134600_CreateInitialUrlWhitelistTest method createQuotedRegexEntry.
@Test
public void createQuotedRegexEntry() {
final HTTPJSONPathDataAdapter.Config config = mock(HTTPJSONPathDataAdapter.Config.class);
when(config.url()).thenReturn("https://www.graylog.com/${key}/test.json/${key}");
final DataAdapterDto dataAdapterDto = mock(DataAdapterDto.class);
when(dataAdapterDto.config()).thenReturn(config);
when(dataAdapterService.findAll()).thenReturn(Collections.singleton(dataAdapterDto));
migration.upgrade();
final ArgumentCaptor<UrlWhitelist> captor = ArgumentCaptor.forClass(UrlWhitelist.class);
verify(whitelistService).saveWhitelist(captor.capture());
final UrlWhitelist whitelist = captor.getValue();
final String whitelisted = "https://www.graylog.com/message/test.json/message";
final String notWhitelisted = "https://wwwXgraylogXcom/message/testXjson/messsage";
assertThat(whitelist.isWhitelisted(whitelisted)).withFailMessage("Whitelist " + whitelist + " is expected to consider url <" + whitelisted + "> whitelisted.").isTrue();
assertThat(whitelist.isWhitelisted(notWhitelisted)).withFailMessage("Whitelist " + whitelist + " is expected to consider url <" + notWhitelisted + "> not whitelisted.").isFalse();
assertThat(whitelist.entries().size()).isEqualTo(1);
assertThat(whitelist.entries().get(0).value()).isEqualTo("^\\Qhttps://www.graylog.com/\\E.*?\\Q/test.json/\\E.*?$");
}
use of org.graylog2.lookup.dto.DataAdapterDto in project graylog2-server by Graylog2.
the class LookupDataAdapterFacadeTest method createExcerpt.
@Test
public void createExcerpt() {
final DataAdapterDto dataAdapterDto = DataAdapterDto.builder().id("1234567890").name("data-adapter-name").title("Data Adapter Title").description("Data Adapter Description").config(new FallbackAdapterConfig()).build();
final EntityExcerpt excerpt = facade.createExcerpt(dataAdapterDto);
assertThat(excerpt.id()).isEqualTo(ModelId.of("1234567890"));
assertThat(excerpt.type()).isEqualTo(ModelTypes.LOOKUP_ADAPTER_V1);
assertThat(excerpt.title()).isEqualTo("Data Adapter Title");
}
use of org.graylog2.lookup.dto.DataAdapterDto in project graylog2-server by Graylog2.
the class LookupDataAdapterFacadeTest method findExistingWithNoExistingEntity.
@Test
@MongoDBFixtures("LookupDataAdapterFacadeTest.json")
public void findExistingWithNoExistingEntity() {
final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.LOOKUP_ADAPTER_V1).data(objectMapper.convertValue(LookupDataAdapterEntity.create(ValueReference.of("some-name"), ValueReference.of("Some title"), ValueReference.of("Some description"), ReferenceMapUtils.toReferenceMap(Collections.emptyMap())), JsonNode.class)).build();
final Optional<NativeEntity<DataAdapterDto>> existingEntity = facade.findExisting(entity, Collections.emptyMap());
assertThat(existingEntity).isEmpty();
}
use of org.graylog2.lookup.dto.DataAdapterDto in project graylog2-server by Graylog2.
the class LookupDataAdapterFacadeTest method findExisting.
@Test
@MongoDBFixtures("LookupDataAdapterFacadeTest.json")
public void findExisting() {
final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.LOOKUP_ADAPTER_V1).data(objectMapper.convertValue(LookupDataAdapterEntity.create(ValueReference.of("http-dsv"), ValueReference.of("HTTP DSV"), ValueReference.of("HTTP DSV"), ReferenceMapUtils.toReferenceMap(Collections.emptyMap())), JsonNode.class)).build();
final NativeEntity<DataAdapterDto> nativeEntity = facade.findExisting(entity, Collections.emptyMap()).orElseThrow(AssertionError::new);
assertThat(nativeEntity.descriptor().id()).isEqualTo(ModelId.of("5adf24a04b900a0fdb4e52c8"));
assertThat(nativeEntity.descriptor().type()).isEqualTo(ModelTypes.LOOKUP_ADAPTER_V1);
assertThat(nativeEntity.entity().name()).isEqualTo("http-dsv");
assertThat(nativeEntity.entity().title()).isEqualTo("HTTP DSV");
assertThat(nativeEntity.entity().description()).isEqualTo("HTTP DSV");
}
Aggregations