use of org.haiku.haikudepotserver.dataobjects.PkgSupplement in project haikudepotserver by haiku.
the class PkgApiIT method testConfigurePkgIcon_ok_hvif.
/**
* <p>This test will configure the icons for the package.</p>
*/
@Test
public void testConfigurePkgIcon_ok_hvif() throws Exception {
setAuthenticatedUserToRoot();
integrationTestSupportService.createStandardTestData();
byte[] sampleHvif = getResourceData("sample.hvif");
ConfigurePkgIconRequest request = new ConfigurePkgIconRequest();
request.pkgName = "pkg1";
request.pkgIcons = Collections.singletonList(new ConfigurePkgIconRequest.PkgIcon(org.haiku.haikudepotserver.dataobjects.MediaType.MEDIATYPE_HAIKUVECTORICONFILE, null, Base64.getEncoder().encodeToString(sampleHvif)));
// ------------------------------------
pkgApi.configurePkgIcon(request);
// ------------------------------------
{
ObjectContext objectContext = serverRuntime.newContext();
PkgSupplement pkgSupplementAfter = Pkg.getByName(objectContext, "pkg1").getPkgSupplement();
org.haiku.haikudepotserver.dataobjects.MediaType mediaTypeHvif = org.haiku.haikudepotserver.dataobjects.MediaType.getByCode(objectContext, org.haiku.haikudepotserver.dataobjects.MediaType.MEDIATYPE_HAIKUVECTORICONFILE);
Assertions.assertThat(pkgSupplementAfter.getPkgIcons().size()).isEqualTo(1);
Optional<PkgIcon> pkgIconHvifOptional = pkgSupplementAfter.getPkgIcon(mediaTypeHvif, null);
Assertions.assertThat(pkgIconHvifOptional.get().getPkgIconImage().getData()).isEqualTo(sampleHvif);
}
}
use of org.haiku.haikudepotserver.dataobjects.PkgSupplement in project haikudepotserver by haiku.
the class PkgImportServiceImplIT method testImport_develPkgHandling.
/**
* <p>When a "_devel" package is imported there is a special behaviour that the localization and the
* icons are copied from the main package over to the "_devel" package.</p>
*/
@Test
public void testImport_develPkgHandling() throws Exception {
ObjectId respositorySourceObjectId;
{
integrationTestSupportService.createStandardTestData();
ObjectContext context = serverRuntime.newContext();
RepositorySource repositorySource = RepositorySource.tryGetByCode(context, "testreposrc_xyz").get();
respositorySourceObjectId = repositorySource.getObjectId();
}
// setup the base package.
{
Pkg importPkg = createPkg("2");
{
ObjectContext importObjectContext = serverRuntime.newContext();
pkgImportService.importFrom(importObjectContext, respositorySourceObjectId, importPkg, false);
importObjectContext.commitChanges();
}
// now add some localization to the imported package.
{
ObjectContext setupObjectContext = serverRuntime.newContext();
org.haiku.haikudepotserver.dataobjects.Pkg persistedPkg = org.haiku.haikudepotserver.dataobjects.Pkg.getByName(setupObjectContext, importPkg.getName());
setupObjectContext.commitChanges();
pkgLocalizationService.updatePkgLocalization(setupObjectContext, persistedPkg.getPkgSupplement(), NaturalLanguage.getByCode(setupObjectContext, NaturalLanguage.CODE_GERMAN), "title_kingston_black", "summary_kingston_black", "description_kingston_black");
setupObjectContext.commitChanges();
try (InputStream inputStream = Resources.asByteSource(Resources.getResource("sample-32x32.png")).openStream()) {
pkgIconService.storePkgIconImage(inputStream, MediaType.getByCode(setupObjectContext, com.google.common.net.MediaType.PNG.toString()), 32, setupObjectContext, persistedPkg.getPkgSupplement());
}
setupObjectContext.commitChanges();
}
}
// setup the devel package.
Pkg importDevelPkg = new Pkg("testpkg" + PkgServiceImpl.SUFFIX_PKG_DEVELOPMENT, new PkgVersion("1", "2", "3", "4", 5), PkgArchitecture.X86_64, null, Collections.emptyList(), Collections.emptyList(), "test-summary-en", "test-description-en", null);
// ---------------------------------
{
ObjectContext importObjectContext = serverRuntime.newContext();
pkgImportService.importFrom(importObjectContext, respositorySourceObjectId, importDevelPkg, false);
importObjectContext.commitChanges();
}
// ---------------------------------
// check it has the icon and the localization.
{
ObjectContext context = serverRuntime.newContext();
org.haiku.haikudepotserver.dataobjects.Pkg persistedDevelPkg = org.haiku.haikudepotserver.dataobjects.Pkg.getByName(context, importDevelPkg.getName());
PkgSupplement persistedDevelPkgSupplement = persistedDevelPkg.getPkgSupplement();
Assertions.assertThat(persistedDevelPkgSupplement.getPkgIcons().size()).isEqualTo(1);
Assertions.assertThat(persistedDevelPkgSupplement.getPkgIcons().get(0).getSize()).isEqualTo(32);
PkgLocalization pkgLocalization = persistedDevelPkgSupplement.getPkgLocalization(NaturalLanguage.CODE_GERMAN).get();
Assertions.assertThat(pkgLocalization.getTitle()).isEqualTo("title_kingston_black");
Assertions.assertThat(pkgLocalization.getSummary()).isEqualTo("summary_kingston_black");
Assertions.assertThat(pkgLocalization.getDescription()).isEqualTo("description_kingston_black");
}
}
Aggregations