Search in sources :

Example 16 with PkgSupplement

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);
    }
}
Also used : PkgIcon(org.haiku.haikudepotserver.dataobjects.PkgIcon) PkgSupplement(org.haiku.haikudepotserver.dataobjects.PkgSupplement) Optional(java.util.Optional) ConfigurePkgIconRequest(org.haiku.haikudepotserver.api1.model.pkg.ConfigurePkgIconRequest) MediaType(com.google.common.net.MediaType) ObjectContext(org.apache.cayenne.ObjectContext) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 17 with PkgSupplement

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");
    }
}
Also used : PkgLocalization(org.haiku.haikudepotserver.dataobjects.PkgLocalization) ObjectId(org.apache.cayenne.ObjectId) InputStream(java.io.InputStream) Pkg(org.haiku.pkg.model.Pkg) PkgSupplement(org.haiku.haikudepotserver.dataobjects.PkgSupplement) RepositorySource(org.haiku.haikudepotserver.dataobjects.RepositorySource) PkgVersion(org.haiku.pkg.model.PkgVersion) ObjectContext(org.apache.cayenne.ObjectContext) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

PkgSupplement (org.haiku.haikudepotserver.dataobjects.PkgSupplement)17 ObjectContext (org.apache.cayenne.ObjectContext)15 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)10 Test (org.junit.jupiter.api.Test)10 Pkg (org.haiku.haikudepotserver.dataobjects.Pkg)5 CSVWriter (com.opencsv.CSVWriter)4 OutputStream (java.io.OutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 IntegrationTestSupportService (org.haiku.haikudepotserver.IntegrationTestSupportService)4 PkgScreenshot (org.haiku.haikudepotserver.api1.model.pkg.PkgScreenshot)4 PkgIcon (org.haiku.haikudepotserver.dataobjects.PkgIcon)4 Repository (org.haiku.haikudepotserver.dataobjects.Repository)4 MediaType (com.google.common.net.MediaType)3 Optional (java.util.Optional)3 ConfigurePkgIconRequest (org.haiku.haikudepotserver.api1.model.pkg.ConfigurePkgIconRequest)3 UpdatePkgChangelogRequest (org.haiku.haikudepotserver.api1.model.pkg.UpdatePkgChangelogRequest)3 JobDataWithByteSink (org.haiku.haikudepotserver.job.model.JobDataWithByteSink)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 RemovePkgIconRequest (org.haiku.haikudepotserver.api1.model.pkg.RemovePkgIconRequest)2