AssetRepository { public List<Asset> findAssetInPath(T component, AssetType type, Path directory) throws IOException { List<Asset> objects = new ArrayList<>(); try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory)) { for (Path path : directoryStream) { objects.add(new Asset() .setName(path.getFileName().toString()) .setType(type) .setScope(AssetScope.forComponent(component)) .setComponentId(component.getId()) .setId(UUID.randomUUID().toString())); } } return objects; } @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_findAssetInPath_asset() throws Exception { Page page = aPage().withId("page-id").build(); write(pagesPath.resolve("file1.css"), "<style>.maclass1{}</style>".getBytes()); write(pagesPath.resolve("file2.css"), "<style>.maclass2{}</style>".getBytes()); List<Asset> assets = assetRepository.findAssetInPath(page, AssetType.CSS, pagesPath); assertThat(assets).hasSize(2); assertThat(assets).extracting("name").contains("file1.css", "file2.css"); }
@Test public void should_findAssetInPath_asset_when_noone_is_present() throws Exception { Page page = aPage().withId("page-id").build(); List<Asset> assets = assetRepository.findAssetInPath(page, AssetType.CSS, pagesPath); assertThat(assets).isEmpty(); }