Esempio n. 1
0
 static void clearRevs(TranslationsResource doc) {
   doc.setRevision(null);
   for (TextFlowTarget tft : doc.getTextFlowTargets()) {
     tft.setRevision(null);
     tft.setTextFlowRevision(null);
   }
 }
  public TranslationsResource getAllExtension() {
    TranslationsResource sr = getPoTargetHeaderTextFlowTargetTest();
    TextFlowTarget stf = sr.getTextFlowTargets().get(0);

    SimpleComment simpleComment = new SimpleComment("textflowtarget comment");

    stf.getExtensions(true).add(simpleComment);
    return sr;
  }
Esempio n. 3
0
 static void clearPoTargetHeaders(TranslationsResource... docs) {
   for (TranslationsResource doc : docs) {
     Iterator<TranslationsResourceExtension> it = doc.getExtensions(true).iterator();
     while (it.hasNext()) {
       if (it.next() instanceof PoTargetHeader) {
         it.remove();
       }
     }
   }
 }
  public TranslationsResource getPoTargetHeaderTextFlowTargetTest() {
    TranslationsResource sr = getTestObject();
    PoTargetHeader poTargetHeader =
        new PoTargetHeader(
            "target header comment\nAdmin user <root@localhost>, 2011. #zanata",
            new HeaderEntry("ht", "vt1"),
            new HeaderEntry("th2", "tv2"),
            new HeaderEntry("Content-Type", "charset=UTF-8"));

    sr.getExtensions(true).add(poTargetHeader);
    return sr;
  }
 public TranslationsResource getTestObject() {
   TranslationsResource entity = new TranslationsResource();
   TextFlowTarget target = new TextFlowTarget("rest1");
   target.setContents("hello world");
   target.setState(ContentState.Approved);
   target.setTranslator(new Person("root@localhost", "Administrator"));
   // for the convenience of test
   target.getExtensions(true);
   entity.getTextFlowTargets().add(target);
   entity.getExtensions(true);
   return entity;
 }
 private static void addSampleTranslation(TranslationsResource translations, String resId) {
   TextFlowTarget target = new TextFlowTarget(resId);
   target.setRevision(1);
   target.setState(ContentState.Translated);
   target.setContents("translated " + resId);
   translations.getTextFlowTargets().add(target);
 }
 public TranslationsResource getTestObject2() {
   TranslationsResource entity = new TranslationsResource();
   TextFlowTarget target = new TextFlowTarget("rest1");
   target.setContents("hello world");
   target.setState(ContentState.Approved);
   target.setTranslator(new Person("root@localhost", "Administrator"));
   target.getExtensions(true);
   TextFlowTarget target2 = new TextFlowTarget("rest2");
   target2.setContents("greeting world");
   target2.setState(ContentState.Approved);
   target2.setTranslator(new Person("root@localhost", "Administrator"));
   target2.getExtensions(true);
   entity.getTextFlowTargets().add(target2);
   entity.getExtensions(true);
   log.debug(entity.toString());
   return entity;
 }
  //    @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);
  }