AssetService { public void delete(T component, final String assetId) { checkArgument(isNotEmpty(assetId), ASSET_ID_IS_REQUIRED); deleteComponentAsset(component, new Predicate<Asset>() { @Override public boolean apply(Asset asset) { return assetId.equals(asset.getId()); } }); repository.updateLastUpdateAndSave(component); } AssetService(Repository<T> repository, AssetRepository<T> assetRepository, AssetImporter<T> assetImporter, JacksonObjectMapper mapper); Asset upload(MultipartFile file, T component, String type); Path findAssetPath(String id, String filename, String type); Asset save(T component, final Asset asset); Asset save(T component, Asset asset, byte[] content); String getAssetContent(T component, Asset asset); void duplicateAsset(Path artifactSourcePath, Path artifactTargetPath, String sourceArtifactId, String targetArtifactId); void delete(T component, final String assetId); Asset changeAssetOrderInComponent(T component, String assetId, OrderType ordering); void changeAssetStateInPreviewable(T component, String assetId, boolean active); void loadDefaultAssets(T content); static final String ASSET_TYPE_IS_REQUIRED; static final String ASSET_URL_IS_REQUIRED; static final String ASSET_ID_IS_REQUIRED; }
@Test public void should_return_error_when_deleting_asset_with_name_empty() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage(is("Asset id is required")); assetService.delete(aPage().withId("page-id").build(), null); }
@Test public void should_delete_existing_asset() throws Exception { Page page = aFilledPage("page-id"); Asset asset = anAsset().withId("UIID").withName("myfile.js").withType(JAVASCRIPT).build(); page.getAssets().add(asset); assetService.delete(page, "UIID"); verify(assetRepository).delete(asset); }
@Test public void should_not_delete_file_for_existing_external_asset() throws Exception { Page page = aFilledPage("page-id"); Asset asset = anAsset().withId("UIID").withName("http: page.getAssets().add(asset); assetService.delete(page, "UIID"); verifyNoMoreInteractions(assetRepository); }