@Test public void shouldBuildPackagesGz() throws Exception { when(tempBlob.get()).thenReturn(getClass().getResourceAsStream(PACKAGES_GZ)); when(asset.name()).thenReturn(PACKAGES_GZ_PATH); when(assetBlob.getBlob()) .thenReturn(blob); doReturn(assetBlob) .when(storageTx).setBlob(any(), any(), any(), any(), any(), any(), anyBoolean()); when(storageFacet.createTempBlob(any(InputStream.class), eq(RFacetUtils.HASH_ALGORITHMS))).thenAnswer( invocation -> { InputStream is = (InputStream) invocation.getArguments()[0]; byte[] content = ByteStreams.toByteArray(is); when(tempBlob.get()).thenAnswer(i -> new ByteArrayInputStream(content)); return tempBlob; }); assets.add(asset); underTest.buildAndPutPackagesGz(BASE_PATH); try (InputStream in = tempBlob.get()) { Map<String, String> attributes = extractDescriptionFromArchive(PACKAGE_NAME, in); assertThat(attributes.get(P_PACKAGE), is(equalTo(PACKAGE_NAME))); assertThat(attributes.get(P_VERSION), is(equalTo(VERSION))); assertThat(attributes.get(P_DEPENDS), is(equalTo(DEPENDS))); assertThat(attributes.get(P_IMPORTS), is(equalTo(IMPORTS))); assertThat(attributes.get(P_SUGGESTS), is(equalTo(SUGGESTS))); assertThat(attributes.get(P_LINKINGTO), is(equalTo(LINKINGTO))); assertThat(attributes.get(P_LICENSE), is(equalTo(LICENSE))); assertThat(attributes.get(P_NEEDS_COMPILATION), is(equalTo(NEEDS_COMPILATION))); } verify(storageTx).saveAsset(asset); }
@Override @TransactionalTouchMetadata public Content buildAndPutPackagesGz(final String basePath) throws IOException { checkNotNull(basePath); StorageTx tx = UnitOfWork.currentTx(); RPackagesBuilder packagesBuilder = new RPackagesBuilder(); Iterable<Asset> archiveAssets = browseAllAssetsByKind(tx, tx.findBucket(getRepository()), ARCHIVE); StreamSupport.stream(archiveAssets.spliterator(), false) .filter(asset -> basePath.equals(getBasePath(asset.name()))) .forEach(packagesBuilder::append); byte[] packagesBytes = packagesBuilder.buildPackagesGz(); StorageFacet storageFacet = getRepository().facet(StorageFacet.class); try (InputStream is = new ByteArrayInputStream(packagesBytes)) { TempBlob tempPackagesGz = storageFacet.createTempBlob(is, RFacetUtils.HASH_ALGORITHMS); return doPutPackagesGz(tx, basePath, tempPackagesGz); } }
RHostedFacetImpl extends FacetSupport implements RHostedFacet { @Override @TransactionalTouchMetadata public Content buildAndPutPackagesGz(final String basePath) throws IOException { checkNotNull(basePath); StorageTx tx = UnitOfWork.currentTx(); RPackagesBuilder packagesBuilder = new RPackagesBuilder(); Iterable<Asset> archiveAssets = browseAllAssetsByKind(tx, tx.findBucket(getRepository()), ARCHIVE); StreamSupport.stream(archiveAssets.spliterator(), false) .filter(asset -> basePath.equals(getBasePath(asset.name()))) .forEach(packagesBuilder::append); byte[] packagesBytes = packagesBuilder.buildPackagesGz(); StorageFacet storageFacet = getRepository().facet(StorageFacet.class); try (InputStream is = new ByteArrayInputStream(packagesBytes)) { TempBlob tempPackagesGz = storageFacet.createTempBlob(is, RFacetUtils.HASH_ALGORITHMS); return doPutPackagesGz(tx, basePath, tempPackagesGz); } } }
RHostedFacetImpl extends FacetSupport implements RHostedFacet { @Override @TransactionalTouchMetadata public Content buildAndPutPackagesGz(final String basePath) throws IOException { checkNotNull(basePath); StorageTx tx = UnitOfWork.currentTx(); RPackagesBuilder packagesBuilder = new RPackagesBuilder(); Iterable<Asset> archiveAssets = browseAllAssetsByKind(tx, tx.findBucket(getRepository()), ARCHIVE); StreamSupport.stream(archiveAssets.spliterator(), false) .filter(asset -> basePath.equals(getBasePath(asset.name()))) .forEach(packagesBuilder::append); byte[] packagesBytes = packagesBuilder.buildPackagesGz(); StorageFacet storageFacet = getRepository().facet(StorageFacet.class); try (InputStream is = new ByteArrayInputStream(packagesBytes)) { TempBlob tempPackagesGz = storageFacet.createTempBlob(is, RFacetUtils.HASH_ALGORITHMS); return doPutPackagesGz(tx, basePath, tempPackagesGz); } }  }
RHostedFacetImpl extends FacetSupport implements RHostedFacet { @Override @TransactionalTouchMetadata public Content buildAndPutPackagesGz(final String basePath) throws IOException { checkNotNull(basePath); StorageTx tx = UnitOfWork.currentTx(); RPackagesBuilder packagesBuilder = new RPackagesBuilder(); Iterable<Asset> archiveAssets = browseAllAssetsByKind(tx, tx.findBucket(getRepository()), ARCHIVE); StreamSupport.stream(archiveAssets.spliterator(), false) .filter(asset -> basePath.equals(getBasePath(asset.name()))) .forEach(packagesBuilder::append); byte[] packagesBytes = packagesBuilder.buildPackagesGz(); StorageFacet storageFacet = getRepository().facet(StorageFacet.class); try (InputStream is = new ByteArrayInputStream(packagesBytes)) { TempBlob tempPackagesGz = storageFacet.createTempBlob(is, RFacetUtils.HASH_ALGORITHMS); return doPutPackagesGz(tx, basePath, tempPackagesGz); } }  @Override @TransactionalTouchBlob Content getStoredContent(final String contentPath); @Override Asset upload(final String path, final Payload payload); @Override @TransactionalTouchMetadata Content buildAndPutPackagesGz(final String basePath); }
RHostedFacetImpl extends FacetSupport implements RHostedFacet { @Override @TransactionalTouchMetadata public Content buildAndPutPackagesGz(final String basePath) throws IOException { checkNotNull(basePath); StorageTx tx = UnitOfWork.currentTx(); RPackagesBuilder packagesBuilder = new RPackagesBuilder(); Iterable<Asset> archiveAssets = browseAllAssetsByKind(tx, tx.findBucket(getRepository()), ARCHIVE); StreamSupport.stream(archiveAssets.spliterator(), false) .filter(asset -> basePath.equals(getBasePath(asset.name()))) .forEach(packagesBuilder::append); byte[] packagesBytes = packagesBuilder.buildPackagesGz(); StorageFacet storageFacet = getRepository().facet(StorageFacet.class); try (InputStream is = new ByteArrayInputStream(packagesBytes)) { TempBlob tempPackagesGz = storageFacet.createTempBlob(is, RFacetUtils.HASH_ALGORITHMS); return doPutPackagesGz(tx, basePath, tempPackagesGz); } }  @Override @TransactionalTouchBlob Content getStoredContent(final String contentPath); @Override Asset upload(final String path, final Payload payload); @Override @TransactionalTouchMetadata Content buildAndPutPackagesGz(final String basePath);  }