static void clearRevs(TranslationsResource doc) { doc.setRevision(null); for (TextFlowTarget tft : doc.getTextFlowTargets()) { tft.setRevision(null); tft.setTextFlowRevision(null); } }
// @Test(enabled = true, description = "this should only be executed manually in IDE") @Ignore @Test @PerformanceProfiling public void pushTranslation() { EntityMaker entityMaker = EntityMakerBuilder.builder() .addFieldOrPropertyMaker( HProject.class, "sourceViewURL", FixedValueMaker.EMPTY_STRING_MAKER) .build(); HProjectIteration iteration = entityMaker.makeAndPersist(getEm(), HProjectIteration.class); HLocale srcLocale = createAndPersistLocale(LocaleId.EN_US, getEm()); HLocale transLocale = createAndPersistLocale(LocaleId.DE, getEm()); String versionSlug = iteration.getSlug(); String projectSlug = iteration.getProject().getSlug(); HDocument document = new HDocument("message", ContentType.PO, srcLocale); document.setProjectIteration(iteration); getEm().persist(document); getEm().flush(); // adjust this number to suit testing purpose int numOfTextFlows = 50; int numOfTextFlowsHavingTarget = createSourceAndSomeTargets(document, transLocale, numOfTextFlows); getEm().getTransaction().commit(); getEm().getTransaction().begin(); Long targetsCountBefore = getEm() .createQuery("select count(*) from HTextFlowTarget where locale = :locale", Long.class) .setParameter("locale", transLocale) .getSingleResult(); Assertions.assertThat(targetsCountBefore).isEqualTo(numOfTextFlowsHavingTarget); // ============ add targets ========= TranslationsResource translations = new TranslationsResource(); translations.setRevision(1); for (int i = 0; i < numOfTextFlows; i++) { addSampleTranslation(translations, "res" + i); } Monitor mon = MonitorFactory.start(""); log.info("==== start translateAllInDoc"); service.translateAllInDoc( projectSlug, versionSlug, document.getDocId(), transLocale.getLocaleId(), translations, extensions, MergeType.AUTO, false, TranslationSourceType.API_UPLOAD); log.info("==== stop translateAllInDoc: {}", mon.stop()); getEm().getTransaction().commit(); getEm().getTransaction().begin(); Long targetsCount = getEm() .createQuery("select count(*) from HTextFlowTarget where locale = :locale", Long.class) .setParameter("locale", transLocale) .getSingleResult(); Assertions.assertThat(targetsCount).isEqualTo(numOfTextFlows); List<HTextFlowTargetHistory> histories = getEm() .createQuery("from HTextFlowTargetHistory", HTextFlowTargetHistory.class) .getResultList(); Assertions.assertThat(histories).hasSize(numOfTextFlowsHavingTarget); }