AssetRepository { protected Path resolveAssetPath(String componentId, Asset asset) { validator.validate(asset); return resolveComponentPath(componentId).resolve("assets").resolve(asset.getType().getPrefix()).resolve(asset.getName()); } @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 public void should_resolveAssetPath() { Page page = aPage().withId("page-id").build(); Asset asset = aFilledAsset(page); when(pageRepository.resolvePathFolder("page-id")).thenReturn(pagesPath); Path path = assetRepository.resolveAssetPath(asset); Assertions.assertThat(path.toUri()).isEqualTo(pagesPath.resolve("assets").resolve("js").resolve(asset.getName()).toUri()); }
@Test public void should_not_resolveAssetPath_when_asset_invalid() { Page page = aPage().withId("page-id").build(); Asset asset = aFilledAsset(page); exception.expect(ConstraintValidationException.class); doThrow(ConstraintValidationException.class).when(validator).validate(asset); assetRepository.resolveAssetPath(asset); }