RHostedFacetImpl extends FacetSupport implements RHostedFacet { @Override @TransactionalTouchBlob public Content getStoredContent(final String contentPath) { checkNotNull(contentPath); StorageTx tx = UnitOfWork.currentTx(); Asset asset = findAsset(tx, tx.findBucket(getRepository()), contentPath); if (asset == null) { return null; } if (asset.markAsDownloaded()) { tx.saveAsset(asset); } return toContent(asset, tx.requireBlob(asset.requireBlobRef())); }  @Override @TransactionalTouchBlob Content getStoredContent(final String contentPath); @Override Asset upload(final String path, final Payload payload); @Override @TransactionalTouchMetadata Content buildAndPutPackagesGz(final String basePath);  }
@Test public void getContentReturnsCorrectContentType() throws Exception { when(asset.requireContentType()).thenReturn("application/x-gzip"); Content packages = underTest.getStoredContent(PACKAGE_PATH); assertThat(packages.getContentType(), is(equalTo("application/x-gzip"))); }
@Test public void getStoredContent() throws Exception { Content archive = underTest.getStoredContent(PACKAGE_PATH); assertThat(archive, is(notNullValue())); }
@Test(expected = NullPointerException.class) public void failFastOnGetContentWithNull() throws Exception { underTest.getStoredContent(null); }
@Test public void nullWhenAssetNullOnGetContent() throws Exception { when(storageTx.findAssetWithProperty(anyString(), anyString(), any(Bucket.class))).thenReturn(null); Content archive = underTest.getStoredContent(PACKAGES_GZ_PATH); assertThat(archive, is(nullValue())); }
@Test public void markAssetAsDownloadedAndSaveOnGetContent() throws Exception { when(asset.markAsDownloaded()).thenReturn(true); underTest.getStoredContent(PACKAGES_GZ_PATH); verify(storageTx).saveAsset(asset); }
@Test public void doNotSaveAssetWhenContentNotMarkedAsDownloaded() throws Exception { when(asset.markAsDownloaded()).thenReturn(false); underTest.getStoredContent(PACKAGES_GZ_PATH); verify(storageTx, never()).saveAsset(asset); }