Search in sources :

Example 26 with ContentPack

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

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

ContentPack (org.graylog2.contentpacks.model.ContentPack)21 Test (org.junit.Test)11 ContentPackInstallation (org.graylog2.contentpacks.model.ContentPackInstallation)10 HashMap (java.util.HashMap)7 ContentPackV1 (org.graylog2.contentpacks.model.ContentPackV1)7 ModelId (org.graylog2.contentpacks.model.ModelId)7 Timed (com.codahale.metrics.annotation.Timed)6 JsonView (com.fasterxml.jackson.annotation.JsonView)6 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 URL (java.net.URL)5 Map (java.util.Map)5 NotFoundException (javax.ws.rs.NotFoundException)5 Path (javax.ws.rs.Path)5 ContentPackException (org.graylog2.contentpacks.exceptions.ContentPackException)5 Entity (org.graylog2.contentpacks.model.entities.Entity)5 ObjectId (org.bson.types.ObjectId)4 EntityWithExcerptFacade (org.graylog2.contentpacks.facades.EntityWithExcerptFacade)4 ContentPackUninstallation (org.graylog2.contentpacks.model.ContentPackUninstallation)4