Search in sources :

Example 26 with ListResponse

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

the class TestSiteMembershipRequests method testValidRequests.

@Test
public void testValidRequests() throws Exception {
    final List<SiteMembershipRequest> expectedSiteMembershipRequests = new ArrayList<SiteMembershipRequest>();
    {
        // GET
        // cloud-2531
        // user has no site membership requests
        {
            log("cloud-2531");
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
            int skipCount = 0;
            int maxItems = 2;
            Paging paging = getPaging(skipCount, maxItems, expectedSiteMembershipRequests.size(), expectedSiteMembershipRequests.size());
            ListResponse<SiteMembershipRequest> resp = siteMembershipRequestsProxy.getSiteMembershipRequests(person11Id, createParams(paging, null));
            checkList(expectedSiteMembershipRequests.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        }
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
            int skipCount = 0;
            Paging paging = getPaging(skipCount, null, expectedSiteMembershipRequests.size(), expectedSiteMembershipRequests.size());
            ListResponse<SiteMembershipRequest> resp = siteMembershipRequestsProxy.getSiteMembershipRequests(person11Id, createParams(paging, null));
            checkList(expectedSiteMembershipRequests.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        }
        // POSTs
        // cloud-2502
        // cloud-2510
        {
            log("cloud-2502");
            log("cloud-2510");
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
            // moderated site
            SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
            siteMembershipRequest.setId(person1ModeratedSites.get(0).getSiteId());
            siteMembershipRequest.setMessage("Please can I join your site?");
            final SiteMembershipRequest moderatedSiteResponse = siteMembershipRequestsProxy.createSiteMembershipRequest("-me-", siteMembershipRequest);
            expectedSiteMembershipRequests.add(moderatedSiteResponse);
            siteMembershipRequest.expected(moderatedSiteResponse);
            // public site
            siteMembershipRequest = new SiteMembershipRequest();
            siteMembershipRequest.setId(person1PublicSites.get(0).getSiteId());
            siteMembershipRequest.setMessage("Please can I join your site?");
            SiteMembershipRequest ret = siteMembershipRequestsProxy.createSiteMembershipRequest(person11Id, siteMembershipRequest);
            siteMembershipRequest.expected(ret);
            // test we have a moderated site request only
            // cloud-2532
            {
                log("cloud-2532");
                int skipCount = 0;
                int maxItems = 4;
                Paging paging = getPaging(skipCount, maxItems, expectedSiteMembershipRequests.size(), expectedSiteMembershipRequests.size());
                ListResponse<SiteMembershipRequest> resp = siteMembershipRequestsProxy.getSiteMembershipRequests(person11Id, createParams(paging, null));
                checkList(expectedSiteMembershipRequests, paging.getExpectedPaging(), resp);
            }
            // test against the underlying invitation service
            List<Invitation> invitations = repoService.getModeratedSiteInvitations(network1.getId(), person11Id, person11Id, null);
            assertEquals(1, invitations.size());
            Invitation invitation = invitations.get(0);
            assertTrue(invitation instanceof ModeratedInvitation);
            ModeratedInvitation moderatedInvitation = (ModeratedInvitation) invitation;
            String siteId = moderatedInvitation.getResourceName();
            Invitation.InvitationType invitationType = moderatedInvitation.getInvitationType();
            Invitation.ResourceType resourceType = moderatedInvitation.getResourceType();
            String inviteeId = moderatedInvitation.getInviteeUserName();
            assertEquals(person11Id, inviteeId);
            assertEquals(Invitation.ResourceType.WEB_SITE, resourceType);
            assertEquals(Invitation.InvitationType.MODERATED, invitationType);
            assertEquals(person1ModeratedSites.get(0).getSiteId(), siteId);
            // test that personId is a member of the public site
            assertTrue(person1PublicSites.get(0).isMember(person11Id));
            // cloud-2534
            // approve the moderated site invitation and check that it is gone from the list
            {
                log("cloud-2534");
                TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

                    @Override
                    public Void doWork() throws Exception {
                        repoService.approveSiteInvitation(person11Id, moderatedSiteResponse.getId());
                        expectedSiteMembershipRequests.remove(0);
                        return null;
                    }
                }, person12Id, network1.getId());
                // make sure the outstanding request has gone
                int skipCount = 0;
                int maxItems = 4;
                Paging paging = getPaging(skipCount, maxItems, expectedSiteMembershipRequests.size(), expectedSiteMembershipRequests.size());
                ListResponse<SiteMembershipRequest> resp = siteMembershipRequestsProxy.getSiteMembershipRequests(person11Id, createParams(paging, null));
                checkList(expectedSiteMembershipRequests, paging.getExpectedPaging(), resp);
            }
        }
        // user from another network - un-authorised
        try {
            log("cloud-2511");
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person24Id));
            // moderated site
            SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
            siteMembershipRequest.setId(person1ModeratedSites.get(0).getSiteId());
            siteMembershipRequest.setMessage("Please can I join your site?");
            siteMembershipRequestsProxy.createSiteMembershipRequest(person24Id, siteMembershipRequest);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
        }
        // cloud-2512
        // cloud-2535
        // invitee from another network
        {
            log("cloud-2512");
            log("cloud-2535");
            log("cloud-2536");
            final List<SiteMembershipRequest> person4ExpectedSiteMembershipRequests = new ArrayList<SiteMembershipRequest>();
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person24Id));
            {
                // public site
                try {
                    SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
                    siteMembershipRequest.setId(person1PublicSites.get(0).getSiteId());
                    siteMembershipRequest.setMessage("Please can I join your site?");
                    siteMembershipRequestsProxy.createSiteMembershipRequest(person24Id, siteMembershipRequest);
                    fail();
                } catch (PublicApiException e) {
                    assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
                }
            }
            {
                // moderated site
                try {
                    SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
                    siteMembershipRequest.setId(person1ModeratedSites.get(0).getSiteId());
                    siteMembershipRequest.setMessage("Please can I join your site?");
                    siteMembershipRequestsProxy.createSiteMembershipRequest(person24Id, siteMembershipRequest);
                    fail();
                } catch (PublicApiException e) {
                    assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
                }
                try {
                    int skipCount = 0;
                    int maxItems = 2;
                    Paging paging = getPaging(skipCount, maxItems, expectedSiteMembershipRequests.size(), expectedSiteMembershipRequests.size());
                    siteMembershipRequestsProxy.getSiteMembershipRequests(person24Id, createParams(paging, null));
                    fail();
                } catch (PublicApiException e) {
                    assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
                }
            }
            {
                // private site
                try {
                    SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
                    siteMembershipRequest.setId(person1PrivateSites.get(0).getSiteId());
                    siteMembershipRequest.setMessage("Please can I join your site?");
                    siteMembershipRequestsProxy.createSiteMembershipRequest(person24Id, siteMembershipRequest);
                    fail();
                } catch (PublicApiException e) {
                    assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
                }
                try {
                    int skipCount = 0;
                    int maxItems = 2;
                    Paging paging = getPaging(skipCount, maxItems, expectedSiteMembershipRequests.size(), expectedSiteMembershipRequests.size());
                    siteMembershipRequestsProxy.getSiteMembershipRequests(person24Id, createParams(paging, null));
                    fail();
                } catch (PublicApiException e) {
                    assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
                }
            }
        }
        // cloud-2513
        try {
            log("cloud-2513");
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
            // unknown site
            SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
            siteMembershipRequest.setId(GUID.generate());
            siteMembershipRequest.setMessage("Please can I join your site?");
            siteMembershipRequestsProxy.createSiteMembershipRequest(person11Id, siteMembershipRequest);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
            // private site
            SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
            siteMembershipRequest.setId(person1PrivateSites.get(0).getSiteId());
            siteMembershipRequest.setMessage("Please can I join your site?");
            siteMembershipRequestsProxy.createSiteMembershipRequest(person11Id, siteMembershipRequest);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
            // moderated site in another network
            SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
            siteMembershipRequest.setId(person4ModeratedSites.get(0).getSiteId());
            siteMembershipRequest.setMessage("Please can I join your site?");
            siteMembershipRequestsProxy.createSiteMembershipRequest(person11Id, siteMembershipRequest);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        // cloud-2514
        try {
            log("cloud-2514");
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
            // already joined the site
            SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
            siteMembershipRequest.setId(person1ModeratedSites.get(0).getSiteId());
            siteMembershipRequest.setMessage("Please can I join your site?");
            siteMembershipRequestsProxy.createSiteMembershipRequest(person11Id, siteMembershipRequest);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
            // already requested to join the site but not yet joined
            SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
            siteMembershipRequest.setId(person1ModeratedSites.get(0).getSiteId());
            siteMembershipRequest.setMessage("Please can I join your site?");
            siteMembershipRequestsProxy.createSiteMembershipRequest(person11Id, siteMembershipRequest);
            siteMembershipRequest = new SiteMembershipRequest();
            siteMembershipRequest.setId(person1ModeratedSites.get(0).getSiteId());
            siteMembershipRequest.setMessage("Please can I join your site?");
            siteMembershipRequestsProxy.createSiteMembershipRequest(person11Id, siteMembershipRequest);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
        // cloud-2538
        // blank message
        {
            log("cloud-2538");
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
            SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
            siteMembershipRequest.setId(person1ModeratedSites.get(1).getSiteId());
            siteMembershipRequest.setMessage("");
            SiteMembershipRequest ret = siteMembershipRequestsProxy.createSiteMembershipRequest(person11Id, siteMembershipRequest);
            expectedSiteMembershipRequests.add(ret);
        }
        // GETs
        // cloud-2501
        // cloud-2509
        // test paging
        {
            log("cloud-2501");
            log("cloud-2509");
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
            // add some more site membership requests to moderated sites
            for (int i = 1; i < person1ModeratedSites.size(); i++) {
                SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
                siteMembershipRequest.setId(person1ModeratedSites.get(i).getSiteId());
                siteMembershipRequest.setMessage("Please can I join your site?");
                try {
                    SiteMembershipRequest ret = siteMembershipRequestsProxy.createSiteMembershipRequest(person11Id, siteMembershipRequest);
                    expectedSiteMembershipRequests.add(ret);
                    siteMembershipRequest.expected(ret);
                } catch (PublicApiException e) {
                // this is ok, already created
                }
            }
            Collections.sort(expectedSiteMembershipRequests);
            {
                int skipCount = 0;
                int maxItems = 2;
                Paging paging = getPaging(skipCount, maxItems, expectedSiteMembershipRequests.size(), expectedSiteMembershipRequests.size());
                ListResponse<SiteMembershipRequest> resp = siteMembershipRequestsProxy.getSiteMembershipRequests(person11Id, createParams(paging, null));
                checkList(expectedSiteMembershipRequests.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
                skipCount = 2;
                maxItems = 5;
                paging = getPaging(skipCount, maxItems, expectedSiteMembershipRequests.size(), expectedSiteMembershipRequests.size());
                resp = siteMembershipRequestsProxy.getSiteMembershipRequests(person11Id, createParams(paging, null));
                checkList(expectedSiteMembershipRequests.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
                skipCount = 5;
                maxItems = 10;
                paging = getPaging(skipCount, maxItems, expectedSiteMembershipRequests.size(), expectedSiteMembershipRequests.size());
                resp = siteMembershipRequestsProxy.getSiteMembershipRequests(person11Id, createParams(paging, null));
                checkList(expectedSiteMembershipRequests.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
                skipCount = 0;
                maxItems = expectedSiteMembershipRequests.size();
                paging = getPaging(skipCount, maxItems, expectedSiteMembershipRequests.size(), expectedSiteMembershipRequests.size());
                resp = siteMembershipRequestsProxy.getSiteMembershipRequests(person11Id, createParams(paging, null));
                checkList(expectedSiteMembershipRequests.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
            }
            // skipCount is greater than the number of site membership requests in the list
            {
                int skipCount = 1000;
                int maxItems = 2;
                Paging paging = getPaging(skipCount, maxItems, expectedSiteMembershipRequests.size(), expectedSiteMembershipRequests.size());
                ListResponse<SiteMembershipRequest> resp = siteMembershipRequestsProxy.getSiteMembershipRequests(person11Id, createParams(paging, null));
                checkList(sublist(expectedSiteMembershipRequests, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
            }
            // cloud-2537
            // -me- user
            {
                log("cloud-2537");
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
                int skipCount = 0;
                int maxItems = 2;
                Paging paging = getPaging(skipCount, maxItems, expectedSiteMembershipRequests.size(), expectedSiteMembershipRequests.size());
                ListResponse<SiteMembershipRequest> resp = siteMembershipRequestsProxy.getSiteMembershipRequests("-me-", createParams(paging, null));
                checkList(expectedSiteMembershipRequests.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
            }
        }
        // DELETEs
        // cloud-2504
        {
            log("cloud-2504");
            SiteMembershipRequest request = getSiteMembershipRequest(network1.getId(), person11Id, person11Id);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
            siteMembershipRequestsProxy.cancelSiteMembershipRequest(person11Id, request.getId());
            expectedSiteMembershipRequests.remove(request);
            Collections.sort(expectedSiteMembershipRequests);
            // cloud-2533
            // check that the site membership request has gone
            log("cloud-2533");
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expectedSiteMembershipRequests.size(), expectedSiteMembershipRequests.size());
            ListResponse<SiteMembershipRequest> resp = siteMembershipRequestsProxy.getSiteMembershipRequests(person11Id, createParams(paging, null));
            checkList(expectedSiteMembershipRequests, paging.getExpectedPaging(), resp);
            // try to cancel the same request
            try {
                log("cloud-2528");
                siteMembershipRequestsProxy.cancelSiteMembershipRequest(person11Id, request.getId());
                fail("");
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
            }
        }
        // cloud-2529
        // cancel a site membership request that has been rejected
        {
            log("cloud-2529");
            final String siteId = person1ModeratedSites.get(1).getSiteId();
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person14Id));
            SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
            siteMembershipRequest.setId(siteId);
            siteMembershipRequest.setMessage("Please can I join your site?");
            SiteMembershipRequest moderatedSiteResponse = siteMembershipRequestsProxy.createSiteMembershipRequest(person14Id, siteMembershipRequest);
            expectedSiteMembershipRequests.add(moderatedSiteResponse);
            Collections.sort(expectedSiteMembershipRequests);
            siteMembershipRequest.expected(moderatedSiteResponse);
            TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

                @Override
                public Void doWork() throws Exception {
                    Invitation invitation = repoService.rejectSiteInvitation(person14Id, siteId);
                    assertNotNull(invitation);
                    return null;
                }
            }, person12Id, network1.getId());
            // try to cancel the request
            try {
                siteMembershipRequestsProxy.cancelSiteMembershipRequest(person14Id, siteId);
                fail("");
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
            }
        }
        // cloud-2530
        // cancel a site membership request that has been approved
        {
            log("cloud-2530");
            final String siteId = person1ModeratedSites.get(2).getSiteId();
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person14Id));
            SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
            siteMembershipRequest.setId(siteId);
            siteMembershipRequest.setMessage("Please can I join your site?");
            SiteMembershipRequest moderatedSiteResponse = siteMembershipRequestsProxy.createSiteMembershipRequest(person14Id, siteMembershipRequest);
            expectedSiteMembershipRequests.add(moderatedSiteResponse);
            Collections.sort(expectedSiteMembershipRequests);
            siteMembershipRequest.expected(moderatedSiteResponse);
            TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

                @Override
                public Void doWork() throws Exception {
                    Invitation invitation = repoService.approveSiteInvitation(person14Id, siteId);
                    assertNotNull(invitation);
                    return null;
                }
            }, person12Id, network1.getId());
            // try to cancel the request
            try {
                siteMembershipRequestsProxy.cancelSiteMembershipRequest(person14Id, siteId);
                fail("");
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
            }
        }
        // PUTs
        // cloud-2503
        // cloud-2517
        // cloud-2518
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person14Id));
            // merged these tests
            // cloud-2503: use -me- pseudo user
            // cloud-2517: initially no message
            log("cloud-2503");
            log("cloud-2517");
            // create a request without a message
            String siteId = person1ModeratedSites.get(7).getSiteId();
            SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
            siteMembershipRequest.setId(siteId);
            SiteMembershipRequest request = siteMembershipRequestsProxy.createSiteMembershipRequest(person14Id, siteMembershipRequest);
            assertNotNull(request);
            // update it, with a message
            request.setMessage("Please can I join your site?");
            SiteMembershipRequest updated = siteMembershipRequestsProxy.updateSiteMembershipRequest(person14Id, request);
            request.expected(updated);
            // check it's updated
            int skipCount = 0;
            int maxItems = 2;
            Paging paging = getPaging(skipCount, maxItems, expectedSiteMembershipRequests.size(), expectedSiteMembershipRequests.size());
            ListResponse<SiteMembershipRequest> resp = siteMembershipRequestsProxy.getSiteMembershipRequests(person14Id, createParams(paging, null));
            List<SiteMembershipRequest> requests = resp.getList();
            assertTrue(requests.size() > 0);
            int idx = requests.indexOf(request);
            SiteMembershipRequest toCheck = requests.get(idx);
            updated.expected(toCheck);
            // cloud-2518
            // update it again, with ammended message
            log("cloud-2518");
            request.setMessage("Please can I join your site, pretty please?");
            updated = siteMembershipRequestsProxy.updateSiteMembershipRequest(person14Id, request);
            request.expected(updated);
            // check it's updated
            skipCount = 0;
            maxItems = 2;
            paging = getPaging(skipCount, maxItems, expectedSiteMembershipRequests.size(), expectedSiteMembershipRequests.size());
            resp = siteMembershipRequestsProxy.getSiteMembershipRequests(person14Id, createParams(paging, null));
            requests = resp.getList();
            assertTrue(requests.size() > 0);
            idx = requests.indexOf(request);
            toCheck = requests.get(idx);
            updated.expected(toCheck);
        }
        // cloud-2515 - no changes
        {
            log("cloud-2515");
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person14Id));
            // create a request
            String siteId = person1ModeratedSites.get(8).getSiteId();
            SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
            siteMembershipRequest.setId(siteId);
            siteMembershipRequest.setMessage("Please can I join your site?");
            SiteMembershipRequest request = siteMembershipRequestsProxy.createSiteMembershipRequest(person14Id, siteMembershipRequest);
            assertNotNull(request);
            // update it, with no changes
            SiteMembershipRequest updated = siteMembershipRequestsProxy.updateSiteMembershipRequest(person14Id, request);
            // should not have changed
            request.expected(updated);
        }
        // cloud-2516 - unknown person id
        try {
            log("cloud-2516");
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
            // get an outstanding request
            int skipCount = 0;
            int maxItems = 2;
            Paging paging = getPaging(skipCount, maxItems, expectedSiteMembershipRequests.size(), expectedSiteMembershipRequests.size());
            ListResponse<SiteMembershipRequest> resp = siteMembershipRequestsProxy.getSiteMembershipRequests(person11Id, createParams(paging, null));
            List<SiteMembershipRequest> requests = resp.getList();
            assertTrue(requests.size() > 0);
            SiteMembershipRequest request = requests.get(0);
            siteMembershipRequestsProxy.updateSiteMembershipRequest(GUID.generate(), request);
            fail("");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        // cloud-2521 - unknown site membership request
        try {
            log("cloud-2521");
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
            SiteMembershipRequest request = new SiteMembershipRequest();
            request.setId(GUID.generate());
            siteMembershipRequestsProxy.updateSiteMembershipRequest(person11Id, request);
            fail("");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        // cloud-2522
        // update a site membership request that has been rejected
        {
            log("cloud-2522");
            String siteId = person1ModeratedSites.get(5).getSiteId();
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person14Id));
            SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
            siteMembershipRequest.setId(siteId);
            siteMembershipRequest.setMessage("Please can I join your site?");
            SiteMembershipRequest moderatedSiteResponse = siteMembershipRequestsProxy.createSiteMembershipRequest(person14Id, siteMembershipRequest);
            expectedSiteMembershipRequests.add(moderatedSiteResponse);
            Collections.sort(expectedSiteMembershipRequests);
            siteMembershipRequest.expected(moderatedSiteResponse);
            repoService.rejectSiteInvitation(person14Id, siteId);
            // try to update the request
            try {
                siteMembershipRequestsProxy.updateSiteMembershipRequest(siteId, moderatedSiteResponse);
                fail("");
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
            }
        }
        // cloud-2523
        // update a site membership request that has been approved
        {
            log("cloud-2523");
            String siteId = person1ModeratedSites.get(6).getSiteId();
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person14Id));
            SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
            siteMembershipRequest.setId(siteId);
            siteMembershipRequest.setMessage("Please can I join your site?");
            SiteMembershipRequest moderatedSiteResponse = siteMembershipRequestsProxy.createSiteMembershipRequest(person14Id, siteMembershipRequest);
            expectedSiteMembershipRequests.add(moderatedSiteResponse);
            Collections.sort(expectedSiteMembershipRequests);
            siteMembershipRequest.expected(moderatedSiteResponse);
            repoService.approveSiteInvitation(person14Id, siteId);
            // try to update the request
            try {
                siteMembershipRequestsProxy.updateSiteMembershipRequest(siteId, moderatedSiteResponse);
                fail("");
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
            }
        }
        {
            // cloud-2539 - probing attack tests
            log("cloud-2539");
            // i) create site membership request to a moderated site
            // ii) site owner changes the site to a private site
            // iii) re-issue create site membership request should be a 404
            {
                final List<SiteMembershipRequest> person2ExpectedSiteMembershipRequests = new ArrayList<SiteMembershipRequest>();
                final TestSite site = person1ModeratedSites.get(0);
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person13Id));
                SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
                siteMembershipRequest.setId(site.getSiteId());
                siteMembershipRequest.setMessage("Please can I join your site?");
                siteMembershipRequestsProxy.createSiteMembershipRequest(person13Id, siteMembershipRequest);
                TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

                    @Override
                    public Void doWork() throws Exception {
                        site.setSiteVisibility(SiteVisibility.PRIVATE);
                        return null;
                    }
                }, person12Id, network1.getId());
                // Can we still GET it? Should be a 404 (private site)
                try {
                    siteMembershipRequestsProxy.getSiteMembershipRequest(person13Id, siteMembershipRequest.getId());
                } catch (PublicApiException e) {
                    assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
                }
                // GET should not contain the site
                {
                    int skipCount = 0;
                    int maxItems = 10;
                    assertEquals(0, person2ExpectedSiteMembershipRequests.size());
                    Paging paging = getPaging(skipCount, maxItems, person2ExpectedSiteMembershipRequests.size(), person2ExpectedSiteMembershipRequests.size());
                    ListResponse<SiteMembershipRequest> resp = siteMembershipRequestsProxy.getSiteMembershipRequests(person13Id, createParams(paging, null));
                    checkList(sublist(person2ExpectedSiteMembershipRequests, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
                }
                try {
                    siteMembershipRequestsProxy.createSiteMembershipRequest(person13Id, siteMembershipRequest);
                    fail("");
                } catch (PublicApiException e) {
                    assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
                }
            }
            // i) create site membership request to a public site
            // ii) site owner changes the site to a private site
            // iii) re-issue create site membership request should be a 404
            {
                final TestSite site = person1PublicSites.get(0);
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person13Id));
                SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
                siteMembershipRequest.setId(site.getSiteId());
                siteMembershipRequest.setMessage("Please can I join your site?");
                siteMembershipRequestsProxy.createSiteMembershipRequest(person13Id, siteMembershipRequest);
                TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

                    @Override
                    public Void doWork() throws Exception {
                        site.setSiteVisibility(SiteVisibility.PRIVATE);
                        return null;
                    }
                }, person12Id, network1.getId());
                try {
                    siteMembershipRequestsProxy.createSiteMembershipRequest(person13Id, siteMembershipRequest);
                    fail("");
                } catch (PublicApiException e) {
                    assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
                }
                try {
                    siteMembershipRequestsProxy.updateSiteMembershipRequest(person13Id, siteMembershipRequest);
                    fail("");
                } catch (PublicApiException e) {
                    assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
                }
                try {
                    siteMembershipRequestsProxy.cancelSiteMembershipRequest(person13Id, siteMembershipRequest.getId());
                    fail("");
                } catch (PublicApiException e) {
                    assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
                }
            }
        }
        // i) create site membership request to a moderated site
        // ii) site owner accepts the request -> user is now a member of the site
        // iii) site owner changes the site to a private site
        // iv) re-issue create site membership request should be a 404
        {
            final TestSite site = person1ModeratedSites.get(1);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person13Id));
            SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
            siteMembershipRequest.setId(site.getSiteId());
            siteMembershipRequest.setMessage("Please can I join your site?");
            siteMembershipRequestsProxy.createSiteMembershipRequest(person13Id, siteMembershipRequest);
            // approve the site invitation request and convert the site to a private site
            TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

                @Override
                public Void doWork() throws Exception {
                    repoService.approveSiteInvitation(person13Id, site.getSiteId());
                    site.setSiteVisibility(SiteVisibility.PRIVATE);
                    return null;
                }
            }, person12Id, network1.getId());
            try {
                siteMembershipRequestsProxy.createSiteMembershipRequest(person13Id, siteMembershipRequest);
                fail("");
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
            }
        }
        // blank message in POST and PUT
        {
            final TestSite site = person1ModeratedSites.get(2);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person13Id));
            SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
            siteMembershipRequest.setId(site.getSiteId());
            siteMembershipRequest.setMessage("");
            SiteMembershipRequest created = siteMembershipRequestsProxy.createSiteMembershipRequest(person13Id, siteMembershipRequest);
            SiteMembershipRequest updated = siteMembershipRequestsProxy.updateSiteMembershipRequest(person13Id, siteMembershipRequest);
            assertTrue(updated.getModifiedAt().after(created.getCreatedAt()));
        }
    }
}
Also used : ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) ArrayList(java.util.ArrayList) ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) Invitation(org.alfresco.service.cmr.invitation.Invitation) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ParseException(java.text.ParseException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) ArrayList(java.util.ArrayList) List(java.util.List) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) SiteMembershipRequest(org.alfresco.rest.api.tests.client.data.SiteMembershipRequest) Test(org.junit.Test)

Example 27 with ListResponse

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

the class TestPersonSites method getSiteMembershipsForPerson32.

/**
 * Retrieves the site memberships associated to a user
 *
 * @param sortColumn
 * @param asc
 * @return
 * @throws Exception
 */
private ListResponse<MemberOfSite> getSiteMembershipsForPerson32(final Paging paging, String sortColumn, boolean asc) throws Exception {
    final Sites sitesProxy = publicApiClient.sites();
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person32.getId()));
    // sort params
    final Map<String, String> params = new HashMap<String, String>();
    if (sortColumn != null) {
        params.put("orderBy", sortColumn + " " + (asc ? "ASC" : "DESC"));
    }
    // get memberships
    ListResponse<MemberOfSite> resp = TenantUtil.runAsUserTenant(new TenantRunAsWork<ListResponse<MemberOfSite>>() {

        @Override
        public ListResponse<MemberOfSite> doWork() throws Exception {
            ListResponse<MemberOfSite> resp = sitesProxy.getPersonSites(person32.getId(), createParams(paging, params));
            return resp;
        }
    }, person32.getId(), network1.getId());
    return resp;
}
Also used : ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) HashMap(java.util.HashMap) MemberOfSite(org.alfresco.rest.api.tests.client.data.MemberOfSite) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) Sites(org.alfresco.rest.api.tests.client.PublicApiClient.Sites)

Example 28 with ListResponse

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

the class TestNetworks method testPersonNetworks.

@Test
public void testPersonNetworks() throws Exception {
    People peopleProxy = publicApiClient.people();
    {
        /**
         * Test http://<host>:<port>/alfresco/a i.e. tenant servlet root - should return user's networks
         */
        final TestNetwork testAccount = getTestFixture().getRandomNetwork();
        Iterator<TestPerson> personIt = testAccount.getPeople().iterator();
        final TestPerson person = personIt.next();
        RequestContext rc = new RequestContext(null, person.getId());
        publicApiClient.setRequestContext(rc);
        HttpResponse response = publicApiClient.delete(null, null, null, null, null);
        // url /null/alfresco/versions/1 does not map to a Web Script
        assertEquals(404, response.getStatusCode());
        PublicApiClient.ExpectedErrorResponse errorResponse = RestApiUtil.parseErrorResponse(response.getJsonResponse());
        assertNotNull(errorResponse);
        assertNotNull(errorResponse.getErrorKey());
        assertNotNull(errorResponse.getBriefSummary());
        response = publicApiClient.put(null, null, null, null, null, null, null);
        assertEquals(404, response.getStatusCode());
        errorResponse = RestApiUtil.parseErrorResponse(response.getJsonResponse());
        assertNotNull(errorResponse);
        assertNotNull(errorResponse.getErrorKey());
        assertNotNull(errorResponse.getBriefSummary());
        response = publicApiClient.post(null, null, null, null, null, null);
        assertEquals(404, response.getStatusCode());
        errorResponse = RestApiUtil.parseErrorResponse(response.getJsonResponse());
        assertNotNull(errorResponse);
        assertNotNull(errorResponse.getErrorKey());
        assertNotNull(errorResponse.getBriefSummary());
        List<PersonNetwork> expectedNetworkMembers = person.getNetworkMemberships();
        int expectedTotal = expectedNetworkMembers.size();
        {
            // GET / - users networks
            Paging paging = getPaging(0, Integer.MAX_VALUE, expectedTotal, expectedTotal);
            publicApiClient.setRequestContext(new RequestContext("-default-", person.getId()));
            response = publicApiClient.index(createParams(paging, null));
            ListResponse<PersonNetwork> resp = PersonNetwork.parseNetworkMembers(response.getJsonResponse());
            assertEquals(200, response.getStatusCode());
            checkList(new ArrayList<PersonNetwork>(expectedNetworkMembers), paging.getExpectedPaging(), resp);
        }
    }
    // user from another network
    {
        publicApiClient.setRequestContext(new RequestContext("-default-", person21.getId()));
        List<PersonNetwork> networksMemberships = Collections.emptyList();
        try {
            int skipCount = 0;
            int maxItems = 2;
            Paging paging = getPaging(skipCount, maxItems, networksMemberships.size(), networksMemberships.size());
            peopleProxy.getNetworkMemberships(person11.getId(), createParams(paging, null));
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
    }
    // user from the same network
    try {
        List<PersonNetwork> networksMemberships = person12.getNetworkMemberships();
        publicApiClient.setRequestContext(new RequestContext("-default-", person12.getId()));
        int skipCount = 0;
        int maxItems = 2;
        Paging paging = getPaging(skipCount, maxItems, networksMemberships.size(), networksMemberships.size());
        peopleProxy.getNetworkMemberships(person11.getId(), createParams(paging, null));
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    List<PersonNetwork> networksMemberships = person11.getNetworkMemberships();
    // Test Case cloud-2203
    // Test Case cloud-1498
    // test paging
    {
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        int skipCount = 0;
        int maxItems = 2;
        Paging paging = getPaging(skipCount, maxItems, networksMemberships.size(), networksMemberships.size());
        ListResponse<PersonNetwork> resp = peopleProxy.getNetworkMemberships(person11.getId(), createParams(paging, null));
        checkList(networksMemberships.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
    }
    // "-me-" user
    {
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        int skipCount = 0;
        int maxItems = Integer.MAX_VALUE;
        Paging paging = getPaging(skipCount, maxItems, networksMemberships.size(), networksMemberships.size());
        ListResponse<PersonNetwork> resp = peopleProxy.getNetworkMemberships(org.alfresco.rest.api.People.DEFAULT_USER, createParams(paging, null));
        checkList(networksMemberships.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
    }
    // unknown person id
    try {
        List<PersonNetwork> networkMemberships = person11.getNetworkMemberships();
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        int skipCount = 0;
        int maxItems = 2;
        Paging expectedPaging = getPaging(skipCount, maxItems, networkMemberships.size(), networkMemberships.size());
        peopleProxy.getNetworkMemberships("invalidUser", createParams(expectedPaging, null));
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // invalid caller authentication
    try {
        List<PersonNetwork> networkMemberships = person11.getNetworkMemberships();
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId(), GUID.generate()));
        int skipCount = 0;
        int maxItems = 2;
        Paging expectedPaging = getPaging(skipCount, maxItems, networkMemberships.size(), networkMemberships.size());
        peopleProxy.getNetworkMemberships(person11.getId(), createParams(expectedPaging, null));
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
    }
    // unknown person id
    try {
        List<PersonNetwork> networkMemberships = person11.getNetworkMemberships();
        assertTrue(networkMemberships.size() > 0);
        PersonNetwork network = networkMemberships.get(0);
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        peopleProxy.getNetworkMembership("invalidUser", network.getId());
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // invalid caller authentication
    try {
        List<PersonNetwork> networkMemberships = person11.getNetworkMemberships();
        assertTrue(networkMemberships.size() > 0);
        PersonNetwork network = networkMemberships.get(0);
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId(), GUID.generate()));
        peopleProxy.getNetworkMembership(person11.getId(), network.getId());
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
    }
    // incorrect network id
    try {
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        peopleProxy.getNetworkMembership(person11.getId(), GUID.generate());
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // POST, POST networkId, PUT, PUT networkId, DELETE, DELETE networkId
    try {
        PersonNetwork pn = new PersonNetwork(GUID.generate());
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        peopleProxy.create("people", person11.getId(), "networks", null, pn.toJSON().toString(), "Unable to POST to person networks");
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        PersonNetwork pn = networksMemberships.get(0);
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        peopleProxy.create("people", person11.getId(), "networks", pn.getId(), pn.toJSON().toString(), "Unable to POST to a person network");
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        PersonNetwork pn = new PersonNetwork(GUID.generate());
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        peopleProxy.update("people", person11.getId(), "networks", null, pn.toJSON().toString(), "Unable to PUT person networks");
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        PersonNetwork pn = networksMemberships.get(0);
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        peopleProxy.update("people", person11.getId(), "networks", pn.getId(), pn.toJSON().toString(), "Unable to PUT a person network");
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        peopleProxy.remove("people", person11.getId(), "networks", null, "Unable to DELETE person networks");
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        PersonNetwork pn = networksMemberships.get(0);
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        peopleProxy.remove("people", person11.getId(), "networks", pn.getId(), "Unable to DELETE a person network");
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    // user not a member of the network
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
        int skipCount = 0;
        int maxItems = 2;
        Paging expectedPaging = getPaging(skipCount, maxItems);
        peopleProxy.getNetworkMemberships(person11.getId(), createParams(expectedPaging, null));
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
    }
}
Also used : ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) People(org.alfresco.rest.api.tests.client.PublicApiClient.People) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) PersonNetwork(org.alfresco.rest.api.tests.client.data.PersonNetwork) Test(org.junit.Test)

Example 29 with ListResponse

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

the class TestNodeRatings method testNodeRatings.

@Test
public void testNodeRatings() throws Exception {
    Iterator<TestNetwork> networksIt = getTestFixture().getNetworksIt();
    assertTrue(networksIt.hasNext());
    final TestNetwork network1 = networksIt.next();
    assertTrue(networksIt.hasNext());
    final TestNetwork network2 = networksIt.next();
    final List<TestPerson> people = new ArrayList<TestPerson>(3);
    // 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);
            return null;
        }
    }, network1.getId());
    TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            TestPerson person = network2.createUser();
            people.add(person);
            return null;
        }
    }, network2.getId());
    final TestPerson person11 = people.get(0);
    final TestPerson person12 = people.get(1);
    final TestPerson person21 = people.get(2);
    PublicApiClient.Sites sitesProxy = publicApiClient.sites();
    Comments commentsProxy = publicApiClient.comments();
    People peopleProxy = publicApiClient.people();
    Nodes nodesProxy = publicApiClient.nodes();
    DateFormat format = PublicApiDateFormat.getDateFormat();
    // Create site and document
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
    String siteId = "TESTSITE" + GUID.generate();
    Site site = new SiteImpl(siteId, siteId, siteId, SiteVisibility.PRIVATE.toString());
    site = sitesProxy.createSite(site);
    SiteContainer sc = sitesProxy.getSingleSiteContainer(site.getSiteId(), "documentLibrary");
    final String node1Id = createTextFile(sc.getId(), "Test Doc 1.txt", "Test Content").getId();
    // TEMP - pending remote api to list node ratings
    NodeRef nodeRef1 = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, node1Id);
    // try to add a rating to a comment
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        Comment comment = new Comment("Test Comment", "Test Comment");
        Comment newComment = commentsProxy.createNodeComment(node1Id, comment);
        NodeRating rating = new NodeRating("likes", true);
        nodesProxy.createNodeRating(newComment.getId(), rating);
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    // invalid node id
    try {
        NodeRating rating = new NodeRating("likes", true);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        nodesProxy.createNodeRating(GUID.generate(), rating);
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // try to add a rating to a tag
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        Tag tag = new Tag("testTag");
        Tag newTag = nodesProxy.createNodeTag(node1Id, tag);
        NodeRating rating = new NodeRating("likes", true);
        nodesProxy.createNodeRating(newTag.getId(), rating);
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    // invalid rating scheme
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        nodesProxy.createNodeRating(node1Id, new NodeRating("missingRatingScheme", Double.valueOf(1.0f)));
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
    }
    // invalid rating
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        nodesProxy.createNodeRating(node1Id, new NodeRating("likes", Double.valueOf(2.0f)));
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
    }
    // invalid rating
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        nodesProxy.createNodeRating(node1Id, new NodeRating("fiveStar", true));
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
    }
    // invalid rating - can't rate own content for fiveStar
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        nodesProxy.createNodeRating(node1Id, new NodeRating("fiveStar", 5));
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
    }
    // valid ratings
    {
        NodeRating rating = new NodeRating("likes", true);
        Date time = new Date();
        // rate by multiple users in more than 1 network
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        NodeRating ret = nodesProxy.createNodeRating(node1Id, rating);
        assertEquals(rating.getMyRating(), ret.getMyRating());
        assertTrue(format.parse(ret.getRatedAt()).after(time));
        assertEquals(rating.getId(), ret.getId());
        assertEquals(new NodeRating.Aggregate(1, null), ret.getAggregate());
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
        ret = nodesProxy.createNodeRating(node1Id, rating);
        assertEquals(rating.getMyRating(), ret.getMyRating());
        assertTrue(format.parse(ret.getRatedAt()).after(time));
        assertEquals(rating.getId(), ret.getId());
        assertEquals(new NodeRating.Aggregate(2, null), ret.getAggregate());
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
        ret = nodesProxy.createNodeRating(node1Id, rating);
        assertEquals(rating.getMyRating(), ret.getMyRating());
        assertTrue(format.parse(ret.getRatedAt()).after(time));
        assertEquals(rating.getId(), ret.getId());
        assertEquals(new NodeRating.Aggregate(2, null), ret.getAggregate());
        // different network - unauthorized
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
            nodesProxy.createNodeRating(node1Id, rating);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
        }
        // Test Case cloud-2209
        // Test Case cloud-2220
        // Test Case cloud-1520
        // check that the node ratings are there, test paging
        {
            // person11
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
            List<NodeRating> expectedRatings = repoService.getNodeRatings(person11.getId(), network1.getId(), nodeRef1);
            {
                int skipCount = 0;
                int maxItems = 1;
                Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size());
                ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
                checkList(expectedRatings.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
            }
            {
                int skipCount = 1;
                int maxItems = Integer.MAX_VALUE;
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
                Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size());
                ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
                checkList(expectedRatings.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
            }
            {
                int skipCount = 1;
                int maxItems = expectedRatings.size();
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
                Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size());
                ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
                checkList(expectedRatings.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
            }
        }
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
            // person12
            List<NodeRating> expectedRatings = repoService.getNodeRatings(person12.getId(), network1.getId(), nodeRef1);
            {
                int skipCount = 0;
                int maxItems = 1;
                Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size());
                ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
                checkList(expectedRatings.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
            }
            {
                int skipCount = 1;
                int maxItems = Integer.MAX_VALUE;
                Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size());
                ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
                checkList(expectedRatings.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
            }
        }
        {
            // person21
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
            List<NodeRating> expectedRatings = Collections.emptyList();
            try {
                int skipCount = 0;
                int maxItems = 1;
                Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size());
                nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
                fail();
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
            }
        }
        // invalid node id
        try {
            int skipCount = 1;
            int maxItems = Integer.MAX_VALUE;
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
            Paging paging = getPaging(skipCount, maxItems);
            nodesProxy.getNodeRatings(GUID.generate(), createParams(paging, null));
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        // check activities have been raised for the created ratings
        repoService.generateFeed();
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
            Paging paging = getPaging(0, Integer.MAX_VALUE);
            ListResponse<Activity> activities = peopleProxy.getActivities(person11.getId(), createParams(paging, null));
            boolean found = false;
            for (Activity activity : activities.getList()) {
                String activityType = activity.getActivityType();
                if (activityType.equals(ActivityType.FILE_LIKED)) {
                    Map<String, Object> summary = activity.getSummary();
                    assertNotNull(summary);
                    String objectId = (String) summary.get("objectId");
                    assertNotNull(objectId);
                    if (node1Id.equals(objectId)) {
                        found = true;
                        break;
                    }
                }
            }
            assertTrue(found);
        }
    }
    {
        // remove node rating
        NodeRating rating = new NodeRating("likes", null);
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
            nodesProxy.removeNodeRating(node1Id, rating);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
        }
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
            nodesProxy.removeNodeRating(node1Id, rating);
        }
        // check list
        {
            List<NodeRating> ratings = repoService.getNodeRatings(person11.getId(), network1.getId(), nodeRef1);
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
            Paging paging = getPaging(skipCount, maxItems, ratings.size(), ratings.size());
            ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
            checkList(ratings.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        }
    }
    // get a node rating
    // 1977
    {
        NodeRating rating = new NodeRating("likes", true);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        NodeRating expected = nodesProxy.createNodeRating(node1Id, rating);
        NodeRating actual = nodesProxy.getNodeRating(node1Id, "likes");
        expected.expected(actual);
    }
    {
        // update node rating
        NodeRating rating = new NodeRating("fiveStar", 2);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
        // create initial rating
        NodeRating createdRating = nodesProxy.createNodeRating(node1Id, rating);
        NodeRating updateRating = new NodeRating(createdRating.getId(), 5);
        // update - not supported
        try {
            nodesProxy.updateNodeRating(node1Id, updateRating);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
        }
    }
    // Test Case cloud-1977
    // invalid methods
    {
        try {
            // -ve test - cannot create multiple ratings in single POST call (unsupported)
            List<NodeRating> ratings = new ArrayList<>(2);
            ratings.add(new NodeRating("likes", true));
            ratings.add(new NodeRating("likes", false));
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
            nodesProxy.create("nodes", node1Id, "ratings", null, JSONArray.toJSONString(ratings), "Unable to POST to multiple ratings");
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
        }
        // get an arbitrary rating
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(getPaging(0, Integer.MAX_VALUE), null));
        List<NodeRating> nodeRatings = resp.getList();
        assertTrue(nodeRatings.size() > 0);
        try {
            NodeRating rating = new NodeRating("likes", true);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
            nodesProxy.create("nodes", node1Id, "ratings", "likes", rating.toJSON().toString(), "Unable to POST to a node rating");
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
        }
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
            nodesProxy.update("nodes", node1Id, "ratings", null, null, "Unable to PUT node ratings");
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
        }
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
            nodesProxy.remove("nodes", node1Id, "ratings", null, "Unable to DELETE node ratings");
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
        }
        try {
            NodeRating rating = nodeRatings.get(0);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
            nodesProxy.update("nodes", node1Id, "ratings", rating.getId(), null, "Unable to PUT a node rating");
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
        }
    }
    // Test case ACE-5453
    {
        try {
            testSkipCountLargeValue(person11, network1, nodeRef1, nodesProxy);
        } catch (PublicApiException e) {
            fail();
        }
    }
}
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) ArrayList(java.util.ArrayList) Activity(org.alfresco.rest.api.tests.client.data.Activity) NodeRating(org.alfresco.rest.api.tests.client.data.NodeRating) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArrayList(java.util.ArrayList) List(java.util.List) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Comment(org.alfresco.rest.api.tests.client.data.Comment) Comments(org.alfresco.rest.api.tests.client.PublicApiClient.Comments) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) People(org.alfresco.rest.api.tests.client.PublicApiClient.People) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) Nodes(org.alfresco.rest.api.tests.client.PublicApiClient.Nodes) Date(java.util.Date) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) SiteImpl(org.alfresco.rest.api.tests.client.data.SiteImpl) DateFormat(java.text.DateFormat) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) PublicApiClient(org.alfresco.rest.api.tests.client.PublicApiClient) Tag(org.alfresco.rest.api.tests.client.data.Tag) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) SiteContainer(org.alfresco.rest.api.tests.client.data.SiteContainer) Test(org.junit.Test)

Example 30 with ListResponse

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

the class TestPersonSites method testPersonSites.

@Test
public void testPersonSites() throws Exception {
    Set<MemberOfSite> personSites = new TreeSet<MemberOfSite>();
    // Get last site for use with personRemoveSite
    TestSite personRemoveSite = sites.get(sites.size() - 1);
    sites.remove(sites.size() - 1);
    personSites.addAll(network1.getSiteMemberships(person11.getId()));
    // Create some sites
    personSites.addAll(TenantUtil.runAsUserTenant(new TenantRunAsWork<List<MemberOfSite>>() {

        @Override
        public List<MemberOfSite> doWork() throws Exception {
            List<MemberOfSite> expectedSites = new ArrayList<MemberOfSite>();
            TestSite site = network1.createSite(SiteVisibility.PRIVATE);
            expectedSites.add(new MemberOfSite(site, SiteRole.SiteManager));
            site = network1.createSite(SiteVisibility.PUBLIC);
            expectedSites.add(new MemberOfSite(site, SiteRole.SiteManager));
            site = network1.createSite(SiteVisibility.MODERATED);
            expectedSites.add(new MemberOfSite(site, SiteRole.SiteManager));
            return expectedSites;
        }
    }, person11.getId(), network1.getId()));
    personSites.addAll(TenantUtil.runAsUserTenant(new TenantRunAsWork<List<MemberOfSite>>() {

        @Override
        public List<MemberOfSite> doWork() throws Exception {
            List<MemberOfSite> expectedSites = new ArrayList<MemberOfSite>();
            TestSite site = network1.createSite(SiteVisibility.PRIVATE);
            site.inviteToSite(person11.getId(), SiteRole.SiteConsumer);
            expectedSites.add(new MemberOfSite(site, SiteRole.SiteConsumer));
            site = network1.createSite(SiteVisibility.PUBLIC);
            site.inviteToSite(person11.getId(), SiteRole.SiteConsumer);
            expectedSites.add(new MemberOfSite(site, SiteRole.SiteConsumer));
            site = network1.createSite(SiteVisibility.MODERATED);
            site.inviteToSite(person11.getId(), SiteRole.SiteConsumer);
            expectedSites.add(new MemberOfSite(site, SiteRole.SiteConsumer));
            return expectedSites;
        }
    }, person12.getId(), network1.getId()));
    final List<MemberOfSite> expectedSites = new ArrayList<MemberOfSite>(personSites);
    Sites sitesProxy = publicApiClient.sites();
    // unknown user
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.getPersonSites(GUID.generate(), null);
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // Test Case cloud-2200
    // Test Case cloud-2213
    // user should be able to list their sites
    {
        int skipCount = 0;
        int maxItems = 2;
        Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), expectedSites.size());
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        ListResponse<MemberOfSite> resp = sitesProxy.getPersonSites(person11.getId(), createParams(paging, null));
        checkList(expectedSites.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
    }
    {
        int skipCount = 2;
        int maxItems = 8;
        Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), expectedSites.size());
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        ListResponse<MemberOfSite> resp = sitesProxy.getPersonSites(person11.getId(), createParams(paging, null));
        checkList(expectedSites.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
    }
    // "-me-" user
    {
        int skipCount = 0;
        int maxItems = 2;
        Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), expectedSites.size());
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        ListResponse<MemberOfSite> resp = sitesProxy.getPersonSites(org.alfresco.rest.api.People.DEFAULT_USER, createParams(paging, null));
        checkList(expectedSites.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
    }
    // a user in another tenant should not be able to list a user's sites
    try {
        int skipCount = 0;
        int maxItems = 2;
        Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), null);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
        sitesProxy.getPersonSites(person11.getId(), createParams(paging, null));
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
    }
    // Test case cloud-1488
    {
        MemberOfSite memberOfSite = expectedSites.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        MemberOfSite ret = sitesProxy.getPersonSite(person11.getId(), memberOfSite.getSiteId());
        memberOfSite.expected(ret);
    }
    try {
        MemberOfSite memberOfSite = expectedSites.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.getPersonSite(GUID.generate(), memberOfSite.getSiteId());
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.getPersonSite(person11.getId(), GUID.generate());
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // unknown person id
    try {
        MemberOfSite memberOfSite = expectedSites.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.getPersonSite(GUID.generate(), memberOfSite.getSiteId());
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.getPersonSite(person11.getId(), GUID.generate());
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    {
        // Tests removing a person from the site
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.remove("people", person11.getId(), "sites", personRemoveSite.getSiteId(), "Unable to DELETE a person site");
        try {
            sitesProxy.getPersonSite(person11.getId(), personRemoveSite.getSiteId());
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
    }
    // Not allowed methods
    try {
        MemberOfSite memberOfSite = expectedSites.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.create("people", person11.getId(), "sites", memberOfSite.getSiteId(), null, "Unable to POST to a person site");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.create("people", person11.getId(), "sites", null, null, "Unable to POST to person sites");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        MemberOfSite memberOfSite = expectedSites.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.update("people", person11.getId(), "sites", memberOfSite.getSiteId(), null, "Unable to PUT a person site");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.update("people", person11.getId(), "sites", null, null, "Unable to PUT person sites");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.remove("people", person11.getId(), "sites", null, "Unable to DELETE person sites");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
}
Also used : ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) ArrayList(java.util.ArrayList) MemberOfSite(org.alfresco.rest.api.tests.client.data.MemberOfSite) Sites(org.alfresco.rest.api.tests.client.PublicApiClient.Sites) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) TreeSet(java.util.TreeSet) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Aggregations

ListResponse (org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse)41 ArrayList (java.util.ArrayList)30 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)22 JSONObject (org.json.simple.JSONObject)21 Test (org.junit.Test)21 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)20 ExpectedPaging (org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging)19 JSONArray (org.json.simple.JSONArray)19 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)18 List (java.util.List)13 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)10 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)8 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)8 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)8 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Sites (org.alfresco.rest.api.tests.client.PublicApiClient.Sites)6 People (org.alfresco.rest.api.tests.client.PublicApiClient.People)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 ParseException (java.text.ParseException)4