Search in sources :

Example 6 with ContentPackInstallation

use of org.graylog2.contentpacks.model.ContentPackInstallation 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 7 with ContentPackInstallation

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

the class ContentPackInstallationPersistenceServiceTest method deleteByIdWithInvalidId.

@Test
@MongoDBFixtures("ContentPackInstallationPersistenceServiceTest.json")
public void deleteByIdWithInvalidId() {
    final int deletedContentPacks = persistenceService.deleteById(new ObjectId("0000000000000000deadbeef"));
    final Set<ContentPackInstallation> contentPacks = persistenceService.loadAll();
    assertThat(deletedContentPacks).isEqualTo(0);
    assertThat(contentPacks).hasSize(4);
}
Also used : ContentPackInstallation(org.graylog2.contentpacks.model.ContentPackInstallation) ObjectId(org.bson.types.ObjectId) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 8 with ContentPackInstallation

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

the class ContentPackInstallationPersistenceServiceTest method findById.

@Test
@MongoDBFixtures("ContentPackInstallationPersistenceServiceTest.json")
public void findById() {
    final ObjectId objectId = new ObjectId("5b4c935b4b900a0000000001");
    final Optional<ContentPackInstallation> contentPacks = persistenceService.findById(objectId);
    assertThat(contentPacks).isPresent().get().satisfies(contentPackInstallation -> assertThat(contentPackInstallation.id()).isEqualTo(objectId));
}
Also used : ContentPackInstallation(org.graylog2.contentpacks.model.ContentPackInstallation) ObjectId(org.bson.types.ObjectId) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 9 with ContentPackInstallation

use of org.graylog2.contentpacks.model.ContentPackInstallation 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 10 with ContentPackInstallation

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

the class ContentPackServiceTest method setUp.

@Before
public void setUp() throws Exception {
    final ContentPackInstallationPersistenceService contentPackInstallationPersistenceService = contentPackInstallService;
    final Set<ConstraintChecker> constraintCheckers = Collections.emptySet();
    pluginMetaData = new HashSet<>();
    outputFactories = new HashMap<>();
    outputFactories2 = new HashMap<>();
    final Map<ModelType, EntityWithExcerptFacade<?, ?>> entityFacades = ImmutableMap.of(ModelTypes.GROK_PATTERN_V1, new GrokPatternFacade(objectMapper, patternService), ModelTypes.STREAM_V1, new StreamFacade(objectMapper, streamService, streamRuleService, alertService, alarmCallbackConfigurationService, legacyAlertConditionMigration, indexSetService, userService), ModelTypes.OUTPUT_V1, new OutputFacade(objectMapper, outputService, pluginMetaData, outputFactories, outputFactories2));
    contentPackService = new ContentPackService(contentPackInstallationPersistenceService, constraintCheckers, entityFacades);
    Map<String, String> entityData = new HashMap<>(2);
    entityData.put("name", "NAME");
    entityData.put("pattern", "\\w");
    grokPattern = GrokPattern.builder().pattern("\\w").name("NAME").build();
    JsonNode jsonData = objectMapper.convertValue(entityData, JsonNode.class);
    EntityV1 entityV1 = EntityV1.builder().id(ModelId.of("12345")).type(ModelTypes.GROK_PATTERN_V1).data(jsonData).build();
    ImmutableSet<Entity> entities = ImmutableSet.of(entityV1);
    NativeEntityDescriptor nativeEntityDescriptor = NativeEntityDescriptor.create(ModelId.of("12345"), "dead-beef1", ModelTypes.GROK_PATTERN_V1, "NAME");
    nativeEntityDescriptors = ImmutableSet.of(nativeEntityDescriptor);
    contentPack = ContentPackV1.builder().description("test").entities(entities).name("test").revision(1).summary("").vendor("").url(URI.create("http://graylog.com")).id(ModelId.of("dead-beef")).build();
    contentPackInstallation = ContentPackInstallation.builder().contentPackId(ModelId.of("dead-beef")).contentPackRevision(1).entities(nativeEntityDescriptors).comment("Installed").parameters(ImmutableMap.copyOf(Collections.emptyMap())).createdAt(Instant.now()).createdBy("me").build();
}
Also used : Entity(org.graylog2.contentpacks.model.entities.Entity) StreamFacade(org.graylog2.contentpacks.facades.StreamFacade) HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityWithExcerptFacade(org.graylog2.contentpacks.facades.EntityWithExcerptFacade) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) ModelType(org.graylog2.contentpacks.model.ModelType) ConstraintChecker(org.graylog2.contentpacks.constraints.ConstraintChecker) GrokPatternFacade(org.graylog2.contentpacks.facades.GrokPatternFacade) OutputFacade(org.graylog2.contentpacks.facades.OutputFacade) Before(org.junit.Before)

Aggregations

ContentPackInstallation (org.graylog2.contentpacks.model.ContentPackInstallation)17 Test (org.junit.Test)11 ObjectId (org.bson.types.ObjectId)8 ContentPack (org.graylog2.contentpacks.model.ContentPack)7 HashMap (java.util.HashMap)6 ModelId (org.graylog2.contentpacks.model.ModelId)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)5 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)5 Map (java.util.Map)4 Optional (java.util.Optional)4 Set (java.util.Set)4 EntityWithExcerptFacade (org.graylog2.contentpacks.facades.EntityWithExcerptFacade)4 ContentPackUninstallation (org.graylog2.contentpacks.model.ContentPackUninstallation)4 Entity (org.graylog2.contentpacks.model.entities.Entity)4 Timed (com.codahale.metrics.annotation.Timed)3 JsonView (com.fasterxml.jackson.annotation.JsonView)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3