Search in sources :

Example 61 with HttpResponse

use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.

the class TestPeople method testUpdatePersonUsingPartialUpdate.

@Test
public void testUpdatePersonUsingPartialUpdate() throws PublicApiException {
    final String personId = account3.createUser().getId();
    publicApiClient.setRequestContext(new RequestContext(account3.getId(), account3Admin, "admin"));
    String updatedFirstName = "Updated firstName";
    HttpResponse response = people.update("people", personId, null, null, "{\n" + "  \"firstName\": \"" + updatedFirstName + "\"\n" + "}", null, "Expected 200 response when updating " + personId, 200);
    Person updatedPerson = Person.parsePerson((JSONObject) response.getJsonResponse().get("entry"));
    assertEquals(updatedFirstName, updatedPerson.getFirstName());
}
Also used : HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Person(org.alfresco.rest.api.tests.client.data.Person) Test(org.junit.Test)

Example 62 with HttpResponse

use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.

the class TestSiteMembers method testSiteMembers.

// TODO set create member for a user who is a member of the site (not the creator)
// TODO split into more manageable test methods
@Test
public void testSiteMembers() throws Exception {
    Iterator<TestNetwork> networksIt = getTestFixture().getNetworksIt();
    final TestNetwork testNetwork = networksIt.next();
    final List<String> networkPeople = testNetwork.getPersonIds();
    String personId = networkPeople.get(0);
    Sites sitesProxy = publicApiClient.sites();
    {
        final List<SiteMember> expectedSiteMembers = new ArrayList<SiteMember>();
        // Create a private site and invite some users
        // TODO create site members using public api rather than directly using the services
        TestSite testSite = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {

            @Override
            public TestSite doWork() throws Exception {
                TestSite testSite = testNetwork.createSite(SiteVisibility.PRIVATE);
                for (int i = 1; i <= 5; i++) {
                    String inviteeId = networkPeople.get(i);
                    testSite.inviteToSite(inviteeId, SiteRole.SiteConsumer);
                    SiteMember sm = new SiteMember(inviteeId, repoService.getPerson(inviteeId), testSite.getSiteId(), SiteRole.SiteConsumer.toString());
                    expectedSiteMembers.add(sm);
                }
                return testSite;
            }
        }, personId, testNetwork.getId());
        {
            SiteMember sm = new SiteMember(personId, repoService.getPerson(personId), testSite.getSiteId(), SiteRole.SiteManager.toString());
            expectedSiteMembers.add(sm);
            Collections.sort(expectedSiteMembers);
        }
        // Test Case cloud-1482
        {
            int skipCount = 0;
            int maxItems = 2;
            Paging paging = getPaging(skipCount, maxItems, expectedSiteMembers.size(), null);
            publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), personId));
            ListResponse<SiteMember> siteMembers = sitesProxy.getSiteMembers(testSite.getSiteId(), createParams(paging, null));
            checkList(expectedSiteMembers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), siteMembers);
        }
        {
            int skipCount = 2;
            int maxItems = 10;
            Paging paging = getPaging(skipCount, maxItems, expectedSiteMembers.size(), null);
            publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), personId));
            ListResponse<SiteMember> siteMembers = sitesProxy.getSiteMembers(testSite.getSiteId(), createParams(paging, null));
            checkList(expectedSiteMembers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), siteMembers);
            HttpResponse response = sitesProxy.getAll("sites", testSite.getSiteId(), "members", null, createParams(paging, Collections.singletonMap("includeSource", "true")), "Failed to get all site members");
            checkList(expectedSiteMembers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), SiteMember.parseSiteMembers(testSite.getSiteId(), response.getJsonResponse()));
            JSONObject source = sitesProxy.parseListSource(response.getJsonResponse());
            Site sourceSite = SiteImpl.parseSite(source);
            assertNotNull(sourceSite);
            testSite.expected(sourceSite);
        }
        // invalid site id
        try {
            int skipCount = 2;
            int maxItems = 10;
            Paging paging = getPaging(skipCount, maxItems, expectedSiteMembers.size(), null);
            publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), personId));
            sitesProxy.getSiteMembers(GUID.generate(), createParams(paging, null));
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        // invalid methods
        try {
            SiteMember siteMember = expectedSiteMembers.get(0);
            publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), personId));
            sitesProxy.update("sites", testSite.getSiteId(), "members", null, siteMember.toJSON().toString(), "Unable to PUT site members");
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
        }
        // Test Case cloud-1965
        try {
            SiteMember siteMember1 = expectedSiteMembers.get(0);
            publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), personId));
            sitesProxy.create("sites", testSite.getSiteId(), "members", siteMember1.getMemberId(), siteMember1.toJSON().toString(), "Unable to POST to a site member");
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
        }
        try {
            SiteMember siteMember1 = expectedSiteMembers.get(0);
            publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), personId));
            sitesProxy.update("sites", testSite.getSiteId(), "members", null, siteMember1.toJSON().toString(), "Unable to PUT site members");
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
        }
        try {
            publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), personId));
            sitesProxy.remove("sites", testSite.getSiteId(), "members", null, "Unable to DELETE site members");
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
        }
        // update site member
        {
            SiteMember siteMember1 = expectedSiteMembers.get(0);
            publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), personId));
            SiteMember ret = sitesProxy.updateSiteMember(testSite.getSiteId(), siteMember1);
            assertEquals(siteMember1.getRole(), ret.getRole());
            Person expectedSiteMember = repoService.getPerson(siteMember1.getMemberId());
            expectedSiteMember.expected(ret.getMember());
        }
        // GET single site member
        {
            SiteMember siteMember1 = expectedSiteMembers.get(0);
            publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), personId));
            SiteMember ret = sitesProxy.getSingleSiteMember(testSite.getSiteId(), siteMember1.getMemberId());
            siteMember1.expected(ret);
        }
    }
    // test: user is member of different tenant, but has site membership(s) in common with the http request user
    {
        Iterator<TestNetwork> accountsIt = getTestFixture().getNetworksIt();
        assertTrue(accountsIt.hasNext());
        final TestNetwork network1 = accountsIt.next();
        assertTrue(accountsIt.hasNext());
        final TestNetwork network2 = accountsIt.next();
        final List<TestPerson> people = new ArrayList<TestPerson>();
        // Create users
        TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                TestPerson person = network1.createUser();
                people.add(person);
                person = network1.createUser();
                people.add(person);
                person = network1.createUser();
                people.add(person);
                return null;
            }
        }, network1.getId());
        final TestPerson person1 = people.get(0);
        final TestPerson person2 = people.get(1);
        final TestPerson person3 = people.get(2);
        TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                TestPerson person = network2.createUser();
                people.add(person);
                return null;
            }
        }, network2.getId());
        final TestPerson person4 = people.get(3);
        // Create site
        final TestSite site = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {

            @Override
            public TestSite doWork() throws Exception {
                TestSite site = network1.createSite(SiteVisibility.PUBLIC);
                return site;
            }
        }, person2.getId(), network1.getId());
        // invalid role - 400
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
            sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person1.getId(), "dodgyRole"));
            fail("");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
        // user in network but not site member, try to create site member
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person3.getId(), SiteRole.SiteContributor.toString()));
            fail("");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
        }
        // unknown invitee - 404
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
            sitesProxy.createSiteMember(site.getSiteId(), new SiteMember("dodgyUser", SiteRole.SiteContributor.toString()));
            fail("");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        // unknown site - 404
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
            sitesProxy.createSiteMember("dodgySite", new SiteMember(person1.getId(), SiteRole.SiteContributor.toString()));
            fail("");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        // inviter is not a member of the site
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person1.getId(), SiteRole.SiteContributor.toString()));
            fail("");
        } catch (PublicApiException e) {
            assertEquals(e.getMessage(), HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
        }
        // inviter is not a member of the site nor a member of the tenant
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person4.getId()));
            sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person1.getId(), SiteRole.SiteContributor.toString()));
            fail("");
        } catch (PublicApiException e) {
            // TODO check that 404 is correct here - external user of network can't see public site??
            assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
        }
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
            SiteMember sm = new SiteMember(person1.getId(), SiteRole.SiteConsumer.toString());
            SiteMember siteMember = sitesProxy.createSiteMember(site.getSiteId(), sm);
            assertEquals(person1.getId(), siteMember.getMemberId());
            assertEquals(SiteRole.SiteConsumer.toString(), siteMember.getRole());
        }
        // already invited
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
            sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person1.getId(), SiteRole.SiteContributor.toString()));
            fail("");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_CONFLICT, e.getHttpResponse().getStatusCode());
        }
        // inviter is consumer member of the site, should not be able to add site member
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person4.getId(), SiteRole.SiteContributor.toString()));
            fail("");
        } catch (PublicApiException e) {
            assertEquals(e.getMessage(), HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        // invitee from another network
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person4.getId(), SiteRole.SiteContributor.toString()));
            fail("");
        } catch (PublicApiException e) {
            assertEquals(e.getMessage(), HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        // missing person id
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
            sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(null, SiteRole.SiteContributor.toString()));
            fail("");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
        // missing role
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
            sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person1.getId(), null));
            fail("");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
        // check site membership in GET
        List<SiteMember> expectedSiteMembers = site.getMembers();
        {
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expectedSiteMembers.size(), null);
            ListResponse<SiteMember> siteMembers = sitesProxy.getSiteMembers(site.getSiteId(), createParams(paging, null));
            checkList(expectedSiteMembers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), siteMembers);
        }
    }
    // test: create site membership, remove it, get list of site memberships
    {
        Iterator<TestNetwork> accountsIt = getTestFixture().getNetworksIt();
        assertTrue(accountsIt.hasNext());
        final TestNetwork network1 = accountsIt.next();
        assertTrue(accountsIt.hasNext());
        final List<TestPerson> people = new ArrayList<TestPerson>();
        // Create user
        TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                TestPerson person = network1.createUser();
                people.add(person);
                person = network1.createUser();
                people.add(person);
                person = network1.createUser();
                people.add(person);
                return null;
            }
        }, network1.getId());
        TestPerson person1 = people.get(0);
        TestPerson person2 = people.get(1);
        TestPerson person3 = people.get(2);
        // Create site
        TestSite site = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {

            @Override
            public TestSite doWork() throws Exception {
                TestSite site = network1.createSite(SiteVisibility.PRIVATE);
                return site;
            }
        }, person2.getId(), network1.getId());
        // remove site membership
        // for -me- user (PUBLICAPI-90)
        {
            // create a site member
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
            SiteMember siteMember = sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person1.getId(), SiteRole.SiteContributor.toString()));
            assertEquals(person1.getId(), siteMember.getMemberId());
            assertEquals(SiteRole.SiteContributor.toString(), siteMember.getRole());
            SiteMember toRemove = new SiteMember("-me-");
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            sitesProxy.removeSiteMember(site.getSiteId(), toRemove);
        }
        {
            // create a site member
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
            SiteMember siteMember = sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person1.getId(), SiteRole.SiteContributor.toString()));
            assertEquals(person1.getId(), siteMember.getMemberId());
            assertEquals(SiteRole.SiteContributor.toString(), siteMember.getRole());
            // note: needed for contains check below, ugh
            siteMember.setSiteId(site.getSiteId());
            // create another site member
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
            SiteMember siteMemberAno = sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person3.getId(), SiteRole.SiteCollaborator.toString()));
            assertEquals(person3.getId(), siteMemberAno.getMemberId());
            assertEquals(SiteRole.SiteCollaborator.toString(), siteMemberAno.getRole());
            // note: needed for contains check below, ugh
            siteMemberAno.setSiteId(site.getSiteId());
            // unknown site
            try {
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
                sitesProxy.removeSiteMember(GUID.generate(), siteMember);
                fail();
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
            }
            // unknown user
            try {
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
                sitesProxy.removeSiteMember(site.getSiteId(), new SiteMember(GUID.generate()));
                fail();
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
            }
            // cannot update site member (without appropriate site "permission" - see SiteService)
            try {
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
                sitesProxy.updateSiteMember(site.getSiteId(), new SiteMember(person1.getId(), SiteRole.SiteCollaborator.toString()));
                fail();
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_UNPROCESSABLE_ENTITY, e.getHttpResponse().getStatusCode());
            }
            // cannot remove another site member (without appropriate site "permission" - see SiteService)
            try {
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
                sitesProxy.removeSiteMember(site.getSiteId(), new SiteMember(person3.getId()));
                fail();
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_UNPROCESSABLE_ENTITY, e.getHttpResponse().getStatusCode());
            }
            // remove site member
            {
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
                sitesProxy.removeSiteMember(site.getSiteId(), siteMember);
            }
            // check site membership in GET
            List<SiteMember> expectedSiteMembers = site.getMembers();
            assertFalse(expectedSiteMembers.contains(siteMember));
            assertTrue(expectedSiteMembers.contains(siteMemberAno));
            {
                int skipCount = 0;
                int maxItems = Integer.MAX_VALUE;
                Paging paging = getPaging(skipCount, maxItems, expectedSiteMembers.size(), null);
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
                ListResponse<SiteMember> siteMembers = sitesProxy.getSiteMembers(site.getSiteId(), createParams(paging, null));
                checkList(expectedSiteMembers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), siteMembers);
            }
            // unknown site
            try {
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
                sitesProxy.updateSiteMember(GUID.generate(), siteMember);
                fail();
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
            }
            // unknown user
            try {
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
                sitesProxy.updateSiteMember(site.getSiteId(), new SiteMember(GUID.generate()));
                fail();
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
            }
            // invalid role
            try {
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
                sitesProxy.updateSiteMember(site.getSiteId(), new SiteMember(person1.getId(), "invalidRole"));
                fail();
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
            }
            // user is not a member of the site - 400
            try {
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
                sitesProxy.updateSiteMember(site.getSiteId(), new SiteMember(person1.getId(), SiteRole.SiteContributor.toString()));
                fail();
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
            }
            // cannot update last member of site to be a non-manager
            try {
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
                sitesProxy.updateSiteMember(site.getSiteId(), new SiteMember(person2.getId(), SiteRole.SiteContributor.toString()));
                fail();
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_UNPROCESSABLE_ENTITY, e.getHttpResponse().getStatusCode());
            }
            // successful update
            {
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
                SiteMember sm = new SiteMember(person1.getId(), SiteRole.SiteContributor.toString());
                SiteMember ret = sitesProxy.createSiteMember(site.getSiteId(), sm);
                assertEquals(SiteRole.SiteContributor.toString(), ret.getRole());
                person1.expected(ret.getMember());
                sm = new SiteMember(person1.getId(), SiteRole.SiteCollaborator.toString());
                ret = sitesProxy.updateSiteMember(site.getSiteId(), sm);
                assertEquals(SiteRole.SiteCollaborator.toString(), ret.getRole());
                person1.expected(ret.getMember());
                // check site membership in GET
                SiteMember smToCheck = sitesProxy.getSingleSiteMember(site.getSiteId(), person1.getId());
                // check that the update site membership is present
                assertNotNull(smToCheck);
                // check that the role is correct
                assertEquals(sm.getRole(), smToCheck.getRole());
                expectedSiteMembers = new ArrayList<>();
                SiteMember sm1 = new SiteMember(person1.getId(), person1, site.getSiteId(), SiteRole.SiteCollaborator.toString());
                expectedSiteMembers.add(sm1);
                SiteMember sm2 = new SiteMember(person2.getId(), person2, site.getSiteId(), SiteRole.SiteManager.toString());
                expectedSiteMembers.add(sm2);
                SiteMember sm3 = new SiteMember(person3.getId(), person3, site.getSiteId(), SiteRole.SiteCollaborator.toString());
                expectedSiteMembers.add(sm3);
                Collections.sort(expectedSiteMembers);
                int skipCount = 0;
                int maxItems = Integer.MAX_VALUE;
                Paging paging = getPaging(skipCount, maxItems, expectedSiteMembers.size(), null);
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
                ListResponse<SiteMember> siteMembers = sitesProxy.getSiteMembers(site.getSiteId(), createParams(paging, null));
                checkList(expectedSiteMembers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), siteMembers);
            }
        }
    }
}
Also used : TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) Site(org.alfresco.rest.api.tests.client.data.Site) ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) SiteMember(org.alfresco.rest.api.tests.client.data.SiteMember) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Sites(org.alfresco.rest.api.tests.client.PublicApiClient.Sites) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) JSONObject(org.json.simple.JSONObject) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) Person(org.alfresco.rest.api.tests.client.data.Person) Test(org.junit.Test)

Example 63 with HttpResponse

use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.

the class TestSites method testUpdateSite.

@Test
public void testUpdateSite() throws PublicApiException {
    Sites sitesProxy = publicApiClient.sites();
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    // +ve test: simple happy path with successful update.
    {
        SiteImpl siteToCreate = new SiteImpl("Initial Title", SiteVisibility.PRIVATE.toString());
        siteToCreate.setRole(SiteRole.SiteManager);
        siteToCreate.setDescription("This is the initial description for the site");
        Site site = sitesProxy.createSite(siteToCreate, 201);
        // Testing with the actual JSON reveals more than testing with rich POJOs.
        // It shows us exactly what the input is and is easy to compare to the Open API spec.
        String updateJSON = "{\n" + "  \"title\": \"Updated Title\",\n" + "  \"description\": \"This is an updated description for the site\",\n" + "  \"visibility\": \"PUBLIC\"\n" + "}";
        // Update the site details
        HttpResponse response = sitesProxy.update("sites", site.getSiteId(), null, null, updateJSON, "Failed to update site " + site.getSiteId());
        Site updatedSite = SiteImpl.parseSite((JSONObject) response.getJsonResponse().get("entry"));
        Site expectedUpdate = new SiteImpl(null, "initial-title", site.getGuid(), "Updated Title", "This is an updated description for the site", SiteVisibility.PUBLIC.toString(), null, SiteRole.SiteManager);
        // Check the updated site is as expected.
        expectedUpdate.expected(updatedSite);
        // Double check by do a fresh get of the details, since the details returned by updateSite()
        // aren't necessarily retrieved from the DB.
        Site fresh = sitesProxy.getSite(site.getSiteId(), 200);
        expectedUpdate.expected(fresh);
        removeSiteQuietly(site.getSiteId());
    }
    // +ve test: remove the description.
    // This is a workaround for being unable to explicitly null the field (see REPO-1409)
    {
        Site site = sitesProxy.createSite(new SiteImpl(null, "NoDescriptionTest", "Initial description", SiteVisibility.PUBLIC.toString()), 201);
        Site updatedSite = sitesProxy.updateSite(site.getSiteId(), new SiteUpdate("title", "", SiteVisibility.PUBLIC), 200);
        // Note the null value for description, as the framework
        // treats empty strings and null as equivalent in responses, and does not return
        // those fields (as per API guidelines)
        Site expectedUpdate = new SiteImpl(null, "nodescriptiontest", site.getGuid(), "title", null, SiteVisibility.PUBLIC.toString(), null, SiteRole.SiteManager);
        // Check the return from updateSite(...)
        expectedUpdate.expected(updatedSite);
        // TODO improve expected (and/or AssertUtil) and affected test cases
        Assert.assertNull(updatedSite.getDescription());
        // Double check a fresh retrieval matches.
        Site fresh = sitesProxy.getSite(site.getSiteId(), 200);
        expectedUpdate.expected(fresh);
        // TODO improve expected (and/or AssertUtil) and affected test cases
        Assert.assertNull(fresh.getDescription());
        removeSiteQuietly(site.getSiteId());
    }
    // +ve test: partial updates must be allowed
    {
        Site site = sitesProxy.createSite(new SiteImpl("partial-updates-test", "title-v1", "description-v1", SiteVisibility.PUBLIC.toString()), 201);
        // Check we can update just the title
        Site updatedSite = sitesProxy.updateSite(site.getSiteId(), new SiteUpdate("title-v2", null, null), 200);
        Site expectedUpdate = new SiteImpl(null, "partial-updates-test", site.getGuid(), "title-v2", "description-v1", SiteVisibility.PUBLIC.toString(), null, SiteRole.SiteManager);
        expectedUpdate.expected(updatedSite);
        // Check we can update just the description
        updatedSite = sitesProxy.updateSite(site.getSiteId(), new SiteUpdate(null, "description-v2", null), 200);
        expectedUpdate = new SiteImpl(null, "partial-updates-test", site.getGuid(), "title-v2", "description-v2", SiteVisibility.PUBLIC.toString(), null, SiteRole.SiteManager);
        expectedUpdate.expected(updatedSite);
        // Check we can update just the visibility
        updatedSite = sitesProxy.updateSite(site.getSiteId(), new SiteUpdate(null, null, SiteVisibility.PRIVATE), 200);
        expectedUpdate = new SiteImpl(null, "partial-updates-test", site.getGuid(), "title-v2", "description-v2", SiteVisibility.PRIVATE.toString(), null, SiteRole.SiteManager);
        expectedUpdate.expected(updatedSite);
        removeSiteQuietly(site.getSiteId());
    }
    // -ve test: 400, bad requests
    {
        Site site = sitesProxy.createSite(new SiteImpl("Site Update Bad Request Tests", SiteVisibility.PRIVATE.toString()), 201);
        // long title
        sitesProxy.updateSite(site.getSiteId(), new SiteUpdate(new String(new char[257]).replace('\0', 'a'), "description", SiteVisibility.PUBLIC), 400);
        // long description
        sitesProxy.updateSite(site.getSiteId(), new SiteUpdate("title", new String(new char[513]).replace('\0', 'a'), SiteVisibility.PUBLIC), 400);
        // Invalid visibility
        sitesProxy.update("sites", site.getSiteId(), null, null, "{\n" + "  \"title\": \"Updated Title\",\n" + "  \"description\": \"This is an updated description for the site\",\n" + "  \"visibility\": \"INVALID_VISIBILITY\"\n" + "}", null, "Expected 400 response when updating " + site.getSiteId(), 400);
        // Invalid fields
        // Check that id, guid and role are not silently ignored. This is until REPO-110
        // is implemented, since we currently have to bind to Site rather than SiteUpdate in
        // SiteEntityResource.update
        sitesProxy.update("sites", site.getSiteId(), null, null, "{\n" + "  \"id\": \"a-new-id\"," + "  \"title\": \"Updated Title\"\n" + "}", null, "Expected 400 response when updating " + site.getSiteId(), 400);
        sitesProxy.update("sites", site.getSiteId(), null, null, "{\n" + "  \"guid\": \"76ba60c1-f05b-406a-86a4-4eeb1bb49aaa\"" + "}", null, "Expected 400 response when updating " + site.getSiteId(), 400);
        sitesProxy.update("sites", site.getSiteId(), null, null, "{\n" + "  \"role\": \"SiteConsumer\"" + "}", null, "Expected 400 response when updating " + site.getSiteId(), 400);
        sitesProxy.update("sites", site.getSiteId(), null, null, "{\n" + "  \"preset\": \"sitePreset\"" + "}", null, "Expected 400 response when updating " + site.getSiteId(), 400);
        // Details should not have changed.
        Site fresh = sitesProxy.getSite(site.getSiteId(), 200);
        site.expected(fresh);
        removeSiteQuietly(site.getSiteId());
    }
    // -ve test: 404 for non-existent site
    {
        // Attempt to update site details using an invalid site ID.
        sitesProxy.updateSite(// Non-existent site.
        UUID.randomUUID().toString(), new SiteUpdate("Updated title", "Updated description", SiteVisibility.PUBLIC), HttpStatus.SC_NOT_FOUND);
    }
    // -ve test: 401 authorization failure
    {
        Site site = sitesProxy.createSite(new SiteImpl("SiteUpdate401", SiteVisibility.PRIVATE.toString()), 201);
        // Invalid auth details
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), GUID.generate(), "password"));
        // Update the site details
        sitesProxy.updateSite(site.getSiteId(), new SiteUpdate("Updated Title", "Updated description", SiteVisibility.PUBLIC), HttpStatus.SC_UNAUTHORIZED);
        // Valid authentication again
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
        // Check the details haven't changed.
        Site fresh = sitesProxy.getSite(site.getSiteId(), 200);
        site.expected(fresh);
        removeSiteQuietly(site.getSiteId());
    }
    // -ve test: 403 for incorrect permissions
    {
        Site site = sitesProxy.createSite(new SiteImpl("SiteUpdate403", SiteVisibility.PUBLIC.toString()), 201);
        // Update as person2
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2Id));
        // Update the site details
        sitesProxy.updateSite(site.getSiteId(), new SiteUpdate("Updated Title", "Updated description", SiteVisibility.PUBLIC), HttpStatus.SC_FORBIDDEN);
        // Check details haven't changed as original creator.
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
        Site fresh = sitesProxy.getSite(site.getSiteId(), 200);
        site.expected(fresh);
        removeSiteQuietly(site.getSiteId());
    }
}
Also used : TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) JSONObject(org.json.simple.JSONObject) SiteUpdate(org.alfresco.rest.api.model.SiteUpdate) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Sites(org.alfresco.rest.api.tests.client.PublicApiClient.Sites) Test(org.junit.Test)

Example 64 with HttpResponse

use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.

the class SharedLinkApiTest method testGetSharedLinksIncludePath.

/**
 * Tests for get /shared-links?include=path
 *
 * <p>GET:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/shared-links?include=path}
 */
@Test
@Category({ LuceneTests.class, RedundantTests.class })
public void testGetSharedLinksIncludePath() throws Exception {
    String contentText = "includePathTest" + RUNID;
    Paging paging = getPaging(0, 100);
    Map<String, String> queryParams = new HashMap<>();
    queryParams.put("include", "path");
    // As user 1: Test the backward compatibility by checking response with and without path is consistent when no shared-links
    setRequestContext(user1);
    // Get all shared links visible to user 1
    HttpResponse response = getAll(URL_SHARED_LINKS, paging, 200);
    List<QuickShareLink> sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
    // Check that the same no of items is returned with include=path
    response = getAll(URL_SHARED_LINKS, paging, queryParams, 200);
    List<QuickShareLink> sharedLinksWithPath = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
    assertEquals("get /shared-links/ API returns same no of shared-links with or without include=path, when there are no shared-links", sharedLinks, sharedLinksWithPath);
    // Create Files in various locations: My Files, SharedFiles, Sites with different visibility
    // Create doc in "My Files"
    Document myFile = createTextFile(getMyNodeId(), "MyFile" + RUNID + ".txt", contentText);
    // Create doc in "Shared" folder
    Document sharedFile = createTextFile(getSharedNodeId(), "SharedFile" + RUNID + ".txt", contentText);
    // Create Sites
    Site publicSite = createSite("TestSite-Public-" + RUNID, SiteVisibility.PUBLIC);
    Site modSite = createSite("TestSite-Moderate-" + RUNID, SiteVisibility.MODERATED);
    Site privateSite = createSite("TestSite-Private-" + RUNID, SiteVisibility.PRIVATE);
    // Create file in Site Public > DocumentLibrary
    String docLibPub = getSiteContainerNodeId(publicSite.getId(), "documentLibrary");
    Document filePublic = createTextFile(docLibPub, "filePublic.txt", contentText);
    // Create files in Site Moderated > DocumentLibrary > Folder 1 and Folder 2
    String docLibMod = getSiteContainerNodeId(modSite.getId(), "documentLibrary");
    Folder folder1 = createFolder(docLibMod, "1");
    Folder folder2 = createFolder(docLibMod, "2");
    Document fileMod = createTextFile(folder1.getId(), "fileMod.txt", contentText);
    Document fileMod2 = createTextFile(folder2.getId(), "fileMod2.txt", contentText);
    // Create file in Site Private > DocumentLibrary
    String docLibPvt = getSiteContainerNodeId(privateSite.getId(), "documentLibrary");
    Document filePrivate = createTextFile(docLibPvt, "filePrivate.txt", contentText);
    // Share the files above in: My Files, SharedFiles, Sites with different visibility
    String myFileLinkId = postSharedLink(myFile);
    String sharedLinkId = postSharedLink(sharedFile);
    String filePublicLinkId = postSharedLink(filePublic);
    String fileModLinkId = postSharedLink(fileMod);
    String fileMod2LinkId = postSharedLink(fileMod2);
    String filePrivateLinkId = postSharedLink(filePrivate);
    // Grant user2: Consumer Permission for Moderated Site > File1
    List<NodePermissions.NodePermission> locallySetPermissions = new ArrayList<>();
    locallySetPermissions.add(new NodePermissions.NodePermission(user2, PermissionService.CONSUMER, AccessStatus.ALLOWED.toString()));
    NodePermissions nodePermissions = new NodePermissions();
    nodePermissions.setIsInheritanceEnabled(false);
    nodePermissions.setLocallySet(locallySetPermissions);
    Document docPermissions = new Document();
    docPermissions.setPermissions(nodePermissions);
    put(URL_NODES, fileMod.getId(), toJsonAsStringNonNull(docPermissions), null, 200);
    // Grant user2: Consumer Permission for Moderated Site > Folder 2, File2
    put(URL_NODES, fileMod2.getId(), toJsonAsStringNonNull(docPermissions), null, 200);
    Folder folderPermissions = new Folder();
    folderPermissions.setPermissions(nodePermissions);
    put(URL_NODES, folder2.getId(), toJsonAsStringNonNull(folderPermissions), null, 200);
    // Get links For User1
    setRequestContext(user1);
    response = getSingle(QuickShareLinkEntityResource.class, myFileLinkId, null, 200);
    QuickShareLink link = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class);
    assertNull("get /shared-links/<id> API does not return Path info by default", link.getPath());
    // Path info is not included for get shared-links/<id>
    response = getSingle(QuickShareLinkEntityResource.class, myFileLinkId, queryParams, 200);
    link = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class);
    assertNull("get /shared-links/<id> API ignores Path info when requested as it is a noAuth API.", link.getPath());
    response = getAll(URL_SHARED_LINKS, paging, 200);
    sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
    assertEquals("API returns correct shared-links as expected: without path info", 6, sharedLinks.size());
    sharedLinks.forEach(sharedLink -> assertNull("API does not return Path info for any shared-links by default", sharedLink.getPath()));
    // Path info is included for get shared-links when requested
    response = getAll(URL_SHARED_LINKS, paging, queryParams, 200);
    sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
    // Complete path info is retrieved for the user with access to the complete path
    assertEquals("API returns correct shared-links as expected: with path info", 6, sharedLinks.size());
    sharedLinks.forEach(sharedLink -> assertTrue("API returns Complete Path info for each link when requested by content owner", sharedLink.getPath().getIsComplete()));
    // Get links For User2
    setRequestContext(user2);
    response = getAll(URL_SHARED_LINKS, paging, 200);
    sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
    // Path info is not included when not requested
    assertEquals("API returns correct shared-links as expected for user2: without path info", 4, sharedLinks.size());
    sharedLinks.forEach(sharedLink -> assertNull("get /shared-links/ API does not return Path info for any shared-links by default", sharedLink.getPath()));
    response = getAll(URL_SHARED_LINKS, paging, queryParams, 200);
    sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
    // Path info is retrieved for the user with access to the complete path: Sorted as LIFO
    assertEquals("API returns correct shared-links as expected for user2: with path info", 4, sharedLinks.size());
    sharedLinks.forEach(sharedLink -> assertNotNull("API returns Path info for each link when requested by user2", sharedLink.getPath()));
    // Moderated Site > fileMod2: Path only includes elements where user2 has access
    QuickShareLink sharedLink = sharedLinks.get(0);
    assertEquals("Incorrect sort order or SharedLink ID for fileMod2: " + sharedLink, fileMod2LinkId, sharedLink.getId());
    PathInfo path = sharedLink.getPath();
    assertEquals("Complete Path is returned even when user2 does not have appropriate permissions. SharedLink Path: " + path, false, path.getIsComplete());
    assertEquals("Path omits immediate Parent folder Name when user has access to it. SharedLink Path: " + path, "/" + folder2.getName(), path.getName());
    assertEquals("Path omits immediate Parent folder ID when user has access to it. SharedLink Path: " + path, folder2.getId(), path.getElements().get(0).getId());
    // Moderated Site > fileMod: Path empty when user2 does not have access to the immediate parent
    sharedLink = sharedLinks.get(1);
    assertEquals("Incorrect sort order or SharedLink ID for fileMod: " + sharedLink, fileModLinkId, sharedLink.getId());
    path = sharedLink.getPath();
    assertNotNull("Path info is not included in the response when user does not have right permissions. SharedLink Path: " + path, path);
    assertNull("Path Name is returned when user does not have right permissions. SharedLink Path: " + path, path.getName());
    assertNull("Path info is returned when user does not have right permissions. SharedLink Path: " + path, path.getIsComplete());
    assertNull("Path Elements are returned when user does not have right permissions. SharedLink Path: " + path, path.getElements());
    // Public Site > filePublic: Path includes all the elements when user2 has appropriate access
    sharedLink = sharedLinks.get(2);
    assertEquals("Incorrect sort order or SharedLink ID for filePublic: " + sharedLink, filePublicLinkId, sharedLink.getId());
    path = sharedLink.getPath();
    assertEquals("Complete Path is not returned for user2 for public files. SharedLink Path: " + path, true, path.getIsComplete());
    assertEquals("Incorrect Path Name for Public Site Files. SharedLink Path: " + path, "/Company Home/Sites/" + publicSite.getId() + "/documentLibrary", path.getName());
    assertEquals("Incorrect Path Elements for Public Site Files. SharedLink Path: " + path, 4, path.getElements().size());
    assertEquals("Incorrect ID in the Path for Company Home. SharedLink Path: " + path, getRootNodeId(), path.getElements().get(0).getId());
    assertEquals("Incorrect ID in the Path for Public Site. SharedLink Path: " + path, publicSite.getGuid(), path.getElements().get(2).getId());
    assertEquals("Incorrect ID in the Path for Public Site DocLib. SharedLink Path: " + path, docLibPub, path.getElements().get(3).getId());
    // Shared Files > shared: Path includes all the elements when user2 has appropriate access
    sharedLink = sharedLinks.get(3);
    assertEquals("Incorrect sort order or SharedLink ID for sharedFiles: " + sharedLink, sharedLinkId, sharedLink.getId());
    path = sharedLink.getPath();
    assertEquals("Complete Path is not returned for user2 for shared files. SharedLink Path: " + path, true, path.getIsComplete());
    assertEquals("Incorrect Path Name for Shared Files. SharedLink Path: " + path, "/Company Home/Shared", path.getName());
    assertEquals("Incorrect Path Elements for Shared Files. SharedLink Path: " + path, 2, path.getElements().size());
    assertEquals("Incorrect ID in the Path for Company Home. SharedLink Path: " + path, getRootNodeId(), path.getElements().get(0).getId());
    assertEquals("Incorrect ID in the path for Shared Files. SharedLink Path: " + path, getSharedNodeId(), path.getElements().get(1).getId());
    // Unauthorized request returns 401
    setRequestContext(null, "UserNotKnown", DEFAULT_ADMIN_PWD);
    queryParams = new HashMap<>();
    getAll(URL_SHARED_LINKS, paging, queryParams, 401);
    // Unauthenticated request returns 401
    setRequestContext(user2, null, null);
    getAll(URL_SHARED_LINKS, paging, queryParams, 401);
    // Delete the shared links
    setRequestContext(user1);
    deleteSharedLink(myFileLinkId);
    deleteSharedLink(sharedLinkId);
    deleteSharedLink(filePublicLinkId);
    deleteSharedLink(fileModLinkId);
    deleteSharedLink(fileMod2LinkId);
    deleteSharedLink(filePrivateLinkId);
}
Also used : Site(org.alfresco.rest.api.model.Site) NodePermissions(org.alfresco.rest.api.model.NodePermissions) HashMap(java.util.HashMap) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) ArrayList(java.util.ArrayList) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Document(org.alfresco.rest.api.tests.client.data.Document) Folder(org.alfresco.rest.api.tests.client.data.Folder) QuickShareLinkEntityResource(org.alfresco.rest.api.quicksharelinks.QuickShareLinkEntityResource) PathInfo(org.alfresco.rest.api.model.PathInfo) QuickShareLink(org.alfresco.rest.api.model.QuickShareLink) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 65 with HttpResponse

use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.

the class SharedLinkApiTest method testEmailSharedLink.

/**
 * Tests emailing shared links.
 * <p>POST:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/shared-links/<sharedId>/email}
 */
@Test
public void testEmailSharedLink() throws Exception {
    setRequestContext(user1);
    // Create plain text document
    String myFolderNodeId = getMyNodeId();
    String contentText = "The quick brown fox jumps over the lazy dog.";
    String fileName = "file-" + RUNID + ".txt";
    Document doc = createTextFile(myFolderNodeId, fileName, contentText);
    String docId = doc.getId();
    // Create shared link to document
    Map<String, String> body = Collections.singletonMap("nodeId", docId);
    HttpResponse response = post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201);
    QuickShareLink resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class);
    String sharedId = resp.getId();
    assertNotNull(sharedId);
    assertEquals(fileName, resp.getName());
    // Email request with minimal properties
    QuickShareLinkEmailRequest request = new QuickShareLinkEmailRequest();
    request.setClient("share");
    List<String> recipients = new ArrayList<>(2);
    recipients.add(user2 + "@acme.test");
    recipients.add(user2 + "@ping.test");
    request.setRecipientEmails(recipients);
    post(getEmailSharedLinkUrl(sharedId), RestApiUtil.toJsonAsString(request), 202);
    // Email request with all the properties
    request = new QuickShareLinkEmailRequest();
    request.setClient("share");
    request.setMessage("My custom message!");
    request.setLocale(Locale.UK.toString());
    recipients = Collections.singletonList(user2 + "@acme.test");
    request.setRecipientEmails(recipients);
    post(getEmailSharedLinkUrl(sharedId), RestApiUtil.toJsonAsString(request), 202);
    // -ve tests
    // sharedId path parameter does not exist
    post(getEmailSharedLinkUrl(sharedId + System.currentTimeMillis()), RestApiUtil.toJsonAsString(request), 404);
    // Unregistered client
    request = new QuickShareLinkEmailRequest();
    request.setClient("VeryCoolClient" + System.currentTimeMillis());
    List<String> user2Email = Collections.singletonList(user2 + "@acme.test");
    request.setRecipientEmails(user2Email);
    post(getEmailSharedLinkUrl(sharedId), RestApiUtil.toJsonAsString(request), 404);
    // client is mandatory
    request.setClient(null);
    post(getEmailSharedLinkUrl(sharedId), RestApiUtil.toJsonAsString(request), 400);
    // recipientEmails is mandatory
    request.setClient("share");
    request.setRecipientEmails(null);
    post(getEmailSharedLinkUrl(sharedId), RestApiUtil.toJsonAsString(request), 400);
    // TODO if and when these tests are optionally runnable via remote env then we could skip this part of the test
    // (else need to verify test mechanism for enterprise admin via jmx ... etc)
    QuickShareLinksImpl quickShareLinks = applicationContext.getBean("quickShareLinks", QuickShareLinksImpl.class);
    try {
        quickShareLinks.setEnabled(false);
        request = new QuickShareLinkEmailRequest();
        request.setClient("share");
        request.setRecipientEmails(user2Email);
        post(getEmailSharedLinkUrl(sharedId), RestApiUtil.toJsonAsString(request), 501);
    } finally {
        quickShareLinks.setEnabled(true);
    }
}
Also used : QuickShareLinkEmailRequest(org.alfresco.rest.api.tests.client.data.QuickShareLinkEmailRequest) ArrayList(java.util.ArrayList) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Document(org.alfresco.rest.api.tests.client.data.Document) QuickShareLinksImpl(org.alfresco.rest.api.impl.QuickShareLinksImpl) QuickShareLink(org.alfresco.rest.api.model.QuickShareLink) Test(org.junit.Test)

Aggregations

HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)162 Test (org.junit.Test)114 HashMap (java.util.HashMap)59 AbstractSingleNetworkSiteTest (org.alfresco.rest.AbstractSingleNetworkSiteTest)50 Document (org.alfresco.rest.api.tests.client.data.Document)49 Node (org.alfresco.rest.api.tests.client.data.Node)49 LinkedHashMap (java.util.LinkedHashMap)31 ArrayList (java.util.ArrayList)29 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)27 Folder (org.alfresco.rest.api.tests.client.data.Folder)26 File (java.io.File)25 NodesEntityResource (org.alfresco.rest.api.nodes.NodesEntityResource)25 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)22 CustomModel (org.alfresco.rest.api.model.CustomModel)16 ContentInfo (org.alfresco.rest.api.tests.client.data.ContentInfo)15 MultiPartBuilder (org.alfresco.rest.api.tests.util.MultiPartBuilder)15 JSONObject (org.json.simple.JSONObject)15 NodeRef (org.alfresco.service.cmr.repository.NodeRef)14 Map (java.util.Map)13 CustomAspect (org.alfresco.rest.api.model.CustomAspect)13