AssetMappingService { protected int mapExactMatches(Long assetExtractionId, Long tmId, Long assetId) { List<AssetMappingDTO> exactMatches = getExactMatches(assetExtractionId, tmId, assetId); return saveExactMatches(exactMatches); }  @Pollable(message = "Mapping AssetTextUnit to TMTextUnit") void mapAssetTextUnitAndCreateTMTextUnit(Long assetExtractionId, Long tmId, Long assetId, User createdByUser, @ParentTask PollableTask parentTask);  }
@Test public void testUpdateExactMatchesAndGetUnmappedAssetTextUnits() throws RepositoryNameAlreadyUsedException { logger.debug("Create data for test"); createOtherTMAssetAndTextUnit("other-repository", "other asset content", "other-asset-path", "TEST1", "Content1", "Comment1"); AssetExtraction assetExtractionOther = assetExtractionRepository.save(new AssetExtraction()); assetExtractionService.createAssetTextUnit(assetExtractionOther, "TEST2", "Content2", "Comment2"); Repository testRepository = repositoryService.createRepository(testIdWatcher.getEntityName("testUpdateExactMatchesAndGetUnmappedAssetTextUnits")); TM tm = testRepository.getTm(); Asset testAsset = assetService.createAssetWithContent(testRepository.getId(), "fake_for_test_real_asset", "fake for test real tm repo"); TMTextUnit addTMTextUnit1 = tmService.addTMTextUnit(tm.getId(), testAsset.getId(), "TEST1", "Content1", "Comment1"); TMTextUnit addTMTextUnit2 = tmService.addTMTextUnit(tm.getId(), testAsset.getId(), "TEST2", "Content2", "Comment2"); tmService.addTMTextUnit(tm.getId(), testAsset.getId(), "TEST4", "Content4", "Comment4"); AssetExtraction assetExtraction = assetExtractionRepository.save(new AssetExtraction()); AssetTextUnit createAssetTextUnit1 = assetExtractionService.createAssetTextUnit(assetExtraction, "TEST1", "Content1", "Comment1"); AssetTextUnit createAssetTextUnit2 = assetExtractionService.createAssetTextUnit(assetExtraction, "TEST2", "Content2", "Comment2"); AssetTextUnit createAssetTextUnit3 = assetExtractionService.createAssetTextUnit(assetExtraction, "TEST3", "Content3", "Comment3"); logger.debug("Done creating data for test, start testing"); assertEquals("Make sure no AssetTextUnit are mapped", 3, assetTextUnitRepository.getUnmappedAssetTextUnits(assetExtraction.getId()).size()); assetMappingService.mapExactMatches(assetExtraction.getId(), tm.getId(), testAsset.getId()); assertEquals("We should now have 1 AssetTextUnit mapped", 1, assetTextUnitRepository.getUnmappedAssetTextUnits(assetExtraction.getId()).size()); Iterator<AssetTextUnitToTMTextUnit> iterator = getAssetTextUnitToTMTextUnit(assetExtraction); AssetTextUnitToTMTextUnit next = iterator.next(); assertEquals("Check for mapping reccords", addTMTextUnit1.getId(), next.getTmTextUnit().getId()); assertEquals("Check for mapping reccords", createAssetTextUnit1.getId(), next.getAssetTextUnit().getId()); next = iterator.next(); assertEquals("Check for mapping reccords", addTMTextUnit2.getId(), next.getTmTextUnit().getId()); assertEquals("Check for mapping reccords", createAssetTextUnit2.getId(), next.getAssetTextUnit().getId()); assertFalse("There shouldn't be any other mapping reccords", iterator.hasNext()); logger.debug("Running twice updateExactMatches should not change anything because everything have been mapped already"); assetMappingService.mapExactMatches(assetExtraction.getId(), tm.getId(), testAsset.getId()); iterator = getAssetTextUnitToTMTextUnit(assetExtraction); next = iterator.next(); assertEquals("Check for mapping reccords", addTMTextUnit1.getId(), next.getTmTextUnit().getId()); assertEquals("Check for mapping reccords", createAssetTextUnit1.getId(), next.getAssetTextUnit().getId()); next = iterator.next(); assertEquals(addTMTextUnit2.getId(), next.getTmTextUnit().getId()); assertEquals("Check for mapping reccords", createAssetTextUnit2.getId(), next.getAssetTextUnit().getId()); assertFalse("There shouldn't be any other mapping reccords", iterator.hasNext()); logger.debug("Adding a new TextUnit that will be a match"); TMTextUnit addTMTextUnit3 = tmService.addTMTextUnit(tm.getId(), testAsset.getId(), "TEST3", "Content3", "Comment3"); logger.debug("Re-map, a new entry should be added"); assetMappingService.mapExactMatches(assetExtraction.getId(), tm.getId(), testAsset.getId()); assertEquals("All AssetTextUnit must be mapped now", 0, assetTextUnitRepository.getUnmappedAssetTextUnits(assetExtraction.getId()).size()); iterator = getAssetTextUnitToTMTextUnit(assetExtraction); next = iterator.next(); assertEquals(addTMTextUnit1.getId(), next.getTmTextUnit().getId()); assertEquals("Check for mapping reccords", createAssetTextUnit1.getId(), next.getAssetTextUnit().getId()); next = iterator.next(); assertEquals(addTMTextUnit2.getId(), next.getTmTextUnit().getId()); assertEquals("Check for mapping reccords", createAssetTextUnit2.getId(), next.getAssetTextUnit().getId()); next = iterator.next(); assertEquals(addTMTextUnit3.getId(), next.getTmTextUnit().getId()); assertEquals("Check for mapping reccords", createAssetTextUnit3.getId(), next.getAssetTextUnit().getId()); assertFalse("There shouldn't be any other mapping reccords", iterator.hasNext()); }