AssetService { public String getAssetContent(T component, Asset asset) throws IOException { return new String(assetRepository.readAllBytes(component.getId(), asset)); } 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_read_asset_content() throws IOException { Asset myAsset = anAsset().withType(CSS).withName("style.css").build(); Page page = aPage() .withVersion("1.7.9").withAsset(myAsset).build(); when(assetRepository.readAllBytes(page.getId(), myAsset)).thenReturn("myContentOfAsset".getBytes()); String content = assetService.getAssetContent(page, myAsset); assertThat(content).isEqualTo("myContentOfAsset"); }