AssetRepository { public void delete(Asset asset) throws IOException { checkNotNull(asset.getComponentId(), COMPONENT_ID_REQUIRED); Files.delete(resolveExistingAssetPath(asset)); } @Inject  AssetRepository(Repository<T> repository, BeanValidator validator); void save(Asset asset, byte[] content); void save(String componentId, Asset asset, byte[] content); void delete(Asset asset); byte[] readAllBytes(Asset asset); byte[] readAllBytes(String componentId, Asset asset); Path findAssetPath(String componentId, final String filename, final AssetType assetType); List<Asset> findAssetInPath(T component, AssetType type, Path directory); List<Asset> findAssetInPathWhithoutComponentId(T component, AssetType type, Path directory); void refreshAssets(final T component); static final String COMPONENT_ID_REQUIRED; }
@Test(expected = NullPointerException.class) public void should_throw_NullPointerException_when_deleting_asset_componentId_null() throws Exception { assetRepository.delete(new Asset()); }
@Test public void should_delete_asset() throws Exception { Page page = aPage().withId("page-id").build(); Asset asset = aFilledAsset(page); Path fileExpected = pagesPath.resolve("assets").resolve("js").resolve(asset.getName()); createDirectories(pagesPath.resolve("assets").resolve("js")); temporaryFolder.newFilePath("assets/js/" + asset.getName()); assertThat(fileExpected.toFile()).exists(); when(pageRepository.resolvePathFolder("page-id")).thenReturn(pagesPath); when(pageRepository.get(asset.getComponentId())).thenReturn(page); assetRepository.delete(asset); assertThat(fileExpected.toFile()).doesNotExist(); }
@Test(expected = NotFoundException.class) public void should_throw_NotFoundException_when_deleting_inexisting_page() throws Exception { Page page = aPage().withId("page-id").build(); Asset asset = aFilledAsset(page); when(pageRepository.resolvePathFolder("page-id")).thenReturn(pagesPath); when(pageRepository.get(asset.getComponentId())).thenReturn(page); assetRepository.delete(asset); }