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);
}
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"));
}
Aggregations