Search in sources :

Example 16 with ModelId

use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.

the class InputFacadeTest method exportEntity.

@Test
@MongoDBFixtures("InputFacadeTest.json")
public void exportEntity() {
    final ModelId id = ModelId.of("5acc84f84b900a4ff290d9a7");
    final EntityDescriptor descriptor = EntityDescriptor.create(id, ModelTypes.INPUT_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportEntity(descriptor, entityDescriptorIds).orElseThrow(AssertionError::new);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.INPUT_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final InputEntity inputEntity = objectMapper.convertValue(entityV1.data(), InputEntity.class);
    assertThat(inputEntity.title()).isEqualTo(ValueReference.of("Local Raw UDP"));
    assertThat(inputEntity.type()).isEqualTo(ValueReference.of("org.graylog2.inputs.raw.udp.RawUDPInput"));
    assertThat(inputEntity.global()).isEqualTo(ValueReference.of(false));
    assertThat(inputEntity.configuration()).containsEntry("bind_address", ValueReference.of("127.0.0.1")).containsEntry("port", ValueReference.of(5555));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) ConverterEntity(org.graylog2.contentpacks.model.entities.ConverterEntity) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) ModelId(org.graylog2.contentpacks.model.ModelId) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 17 with ModelId

use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.

the class ContentPackInstallationPersistenceServiceTest method findByContentPackId.

@Test
@MongoDBFixtures("ContentPackInstallationPersistenceServiceTest.json")
public void findByContentPackId() {
    final ModelId id = ModelId.of("4e3d7025-881e-6870-da03-cafebabe0001");
    final Set<ContentPackInstallation> contentPacks = persistenceService.findByContentPackId(id);
    assertThat(contentPacks).hasSize(2).allSatisfy(contentPackInstallation -> assertThat(contentPackInstallation.contentPackId()).isEqualTo(id)).anySatisfy(contentPackInstallation -> assertThat(contentPackInstallation.id()).isEqualTo(new ObjectId("5b4c935b4b900a0000000001"))).anySatisfy(contentPackInstallation -> assertThat(contentPackInstallation.id()).isEqualTo(new ObjectId("5b4c935b4b900a0000000002")));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ModelId(org.graylog2.contentpacks.model.ModelId) ImmutableMap(com.google.common.collect.ImmutableMap) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) ContentPackInstallation(org.graylog2.contentpacks.model.ContentPackInstallation) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) Set(java.util.Set) Test(org.junit.Test) Rule(org.junit.Rule) MongoDBInstance(org.graylog.testing.mongodb.MongoDBInstance) ObjectId(org.bson.types.ObjectId) Optional(java.util.Optional) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) ZoneOffset(java.time.ZoneOffset) Before(org.junit.Before) ContentPackInstallation(org.graylog2.contentpacks.model.ContentPackInstallation) ObjectId(org.bson.types.ObjectId) ModelId(org.graylog2.contentpacks.model.ModelId) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 18 with ModelId

use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.

the class ContentPackInstallationPersistenceServiceTest method findByContentPackIdAndRevision.

@Test
@MongoDBFixtures("ContentPackInstallationPersistenceServiceTest.json")
public void findByContentPackIdAndRevision() {
    final ModelId id = ModelId.of("4e3d7025-881e-6870-da03-cafebabe0001");
    final Set<ContentPackInstallation> contentPack = persistenceService.findByContentPackIdAndRevision(id, 1);
    assertThat(contentPack).hasSize(1).anySatisfy(c -> assertThat(c.contentPackId()).isEqualTo(id));
}
Also used : ContentPackInstallation(org.graylog2.contentpacks.model.ContentPackInstallation) ModelId(org.graylog2.contentpacks.model.ModelId) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 19 with ModelId

use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.

the class ContentPackResourceTest method notDeleteContentPack.

@Test
public void notDeleteContentPack() throws Exception {
    final ModelId id = ModelId.of("1");
    when(contentPackInstallations.size()).thenReturn(1);
    when(contentPackInstallationPersistenceService.findByContentPackId(id)).thenReturn(contentPackInstallations);
    boolean exceptionCalled = false;
    try {
        contentPackResource.deleteContentPack(id);
    } catch (BadRequestException e) {
        exceptionCalled = true;
    }
    assertThat(exceptionCalled).isEqualTo(true);
    verify(contentPackInstallationPersistenceService, times(1)).findByContentPackId(id);
    verify(contentPackPersistenceService, times(0)).deleteById(id);
    when(contentPackInstallations.size()).thenReturn(1);
    when(contentPackInstallationPersistenceService.findByContentPackIdAndRevision(id, 1)).thenReturn(contentPackInstallations);
    exceptionCalled = false;
    try {
        contentPackResource.deleteContentPack(id, 1);
    } catch (BadRequestException e) {
        exceptionCalled = true;
    }
    assertThat(exceptionCalled).isEqualTo(true);
    verify(contentPackInstallationPersistenceService, times(1)).findByContentPackIdAndRevision(id, 1);
    verify(contentPackPersistenceService, times(0)).deleteByIdAndRevision(id, 1);
}
Also used : BadRequestException(javax.ws.rs.BadRequestException) ModelId(org.graylog2.contentpacks.model.ModelId) Test(org.junit.Test)

Example 20 with ModelId

use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.

the class ContentPackResourceTest method getContentPack.

@Test
public void getContentPack() throws Exception {
    final ContentPack contentPack = objectMapper.readValue(CONTENT_PACK, ContentPack.class);
    final Set<ContentPack> contentPackSet = Collections.singleton(contentPack);
    final Set<ConstraintCheckResult> constraints = Collections.emptySet();
    final Map<Integer, ContentPack> contentPacks = Collections.singletonMap(1, contentPack);
    final Map<Integer, Set<ConstraintCheckResult>> constraintMap = Collections.singletonMap(1, constraints);
    final ContentPackRevisions expectedRevisions = ContentPackRevisions.create(contentPacks, constraintMap);
    final ModelId id = ModelId.of("1");
    when(contentPackPersistenceService.findAllById(id)).thenReturn(contentPackSet);
    final ContentPackRevisions contentPackRevisions = contentPackResource.listContentPackRevisions(id);
    verify(contentPackPersistenceService, times(1)).findAllById(id);
    assertThat(contentPackRevisions).isEqualTo(expectedRevisions);
    when(contentPackPersistenceService.findByIdAndRevision(id, 1)).thenReturn(Optional.ofNullable(contentPack));
    final ContentPackResponse contentPackResponse = contentPackResource.getContentPackRevisions(id, 1);
    verify(contentPackPersistenceService, times(1)).findByIdAndRevision(id, 1);
    assertThat(contentPackResponse.contentPack()).isEqualTo(contentPack);
}
Also used : ConstraintCheckResult(org.graylog2.contentpacks.model.constraints.ConstraintCheckResult) Set(java.util.Set) ContentPackRevisions(org.graylog2.rest.models.system.contentpacks.responses.ContentPackRevisions) ContentPack(org.graylog2.contentpacks.model.ContentPack) ContentPackResponse(org.graylog2.rest.models.system.contentpacks.responses.ContentPackResponse) ModelId(org.graylog2.contentpacks.model.ModelId) Test(org.junit.Test)

Aggregations

ModelId (org.graylog2.contentpacks.model.ModelId)31 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)16 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)16 Entity (org.graylog2.contentpacks.model.entities.Entity)11 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)11 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)11 Map (java.util.Map)10 Set (java.util.Set)10 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)10 Test (org.junit.Test)10 Optional (java.util.Optional)9 ContentPack (org.graylog2.contentpacks.model.ContentPack)9 Collectors (java.util.stream.Collectors)8 Inject (javax.inject.Inject)8 ContentPackInstallation (org.graylog2.contentpacks.model.ContentPackInstallation)8 NotFoundException (org.graylog2.database.NotFoundException)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 Graph (com.google.common.graph.Graph)7 GraphBuilder (com.google.common.graph.GraphBuilder)7