TMService { public TMTextUnit addTMTextUnit(Long tmId, Long assetId, String name, String content, String comment) { TM tm = tmRepository.findById(tmId).orElse(null); Asset asset = assetRepository.findById(assetId).orElse(null); return addTMTextUnit(tm, asset, name, content, comment, null, null, null); }  TMTextUnit addTMTextUnit(Long tmId, Long assetId, String name, String content, String comment); TMTextUnit addTMTextUnit(
            TM tm,
            Asset asset,
            String name,
            String content,
            String comment,
            DateTime createdDate,
            PluralForm pluralForm,
            String pluralFormOther); TMTextUnit addTMTextUnit(
            TM tm,
            Asset asset,
            String name,
            String content,
            String comment,
            User createdByUser,
            DateTime createdDate,
            PluralForm pluralForm,
            String pluralFormOther); TMTextUnitVariant addCurrentTMTextUnitVariant(Long tmTextUnitId, Long localeId, String content); TMTextUnitVariant addCurrentTMTextUnitVariant(Long tmTextUnitId, Long localeId, String content, TMTextUnitVariant.Status status, boolean includedInLocalizedFile); TMTextUnitVariant addCurrentTMTextUnitVariant(Long tmTextUnitId, Long localeId, String content, TMTextUnitVariant.Status status, boolean includedInLocalizedFile, DateTime createdDate); TMTextUnitCurrentVariant addTMTextUnitCurrentVariant(Long tmTextUnitId, Long localeId, String content, String comment); TMTextUnitCurrentVariant addTMTextUnitCurrentVariant(Long tmTextUnitId, Long localeId, String content, String comment, TMTextUnitVariant.Status status); TMTextUnitCurrentVariant addTMTextUnitCurrentVariant(
            Long tmTextUnitId,
            Long localeId,
            String content,
            String comment,
            TMTextUnitVariant.Status status,
            boolean includedInLocalizedFile); TMTextUnitCurrentVariant addTMTextUnitCurrentVariant(
            Long tmTextUnitId,
            Long localeId,
            String content,
            String comment,
            TMTextUnitVariant.Status status,
            boolean includedInLocalizedFile,
            DateTime createdDate); AddTMTextUnitCurrentVariantResult addTMTextUnitCurrentVariantWithResult(
            Long tmTextUnitId,
            Long localeId,
            String content,
            String comment,
            TMTextUnitVariant.Status status,
            boolean includedInLocalizedFile,
            DateTime createdDate); AddTMTextUnitCurrentVariantResult addTMTextUnitCurrentVariantWithResult(
            TMTextUnitCurrentVariant tmTextUnitCurrentVariant,
            Long tmId,
            Long tmTextUnitId,
            Long localeId,
            String content,
            String comment,
            TMTextUnitVariant.Status status,
            boolean includedInLocalizedFile,
            DateTime createdDate,
            User createdBy); boolean isUpdateNeededForTmTextUnitVariant(
            TMTextUnitVariant.Status currentStatus,
            String currentContentMd5,
            boolean currentIncludedInLocalizedFile,
            String currentComment,
            TMTextUnitVariant.Status newStatus,
            String newContentMd5,
            boolean newIncludedInLocalizedFile,
            String newComment); TMTextUnitVariant addTMTextUnitVariant(
            Long tmTextUnitId,
            Long localeId,
            String content,
            String comment,
            TMTextUnitVariant.Status status,
            boolean includedInLocalizedFile,
            DateTime createdDate); TMTextUnitVariant addTMTextUnitVariant(
            Long tmTextUnitId,
            Long localeId,
            String content,
            String comment,
            TMTextUnitVariant.Status status,
            boolean includedInLocalizedFile,
            DateTime createdDate,
            User createdBy); UpdateTMWithXLIFFResult updateTMWithTranslationKitXLIFF(
            String xliffContent,
            TMTextUnitVariant.Status importStatus,
            String dropImporterUsernameOverride); UpdateTMWithXLIFFResult updateTMWithXLIFFById(
            String xliffContent,
            TMTextUnitVariant.Status importStatus); UpdateTMWithXLIFFResult updateTMWithXLIFFByMd5(
            String xliffContent,
            TMTextUnitVariant.Status importStatus,
            Repository repository); @Transactional String exportAssetAsXLIFF(Long assetId, String bcp47Tag); String generateLocalized(
            Asset asset,
            String content,
            RepositoryLocale repositoryLocale,
            String outputBcp47tag,
            FilterConfigIdOverride filterConfigIdOverride,
            List<String> filterOptions,
            Status status,
            InheritanceMode inheritanceMode); String generatePseudoLocalized(
            Asset asset,
            String content,
            FilterConfigIdOverride filterConfigIdOverride); PollableFuture<Void> importLocalizedAssetAsync(
            Long assetId,
            String content,
            Long localeId,
            StatusForEqualTarget statusForEqualtarget,
            FilterConfigIdOverride filterConfigIdOverride,
            List<String> filterOptions); void importLocalizedAsset(
            Long assetId,
            String content,
            Long localeId,
            StatusForEqualTarget statusForEqualtarget,
            FilterConfigIdOverride filterConfigIdOverride,
            List<String> filterOptions); @Pollable(async = true, message = "Export asset as xliff") PollableFuture<String> exportAssetAsXLIFFAsync(
            Long tmXliffId,
            Long assetId,
            String bcp47Tag,
            @InjectCurrentTask PollableTask currentTask); TMXliff createTMXliff(Long assetId, String bcp47Tag, String content, PollableTask pollableTask);  }
@Test public void testAddTMTextUnit() throws RepositoryNameAlreadyUsedException { createTestData(); logger.debug("Done creating data for test, start testing"); logger.debug("Add a first text unit"); Long addTextUnitAndCheck1 = addTextUnitAndCheck(tmId, assetId, "name", "this is the content", "some comment", "3063c39d3cf8ab69bcabbbc5d7187dc9", "cf8ea6b6848f23345648038bc3abf324"); logger.debug("TMTextUnit tmTextUnit = tmTextUnitRepository.findByMd5AndTmIdAndAssetId(md5, assetId, tmId);"); String md5 = textUnitUtils.computeTextUnitMD5("name", "this is the content", "some comment"); TMTextUnit tmTextUnit = tmTextUnitRepository.findByMd5AndTmIdAndAssetId(md5, tmId, assetId); logger.debug("tmtextunit: {}", tmTextUnit); logger.debug("Add the second text unit"); Long addTextUnitAndCheck2 = addTextUnitAndCheck(tmId, assetId, "name2", "content", "comment", "d00c1170937aa79458be2424f4d9720e", "9a0364b9e99bb480dd25e1f0284c8555"); logger.debug("Check the text units"); Iterator<TMTextUnit> tmTextUnitIterator = tmTextUnitRepository.findByTm_id(tmId).iterator(); assertEquals(addTextUnitAndCheck1, tmTextUnitIterator.next().getId()); assertEquals(addTextUnitAndCheck2, tmTextUnitIterator.next().getId()); assertFalse(tmTextUnitIterator.hasNext()); logger.debug("Check the text units variants for the default locale"); Iterator<TMTextUnitVariant> tmTextUnitVariantIterator = tmTextUnitVariantRepository.findAllByLocale_IdAndTmTextUnit_Tm_id(localeService.getDefaultLocale().getId(), tmId).iterator(); assertEquals("this is the content", tmTextUnitVariantIterator.next().getContent()); assertEquals("content", tmTextUnitVariantIterator.next().getContent()); assertFalse(tmTextUnitVariantIterator.hasNext()); }
@Test(expected = DataIntegrityViolationException.class) public void testAddTMTextUnitTwice() throws RepositoryNameAlreadyUsedException { createTestData(); logger.debug("Add a first text unit"); Long addTextUnitAndCheck1 = addTextUnitAndCheck(tmId, assetId, "name", "this is the content", "some comment", "3063c39d3cf8ab69bcabbbc5d7187dc9", "cf8ea6b6848f23345648038bc3abf324"); logger.debug("TMTextUnit tmTextUnit = tmTextUnitRepository.findByMd5AndTmIdAndAssetId(md5, assetId, tmId);"); String md5 = textUnitUtils.computeTextUnitMD5("name", "this is the content", "some comment"); TMTextUnit tmTextUnit = tmTextUnitRepository.findByMd5AndTmIdAndAssetId(md5, tmId, assetId); logger.debug("tmtextunit: {}", tmTextUnit); logger.debug("Try to add a second text unit with same logical key, throws a DataIntegrityViolationException"); TMTextUnit reAdd = tmService.addTMTextUnit(tmId, assetId, "name", "this is the content", "some comment"); }
@Test public void testAddTMTextUnitInvalidInput() { try { tmService.addTMTextUnit(-15L, -1L, "fail", "fail", "fail"); fail(); } catch (NullPointerException npe) { logger.debug("expected NullPointerException"); } }