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