Package org.zanata.model

Examples of org.zanata.model.HDocument


        documentService = new DocumentServiceImpl();
        documentService.init(projectIterationDAO, documentDAO, msgs);

        HProjectIteration version = Mockito.mock(HProjectIteration.class);
        HProject project = Mockito.mock(HProject.class);
        HDocument document = Mockito.mock(HDocument.class);

        webHooks = Lists.newArrayList();
        webHooks.add(new WebHook(project, "http://test.com"));
        webHooks.add(new WebHook(project, "http://test1.com"));

        when(projectIterationDAO.findById(versionId)).thenReturn(version);
        when(version.getProject()).thenReturn(project);
        when(version.getSlug()).thenReturn(versionSlug);
        when(project.getSlug()).thenReturn(projectSlug);
        when(project.getWebHooks()).thenReturn(webHooks);
        when(documentDAO.getById(docId)).thenReturn(document);
        when(document.getDocId()).thenReturn(docIdString);

        when(msgs.format(anyString())).thenReturn("test message");
    }
View Full Code Here


                }
            }
        }

        // Create the document
        HDocument doc = new HDocument();
        doc.setContentType(ContentType.TextPlain);
        doc.setLocale(localeDAO.findByLocaleId(LocaleId.EN_US));
        doc.setProjectIteration(projectIteration);
        if (execution.documentMatches) {
            doc.setFullPath("/same/document");
        } else {
            doc.setFullPath("/different/document");
        }
        projectIteration.getDocuments().put(doc.getDocId(), doc);

        // Create the text Flow
        HTextFlow textFlow = new HTextFlow();
        textFlow.setContents("Source Content"); // Source content matches
        textFlow.setPlural(false);
        textFlow.setObsolete(false);
        textFlow.setDocument(doc);
        if (execution.contextMatches) {
            textFlow.setResId("same-context");
        } else {
            textFlow.setResId("different-context");
        }
        doc.getTextFlows().add(textFlow);

        projectIteration = iterationDAO.makePersistent(projectIteration);
        getEm().flush(); // So the rest of the test sees the results

        HCopyTransOptions options =
                new HCopyTransOptions(execution.getContextMismatchAction(),
                        execution.getDocumentMismatchAction(),
                        execution.getProjectMismatchAction());
        CopyTransService copyTransService =
                seam.autowire(CopyTransServiceImpl.class);
        copyTransService.copyTransForIteration(projectIteration, options,
                new CopyTransTaskHandle());
        getEm().flush();

        // Validate execution
        HTextFlow targetTextFlow =
                (HTextFlow) getEm()
                        .createQuery(
                                "from HTextFlow tf where tf.document.projectIteration = :projectIteration "
                                        + "and tf.document.docId = :docId and tf.resId = :resId")
                        .setParameter("projectIteration", projectIteration)
                        .setParameter("docId", doc.getDocId())
                        .setParameter("resId", textFlow.getResId())
                        .getSingleResult();
        // Id: 3L for Locale de
        HTextFlowTarget target = targetTextFlow.getTargets().get(3L);
View Full Code Here

        from.setName("name");
        from.setType(ResourceType.FILE);

        HLocale hLocale = new HLocale(LocaleId.EN_US);

        HDocument to = new HDocument("fullPath", ContentType.PO, hLocale);

        Set<String> commentExt = new HashSet<String>();
        commentExt.add(SimpleComment.ID);
        resourceUtils.transferFromResourceMetadata(from, to, commentExt,
                hLocale, 1);
View Full Code Here

        for (int i = 0; i < numOfTextFlows; i++) {
            addSampleTextFlow(from, localeId, i);
        }

        // this is the same from org/zanata/service/impl/DocumentServiceImpl.java:140
        HDocument to = new HDocument(from.getName(), from.getContentType(), locale);
        to.setProjectIteration(iteration);
        getEm().persist(to);
        getEm().flush();


        log.info("======= start of transfer {} textflows ======", numOfTextFlows);
View Full Code Here

        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);
        log.info("==== stop translateAllInDoc: {}", mon.stop());
        getEm().getTransaction().commit();
        getEm().getTransaction().begin();
View Full Code Here

    public void testTextFlowBatching() {
        String newVersionSlug = "new-version";
        CopyVersionServiceImpl spyService = spy(service);
        int tfCount = spyService.TF_BATCH_SIZE + 1;

        HDocument existingDoc = getTestDocWithNoTF();
        String existingProjectSlug =
                existingDoc.getProjectIteration().getProject().getSlug();
        String existingVersionSlug =
                existingDoc.getProjectIteration().getSlug();

        createNewVersion(existingProjectSlug, existingVersionSlug,
                newVersionSlug);

        insertTextFlowAndTargetToDoc(existingDoc, tfCount, false);

        spyService.copyVersion(existingProjectSlug, existingVersionSlug,
                newVersionSlug, new CopyVersionTaskHandle());

        int expectedTfBatchRuns =
                (tfCount / spyService.TF_BATCH_SIZE)
                        + (tfCount % spyService.TF_BATCH_SIZE == 0 ? 0 : 1);

        verify(spyService, times(expectedTfBatchRuns)).copyTextFlowBatch(
                Matchers.eq(existingDoc.getId()), Matchers.anyLong(),
                Matchers.anyInt(), Matchers.anyInt());
    }
View Full Code Here

    @Test
    public void testTextFlowTargetBatching() {
        String newVersionSlug = "new-version";
        CopyVersionServiceImpl spyService = spy(service);
        HDocument existingDoc = getTestDocWithNoTF();

        String existingProjectSlug =
                existingDoc.getProjectIteration().getProject().getSlug();
        String existingVersionSlug =
                existingDoc.getProjectIteration().getSlug();

        createNewVersion(existingProjectSlug, existingVersionSlug,
                newVersionSlug);

        int tftSize = insertTextFlowAndTargetToDoc(existingDoc, 1, true);
View Full Code Here

        assertVersion(existingVersion, newVersion, newVersionSlug,
                existingVersion.getStatus());

        for (Map.Entry<String, HDocument> entry : newVersion.getDocuments()
                .entrySet()) {
            HDocument existingDoc = existingVersion.getDocuments().get(
                    entry.getValue().getDocId());
            HDocument newDoc = entry.getValue();

            assertDocument(existingDoc, newDoc);

            HRawDocument newRawDoc =
                    rawDocumentDAO.getByDocumentId(newDoc.getId());
            HRawDocument oldRawDoc = existingDoc.getRawDocument();
            assertRawDocument(newRawDoc, oldRawDoc);

            assertThat(newDoc.getTextFlows().size()).isEqualTo(
                    existingDoc.getTextFlows().size());

            for (int i = 0; i < existingDoc.getTextFlows().size(); i++) {
                HTextFlow existingTf = existingDoc.getTextFlows().get(i);
                HTextFlow newTf = newDoc.getTextFlows().get(i);

                assertTextFlow(true, existingTf, newTf, newDoc);

                assertThat(newTf.getTargets().size()).isEqualTo(
                        existingTf.getTargets().size());
View Full Code Here

    }

    @Test
    public void testCopyDocument() throws Exception {
        HProjectIteration dummyVersion = getDummyVersion("new-version");
        HDocument existingDoc = documentDAO.getById(1L);

        HDocument newDocument =
                service.copyDocument(dummyVersion, existingDoc);

        assertDocument(existingDoc, newDocument);
    }
View Full Code Here

        assertDocument(existingDoc, newDocument);
    }

    @Test
    public void testCopyRawDocument() throws Exception {
        HDocument existingDoc = documentDAO.getById(1L);
        HRawDocument newRawDoc =
                service.copyRawDocument(getDummyDocument(),
                        existingDoc.getRawDocument());

        assertRawDocument(newRawDoc, existingDoc.getRawDocument());
    }
View Full Code Here

TOP

Related Classes of org.zanata.model.HDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.