TMTextUnitHistoryService { public List<TMTextUnitVariant> findHistory(Long tmTextUnitId, Long localeId) { return tmTextUnitVariantRepository.findAllByTmTextUnit_IdAndLocale_IdOrderByCreatedDateDesc(tmTextUnitId, localeId); }  List<TMTextUnitVariant> findHistory(Long tmTextUnitId, Long localeId);  }
@Test public void testEmptyHistory() throws RepositoryNameAlreadyUsedException { createTestData(); logger.debug("Done creating data for test, start testing"); Long addTextUnitAndCheck1 = addTextUnitAndCheck(tmId, assetId, "name", "this is the content", "some comment", "3063c39d3cf8ab69bcabbbc5d7187dc9", "cf8ea6b6848f23345648038bc3abf324"); Locale frFRLocale = localeService.findByBcp47Tag("fr-FR"); List<TMTextUnitVariant> history = tmHistoryService.findHistory(addTextUnitAndCheck1, frFRLocale.getId()); assertNotNull(history); assertTrue(history.isEmpty()); }
@Test public void testHistoryOneVariant() throws RepositoryNameAlreadyUsedException { createTestData(); logger.debug("Done creating data for test, start testing"); Long addTextUnitAndCheck1 = addTextUnitAndCheck(tmId, assetId, "name", "this is the content", "some comment", "3063c39d3cf8ab69bcabbbc5d7187dc9", "cf8ea6b6848f23345648038bc3abf324"); logger.debug("Add a current translation for french"); Locale frFRLocale = localeService.findByBcp47Tag("fr-FR"); 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); TMTextUnitVariant addCurrentTMTextUnitVariant = addCurrentTMTextUnitVariant(tmTextUnit.getId(), frFRLocale.getId(), "FR[this is the content]", "0a30a359b20fd4095fc17fb586e8db4d"); List<TMTextUnitVariant> history = tmHistoryService.findHistory(addTextUnitAndCheck1, frFRLocale.getId()); assertNotNull(history); assertFalse(history.isEmpty()); Iterator<TMTextUnitVariant> iterator = history.iterator(); assertTrue(iterator.hasNext()); TMTextUnitVariant first = iterator.next(); assertEquals(first.getContent(), "FR[this is the content]"); assertEquals(first.getLocale().getBcp47Tag(), "fr-FR"); assertEquals(first.getStatus(), TMTextUnitVariant.Status.APPROVED); assertNotNull(first.getCreatedByUser()); assertFalse(iterator.hasNext()); }
@Test public void testHistoryMultipleVariants() throws RepositoryNameAlreadyUsedException { createTestData(); logger.debug("Done creating data for test, start testing"); Long addTextUnitAndCheck1 = addTextUnitAndCheck(tmId, assetId, "name", "this is the content", "some comment", "3063c39d3cf8ab69bcabbbc5d7187dc9", "cf8ea6b6848f23345648038bc3abf324"); logger.debug("Add a current translation for french"); Locale frFRLocale = localeService.findByBcp47Tag("fr-FR"); Long frLocaleId = frFRLocale.getId(); 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); addCurrentTMTextUnitVariant(tmTextUnit.getId(), frLocaleId, "FR[this is the content]", "0a30a359b20fd4095fc17fb586e8db4d"); DateTime now = DateTime.now(); tmService.addTMTextUnitVariant(tmTextUnit.getId(), frLocaleId, "Ceci est le content", "comment 1", TMTextUnitVariant.Status.REVIEW_NEEDED, true, now.minusHours(1)); tmService.addTMTextUnitVariant(tmTextUnit.getId(), frLocaleId, "Ceci, c'est le content", "comment 2", TMTextUnitVariant.Status.TRANSLATION_NEEDED, true, now.minusHours(2)); List<TMTextUnitVariant> history = tmHistoryService.findHistory(addTextUnitAndCheck1, frFRLocale.getId()); assertNotNull(history); assertFalse(history.isEmpty()); assertEquals(history.size(), 3); Iterator<TMTextUnitVariant> iterator = history.iterator(); assertTrue(iterator.hasNext()); TMTextUnitVariant variant = iterator.next(); assertEquals(variant.getContent(), "FR[this is the content]"); assertEquals(variant.getLocale().getBcp47Tag(), "fr-FR"); assertEquals(variant.getStatus(), TMTextUnitVariant.Status.APPROVED); assertNotNull(variant.getCreatedByUser()); variant = iterator.next(); assertEquals(variant.getContent(), "Ceci est le content"); assertEquals(variant.getLocale().getBcp47Tag(), "fr-FR"); assertEquals(variant.getStatus(), TMTextUnitVariant.Status.REVIEW_NEEDED); assertNotNull(variant.getCreatedByUser()); variant = iterator.next(); assertEquals(variant.getContent(), "Ceci, c'est le content"); assertEquals(variant.getLocale().getBcp47Tag(), "fr-FR"); assertEquals(variant.getStatus(), TMTextUnitVariant.Status.TRANSLATION_NEEDED); assertNotNull(variant.getCreatedByUser()); assertFalse(iterator.hasNext()); }