Package org.zanata.apicompat.rest.client

Examples of org.zanata.apicompat.rest.client.ITranslatedDocResource


    }

    @Test
    @RunAsClient
    public void getTranslations() throws Exception {
        ITranslatedDocResource translationsClient =
                super.createProxy(
                        createClientProxyFactory(TRANSLATOR, TRANSLATOR_KEY),
                        ITranslatedDocResource.class,
                        "/projects/p/sample-project/iterations/i/1.0/r/");
        ClientResponse<TranslationsResource> response =
                translationsClient.getTranslations("my,path,document-2.txt",
                        LocaleId.EN_US, new StringSet(SimpleComment.ID));
        TranslationsResource transRes = response.getEntity();

        assertThat(response.getStatus(), is(Status.OK.getStatusCode())); // 200
        assertThat(transRes.getTextFlowTargets().size(),
View Full Code Here


    }

    @Test
    @RunAsClient
    public void putTranslations() throws Exception {
        ITranslatedDocResource translationsClient =
                super.createProxy(createClientProxyFactory(ADMIN, ADMIN_KEY),
                        ITranslatedDocResource.class,
                        "/projects/p/sample-project/iterations/i/1.0/r/");
        ClientResponse<TranslationsResource> response =
                translationsClient.getTranslations("my,path,document-2.txt",
                        LocaleId.EN_US, new StringSet(SimpleComment.ID));
        TranslationsResource transRes = response.getEntity();

        assertThat(response.getStatus(), is(Status.OK.getStatusCode())); // 200
        assertThat(transRes.getTextFlowTargets().size(),
                greaterThanOrEqualTo(3));

        // Alter the translations
        transRes.getTextFlowTargets().get(0).setContents("Translated 1");
        transRes.getTextFlowTargets().get(1).setContents("Translated 2");
        transRes.getTextFlowTargets().get(2).setContents("Translated 3");

        transRes.getTextFlowTargets().get(0).setState(ContentState.Approved);
        transRes.getTextFlowTargets().get(1).setState(ContentState.Approved);
        transRes.getTextFlowTargets().get(2).setState(ContentState.Approved);

        transRes.getTextFlowTargets().get(0).getExtensions(true)
                .add(new SimpleComment("Translated Comment 1"));
        transRes.getTextFlowTargets().get(1).getExtensions(true)
                .add(new SimpleComment("Translated Comment 2"));
        transRes.getTextFlowTargets().get(2).getExtensions(true)
                .add(new SimpleComment("Translated Comment 3"));

        // Put the translations
        ClientResponse<String> putResponse =
                translationsClient.putTranslations("my,path,document-2.txt",
                        LocaleId.EN_US, transRes, new StringSet(
                                SimpleComment.ID));

        assertThat(putResponse.getStatus(), is(Status.OK.getStatusCode())); // 200
        putResponse.releaseConnection();

        // Retrieve the translations once more to make sure they were changed
        // accordingly
        response =
                translationsClient.getTranslations("my,path,document-2.txt",
                        LocaleId.EN_US, new StringSet(SimpleComment.ID));
        transRes = response.getEntity();

        assertThat(response.getStatus(), is(Status.OK.getStatusCode())); // 200
        assertThat(transRes.getTextFlowTargets().size(),
View Full Code Here

    }

    @Test
    @RunAsClient
    public void deleteTranslations() throws Exception {
        ITranslatedDocResource translationsClient =
                super.createProxy(createClientProxyFactory(ADMIN, ADMIN_KEY),
                        ITranslatedDocResource.class,
                        "/projects/p/sample-project/iterations/i/1.0/r/");
        ClientResponse<String> response =
                translationsClient.deleteTranslations("my,path,document-3.txt",
                        LocaleId.EN_US);

        assertThat(response.getStatus(), is(Status.OK.getStatusCode())); // 200
        response.releaseConnection();

        // try to fetch them again
        ClientResponse<TranslationsResource> getResponse =
                translationsClient.getTranslations("my,path,document-3.txt",
                        LocaleId.EN_US, new StringSet(PoHeader.ID + ";"
                                + SimpleComment.ID));
        List<TextFlowTarget> targets =
                getResponse.getEntity().getTextFlowTargets();
        for (TextFlowTarget target : targets) {
View Full Code Here

    @Test
    @RunAsClient
    public void putJsonTranslations() throws Exception {
        // Get the original translations
        ITranslatedDocResource translationsClient =
                super.createProxy(
                        createClientProxyFactory(TRANSLATOR, TRANSLATOR_KEY),
                        ITranslatedDocResource.class,
                        "/projects/p/sample-project/iterations/i/1.0/r/");
        ClientResponse<TranslationsResource> response =
                translationsClient.getTranslations("my,path,document-2.txt",
                        LocaleId.EN_US, new StringSet(SimpleComment.ID));
        final TranslationsResource transRes = response.getEntity();

        assertThat(response.getStatus(), is(Status.OK.getStatusCode())); // 200
        assertThat(transRes.getTextFlowTargets().size(),
                greaterThanOrEqualTo(3));

        // Alter the translations
        transRes.getTextFlowTargets().get(0).setContents("Translated 1");
        transRes.getTextFlowTargets().get(1).setContents("Translated 2");
        transRes.getTextFlowTargets().get(2).setContents("Translated 3");

        transRes.getTextFlowTargets().get(0).setState(ContentState.Approved);
        transRes.getTextFlowTargets().get(1).setState(ContentState.Approved);
        transRes.getTextFlowTargets().get(2).setState(ContentState.Approved);

        transRes.getTextFlowTargets().get(0).getExtensions(true)
                .add(new SimpleComment("Translated Comment 1"));
        transRes.getTextFlowTargets().get(1).getExtensions(true)
                .add(new SimpleComment("Translated Comment 2"));
        transRes.getTextFlowTargets().get(2).getExtensions(true)
                .add(new SimpleComment("Translated Comment 3"));

        // Put the translations
        new ResourceRequest(
                getRestEndpointUrl("/projects/p/sample-project/iterations/i/1.0/r/my,path,document-2.txt/translations/"
                        + LocaleId.EN_US), "PUT", getAuthorizedEnvironment()) {
            @Override
            protected void prepareRequest(ClientRequest request) {
                request.queryParameter("ext", SimpleComment.ID);
                request.body(MediaType.APPLICATION_JSON, jsonMarshal(transRes));
            }

            @Override
            protected void onResponse(ClientResponse response) {
                assertThat(response.getStatus(), is(Status.OK.getStatusCode())); // 200
            }
        }.run();

        // Retrieve the translations once more to make sure they were changed
        // accordingly
        response =
                translationsClient.getTranslations("my,path,document-2.txt",
                        LocaleId.EN_US, new StringSet(SimpleComment.ID));
        TranslationsResource updatedTransRes = response.getEntity();

        assertThat(response.getStatus(), is(Status.OK.getStatusCode())); // 200
        assertThat(updatedTransRes.getTextFlowTargets().size(),
View Full Code Here

TOP

Related Classes of org.zanata.apicompat.rest.client.ITranslatedDocResource

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.