use of org.haiku.haikudepotserver.pkg.model.PkgIconImportArchiveJobSpecification in project haikudepotserver by haiku.
the class PkgIconImportArchiveJobRunnerIT method testImport.
/**
* <p>The package 'pkg2' has initially no icons associated with it, but one 16x16 icons is then added. The
* tar-ball is loaded and in doing so, two new icons are populated for 'pkg2', but the old 16x16 is not
* present as importing for a package will remove any previously present icon data.</p>
*/
@Test
public void testImport() throws Exception {
integrationTestSupportService.createStandardTestData();
// check that there are no icons stored for pkg2.
{
ObjectContext context = serverRuntime.newContext();
Assertions.assertThat(Pkg.getByName(context, "pkg2").getPkgSupplement().getPkgIcons()).hasSize(0);
}
try (InputStream iconInputStream = Resources.asByteSource(Resources.getResource("sample-16x16-2.png")).openStream()) {
ObjectContext context = serverRuntime.newContext();
pkgIconService.storePkgIconImage(iconInputStream, org.haiku.haikudepotserver.dataobjects.MediaType.tryGetByCode(context, org.haiku.haikudepotserver.dataobjects.MediaType.MEDIATYPE_PNG).get(), // expected size along both axiis
16, context, Pkg.getByName(context, "pkg2").getPkgSupplement());
}
// now load in the data to the job's storage system.
PkgIconImportArchiveJobSpecification spec = new PkgIconImportArchiveJobSpecification();
spec.setInputDataGuid(jobService.storeSuppliedData("sample-pkgiconimportarchive-supplied.tgz", MediaType.TAR.toString(), getResourceByteSource("sample-pkgiconimportarchive-supplied.tgz")).getGuid());
// run the job to import the data
// ------------------------------------
String jobGuid = jobService.immediate(spec, false);
// ------------------------------------
JobSnapshot snapshot = jobService.tryGetJob(jobGuid).get();
Assertions.assertThat(snapshot.getStatus()).isEqualTo(JobSnapshot.Status.FINISHED);
// check that the pkg2 is now loaded-up with icons from the tar-ball.
{
ObjectContext context = serverRuntime.newContext();
Pkg pkg2 = Pkg.getByName(context, "pkg2");
Assertions.assertThat(pkg2.getPkgSupplement().getPkgIcons()).hasSize(2);
Assertions.assertThat(pkg2.getPkgSupplement().getPkgIcon(org.haiku.haikudepotserver.dataobjects.MediaType.getByCode(context, org.haiku.haikudepotserver.dataobjects.MediaType.MEDIATYPE_HAIKUVECTORICONFILE), null).isPresent()).isTrue();
Assertions.assertThat(pkg2.getPkgSupplement().getPkgIcon(org.haiku.haikudepotserver.dataobjects.MediaType.getByCode(context, org.haiku.haikudepotserver.dataobjects.MediaType.MEDIATYPE_PNG), 32).isPresent()).isTrue();
}
// check that the output report is as expected.
{
String dataGuid = snapshot.getGeneratedDataGuids().stream().collect(SingleCollector.single());
JobDataWithByteSource jobSource = jobService.tryObtainData(dataGuid).get();
ByteSource expectedByteSource = getResourceByteSource("sample-pkgiconimportarchive-generated.csv");
// write the report to the console in order to help with diagnosis
LOGGER.info("actual output;\n{}", jobSource.getByteSource().asCharSource(Charsets.UTF_8).read());
try (BufferedReader jobReader = jobSource.getByteSource().asCharSource(Charsets.UTF_8).openBufferedStream();
BufferedReader sampleReader = expectedByteSource.asCharSource(Charsets.UTF_8).openBufferedStream()) {
assertEqualsLineByLine(sampleReader, jobReader);
}
}
}
Aggregations