AssetService { public Asset createAssetWithContent(Long repositoryId, String assetPath, String assetContent) { Asset asset = createAsset(repositoryId, assetPath, false); assetContentService.createAssetContent(asset, assetContent); return asset; }  PollableFuture<Asset> addOrUpdateAssetAndProcessIfNeeded(
            Long repositoryId,
            String assetPath,
            String assetContent,
            boolean extractedContent,
            String branch,
            String branchCreatedByUsername,
            FilterConfigIdOverride filterConfigIdOverride,
            List<String> filterOptions); Asset createAsset(Long repositoryId, String assetPath, boolean virtualContent); Asset createAssetWithContent(Long repositoryId, String assetPath, String assetContent); @Transactional void deleteAsset(Asset asset); @Transactional void deleteAssets(Set<Long> assetIds); PollableFuture<Void> asyncDeleteAssetsOfBranch(Set<Long> assetIds, Long branchId); void deleteAssetsOfBranch(Set<Long> assetIds, Long branchId); void deleteAssetOfBranch(Long assetId, Long branchId); List<Asset> findAll(Long repositoryId, String path, Boolean deleted, Boolean virtual, Long branchId); Set<Long> findAllAssetIds(Long repositoryId, String path, Boolean deleted, Boolean virtual, Long branchId);  }
@Test public void testAddOrUpdateAssetAndProcessIfNeededShouldStartExtractionIfAssetExistButAssetExtractionIsMissing() throws Exception { String content = "content"; String path = "path/to/asset.csv"; Repository repository = repositoryService.createRepository(testIdWatcher.getEntityName("repository")); logger.debug("initialize repository ...: {}", repository.getId()); Asset asset = assetService.createAssetWithContent(repository.getId(), path, content); addAssetAndWaitUntilDoneProcessing(repository.getId(), content, path, null); List<AssetExtraction> assetExtractions = assetExtractionRepository.findByAsset(asset); assertEquals("There should be 1 assetExtraction created when updating an exising asset without assetExtraction (due to some processing failure)", 1, assetExtractions.size()); }
@Test public void testAddOrUpdateAssetAndProcessIfNeededShouldStartExtractionIfAssetExistButAssetExtractionIsOutdated() throws Exception { String content = "content"; String path = "path/to/asset.csv"; Repository repository = repositoryService.createRepository(testIdWatcher.getEntityName("repository")); Asset asset = assetService.createAssetWithContent(repository.getId(), path, content); Asset fakePreviousAssetVersion = new Asset(); fakePreviousAssetVersion.setId(asset.getId()); AssetExtraction createAssetExtraction = assetExtractionService.createAssetExtraction(fakePreviousAssetVersion, null); assetExtractionService.markAssetExtractionAsLastSuccessful(asset, createAssetExtraction); addAssetAndWaitUntilDoneProcessing(repository.getId(), content, path, null); List<AssetExtraction> assetExtractions = assetExtractionRepository.findByAsset(asset); assertEquals("There should be 1 assetExtraction created when updating an exising asset with outdated assetExtraction (due to some processing failure)", 2, assetExtractions.size()); }
@Test public void testAddOrUpdateAssetAndProcessIfNeededShouldUpdateAssetContentAndStartExtractionIfContentOfExistingAssetChanged() throws Exception { String content = "content"; String newContent = "newContent"; String path = "path/to/existing/asset.csv"; Repository repository = repositoryService.createRepository(testIdWatcher.getEntityName("repository")); assetService.createAssetWithContent(repository.getId(), path, content); Asset asset = addAssetAndWaitUntilDoneProcessing(repository.getId(), newContent, path, null); asset = assetRepository.findById(asset.getId()).orElse(null); assertEquals("Content of existing asset should be updated if changed", newContent, asset.getLastSuccessfulAssetExtraction().getAssetContent().getContent()); List<AssetExtraction> assetExtractions = assetExtractionRepository.findByAsset(asset); assertEquals("There should be one assetExtraction created when the adding an asset with changed content", 1, assetExtractions.size()); }