Package org.zanata.apicompat.rest.dto.resource

Examples of org.zanata.apicompat.rest.dto.resource.Resource


    @Test
    @RunAsClient
    public void postJsonResource() throws Exception {
        // Create a new Resource
        final Resource res = new Resource("new-resource");
        res.setType(ResourceType.FILE);
        res.setContentType(ContentType.TextPlain);
        res.setLang(LocaleId.EN_US);
        res.setRevision(1);
        res.getExtensions(true).add(new PoHeader("This is a PO Header"));

        TextFlow tf1 = new TextFlow("tf1", LocaleId.EN_US, "First Text Flow");
        tf1.getExtensions(true).add(new SimpleComment("This is one comment"));
        res.getTextFlows().add(tf1);

        new ResourceRequest(
                getRestEndpointUrl("/projects/p/sample-project/iterations/i/1.0/r"),
                "POST", getAuthorizedEnvironment()) {
            @Override
            protected void prepareRequest(ClientRequest request) {
                request.queryParameter("ext", PoHeader.ID).queryParameter(
                        "ext", SimpleComment.ID);
                request.body(MediaType.APPLICATION_JSON, jsonMarshal(res));
            }

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

        // Verify that it was created successfully
        ISourceDocResource sourceDocClient =
                super.createProxy(
                        createClientProxyFactory(TRANSLATOR, TRANSLATOR_KEY),
                        ISourceDocResource.class,
                        "/projects/p/sample-project/iterations/i/1.0/r");
        ClientResponse<Resource> resourceResponse =
                sourceDocClient.getResource(res.getName(), new StringSet(
                        PoHeader.ID + ";" + SimpleComment.ID));

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

        Resource createdResource = resourceResponse.getEntity();

        assertThat(createdResource.getName(), is(res.getName()));
        assertThat(createdResource.getType(), is(res.getType()));
        assertThat(createdResource.getContentType(), is(res.getContentType()));
        assertThat(createdResource.getLang(), is(res.getLang()));
        assertThat(createdResource.getRevision(), is(1)); // Created, so
                                                          // revision 1

        // Extensions
        assertThat(createdResource.getExtensions(true).size(),
                greaterThanOrEqualTo(1));
        assertThat(
                createdResource.getExtensions(true).findByType(PoHeader.class)
                        .getComment(), is("This is a PO Header"));

        // Text Flow
        assertThat(createdResource.getTextFlows().size(), is(1));

        TextFlow createdTf = createdResource.getTextFlows().get(0);
        assertThat(createdTf.getContents(), is(tf1.getContents()));
        assertThat(createdTf.getId(), is(tf1.getId()));
        assertThat(createdTf.getLang(), is(tf1.getLang()));
        assertThat(createdTf.getRevision(), is(1)); // Create, so revision 1
View Full Code Here


    @Test
    @RunAsClient
    public void putJsonResource() throws Exception {
        // Create a new Resource
        final Resource res = new Resource("new-put-resource");
        res.setType(ResourceType.FILE);
        res.setContentType(ContentType.TextPlain);
        res.setLang(LocaleId.EN_US);
        res.setRevision(1);
        res.getExtensions(true).add(new PoHeader("This is a PO Header"));

        TextFlow tf1 = new TextFlow("tf1", LocaleId.EN_US, "First Text Flow");
        tf1.getExtensions(true).add(new SimpleComment("This is one comment"));
        res.getTextFlows().add(tf1);

        new ResourceRequest(
                getRestEndpointUrl("/projects/p/sample-project/iterations/i/1.0/r/"
                        + res.getName()), "PUT", getAuthorizedEnvironment()) {
            @Override
            protected void prepareRequest(ClientRequest request) {
                request.queryParameter("ext", SimpleComment.ID).queryParameter(
                        "ext", PoHeader.ID);
                request.body(MediaType.APPLICATION_JSON, jsonMarshal(res));
            }

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

        ISourceDocResource translationsClient =
                super.createProxy(
                        createClientProxyFactory(TRANSLATOR, TRANSLATOR_KEY),
                        ISourceDocResource.class,
                        "/projects/p/sample-project/iterations/i/1.0/r/");
        // Verify that it was created successfully
        ClientResponse<Resource> resourceResponse =
                translationsClient.getResource(res.getName(), new StringSet(
                        PoHeader.ID + ";" + SimpleComment.ID));
        Resource createdResource = resourceResponse.getEntity();

        assertThat(createdResource.getName(), is(res.getName()));
        assertThat(createdResource.getType(), is(res.getType()));
        assertThat(createdResource.getContentType(), is(res.getContentType()));
        assertThat(createdResource.getLang(), is(res.getLang()));
        assertThat(createdResource.getRevision(), is(1)); // Created, so
                                                          // revision 1

        // Extensions
        assertThat(createdResource.getExtensions(true).size(),
                greaterThanOrEqualTo(1));
        assertThat(
                createdResource.getExtensions(true).findByType(PoHeader.class)
                        .getComment(), is("This is a PO Header"));

        // Text Flow
        assertThat(createdResource.getTextFlows().size(), is(1));

        TextFlow createdTf = createdResource.getTextFlows().get(0);
        assertThat(createdTf.getContents(), is(tf1.getContents()));
        assertThat(createdTf.getId(), is(tf1.getId()));
        assertThat(createdTf.getLang(), is(tf1.getLang()));
        assertThat(createdTf.getRevision(), is(1)); // Create, so revision 1
View Full Code Here

    @Test
    @RunAsClient
    public void postResource() throws Exception {
        // Create a new Resource
        Resource res = new Resource("new-resource");
        res.setType(ResourceType.FILE);
        res.setContentType(ContentType.TextPlain);
        res.setLang(LocaleId.EN_US);
        res.setRevision(1);
        res.getExtensions(true).add(new PoHeader("This is a PO Header"));

        TextFlow tf1 = new TextFlow("tf1", LocaleId.EN_US, "First Text Flow");
        tf1.getExtensions(true).add(new SimpleComment("This is one comment"));
        res.getTextFlows().add(tf1);

        ISourceDocResource sourceDocClient =
                super.createProxy(createClientProxyFactory(ADMIN, ADMIN_KEY),
                        ISourceDocResource.class,
                        "/projects/p/sample-project/iterations/i/1.0/r/");
        ClientResponse<String> response =
                sourceDocClient.post(res, new StringSet(PoHeader.ID + ";"
                        + SimpleComment.ID), true);

        assertThat(response.getStatus(), is(Status.CREATED.getStatusCode())); // 201
        response.releaseConnection();

        // Verify that it was created successfully
        ClientResponse<Resource> resourceResponse =
                sourceDocClient.getResource(res.getName(), new StringSet(
                        PoHeader.ID + ";" + SimpleComment.ID));
        Resource createdResource = resourceResponse.getEntity();

        assertThat(createdResource.getName(), is(res.getName()));
        assertThat(createdResource.getType(), is(res.getType()));
        assertThat(createdResource.getContentType(), is(res.getContentType()));
        assertThat(createdResource.getLang(), is(res.getLang()));
        assertThat(createdResource.getRevision(), is(1)); // Created, so
                                                          // revision 1

        // Extensions
        assertThat(createdResource.getExtensions(true).size(),
                greaterThanOrEqualTo(1));
        assertThat(
                createdResource.getExtensions(true).findByType(PoHeader.class)
                        .getComment(), is("This is a PO Header"));

        // Text Flow
        assertThat(createdResource.getTextFlows().size(), is(1));

        TextFlow createdTf = createdResource.getTextFlows().get(0);
        assertThat(createdTf.getContents().get(0), is(tf1.getContents().get(0)));
        assertThat(createdTf.getId(), is(tf1.getId()));
        assertThat(createdTf.getLang(), is(tf1.getLang()));
        assertThat(createdTf.getRevision(), is(1)); // Create, so revision 1
View Full Code Here

    @Test
    @RunAsClient
    public void doublePostResource() throws Exception {
        // Create a new Resource
        Resource res = new Resource("double-posted-resource");
        res.setType(ResourceType.FILE);
        res.setContentType(ContentType.TextPlain);
        res.setLang(LocaleId.EN_US);
        res.setRevision(1);

        // Post once
        ISourceDocResource sourceDocClient =
                super.createProxy(createClientProxyFactory(ADMIN, ADMIN_KEY),
                        ISourceDocResource.class,
View Full Code Here

    @Test
    @RunAsClient
    public void putResource() throws Exception {
        // Create a new Resource
        Resource res = new Resource("new-put-resource");
        res.setType(ResourceType.FILE);
        res.setContentType(ContentType.TextPlain);
        res.setLang(LocaleId.EN_US);
        res.setRevision(1);
        res.getExtensions(true).add(new PoHeader("This is a PO Header"));

        TextFlow tf1 = new TextFlow("tf1", LocaleId.EN_US, "First Text Flow");
        tf1.getExtensions(true).add(new SimpleComment("This is one comment"));
        res.getTextFlows().add(tf1);

        ISourceDocResource sourceDocClient =
                super.createProxy(createClientProxyFactory(ADMIN, ADMIN_KEY),
                        ISourceDocResource.class,
                        "/projects/p/sample-project/iterations/i/1.0/r/");
        ClientResponse<String> response =
                sourceDocClient.putResource(res.getName(), res, new StringSet(
                        PoHeader.ID + ";" + SimpleComment.ID));

        assertThat(response.getStatus(), is(Status.CREATED.getStatusCode())); // 201
        response.releaseConnection();

        // Verify that it was created successfully
        ClientResponse<Resource> resourceResponse =
                sourceDocClient.getResource(res.getName(), new StringSet(
                        PoHeader.ID + ";" + SimpleComment.ID));
        Resource createdResource = resourceResponse.getEntity();

        assertThat(createdResource.getName(), is(res.getName()));
        assertThat(createdResource.getType(), is(res.getType()));
        assertThat(createdResource.getContentType(), is(res.getContentType()));
        assertThat(createdResource.getLang(), is(res.getLang()));
        assertThat(createdResource.getRevision(), is(1)); // Created, so
                                                          // revision 1

        // Extensions
        assertThat(createdResource.getExtensions(true).size(),
                greaterThanOrEqualTo(1));
        assertThat(
                createdResource.getExtensions(true).findByType(PoHeader.class)
                        .getComment(), is("This is a PO Header"));

        // Text Flow
        assertThat(createdResource.getTextFlows().size(), is(1));

        TextFlow createdTf = createdResource.getTextFlows().get(0);
        assertThat(createdTf.getContents().get(0), is(tf1.getContents().get(0)));
        assertThat(createdTf.getId(), is(tf1.getId()));
        assertThat(createdTf.getLang(), is(tf1.getLang()));
        assertThat(createdTf.getRevision(), is(1)); // Create, so revision 1
View Full Code Here

                        ISourceDocResource.class,
                        "/projects/p/sample-project/iterations/i/1.0/r/");
        ClientResponse<Resource> response =
                sourceDocClient.getResource("my,path,document-2.txt",
                        new StringSet(SimpleComment.ID));
        Resource resource = response.getEntity();

        assertThat(resource.getName(), is("my/path/document-2.txt"));
        assertThat(resource.getType(), is(ResourceType.FILE));
        assertThat(resource.getLang(), is(LocaleId.EN_US));

        // Make sure all Text Flows are present
        assertThat(resource.getTextFlows().size(), greaterThanOrEqualTo(3));

        // Evaluate individual text flows
        TextFlow txtFlow = resource.getTextFlows().get(0);
        assertThat(txtFlow.getId(), is("tf2"));
        assertThat(txtFlow.getRevision(), is(1));
        assertThat(txtFlow.getContents().get(0), is("mssgId1"));

        txtFlow = resource.getTextFlows().get(1);
        assertThat(txtFlow.getId(), is("tf3"));
        assertThat(txtFlow.getRevision(), is(1));
        assertThat(txtFlow.getContents().get(0), is("mssgId2"));

        txtFlow = resource.getTextFlows().get(2);
        assertThat(txtFlow.getId(), is("tf4"));
        assertThat(txtFlow.getRevision(), is(1));
        assertThat(txtFlow.getContents().get(0), is("mssgId3"));
    }
View Full Code Here

    @Test
    @RunAsClient
    public void deleteResource() throws Exception {
        // Create a new Resource
        Resource res = new Resource("delete-resource");
        res.setType(ResourceType.FILE);
        res.setContentType(ContentType.TextPlain);
        res.setLang(LocaleId.EN_US);
        res.setRevision(1);

        ISourceDocResource sourceDocClient =
                super.createProxy(createClientProxyFactory(ADMIN, ADMIN_KEY),
                        ISourceDocResource.class,
                        "/projects/p/sample-project/iterations/i/1.0/r/");
        ClientResponse<String> response =
                sourceDocClient.putResource(res.getName(), res, new StringSet(
                        PoHeader.ID + ";" + SimpleComment.ID));

        assertThat(response.getStatus(), is(Status.CREATED.getStatusCode())); // 201
        response.releaseConnection();

        // Delete the resource
        ClientResponse<String> deleteResponse =
                sourceDocClient.deleteResource(res.getName());

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

        // try to fetch it again
        ClientResponse<Resource> getResponse =
                sourceDocClient.getResource(res.getName(), null);
        assertThat(getResponse.getStatus(),
                is(Status.NOT_FOUND.getStatusCode())); // 404
        getResponse.releaseConnection();
    }
View Full Code Here

            @Override
            protected void onResponse(ClientResponse response) {
                assertJsonUnmarshal(response, Resource.class);

                Resource resource = jsonUnmarshal(response, Resource.class);
                assertThat(resource.getName(), is("my/path/document-2.txt"));
                assertThat(resource.getType(), is(ResourceType.FILE));
                assertThat(resource.getLang(), is(LocaleId.EN_US));

                // Make sure all Text Flows are present
                assertThat(resource.getTextFlows().size(),
                        greaterThanOrEqualTo(3));

                // Evaluate individual text flows
                TextFlow txtFlow = resource.getTextFlows().get(0);
                assertThat(txtFlow.getId(), is("tf2"));
                assertThat(txtFlow.getRevision(), is(1));
                assertThat(txtFlow.getContent(), is("mssgId1"));

                txtFlow = resource.getTextFlows().get(1);
                assertThat(txtFlow.getId(), is("tf3"));
                assertThat(txtFlow.getRevision(), is(1));
                assertThat(txtFlow.getContent(), is("mssgId2"));

                txtFlow = resource.getTextFlows().get(2);
                assertThat(txtFlow.getId(), is("tf4"));
                assertThat(txtFlow.getRevision(), is(1));
                assertThat(txtFlow.getContent(), is("mssgId3"));
            }
        }.run();
View Full Code Here

TOP

Related Classes of org.zanata.apicompat.rest.dto.resource.Resource

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.