Search in sources :

Example 11 with ContentPackInstallation

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

the class ContentPackInstallationPersistenceServiceTest method insert.

@Test
public void insert() {
    final ContentPackInstallation contentPackInstallation = ContentPackInstallation.builder().contentPackId(ModelId.of("content-pack-id")).contentPackRevision(1).parameters(ImmutableMap.of()).entities(ImmutableSet.of()).comment("Comment").createdAt(ZonedDateTime.of(2018, 7, 16, 14, 0, 0, 0, ZoneOffset.UTC).toInstant()).createdBy("username").build();
    final ContentPackInstallation savedContentPack = persistenceService.insert(contentPackInstallation);
    assertThat(savedContentPack.id()).isNotNull();
    assertThat(savedContentPack).isEqualToIgnoringGivenFields(contentPackInstallation, "id");
}
Also used : ContentPackInstallation(org.graylog2.contentpacks.model.ContentPackInstallation) Test(org.junit.Test)

Example 12 with ContentPackInstallation

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

the class ContentPackInstallationPersistenceServiceTest method deleteById.

@Test
@MongoDBFixtures("ContentPackInstallationPersistenceServiceTest.json")
public void deleteById() {
    final ObjectId objectId = new ObjectId("5b4c935b4b900a0000000001");
    final int deletedContentPacks = persistenceService.deleteById(objectId);
    final Set<ContentPackInstallation> contentPacks = persistenceService.loadAll();
    assertThat(deletedContentPacks).isEqualTo(1);
    assertThat(contentPacks).hasSize(3).noneSatisfy(contentPack -> assertThat(contentPack.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 13 with ContentPackInstallation

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

the class ContentPackServiceTest method getUninstallDetails.

@Test
public void getUninstallDetails() throws NotFoundException {
    /* Test will be uninstalled */
    when(contentPackInstallService.countInstallationOfEntityById(ModelId.of("dead-beef1"))).thenReturn((long) 1);
    ContentPackUninstallDetails expect = ContentPackUninstallDetails.create(nativeEntityDescriptors);
    ContentPackUninstallDetails result = contentPackService.getUninstallDetails(contentPack, contentPackInstallation);
    assertThat(result).isEqualTo(expect);
    /* Test nothing will be uninstalled */
    when(contentPackInstallService.countInstallationOfEntityById(ModelId.of("dead-beef1"))).thenReturn((long) 2);
    ContentPackUninstallDetails expectNon = ContentPackUninstallDetails.create(ImmutableSet.of());
    ContentPackUninstallDetails resultNon = contentPackService.getUninstallDetails(contentPack, contentPackInstallation);
    assertThat(resultNon).isEqualTo(expectNon);
}
Also used : ContentPackUninstallDetails(org.graylog2.contentpacks.model.ContentPackUninstallDetails) Test(org.junit.Test)

Example 14 with ContentPackInstallation

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

the class ContentPackServiceTest method uninstallContentPack.

@Test
public void uninstallContentPack() throws NotFoundException {
    /* Test successful uninstall */
    when(patternService.load("dead-beef1")).thenReturn(grokPattern);
    ContentPackUninstallation expectSuccess = ContentPackUninstallation.builder().skippedEntities(ImmutableSet.of()).failedEntities(ImmutableSet.of()).entities(nativeEntityDescriptors).build();
    ContentPackUninstallation resultSuccess = contentPackService.uninstallContentPack(contentPack, contentPackInstallation);
    assertThat(resultSuccess).isEqualTo(expectSuccess);
    /* Test skipped uninstall */
    when(contentPackInstallService.countInstallationOfEntityById(ModelId.of("dead-beef1"))).thenReturn((long) 2);
    ContentPackUninstallation expectSkip = ContentPackUninstallation.builder().skippedEntities(nativeEntityDescriptors).failedEntities(ImmutableSet.of()).entities(ImmutableSet.of()).build();
    ContentPackUninstallation resultSkip = contentPackService.uninstallContentPack(contentPack, contentPackInstallation);
    assertThat(resultSkip).isEqualTo(expectSkip);
    /* Test skipped uninstall */
    when(contentPackInstallService.countInstallationOfEntityById(ModelId.of("dead-beef1"))).thenReturn((long) 1);
    when(contentPackInstallService.countInstallationOfEntityByIdAndFoundOnSystem(ModelId.of("dead-beef1"))).thenReturn((long) 1);
    ContentPackUninstallation expectSkip2 = ContentPackUninstallation.builder().skippedEntities(nativeEntityDescriptors).failedEntities(ImmutableSet.of()).entities(ImmutableSet.of()).build();
    ContentPackUninstallation resultSkip2 = contentPackService.uninstallContentPack(contentPack, contentPackInstallation);
    assertThat(resultSkip2).isEqualTo(expectSkip2);
    /* Test not found while uninstall */
    when(contentPackInstallService.countInstallationOfEntityById(ModelId.of("dead-beef1"))).thenReturn((long) 1);
    when(contentPackInstallService.countInstallationOfEntityByIdAndFoundOnSystem(ModelId.of("dead-beef1"))).thenReturn((long) 0);
    when(patternService.load("dead-beef1")).thenThrow(new NotFoundException("Not found."));
    ContentPackUninstallation expectFailure = ContentPackUninstallation.builder().skippedEntities(ImmutableSet.of()).failedEntities(ImmutableSet.of()).entities(ImmutableSet.of()).build();
    ContentPackUninstallation resultFailure = contentPackService.uninstallContentPack(contentPack, contentPackInstallation);
    assertThat(resultFailure).isEqualTo(expectFailure);
}
Also used : ContentPackUninstallation(org.graylog2.contentpacks.model.ContentPackUninstallation) NotFoundException(org.graylog2.database.NotFoundException) Test(org.junit.Test)

Example 15 with ContentPackInstallation

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

the class V20191219090834_AddSourcesPageTest method upgradeSuccessfully.

@Test
public void upgradeSuccessfully() throws IOException {
    final URL contentPackURL = V20191219090834_AddSourcesPage.class.getResource("V20191219090834_AddSourcesPage_Content_Pack.json");
    final ContentPack contentPack = ContentPackV1.builder().id(ModelId.of("04fcf179-49e0-4e8f-9c02-0ff13062efbe")).summary("summary").revision(1).name("Sources Page").description("description").vendor("").url(URI.create("http://graylog.com")).entities(ImmutableSet.of()).build();
    final ContentPackInstallation contentPackInstallation = ContentPackInstallation.builder().contentPackId(contentPack.id()).contentPackRevision(1).parameters(ImmutableMap.of()).entities(ImmutableSet.of()).comment("Comment").createdAt(Instant.now()).createdBy("admin").build();
    when(configService.get(V20191219090834_AddSourcesPage.MigrationCompleted.class)).thenReturn(null);
    when(contentPackPersistenceService.insert(contentPack)).thenReturn(Optional.ofNullable(contentPack));
    when(contentPackService.installContentPack(contentPack, Collections.emptyMap(), "Add Sources Page", "admin")).thenReturn(contentPackInstallation);
    when(objectMapper.readValue(contentPackURL, ContentPack.class)).thenReturn(contentPack);
    migration.upgrade();
    verify(contentPackService).installContentPack(contentPack, Collections.emptyMap(), "Add Sources Page", "admin");
    verify(configService).write(V20191219090834_AddSourcesPage.MigrationCompleted.create("04fcf179-49e0-4e8f-9c02-0ff13062efbe"));
}
Also used : ContentPackInstallation(org.graylog2.contentpacks.model.ContentPackInstallation) ContentPack(org.graylog2.contentpacks.model.ContentPack) URL(java.net.URL) Test(org.junit.Test)

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