Search in sources :

Example 11 with DataAdapterDto

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"));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) FallbackAdapterConfig(org.graylog2.plugin.lookup.FallbackAdapterConfig) Test(org.junit.Test)

Example 12 with DataAdapterDto

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.*?$");
}
Also used : DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) HTTPJSONPathDataAdapter(org.graylog2.lookup.adapters.HTTPJSONPathDataAdapter) UrlWhitelist(org.graylog2.system.urlwhitelist.UrlWhitelist) Test(org.junit.Test)

Example 13 with DataAdapterDto

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");
}
Also used : DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) FallbackAdapterConfig(org.graylog2.plugin.lookup.FallbackAdapterConfig) Test(org.junit.Test)

Example 14 with DataAdapterDto

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();
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 15 with DataAdapterDto

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");
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

DataAdapterDto (org.graylog2.lookup.dto.DataAdapterDto)17 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)8 Test (org.junit.Test)7 ApiOperation (io.swagger.annotations.ApiOperation)6 Path (javax.ws.rs.Path)6 Entity (org.graylog2.contentpacks.model.entities.Entity)5 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)5 BadRequestException (javax.ws.rs.BadRequestException)4 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)4 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)4 LookupTableDto (org.graylog2.lookup.dto.LookupTableDto)4 AuditEvent (org.graylog2.audit.jersey.AuditEvent)3 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)3 FallbackAdapterConfig (org.graylog2.plugin.lookup.FallbackAdapterConfig)3 LookupDataAdapter (org.graylog2.plugin.lookup.LookupDataAdapter)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)2